Module: FlexConsole
- Defined in:
- lib/flex_console.rb
Class Attribute Summary collapse
-
.bound_obj ⇒ Object
readonly
Returns the value of attribute bound_obj.
-
.plain_loop ⇒ Object
readonly
Returns the value of attribute plain_loop.
-
.test_args ⇒ Object
readonly
Returns the value of attribute test_args.
-
.test_method ⇒ Object
readonly
Returns the value of attribute test_method.
-
.test_object ⇒ Object
readonly
Returns the value of attribute test_object.
Class Method Summary collapse
Instance Method Summary collapse
Class Attribute Details
.bound_obj ⇒ Object (readonly)
Returns the value of attribute bound_obj.
6 7 8 |
# File 'lib/flex_console.rb', line 6 def bound_obj @bound_obj end |
.plain_loop ⇒ Object (readonly)
Returns the value of attribute plain_loop.
6 7 8 |
# File 'lib/flex_console.rb', line 6 def plain_loop @plain_loop end |
.test_args ⇒ Object (readonly)
Returns the value of attribute test_args.
6 7 8 |
# File 'lib/flex_console.rb', line 6 def test_args @test_args end |
.test_method ⇒ Object (readonly)
Returns the value of attribute test_method.
6 7 8 |
# File 'lib/flex_console.rb', line 6 def test_method @test_method end |
.test_object ⇒ Object (readonly)
Returns the value of attribute test_object.
6 7 8 |
# File 'lib/flex_console.rb', line 6 def test_object @test_object end |
Class Method Details
.bind(obj, binding) ⇒ Object
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 35 36 37 38 39 40 41 42 |
# File 'lib/flex_console.rb', line 9 def bind(obj, binding) @plain_loop = ->() { commands = [] begin puts quit = false until quit response = gets.chomp commands << response if response == 'q' || response == 'exit' quit = true elsif response == '' commands[-1] = commands[-2] puts 'repeating' binding.eval(commands[-2].strip.gsub("\n", '')) puts '------------------' else binding.eval(response.strip.gsub("\n", '')) puts '------------------' end end rescue Exception => e puts e puts e. puts e.backtrace puts '---------------' retry end } @binding = binding @bound_obj = obj end |
.bind_lib ⇒ Object
44 45 46 47 48 |
# File 'lib/flex_console.rb', line 44 def bind_lib file = @binding.eval('__FILE__') file_name = file.split('/')[-1] @lib_file = file.split('/')[0..-3].join('/') + "/lib/#{file_name}" end |
.set(test_object, test_method, *test_args) ⇒ Object
50 51 52 53 54 |
# File 'lib/flex_console.rb', line 50 def set (test_object, test_method, *test_args) @test_object = test_object @test_method = test_method @test_args = test_args end |
Instance Method Details
#loop_eval(message) ⇒ Object
58 59 60 |
# File 'lib/flex_console.rb', line 58 def loop_eval() FlexConsole.bound_obj.instance_exec(, &FlexConsole.plain_loop) end |
#reload_lib ⇒ Object
62 63 64 |
# File 'lib/flex_console.rb', line 62 def reload_lib FlexConsole.binding.eval("load '#{FlexConsole.lib_file}'") end |
#run ⇒ Object
66 67 68 69 70 71 72 |
# File 'lib/flex_console.rb', line 66 def run obj = FlexConsole.test_object method = FlexConsole.test_method args = FlexConsole.test_args obj.send(method, *args) end |