Module: Bond
- Extended by:
- Bond
- Included in:
- Bond
- Defined in:
- lib/bond.rb,
lib/bond/m.rb,
lib/bond/rc.rb,
lib/bond/agent.rb,
lib/bond/input.rb,
lib/bond/search.rb,
lib/bond/mission.rb,
lib/bond/version.rb,
lib/bond/missions/method_mission.rb,
lib/bond/missions/operator_method_mission.rb
Defined Under Namespace
Modules: M, Rc, Search Classes: Agent, AnywhereMission, DefaultMission, FailedMissionError, Input, InvalidMissionError, Jruby, MethodMission, Mission, ObjectMission, OperatorMethodMission, Rawline, Readline, Ruby
Constant Summary collapse
- VERSION =
'0.5.1'
Instance Method Summary collapse
-
#agent ⇒ Object
An Agent who saves all Bond.complete missions and executes the correct one when a completion is called.
-
#complete(options = {}, &block) ⇒ Object
Creates a completion rule (Mission).
-
#config ⇒ Hash
Global config.
-
#list_methods ⇒ Object
Lists all methods that have argument completion.
-
#load_gems(*gems) ⇒ Object
Loads completions for gems that ship with them under lib/bond/completions/, relative to the gem’s base directory.
-
#recomplete(options = {}, &block) ⇒ Object
Redefines an existing completion mission to have a different action.
-
#restart(options = {}, &block) ⇒ Object
Restarts completions with given options, ensuring to delete current completions.
-
#spy(*args) ⇒ Object
Reports what completion mission matches for a given input.
-
#start(options = {}, &block) ⇒ Object
Starts Bond with a default set of completions that replace and improve irb’s completion.
-
#started? ⇒ Boolean
Indicates if Bond has already started.
Instance Method Details
#agent ⇒ Object
An Agent who saves all Bond.complete missions and executes the correct one when a completion is called.
123 |
# File 'lib/bond.rb', line 123 def agent; M.agent; end |
#complete(options = {}, &block) ⇒ Object
Creates a completion rule (Mission). A valid Mission consists of a condition and an action. A condition is specified with one of the following options: :on, :object, :anywhere or :method(s). Each of these options creates a different Mission class. An action is either the method’s block or :action. An action takes what the user has typed (Input) and returns an array of possible completions. Bond searches these completions and returns matching completions. This searching behavior can be configured or turned off per mission with :search. If turned off, the action must also handle searching.
Examples:
Bond.complete(:method => 'shoot') {|input| %w{to kill} }
Bond.complete(:on => /^((([a-z][^:.\(]*)+):)+/, :search => false) {|input| Object.constants.grep(/#{input.matched[1]}/) }
Bond.complete(:object => ActiveRecord::Base, :search => :underscore, :place => :last)
Bond.complete(:method => 'you', :search => proc {|input, list| list.grep(/#{input}/i)} ) {|input| %w{Only Live Twice} }
Bond.complete(:method => 'system', :action => :shell_commands)
61 |
# File 'lib/bond.rb', line 61 def complete(={}, &block); M.complete(, &block); end |
#list_methods ⇒ Object
Lists all methods that have argument completion.
126 |
# File 'lib/bond.rb', line 126 def list_methods; MethodMission.all_methods; end |
#load_gems(*gems) ⇒ Object
Loads completions for gems that ship with them under lib/bond/completions/, relative to the gem’s base directory.
120 |
# File 'lib/bond.rb', line 120 def load_gems(*gems); M.load_gems(*gems); end |
#recomplete(options = {}, &block) ⇒ Object
67 |
# File 'lib/bond.rb', line 67 def recomplete(={}, &block); M.recomplete(, &block); end |
#restart(options = {}, &block) ⇒ Object
Restarts completions with given options, ensuring to delete current completions. Takes same options as Bond#start.
114 |
# File 'lib/bond.rb', line 114 def restart(={}, &block); M.restart(, &block); end |
#spy(*args) ⇒ Object
Reports what completion mission matches for a given input. Helpful for debugging missions.
Example:
>> Bond.spy "shoot oct"
Matches completion mission for method matching "shoot".
Possible completions: ["octopussy"]
74 |
# File 'lib/bond.rb', line 74 def spy(*args); M.spy(*args); end |
#start(options = {}, &block) ⇒ Object
Starts Bond with a default set of completions that replace and improve irb’s completion. Loads completions in this order: lib/bond/completion.rb, lib/bond/completions/*.rb and the following optional completions: completions from :gems, ~/.bondrc, ~/.bond/completions/*.rb and from block. See Rc for the DSL to use in completion files and in the block.
Examples:
Bond.start :gems => %w{hirb}
Bond.start(:default_search => :ignore_case) do
complete(:method => "Object#respond_to?") {|e| e.object.methods }
end
110 |
# File 'lib/bond.rb', line 110 def start(={}, &block); M.start(, &block); end |