Module: Bond::M
Overview
Takes international quagmires (a user’s completion setup) and passes them on as missions to an Agent.
Instance Method Summary collapse
-
#agent ⇒ Object
See #agent.
-
#complete(options = {}, &block) ⇒ Object
See #complete.
-
#config ⇒ Object
See #config.
-
#debrief(options = {}) ⇒ Object
Validates and sets values in M.config.
-
#find_gem_file(rubygem, file) ⇒ Object
Finds the full path to a gem’s file relative it’s load path directory.
-
#home ⇒ Object
Find a user’s home in a cross-platform way.
-
#load_dir(base_dir) ⇒ Object
Loads completion files in given directory.
-
#load_file(file) ⇒ Object
Loads a completion file in Rc namespace.
-
#load_gems(*gems) ⇒ Object
Loads completions from gems.
-
#recomplete(options = {}, &block) ⇒ Object
See #recomplete.
-
#reset ⇒ Object
Resets M’s missions and config.
-
#restart(options = {}, &block) ⇒ Object
See #restart.
-
#spy(input) ⇒ Object
See #spy.
-
#start(options = {}, &block) ⇒ Object
See #start.
-
#started? ⇒ Boolean
See #started?.
Instance Method Details
#agent ⇒ Object
See Bond#agent
27 28 29 |
# File 'lib/bond/m.rb', line 27 def agent @agent ||= Agent.new(config) end |
#complete(options = {}, &block) ⇒ Object
See Bond#complete
7 8 9 10 11 12 13 14 |
# File 'lib/bond/m.rb', line 7 def complete(={}, &block) if (result = agent.complete(, &block)).is_a?(String) $stderr.puts "Bond Error: "+result false else true end end |
#config ⇒ Object
See Bond#config
32 33 34 |
# File 'lib/bond/m.rb', line 32 def config @config ||= {:readline_plugin=>Bond::Readline, :debug=>false, :default_search=>:underscore} end |
#debrief(options = {}) ⇒ Object
Validates and sets values in M.config.
48 49 50 51 52 53 54 55 |
# File 'lib/bond/m.rb', line 48 def debrief(={}) config.merge! plugin_methods = %w{setup line_buffer} unless config[:readline_plugin].is_a?(Module) && plugin_methods.all? {|e| config[:readline_plugin].instance_methods.map {|f| f.to_s}.include?(e)} $stderr.puts "Bond Error: Invalid readline plugin given." end end |
#find_gem_file(rubygem, file) ⇒ Object
Finds the full path to a gem’s file relative it’s load path directory. Returns nil if not found.
78 79 80 81 |
# File 'lib/bond/m.rb', line 78 def find_gem_file(rubygem, file) begin gem(rubygem); rescue Exception; end (dir = $:.find {|e| File.exists?(File.join(e, file)) }) && File.join(dir, file) end |
#home ⇒ Object
Find a user’s home in a cross-platform way
104 105 106 107 108 109 110 |
# File 'lib/bond/m.rb', line 104 def home ['HOME', 'USERPROFILE'].each {|e| return ENV[e] if ENV[e] } return "#{ENV['HOMEDRIVE']}#{ENV['HOMEPATH']}" if ENV['HOMEDRIVE'] && ENV['HOMEPATH'] File.("~") rescue File::ALT_SEPARATOR ? "C:/" : "/" end |
#load_dir(base_dir) ⇒ Object
Loads completion files in given directory.
91 92 93 94 95 96 |
# File 'lib/bond/m.rb', line 91 def load_dir(base_dir) if File.exists?(dir = File.join(base_dir, 'completions')) Dir[dir + '/*.rb'].each {|file| load_file(file) } true end end |
#load_file(file) ⇒ Object
Loads a completion file in Rc namespace.
84 85 86 87 88 |
# File 'lib/bond/m.rb', line 84 def load_file(file) Rc.module_eval File.read(file) rescue Exception => e $stderr.puts "Bond Error: Completion file '#{file}' failed to load with:", e. end |
#load_gems(*gems) ⇒ Object
Loads completions from gems
99 100 101 |
# File 'lib/bond/m.rb', line 99 def load_gems(*gems) gems.select {|e| load_gem_completion(e) } end |
#recomplete(options = {}, &block) ⇒ Object
See Bond#recomplete
17 18 19 20 21 22 23 24 |
# File 'lib/bond/m.rb', line 17 def recomplete(={}, &block) if (result = agent.recomplete(, &block)).is_a?(String) $stderr.puts "Bond Error: "+result false else true end end |
#reset ⇒ Object
Resets M’s missions and config
37 38 39 40 |
# File 'lib/bond/m.rb', line 37 def reset MethodMission.reset @config = @agent = nil end |
#restart(options = {}, &block) ⇒ Object
See Bond#restart
58 59 60 61 |
# File 'lib/bond/m.rb', line 58 def restart(={}, &block) reset start(, &block) end |
#spy(input) ⇒ Object
See Bond#spy
43 44 45 |
# File 'lib/bond/m.rb', line 43 def spy(input) agent.spy(input) end |
#start(options = {}, &block) ⇒ Object
See Bond#start
64 65 66 67 68 69 70 |
# File 'lib/bond/m.rb', line 64 def start(={}, &block) debrief @started = true load_completions Rc.module_eval(&block) if block true end |
#started? ⇒ Boolean
See Bond#started?
73 74 75 |
# File 'lib/bond/m.rb', line 73 def started? !!@started end |