Permalink
Browse files

tweak code styling: rocket spacing and comment width

  • Loading branch information...
1 parent 85ceedc commit 5cc5b76c60d31fbcd24006f808680de937f7c4f0 @cldwalker committed Jan 10, 2011
View
18 lib/bond.rb
@@ -26,11 +26,11 @@ module Bond
# 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)
+ # 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)
#
# @param [Hash] options When using :method(s) or :object, some hash keys may have different behavior. See
# Bond.complete sections of {MethodMission} and {ObjectMission} respectively.
@@ -63,7 +63,7 @@ def complete(options={}, &block); M.complete(options, &block); end
# Redefines an existing completion mission to have a different action. The condition can only be varied if :name is
# used to identify and replace a mission. Takes same options as {#complete}.
# ==== Example:
- # Bond.recomplete(:on=>/man/, :name=>:count) { %w{4 5 6}}
+ # Bond.recomplete(:on => /man/, :name => :count) { %w{4 5 6}}
def recomplete(options={}, &block); M.recomplete(options, &block); end
# Reports what completion mission matches for a given input. Helpful for debugging missions.
@@ -82,9 +82,9 @@ def config; M.config; end
# {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 }
+ # Bond.start :gems => %w{hirb}
+ # Bond.start(:default_search => :ignore_case) do
+ # complete(:method => "Object#respond_to?") {|e| e.object.methods }
# end
#
# @param [Hash] options Sets global keys in {#config}, some which specify what completions to load.
View
20 lib/bond/agent.rb
@@ -1,6 +1,7 @@
module Bond
- # Every time a completion is attempted, the Agent searches its missions for the first one that matches the user input.
- # Using either the found mission or Agent.default_mission, the Agent executes the mission's action.
+ # Every time a completion is attempted, the Agent searches its missions for
+ # the first one that matches the user input. Using either the found mission
+ # or Agent.default_mission, the Agent executes the mission's action.
class Agent
# The array of missions that will be searched when a completion occurs.
attr_reader :missions
@@ -37,28 +38,29 @@ def recomplete(options={}, &block)
mission
end
- # This is where the action starts when a completion is initiated. Optional line_buffer
- # overrides line buffer from readline plugin.
+ # This is where the action starts when a completion is initiated. Optional
+ # line_buffer overrides line buffer from readline plugin.
def call(input, line_buffer=nil)
mission_input = line_buffer || @weapon.line_buffer
mission_input = $1 if mission_input !~ /#{Regexp.escape(input)}$/ && mission_input =~ /^(.*#{Regexp.escape(input)})/
(mission = find_mission(mission_input)) ? mission.execute : default_mission.execute(Input.new(input))
- rescue FailedMissionError=>e
+ rescue FailedMissionError => e
completion_error(e.message, "Completion Info: #{e.mission.match_message}")
rescue
completion_error "Failed internally with '#{$!.message}'.",
"Please report this issue with debug on: Bond.config[:debug] = true."
end
- # Given a hypothetical user input, reports back what mission it would have found and executed.
+ # Given a hypothetical user input, reports back what mission it would have
+ # found and executed.
def spy(input)
if (mission = find_mission(input))
puts mission.match_message, "Possible completions: #{mission.execute.inspect}",
"Matches for #{mission.condition.inspect} are #{mission.matched.to_a.inspect}"
else
puts "Doesn't match a completion."
end
- rescue FailedMissionError=>e
+ rescue FailedMissionError => e
puts e.mission.match_message, e.message,
"Matches for #{e.mission.condition.inspect} are #{e.mission.matched.to_a.inspect}"
end
@@ -69,7 +71,7 @@ def find_mission(input) #@private
# Default mission used by agent. An instance of DefaultMission.
def default_mission
- @default_mission ||= DefaultMission.new(:action=>@default_mission_action)
+ @default_mission ||= DefaultMission.new(:action => @default_mission_action)
end
# Resets an agent's missions
@@ -86,7 +88,7 @@ def setup_readline(plugin)
end
def create_mission(options, &block)
- Mission.create options.merge!(:action=>options[:action] || block)
+ Mission.create options.merge!(:action => options[:action] || block)
rescue InvalidMissionError
"Invalid #{$!.message} for completion with options: #{options.inspect}"
rescue
View
8 lib/bond/m.rb
@@ -1,5 +1,6 @@
module Bond
- # Takes international quagmires (a user's completion setup) and passes them on as missions to an Agent.
+ # Takes international quagmires (a user's completion setup) and passes them on
+ # as missions to an Agent.
module M
extend self
@@ -30,7 +31,7 @@ def agent
# See {Bond#config}
def config
- @config ||= {:debug=>false, :default_search=>:underscore}
+ @config ||= {:debug => false, :default_search => :underscore}
end
# Resets M's missions and config
@@ -77,7 +78,8 @@ def started?
!!@started
end
- # Finds the full path to a gem's file relative it's load path directory. Returns nil if not found.
+ # Finds the full path to a gem's file relative it's load path directory.
+ # Returns nil if not found.
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)
View
2 lib/bond/mission.rb
@@ -145,7 +145,7 @@ def unique_id
end
def create_input(input, options={})
- @input = Input.new(input, options.merge(:line=>@line, :matched=>@matched))
+ @input = Input.new(input, options.merge(:line => @line, :matched => @matched))
end
end
end
View
7 lib/bond/missions/anywhere_mission.rb
@@ -1,6 +1,7 @@
-# A mission which completes anywhere i.e. even after non word break characters such as '[' or '}'.
-# With options :prefix and :anywhere, this mission matches on the following regexp condition
-# /:prefix?(:anywhere)$/ and passes the first capture group to the mission action.
+# A mission which completes anywhere i.e. even after non word break characters
+# such as '[' or '}'. With options :prefix and :anywhere, this mission matches
+# on the following regexp condition /:prefix?(:anywhere)$/ and passes the first
+# capture group to the mission action.
class Bond::AnywhereMission < Bond::Mission
def initialize(options={}) #@private
options[:on] = Regexp.new("#{options[:prefix]}(#{options[:anywhere]})$")
View
16 lib/bond/missions/method_mission.rb
@@ -13,13 +13,13 @@ module Bond
# Otherwise defaults to normal :search behavior.
# [:name, :place] These options aren't supported by a MethodMission/OperatorMethodMission completion.
# ==== Examples:
- # Bond.complete(:methods=>%w{delete index rindex}, :class=>"Array#") {|e| e.object }
- # Bond.complete(:method=>"Hash#index") {|e| e.object.values }
+ # Bond.complete(:methods => %w{delete index rindex}, :class => "Array#") {|e| e.object }
+ # Bond.complete(:method => "Hash#index") {|e| e.object.values }
#
# ==== Argument Format
# All method arguments can autocomplete as symbols or strings and the first argument can be prefixed
# with '(':
- # >> Bond.complete(:method=>'example') { %w{some example eh} }
+ # >> Bond.complete(:method => 'example') { %w{some example eh} }
# => true
# >> example '[TAB]
# eh example some
@@ -33,7 +33,7 @@ module Bond
# Every time a comma appears after a method, Bond starts a new completion. This allows a method to
# complete multiple arguments as well as complete keys for a hash. *Each* argument can be have a unique
# set of completions since a completion action is aware of what argument it is currently completing:
- # >> Bond.complete(:method=>'FileUtils.chown') {|e|
+ # >> Bond.complete(:method => 'FileUtils.chown') {|e|
# e.argument > 3 ? %w{noop verbose} : %w{root admin me} }
# => true
# >> FileUtils.chown 'r[TAB]
@@ -42,7 +42,7 @@ module Bond
# >> FileUtils.chown 'root', 'admin'
# >> FileUtils.chown 'root', 'admin', 'some_file', :v[TAB]
# >> FileUtils.chown 'root', 'admin', 'some_file', :verbose
- # >> FileUtils.chown 'root', 'admin', 'some_file', :verbose=>true
+ # >> FileUtils.chown 'root', 'admin', 'some_file', :verbose => true
#
# ==== Developer Notes
# Unlike other missions, creating these missions with Bond.complete doesn't add more completion rules
@@ -183,8 +183,8 @@ def set_action_and_search
def after_match(input)
set_action_and_search
@completion_prefix, typed = @matched[3], @matched[-1]
- input_options = {:object=>@evaled_object, :argument=>1+typed.count(','),
- :arguments=>(@completion_prefix.to_s+typed).split(/\s*,\s*/) }
+ input_options = {:object => @evaled_object, :argument => 1+typed.count(','),
+ :arguments => (@completion_prefix.to_s+typed).split(/\s*,\s*/) }
if typed.to_s.include?(',') && (match = typed.match(/(.*?\s*)([^,]*)$/))
typed = match[2]
typed.sub!(/^(['":])/,'')
@@ -194,4 +194,4 @@ def after_match(input)
end
end
-end
+end
View
18 lib/bond/missions/object_mission.rb
@@ -1,14 +1,14 @@
-# A mission which completes an object's methods. For this mission to match,
-# the condition must match and the current object must have an ancestor that matches :object.
-# Note: To access to the current object being completed on within an action, use the input's
-# object attribute.
+# A mission which completes an object's methods. For this mission to match, the
+# condition must match and the current object must have an ancestor that matches
+# :object. Note: To access to the current object being completed on within an
+# action, use the input's object attribute.
#
# ==== Bond.complete Options:
-# [:action] If an action is not specified, the default action is to complete an object's
-# non-operator methods.
+# [:action] If an action is not specified, the default action is to complete an
+# object's non-operator methods.
#
# ===== Example:
-# Bond.complete(:object=>'ActiveRecord::Base') {|input| input.object.class.instance_methods(false) }
+# Bond.complete(:object => 'ActiveRecord::Base') {|input| input.object.class.instance_methods(false) }
class Bond::ObjectMission < Bond::Mission
OBJECTS = %w<\S+> + Bond::Mission::OBJECTS
CONDITION = '(OBJECTS)\.(\w*(?:\?|!)?)$'
@@ -35,10 +35,10 @@ def do_match(input)
def after_match(input)
@completion_prefix = @matched[1] + "."
@action ||= lambda {|e| default_action(e.object) }
- create_input @matched[2], :object=>@evaled_object
+ create_input @matched[2], :object => @evaled_object
end
def default_action(obj)
obj.methods.map {|e| e.to_s} - OPERATORS
end
-end
+end
View
12 lib/bond/missions/operator_method_mission.rb
@@ -1,7 +1,9 @@
module Bond
- # A mission which completes arguments for any module/class method that is an operator i.e. '>' or '*'.
- # Takes same Bond.complete options as MethodMission. The only operator method this mission doesn't
- # complete is '[]='. The operator '[]' should cover the first argument completion of '[]=' anyways.
+ # A mission which completes arguments for any module/class method that is an
+ # operator i.e. '>' or '*'. Takes same Bond.complete options as
+ # MethodMission. The only operator method this mission doesn't complete is
+ # '[]='. The operator '[]' should cover the first argument completion of '[]='
+ # anyways.
class OperatorMethodMission < MethodMission
OPERATORS = Mission::OPERATORS - ["[]", "[]="]
OBJECTS = Mission::OBJECTS + %w{\S+}
@@ -19,7 +21,7 @@ def matched_method
def after_match(input)
set_action_and_search
@completion_prefix, typed = input.to_s.sub(/#{Regexp.quote(@matched[-1])}$/, ''), @matched[-1]
- create_input typed, :object=>@evaled_object, :argument=>1
+ create_input typed, :object => @evaled_object, :argument => 1
end
end
-end
+end
View
10 lib/bond/rc.rb
@@ -4,13 +4,13 @@ module Bond
#
# === Example ~/.bondrc
# # complete arguments for any object's :respond_to?
- # complete(:method=>"Object#respond_to?") {|e| e.object.methods }
+ # complete(:method => "Object#respond_to?") {|e| e.object.methods }
# # complete arguments for any module's :public
- # complete(:method=>"Module#public") {|e| e.object.instance_methods }
+ # complete(:method => "Module#public") {|e| e.object.instance_methods }
#
# # Share generate_tags action across completions
- # complete(:method=>"edit_tags", :action=>:generate_tags)
- # complete(:method=>"delete_tags", :search=>false) {|e| generate_tags(e).grep(/#{e}/i) }
+ # complete(:method => "edit_tags", :action => :generate_tags)
+ # complete(:method => "delete_tags", :search => false) {|e| generate_tags(e).grep(/#{e}/i) }
#
# def generate_tags(input)
# ...
@@ -45,4 +45,4 @@ def eval(str)
raise if Bond.config[:debug]
end
end
-end
+end
View
4 lib/bond/search.rb
@@ -10,7 +10,7 @@ module Bond
# normal_search(input, list.select {|e| e !~ /-/ })
# end
#
- # Now you can pass this custom search to any complete() as :search=>:ignore_hyphen
+ # Now you can pass this custom search to any complete() as :search => :ignore_hyphen
module Search
class<<self
# Default search used across missions, set by Bond.config[:default_search]
@@ -71,4 +71,4 @@ def incremental_filter(input, list, delim)
(current_matches + future_matches.map {|e| e[/^(([^#{delim_chars}]*#{delim}){0,#{i+1}})/, 1] }).uniq
end
end
-end
+end
View
4 test/test_helper.rb
@@ -15,7 +15,7 @@ module ::IRB
module InputCompletor; CompletionProc = lambda {|e| [] }; end
end
]
- ::IRB.CurrentContext = stub(:workspace=>stub(:binding=>binding))
+ ::IRB.CurrentContext = stub(:workspace => stub(:binding => binding))
end
end
@@ -65,5 +65,5 @@ class Bacon::Context
end
# Default settings
-Bond::M.debrief(:readline=>TestHelpers.valid_readline, :debug=>true)
+Bond::M.debrief(:readline => TestHelpers.valid_readline, :debug => true)
include Bond

0 comments on commit 5cc5b76

Please sign in to comment.