Skip to content

Commit

Permalink
Introduce Binding#console
Browse files Browse the repository at this point in the history
This interface can spawn a console a bit more quickly as it doesn't need
to pry open the stack frames.
  • Loading branch information
gsamokovarov committed Apr 25, 2019
1 parent d6deacd commit 96127aa
Showing 1 changed file with 13 additions and 2 deletions.
15 changes: 13 additions & 2 deletions lib/web_console/extensions.rb
Original file line number Diff line number Diff line change
Expand Up @@ -8,8 +8,8 @@ module Kernel
# 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 double +console+ invocation per request is
# detected.
# 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]

Expand All @@ -21,3 +21,14 @@ def console(binding = Bindex.current_bindings.second)
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

0 comments on commit 96127aa

Please sign in to comment.