module Bond::M

Takes international quagmires (a user's completion setup) and passes them on as missions to an Agent.

Public Instance Methods

agent() click to toggle source

See {Bond#agent}

# File lib/bond/m.rb, line 28
def agent
  @agent ||= Agent.new(config)
end
complete(options={}, &block) click to toggle source

See {Bond#complete}

# File lib/bond/m.rb, line 8
def complete(options={}, &block)
  if (result = agent.complete(options, &block)).is_a?(String)
    $stderr.puts "Bond Error: "+result
    false
  else
    true
  end
end
config() click to toggle source

See {Bond#config}

# File lib/bond/m.rb, line 33
def config
  @config ||= {:debug => false, :default_search => :underscore}
end
debrief(options={}) click to toggle source

Validates and sets values in #config.

# File lib/bond/m.rb, line 49
def debrief(options={})
  config.merge! options
  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) click to toggle source

Finds the full path to a gem's file relative it's load path directory. Returns nil if not found.

# 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() click to toggle source

Find a user's home in a cross-platform way

# 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.expand_path("~")
rescue
  File::ALT_SEPARATOR ? "C:/" : "/"
end
load_dir(base_dir) click to toggle source

Loads completion files in given directory.

# 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) click to toggle source

Loads a completion file in Rc namespace.

# 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.message
end
load_gems(*gems) click to toggle source

Loads completions from gems

# File lib/bond/m.rb, line 104
def load_gems(*gems)
  gems.select {|e| load_gem_completion(e) }
end
recomplete(options={}, &block) click to toggle source

See {Bond#recomplete}

# File lib/bond/m.rb, line 18
def recomplete(options={}, &block)
  if (result = agent.recomplete(options, &block)).is_a?(String)
    $stderr.puts "Bond Error: "+result
    false
  else
    true
  end
end
reset() click to toggle source

Resets M's missions and config

# File lib/bond/m.rb, line 38
def reset
  MethodMission.reset
  @config = @agent = nil
end
restart(options={}, &block) click to toggle source

See {Bond#restart}

# File lib/bond/m.rb, line 62
def restart(options={}, &block)
  reset
  start(options, &block)
end
spy(input) click to toggle source

See {Bond#spy}

# File lib/bond/m.rb, line 44
def spy(input)
  agent.spy(input)
end
start(options={}, &block) click to toggle source

See {Bond#start}

# File lib/bond/m.rb, line 68
def start(options={}, &block)
  debrief options
  @started = true
  load_completions
  Rc.module_eval(&block) if block
  true
end
started?() click to toggle source

See {Bond#started?}

# File lib/bond/m.rb, line 77
def started?
  !!@started
end

Protected Instance Methods

default_readline() click to toggle source
# File lib/bond/m.rb, line 118
def default_readline
  RUBY_PLATFORM[/mswin|mingw|bccwin|wince/i] ? Ruby :
    RUBY_PLATFORM[/java/i] ? Jruby : Bond::Readline
end
load_completions() click to toggle source
# File lib/bond/m.rb, line 138
def load_completions
  load_file File.join(File.dirname(__FILE__), 'completion.rb') unless config[:bare]
  load_dir File.dirname(__FILE__) unless config[:bare]
  load_gems *config[:gems] if config[:gems]
  load_file(File.join(home,'.bondrc')) if File.exist?(File.join(home, '.bondrc')) && !config[:bare]
  load_dir File.join(home, '.bond') unless config[:bare]
end
load_gem_completion(rubygem) click to toggle source
# File lib/bond/m.rb, line 123
def load_gem_completion(rubygem)
  (dir = find_gem_file(rubygem, File.join(rubygem, '..', 'bond'))) ? load_dir(dir) :
    rubygem[/\/|-/] ? load_plugin_file(rubygem) :
    $stderr.puts("Bond Error: No completions found for gem '#{rubygem}'.")
end
load_plugin_file(rubygem) click to toggle source
# File lib/bond/m.rb, line 129
def load_plugin_file(rubygem)
  namespace, file = rubygem.split(/\/|-/, 2)
  file += '.rb' unless file[/\.rb$/]
  if (dir = $:.find {|e| File.exist?(File.join(e, namespace, 'completions', file)) })
    load_file File.join(dir, namespace, 'completions', file)
    true
  end
end