class Bond::ObjectMission
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.
Example:¶ ↑
Bond.complete(:object => 'ActiveRecord::Base') {|input| input.object.class.instance_methods(false) }
Constants
- CONDITION
- OBJECTS
Public Class Methods
new(options={})
click to toggle source
Calls superclass method
Bond::Mission.new
# File lib/bond/missions/object_mission.rb, line 15 def initialize(options={}) #@private @object_condition = /^#{options[:object]}$/ options[:on] ||= Regexp.new condition_with_objects super end
Public Instance Methods
match_message()
click to toggle source
# File lib/bond/missions/object_mission.rb, line 21 def match_message #@private "Matches completion for object with ancestor matching #{@object_condition.inspect}." end
Protected Instance Methods
after_match(input)
click to toggle source
# File lib/bond/missions/object_mission.rb, line 34 def after_match(input) @completion_prefix = @matched[1] + "." @action ||= lambda {|e| default_action(e.object) } create_input @matched[2], :object => @evaled_object end
default_action(obj)
click to toggle source
# File lib/bond/missions/object_mission.rb, line 40 def default_action(obj) klass(obj).instance_methods.map {|e| e.to_s} - OPERATORS end
do_match(input)
click to toggle source
Calls superclass method
Bond::Mission#do_match
# File lib/bond/missions/object_mission.rb, line 30 def do_match(input) super && eval_object(@matched[1]) && klass(@evaled_object).ancestors.any? {|e| e.to_s =~ @object_condition } end
klass(obj)
click to toggle source
# File lib/bond/missions/object_mission.rb, line 44 def klass(obj) (class << obj; self; end) rescue TypeError # can't define singleton obj.class end
unique_id()
click to toggle source
# File lib/bond/missions/object_mission.rb, line 26 def unique_id "#{@object_condition.inspect}+#{@on.inspect}" end