rack_console 0.2.2 → 0.3.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: 7120aad9356f5f31cf013d2adb6e3c0df0707358
4
- data.tar.gz: 86fdf0c4a1d680d5c1dcad8c35716fb71e0778a2
3
+ metadata.gz: 8635759efe0c98de153499de75f6cd6637cbf804
4
+ data.tar.gz: 7c003b7f68057c920ae1d966949fd8885463655e
5
5
  SHA512:
6
- metadata.gz: 47c26a65af32882b275722bd22f7ad8a2b84d009b110b3505f19eaa4192624910a32262e2d86b64b778f31c1d029f6737a44e7469c6aeb1efa96482e19037063
7
- data.tar.gz: 3a9795aa14d8a82c105778929a2a458c450893b027dcc626ee60a2f011f21f0c290fde5116e07229c55d6f0f7e51e40c36b367b9b6e79ed42c586c7129e24e73
6
+ metadata.gz: 7a254fd07d115832dbae6d9c0b64ce0fe609a3325730f747e39d64207933cd96b9904dd0680ae2d25136fcbffe444187b09a5ec87e6c2b5fa5a10e1a1ca3b449
7
+ data.tar.gz: 43d74977d408bf5f519ee99e3e1c89b50374398d2fa5c6e2043b3868807f7ea857184cf0122dd931d461324b53577e3f873bf134736967885d18a1d9ca0af8a9
@@ -3,9 +3,12 @@ require 'active_support/core_ext/object/blank'
3
3
  require 'pp'
4
4
  require 'stringio'
5
5
  require 'rack_console/ansi2html'
6
+ require 'rack_console/expr_helpers'
6
7
 
7
8
  module RackConsole
8
9
  module AppHelpers
10
+ include ExprHelpers
11
+
9
12
  def has_console_access?
10
13
  true
11
14
  end
@@ -49,6 +52,7 @@ module RackConsole
49
52
  end
50
53
 
51
54
  def evaluate_expr!
55
+ return if @result_evaled
52
56
  result_capture! do
53
57
  @stdin = StringIO.new('')
54
58
  @stdout = StringIO.new('')
@@ -57,15 +61,11 @@ module RackConsole
57
61
  @expr = (params[:expr] || '').strip
58
62
  unless @expr.blank?
59
63
  @result_evaled = true
60
- Timeout.timeout(30) do
61
- _stdin, _stdout, _stderr = $stdin, $stdout, $stderr
62
- $stdin, $stdout, $stderr = @stdin, @stdout, @stderr
63
- begin
64
+ Timeout.timeout(config[:eval_timeout] || 120) do
65
+ capture_stdio! do
64
66
  expr_str = "begin; #{@expr} \n; end"
65
67
  @result = eval(expr_str)
66
68
  @result_ok = true
67
- ensure
68
- $stdin, $stdout, $stderr = _stdin, _stdout, _stderr
69
69
  end
70
70
  end
71
71
  end
@@ -74,22 +74,17 @@ module RackConsole
74
74
 
75
75
  def evaluate_module!
76
76
  evaluate_expr!
77
+ @show_stdio = @show_result = false
77
78
  if @result_ok && @result.is_a?(Module)
78
79
  result_capture! do
79
80
  @module = @result
80
- @ancestors = @module.ancestors.drop(1)
81
- if @is_class = @module.is_a?(Class)
82
- @superclass = @module.superclass
83
- @subclasses = @module.subclasses.sort_by{|c| c.name || ''}
84
- end
85
- @constants = @module.constants(false).sort.map{|n| [ n, const_get_safe(@module, n) ]}
86
- @methods = methods_for_module(@module)
87
81
  end
88
82
  end
89
83
  end
90
84
 
91
85
  def evaluate_method!
92
86
  evaluate_expr!
87
+ @show_stdio = @show_result = false
93
88
  if @result_ok && @result.is_a?(Module)
94
89
  result_capture! do
95
90
  @module = @result
@@ -103,10 +98,23 @@ module RackConsole
103
98
  @method_source_location = @method.source_location
104
99
  @method_source = @method_source_location && SourceFile.new(@method_source_location).load!.narrow_to_block!
105
100
  @result = @method
101
+ @is_method = true
102
+ expr_for_object! @method, @module, @method_kind
106
103
  end
107
104
  end
108
105
  end
109
106
 
107
+ def capture_stdio!
108
+ @captured_stdio = true
109
+ _stdin, _stdout, _stderr = $stdin, $stdout, $stderr
110
+ $stdin, $stdout, $stderr = @stdin, @stdout, @stderr
111
+ begin
112
+ yield
113
+ ensure
114
+ $stdin, $stdout, $stderr = _stdin, _stdout, _stderr
115
+ end
116
+ end
117
+
110
118
  def evaluate_methods!
111
119
  @methods = nil
112
120
  result_capture! do
@@ -137,6 +145,16 @@ module RackConsole
137
145
  ensure
138
146
  @result_extended = @result.singleton_class.included_modules rescue nil
139
147
  @result_class = @result.class.name
148
+ if @is_module = Module === @result
149
+ @module = @result
150
+ @ancestors = @module.ancestors.drop(1)
151
+ if @is_class = @module.is_a?(Class)
152
+ @superclass = @module.superclass
153
+ @subclasses = @module.subclasses.sort_by{|c| c.name || ''}
154
+ end
155
+ @constants = @module.constants(false).sort.map{|n| [ n, const_get_safe(@module, n) ]}
156
+ @methods = methods_for_module(@module)
157
+ end
140
158
  end
141
159
 
142
160
  def server_info
@@ -0,0 +1,43 @@
1
+ require 'time'
2
+ require 'date'
3
+
4
+ module RackConsole
5
+ module ExprHelpers
6
+ def expr_for_object! obj, mod = nil, kind = nil
7
+ @result = result_capture! do
8
+ @expr = expr_for_object obj, mod, kind
9
+ obj
10
+ end
11
+ @result_evaled = true
12
+ @result_ok = true
13
+ end
14
+
15
+ def expr_for_object obj, mod = nil, kind = nil
16
+ case obj
17
+ when nil, true, false
18
+ obj.to_s
19
+ when Float, Integer
20
+ obj.inspect
21
+ when Time
22
+ "Time.parse(#{obj.iso8601(6).inspect})"
23
+ when Date
24
+ "Date.parse(#{obj.to_s.inspect})"
25
+ when Module
26
+ expr_for_object obj
27
+ when Method, UnboundMethod
28
+ expr_for_method(mod, obj.name, kind) if mod && kind
29
+ else
30
+ nil
31
+ end
32
+ end
33
+
34
+ def expr_for_method mod, name, kind
35
+ "#{mod}.#{kind}(#{name.to_sym.inspect})"
36
+ end
37
+
38
+ def expr_for_Module obj
39
+ obj && obj.name
40
+ end
41
+ end
42
+ end
43
+
@@ -0,0 +1,8 @@
1
+ .eval
2
+ - evaluate_expr!
3
+ %form{action: url_root("/"), method: "post"}
4
+ %div
5
+ %textarea.expr{name: 'expr'}=h @expr
6
+ %div
7
+ %input{ type: 'submit', value: 'Evaluate' }
8
+ = haml :'console/result'
@@ -1,29 +1,6 @@
1
1
  .rack_console
2
2
  =haml :'console/server_info', locals: locals
3
3
  - evaluate_method!
4
- .result
5
- .method
6
- %dl
7
- - if @result_evaled && @result_ok
8
- %dt Class:
9
- %dd= format_module(@method.class)
10
- %dt Name:
11
- %dd= format_methods(@method.name)
12
- %dt Owner:
13
- %dd= format_module(@module)
14
- %dt Parameters:
15
- %dd= h @method.parameters.inspect
16
- %dt Arity:
17
- %dd= h @method.arity
18
- %dt Source Location:
19
- %dd= format_source_location(@method_source_location, @method, nil, @module)
20
- - if @method_source
21
- %dt Source:
22
- %dd
23
- %table.source_listing
24
- - @method_source.lines.each do | line |
25
- %tr
26
- %td{class: line[:class] * ' '}= h("%4d %s" % [ line[:line], line[:str] ]).gsub(' ', '&nbsp')
27
-
4
+ =haml :'console/eval', locals: locals
28
5
  =haml :'console/error', locals: locals
29
6
 
@@ -1,5 +1,4 @@
1
1
  .methods
2
- =haml :'console/server_info', locals: locals
3
2
  - if methods = locals[:methods]
4
3
  %table
5
4
  - @methods.each do | meth |
@@ -1,61 +1,6 @@
1
1
  .rack_console
2
2
  =haml :'console/server_info', locals: locals
3
3
  - evaluate_module!
4
- .result
5
- .module
6
- %dl
7
- - if @result_evaled && @result_ok
8
- %dt Class:
9
- %dd= format_module(@result.class)
10
- %dt Result:
11
- %dd= format_module(@result)
12
- - if @is_class
13
- %dt Superclass:
14
- %dd= format_module(@superclass)
15
- %dt Ancestors:
16
- %dd
17
- - if (@ancestors || [ ]).empty?
18
- %span.none NONE
19
- - else
20
- %table.ancestors
21
- - @ancestors.each do | mod |
22
- %tr
23
- %td= format_module(mod)
24
- - if @subclasses
25
- %dt Subclasses:
26
- %dd
27
- - if @subclasses.empty?
28
- %span.none NONE
29
- - else
30
- %table.subclasses
31
- - @subclasses.each do | mod |
32
- %tr
33
- %td= format_module(mod)
34
- %dt Extended By:
35
- %dd
36
- - if (@result_extended || [ ]).empty?
37
- %span.none NONE
38
- - else
39
- %table.extended_by
40
- - @result_extended.each do | mod |
41
- %tr
42
- %td= format_module(mod)
43
- %dt Constants:
44
- %dd
45
- - if (@constants || [ ]).empty?
46
- %span.none NONE
47
- - else
48
- %table.constants
49
- - @constants.each do | name, value |
50
- %tr.constant
51
- %td
52
- %tt=h name
53
- %td= format_module(value.class)
54
- %td= format_object(value, :inline)
55
- %dt
56
- Methods:
57
- %dd
58
- = haml :'console/methods_table', locals: locals.merge(methods: @methods)
59
-
4
+ =haml :'console/eval', locals: locals
60
5
  =haml :'console/error', locals: locals
61
6
 
@@ -0,0 +1,28 @@
1
+ %dt Class:
2
+ %dd
3
+ .class= format_module(@result.class)
4
+ - if @show_result != false
5
+ %dt Result:
6
+ %dd
7
+ .result
8
+ ~ format_object(@result)
9
+ %dt Extended By:
10
+ %dd
11
+ .extended_by
12
+ - extensions = (@result_extended || [ ])
13
+ - if extensions.empty?
14
+ %span.none NONE
15
+ - else
16
+ %table
17
+ - extensions.each do | mod |
18
+ %tr
19
+ %td= format_module(mod)
20
+ - if @captured_stdio && @show_stdio != false
21
+ %dt $stdout:
22
+ %dd
23
+ .io.stdout
24
+ ~ format_as_terminal(@stdout && @stdout.string)
25
+ %dt $stderr:
26
+ %dd
27
+ .io.stderr
28
+ ~ format_as_terminal(@stderr && @stderr.string)
@@ -0,0 +1,17 @@
1
+ %dt Name:
2
+ %dd= format_methods(@method.name)
3
+ %dt Owner:
4
+ %dd= format_module(@module)
5
+ %dt Parameters:
6
+ %dd= h @method.parameters.inspect
7
+ %dt Arity:
8
+ %dd= h @method.arity
9
+ %dt Source Location:
10
+ %dd= format_source_location(@method_source_location, @method, nil, @module)
11
+ - if @method_source
12
+ %dt Source:
13
+ %dd
14
+ %table.source_listing
15
+ - @method_source.lines.each do | line |
16
+ %tr
17
+ %td{class: line[:class] * ' '}= h("%4d %s" % [ line[:line], line[:str] ]).gsub(' ', '&nbsp')
@@ -0,0 +1,47 @@
1
+ - if @is_class
2
+ %dt Superclass:
3
+ %dd= format_module(@superclass)
4
+ %dt Ancestors:
5
+ %dd
6
+ - if (@ancestors || [ ]).empty?
7
+ %span.none NONE
8
+ - else
9
+ %table.ancestors
10
+ - @ancestors.each do | mod |
11
+ %tr
12
+ %td= format_module(mod)
13
+ - if @subclasses
14
+ %dt Subclasses:
15
+ %dd
16
+ - if @subclasses.empty?
17
+ %span.none NONE
18
+ - else
19
+ %table.subclasses
20
+ - @subclasses.each do | mod |
21
+ %tr
22
+ %td= format_module(mod)
23
+ %dt Extended By:
24
+ %dd
25
+ - if (@result_extended || [ ]).empty?
26
+ %span.none NONE
27
+ - else
28
+ %table.extended_by
29
+ - @result_extended.each do | mod |
30
+ %tr
31
+ %td= format_module(mod)
32
+ %dt Constants:
33
+ %dd
34
+ - if (@constants || [ ]).empty?
35
+ %span.none NONE
36
+ - else
37
+ %table.constants
38
+ - @constants.each do | name, value |
39
+ %tr.constant
40
+ %td
41
+ %tt=h name
42
+ %td= format_module(value.class)
43
+ %td= format_object(value, :inline)
44
+ %dt
45
+ Methods:
46
+ %dd
47
+ = haml :'console/methods_table', locals: locals.merge(methods: @methods)
@@ -0,0 +1,9 @@
1
+ .result
2
+ %dl
3
+ - if @result_evaled && @result_ok
4
+ = haml :'console/result/basic', locals: locals
5
+ - if @is_module
6
+ = haml :'console/result/module', locals: locals
7
+ - if @is_method
8
+ = haml :'console/result/method', locals: locals
9
+
@@ -1,41 +1,5 @@
1
1
  .rack_console
2
2
  =haml :'console/server_info', locals: locals
3
- .eval
4
- - evaluate_expr!
5
- %form{action: url_root("/"), method: "post"}
6
- %div
7
- %textarea.expr{name: 'expr'}=h @expr
8
- %div
9
- %input{ type: 'submit', value: 'Evaluate' }
10
- .result
11
- - if @result_evaled && @result_ok
12
- %dl
13
- %dt Class:
14
- %dd
15
- .class= format_module(@result.class)
16
- %dt Result:
17
- %dd
18
- .result
19
- ~ format_object(@result)
20
- %dt Extended By:
21
- %dd
22
- .extended_by
23
- - extensions = (@result_extended || [ ])
24
- - if extensions.empty?
25
- %span.none NONE
26
- - else
27
- %table
28
- - extensions.each do | mod |
29
- %tr
30
- %td= format_module(mod)
31
- %dt $stdout:
32
- %dd
33
- .io.stdout
34
- ~ format_as_terminal(@stdout && @stdout.string)
35
- %dt $stderr:
36
- %dd
37
- .io.stderr
38
- ~ format_as_terminal(@stderr && @stderr.string)
39
-
3
+ =haml :'console/eval', locals: locals
40
4
  =haml :'console/error', locals: locals
41
5
 
@@ -1,3 +1,3 @@
1
1
  module RackConsole
2
- VERSION = "0.2.2"
2
+ VERSION = "0.3.0"
3
3
  end
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: rack_console
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.2.2
4
+ version: 0.3.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - Kurt Stephens
8
8
  autorequire:
9
9
  bindir: exe
10
10
  cert_chain: []
11
- date: 2015-10-26 00:00:00.000000000 Z
11
+ date: 2015-12-01 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: sinatra
@@ -173,16 +173,22 @@ files:
173
173
  - lib/rack_console/ansi2html.rb
174
174
  - lib/rack_console/app.rb
175
175
  - lib/rack_console/app_helpers.rb
176
+ - lib/rack_console/expr_helpers.rb
176
177
  - lib/rack_console/source_file.rb
177
178
  - lib/rack_console/template/css/ansi.css
178
179
  - lib/rack_console/template/css/rack_console.css
179
180
  - lib/rack_console/template/haml/console.haml
180
181
  - lib/rack_console/template/haml/console/error.haml
182
+ - lib/rack_console/template/haml/console/eval.haml
181
183
  - lib/rack_console/template/haml/console/file.haml
182
184
  - lib/rack_console/template/haml/console/method.haml
183
185
  - lib/rack_console/template/haml/console/methods.haml
184
186
  - lib/rack_console/template/haml/console/methods_table.haml
185
187
  - lib/rack_console/template/haml/console/module.haml
188
+ - lib/rack_console/template/haml/console/result.haml
189
+ - lib/rack_console/template/haml/console/result/basic.haml
190
+ - lib/rack_console/template/haml/console/result/method.haml
191
+ - lib/rack_console/template/haml/console/result/module.haml
186
192
  - lib/rack_console/template/haml/console/server_info.haml
187
193
  - lib/rack_console/template/haml/layout.haml
188
194
  - lib/rack_console/version.rb
@@ -207,7 +213,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
207
213
  version: '0'
208
214
  requirements: []
209
215
  rubyforge_project:
210
- rubygems_version: 2.2.2
216
+ rubygems_version: 2.4.3
211
217
  signing_key:
212
218
  specification_version: 4
213
219
  summary: A Rack App that provides a basic interactive Ruby console and introspection.