File: extensions.rb

package info (click to toggle)
ruby-web-console 4.2.1-1
  • links: PTS, VCS
  • area: main
  • in suites: forky, sid, trixie
  • size: 632 kB
  • sloc: ruby: 1,496; javascript: 497; sh: 19; makefile: 4
file content (34 lines) | stat: -rw-r--r-- 1,024 bytes parent folder | download | duplicates (3)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
# frozen_string_literal: true

module Kernel
  module_function

  # Instructs Web Console to render a console in the specified binding.
  #
  # If +binding+ isn't explicitly given it will default to the binding of the
  # previous frame. E.g. the one that invoked +console+.
  #
  # Raises +DoubleRenderError+ if a more than one +console+ invocation per
  # request is detected.
  def console(binding = Bindex.current_bindings.second)
    raise WebConsole::DoubleRenderError if Thread.current[:__web_console_binding]

    Thread.current[:__web_console_binding] = binding

    # Make sure nothing is rendered from the view helper. Otherwise
    # you're gonna see unexpected #<Binding:0x007fee4302b078> in the
    # templates.
    nil
  end
end

class Binding
  # Instructs Web Console to render a console in the current binding, without
  # the need to unroll the stack.
  #
  # Raises +DoubleRenderError+ if a more than one +console+ invocation per
  # request is detected.
  def console
    Kernel.console(self)
  end
end