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.
4 5 6 |
# File 'lib/flex_console.rb', line 4 def bound_obj @bound_obj end |
.plain_loop ⇒ Object (readonly)
Returns the value of attribute plain_loop.
4 5 6 |
# File 'lib/flex_console.rb', line 4 def plain_loop @plain_loop end |
.test_args ⇒ Object (readonly)
Returns the value of attribute test_args.
4 5 6 |
# File 'lib/flex_console.rb', line 4 def test_args @test_args end |
.test_method ⇒ Object (readonly)
Returns the value of attribute test_method.
4 5 6 |
# File 'lib/flex_console.rb', line 4 def test_method @test_method end |
.test_object ⇒ Object (readonly)
Returns the value of attribute test_object.
4 5 6 |
# File 'lib/flex_console.rb', line 4 def test_object @test_object end |
Class Method Details
.bind(obj, binding) ⇒ Object
7 8 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 |
# File 'lib/flex_console.rb', line 7 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
42 43 44 45 46 |
# File 'lib/flex_console.rb', line 42 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
48 49 50 51 52 |
# File 'lib/flex_console.rb', line 48 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
56 57 58 |
# File 'lib/flex_console.rb', line 56 def loop_eval() FlexConsole.bound_obj.instance_exec(, &FlexConsole.plain_loop) end |
#reload_lib ⇒ Object
60 61 62 |
# File 'lib/flex_console.rb', line 60 def reload_lib FlexConsole.binding.eval("load '#{FlexConsole.lib_file}'") end |
#run ⇒ Object
64 65 66 67 68 69 70 |
# File 'lib/flex_console.rb', line 64 def run obj = FlexConsole.test_object method = FlexConsole.test_method args = FlexConsole.test_args obj.send(method, *args) end |