Module: RoBinHelper
- Defined in:
- lib/ro_helpers/ro_bin_helper.rb
Class Method Summary collapse
- .autoload_all_ro_commands ⇒ Object
- .autoload_all_ro_commands_in_other_gems ⇒ Object
- .autoload_ro_commands_file(file) ⇒ Object
- .define_drb_method_and_start_service ⇒ Object
- .load_path ⇒ Object
- .require_all_ro_commands ⇒ Object
- .set_ro_commands_file_map(project_root, port_prefix = 77) ⇒ Object
- .show_ro_commands_help ⇒ Object
- .use_drb_method ⇒ Object
Class Method Details
.autoload_all_ro_commands ⇒ Object
42 43 44 45 46 |
# File 'lib/ro_helpers/ro_bin_helper.rb', line 42 def autoload_all_ro_commands ::RoCommands::file_map.each do |file, port| autoload_ro_commands_file(file) end end |
.autoload_all_ro_commands_in_other_gems ⇒ Object
53 54 55 56 57 58 59 60 61 62 63 64 |
# File 'lib/ro_helpers/ro_bin_helper.rb', line 53 def autoload_all_ro_commands_in_other_gems futures = [] load_path.each do |path| if test(?d, path) and path.match(%r{lib$}) futures << ::RoCells::Gem.new(path).future.ro_commands_paths end end futures.map(&:value).flatten.each do |file| autoload_ro_commands_file(file) end end |
.autoload_ro_commands_file(file) ⇒ Object
48 49 50 51 |
# File 'lib/ro_helpers/ro_bin_helper.rb', line 48 def autoload_ro_commands_file(file) filename = File.basename(file.to_s).gsub(%r{\.\w+$}, "") ::RoCommands.autoload filename.camelize, file.to_s end |
.define_drb_method_and_start_service ⇒ Object
84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 |
# File 'lib/ro_helpers/ro_bin_helper.rb', line 84 def define_drb_method_and_start_service ::RoCommands.file_map.each do |file, port| basename = File.basename(file.to_s).gsub(%r{\.rb}, "") klass_name = basename.to_s.camelize Out.out "#{RoCommands.const_get(klass_name.to_sym)} defining methods" RoCommands.const_get(klass_name.to_sym).class_eval do RoCommands.const_get(klass_name.to_sym).meths.each do |m| desc usage("drb_#{m}"), "" define_method("drb_#{m}".to_sym) do |*args| result = send(m.to_sym, *args) Out.out result end end end url = "druby://localhost:#{port}" puts "At #{Time.now}" puts "#{RoCommands.const_get(klass_name.to_sym)} at #{url}" DRb.start_service(url, RoCommands.const_get(klass_name.to_sym)) end end |
.load_path ⇒ Object
66 67 68 |
# File 'lib/ro_helpers/ro_bin_helper.rb', line 66 def load_path $LOAD_PATH end |
.require_all_ro_commands ⇒ Object
36 37 38 39 40 |
# File 'lib/ro_helpers/ro_bin_helper.rb', line 36 def require_all_ro_commands ::RoCommands::file_map.each do |file, port| require file.to_s end end |
.set_ro_commands_file_map(project_root, port_prefix = 77) ⇒ Object
30 31 32 33 34 |
# File 'lib/ro_helpers/ro_bin_helper.rb', line 30 def set_ro_commands_file_map(project_root, port_prefix=77) if test(?d, project_root) ::RoCommands.set_file_map project_root, port_prefix end end |
.show_ro_commands_help ⇒ Object
70 71 72 73 74 75 76 77 78 79 80 81 82 |
# File 'lib/ro_helpers/ro_bin_helper.rb', line 70 def show_ro_commands_help args = [] ::RoCommands::file_map.each do |file, port| filename = File.basename(file.to_s).gsub(%r{\.\w+$}, "") args << filename end args.flatten.compact.each do |arg| unless arg.match(%r{version}) Out.out " #{"ro #{arg}".ljust(20)} ##{::RoCommands.const_get(arg.camelize.to_sym).new.send(:introduction)}", "blue" end end end |
.use_drb_method ⇒ Object
8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 |
# File 'lib/ro_helpers/ro_bin_helper.rb', line 8 def use_drb_method item = ARGV.shift DRb.start_service file = RoCommands.file_map.keys.grep(%r{#{item}}).first if file port = RoCommands.file_map[file.to_sym] end if ARGV.empty? ::RoBinHelper.show_ro_commands_help else meth = ARGV.shift args = ARGV drb_obj = DRbObject.new_with_uri("druby://localhost:#{port}") r = drb_obj.start(["drb_#{meth}", *args, {pwd: Dir.pwd}]) Out.out(r) end end |