Class: Bond::Missions::ObjectMission
- Inherits:
-
Bond::Mission
- Object
- Bond::Mission
- Bond::Missions::ObjectMission
- Defined in:
- lib/bond/missions/object_mission.rb
Overview
Represents a completion mission specified by :object in Bond.complete. Unlike other missions, this one needs to both match the mission condition and have the current object being completed have an ancestor specified by :object.
Constant Summary
Constants inherited from Bond::Mission
Instance Attribute Summary collapse
-
#object_condition ⇒ Object
readonly
:stopdoc:.
Attributes inherited from Bond::Mission
Instance Method Summary collapse
- #default_action(obj) ⇒ Object
- #eval_object(match) ⇒ Object
- #handle_valid_match(input) ⇒ Object
-
#initialize(options = {}) ⇒ ObjectMission
constructor
A new instance of ObjectMission.
- #unique_id ⇒ Object
Methods inherited from Bond::Mission
action_object, create, current_eval, default_eval_binding, #execute, #matches?, #set_input
Methods included from Search
#anywhere_search, #default_search, #ignore_case_search, #underscore_search
Constructor Details
#initialize(options = {}) ⇒ ObjectMission
Returns a new instance of ObjectMission.
8 9 10 11 12 13 14 |
# File 'lib/bond/missions/object_mission.rb', line 8 def initialize(={}) @object_condition = .delete(:object) @object_condition = /^#{Regexp.escape(@object_condition.to_s)}$/ unless @object_condition.is_a?(Regexp) [:on] ||= /(\S+|[^.]+)\.([^.\s]*)$/ @eval_binding = [:eval_binding] super end |
Instance Attribute Details
#object_condition ⇒ Object (readonly)
:stopdoc:
6 7 8 |
# File 'lib/bond/missions/object_mission.rb', line 6 def object_condition @object_condition end |
Instance Method Details
#default_action(obj) ⇒ Object
45 46 47 |
# File 'lib/bond/missions/object_mission.rb', line 45 def default_action(obj) obj.methods.map {|e| e.to_s} - OPERATORS end |
#eval_object(match) ⇒ Object
40 41 42 43 |
# File 'lib/bond/missions/object_mission.rb', line 40 def eval_object(match) @matched = match @evaled_object = self.class.current_eval(match[1], @eval_binding) end |
#handle_valid_match(input) ⇒ Object
20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 |
# File 'lib/bond/missions/object_mission.rb', line 20 def handle_valid_match(input) if (match = super) begin eval_object(match) rescue Exception return false end if (match = @evaled_object.class.ancestors.any? {|e| e.to_s =~ @object_condition }) @completion_prefix = @matched[1] + "." @input = @matched[2] @input.instance_variable_set("@object", @evaled_object) @input.instance_eval("def self.object; @object ; end") @action ||= lambda {|e| default_action(e.object) } else match = false end end match end |
#unique_id ⇒ Object
16 17 18 |
# File 'lib/bond/missions/object_mission.rb', line 16 def unique_id "#{@object_condition.inspect}+#{@condition.inspect}" end |