Class: Rack::Webconsole

Inherits:
Object
  • Object
show all
Defined in:
lib/rack/webconsole.rb,
lib/rack/webconsole/repl.rb,
lib/rack/webconsole/assets.rb,
lib/rack/webconsole/railtie.rb,
lib/rack/webconsole/version.rb,
lib/rack/webconsole/asset_helpers.rb

Overview

Webconsole is a Rack middleware that provides an interactive console à la Rails console, but for any kind of Rack application (Rails, Sinatra, Padrino…), accessible from your web application’s front-end.

For every request, it normally passes control to the Assets middleware, which injects needed JavaScript, CSS and HTML code for the console to work properly.

It also exposes a special route used by the Repl, a Ruby evaluator which is responsible of keeping state between requests, remembering local variables and giving a true IRB-esque experience.

Defined Under Namespace

Modules: AssetHelpers, ResponseMethods Classes: Assets, Railtie, Repl

Constant Summary collapse

VERSION =

rack-webconsole version number.

"0.1.9"
@@config =
{:inject_jquery => false, :key_code => "[96]"}

Class Method Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(app) ⇒ Webconsole

Honor the Rack contract by saving the passed Rack application in an ivar.

Parameters:

  • app (Rack::Application)

    the previous Rack application in the middleware chain.



65
66
67
# File 'lib/rack/webconsole.rb', line 65

def initialize(app)
  @app = app
end

Class Method Details

.inject_jqueryBoolean

Returns whether the Asset injecter must inject JQuery or not.

Returns:

  • (Boolean)

    whether to inject JQuery or not.



32
33
34
# File 'lib/rack/webconsole.rb', line 32

def inject_jquery
  @@config[:inject_jquery]
end

.inject_jquery=(value) ⇒ Object

Sets whether the Asset injecter must inject JQuery or not.

Parameters:

  • value (Boolean)

    whether to inject JQuery or not.



39
40
41
# File 'lib/rack/webconsole.rb', line 39

def inject_jquery=(value)
  @@config[:inject_jquery] = value
end

.key_codeString

Returns key code used to start web console.

Returns:

  • (String)

    key code used at keypress event to start web console.



46
47
48
# File 'lib/rack/webconsole.rb', line 46

def key_code
  @@config[:key_code]
end

.key_code=(value) ⇒ Object

Sets key code used to start web console.

Parameters:

  • value (String)

    key code used at keypress event to start web console.



53
54
55
56
57
58
# File 'lib/rack/webconsole.rb', line 53

def key_code=(value)
  value = [value] unless value.kind_of?(Array)
  value.map! {|v| v.to_i }
  value = MultiJson::encode(value)
  @@config[:key_code] = value
end

Instance Method Details

#call(env) ⇒ Object

Decides where to send the request. In case the path is ‘/webconsole` (e.g. when calling the Repl endpoint), pass the request onto the Repl. Otherwise, pass it onto the Assets middleware, which will inject the needed assets for the Webconsole to work.

Parameters:

  • env (Hash)

    a Rack request environment.



75
76
77
78
79
80
81
# File 'lib/rack/webconsole.rb', line 75

def call(env)
  if env['PATH_INFO'] == '/webconsole'
    Repl.new(@app).call(env)
  else
    Assets.new(@app).call(env)
  end
end