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
28 29 30 |
# File 'lib/bond/m.rb', line 28 def agent @agent ||= Agent.new(config) end |
#complete(options = {}, &block) ⇒ Object
See Bond#complete
8 9 10 11 12 13 14 15 |
# File 'lib/bond/m.rb', line 8 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
33 34 35 |
# File 'lib/bond/m.rb', line 33 def config @config ||= {:debug => false, :default_search => :underscore} end |
#debrief(options = {}) ⇒ Object
Validates and sets values in M.config.
49 50 51 52 53 54 55 56 57 58 59 |
# File 'lib/bond/m.rb', line 49 def debrief(={}) config.merge! config[:readline] ||= default_readline if !config[:readline].is_a?(Module) && Bond.const_defined?(config[:readline].to_s.capitalize) config[:readline] = Bond.const_get(config[:readline].to_s.capitalize) end unless %w{setup line_buffer}.all? {|e| config[:readline].respond_to?(e) } $stderr.puts "Bond Error: Invalid readline plugin '#{config[:readline]}'." 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.
83 84 85 86 |
# File 'lib/bond/m.rb', line 83 def find_gem_file(rubygem, file) begin gem(rubygem); rescue Exception; end (dir = $:.find {|e| File.exist?(File.join(e, file)) }) && File.join(dir, file) end |
#home ⇒ Object
Find a user’s home in a cross-platform way
109 110 111 112 113 114 115 |
# File 'lib/bond/m.rb', line 109 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.
96 97 98 99 100 101 |
# File 'lib/bond/m.rb', line 96 def load_dir(base_dir) if File.exist?(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.
89 90 91 92 93 |
# File 'lib/bond/m.rb', line 89 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
104 105 106 |
# File 'lib/bond/m.rb', line 104 def load_gems(*gems) gems.select {|e| load_gem_completion(e) } end |
#recomplete(options = {}, &block) ⇒ Object
See Bond#recomplete
18 19 20 21 22 23 24 25 |
# File 'lib/bond/m.rb', line 18 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
38 39 40 41 |
# File 'lib/bond/m.rb', line 38 def reset MethodMission.reset @config = @agent = nil end |
#restart(options = {}, &block) ⇒ Object
See Bond#restart
62 63 64 65 |
# File 'lib/bond/m.rb', line 62 def restart(={}, &block) reset start(, &block) end |
#spy(input) ⇒ Object
See Bond#spy
44 45 46 |
# File 'lib/bond/m.rb', line 44 def spy(input) agent.spy(input) end |
#start(options = {}, &block) ⇒ Object
See Bond#start
68 69 70 71 72 73 74 |
# File 'lib/bond/m.rb', line 68 def start(={}, &block) debrief @started = true load_completions Rc.module_eval(&block) if block true end |
#started? ⇒ Boolean
See Bond#started?
77 78 79 |
# File 'lib/bond/m.rb', line 77 def started? !!@started end |