Module: Rack::Webconsole::Shell

Defined in:
lib/rack/webconsole/shell.rb

Class Method Summary collapse

Instance Method Summary collapse

Class Method Details

.eval_query(query) ⇒ Object



5
6
7
8
9
10
11
12
13
14
15
16
17
18
# File 'lib/rack/webconsole/shell.rb', line 5

def self.eval_query(query)
  # Initialize ripl plugins
  @before_loop_called ||= Ripl.shell.before_loop

  Ripl.shell.input = query
  Ripl.shell.loop_once
  {}.tap do |hash|
    hash[:result] = Ripl.shell.return_result
    hash[:multi_line] = Ripl.shell.multi_line?
    hash[:previous_multi_line] = Ripl.shell.previous_multi_line?
    hash[:prompt] = Ripl.shell.previous_multi_line? ?
      Ripl.config[:multi_line_prompt] : Ripl.config[:prompt]
  end
end

Instance Method Details

#get_inputObject



29
30
31
32
33
# File 'lib/rack/webconsole/shell.rb', line 29

def get_input
  @old_buffer = @buffer
  history << @input
  @input
end

#loop_eval(query) ⇒ Object



35
36
37
38
39
40
41
42
43
44
45
46
47
48
# File 'lib/rack/webconsole/shell.rb', line 35

def loop_eval(query)
  # Force conversion to symbols due to issues with lovely 1.8.7
  boilerplate = local_variables.map(&:to_sym) + [:ls, :result]

  $sandbox.instance_eval """
    result = (#{query})
    ls = (local_variables.map(&:to_sym) - [#{boilerplate.map(&:inspect).join(', ')}])
    @locals ||= {}
    @locals.update(ls.inject({}) do |hash, value|
      hash.update({value => eval(value.to_s)})
    end)
    result
  """
end

#multi_line?Boolean

TODO: move to plugin

Returns:

  • (Boolean)


21
22
23
# File 'lib/rack/webconsole/shell.rb', line 21

def multi_line?
  @buffer.is_a?(Array)
end

#previous_multi_line?Boolean

Returns:

  • (Boolean)


25
26
27
# File 'lib/rack/webconsole/shell.rb', line 25

def previous_multi_line?
  @old_buffer.is_a?(Array)
end


50
51
52
# File 'lib/rack/webconsole/shell.rb', line 50

def print_eval_error(err)
  @result = "Error: " + err.message
end


58
# File 'lib/rack/webconsole/shell.rb', line 58

def print_result(result) end

#return_resultObject



54
55
56
# File 'lib/rack/webconsole/shell.rb', line 54

def return_result
  @error_raised ? result : result.inspect
end