Class: AngryMob::Target::Call
Instance Attribute Summary collapse
-
#actions ⇒ Object
readonly
Returns the value of attribute actions.
-
#args ⇒ Object
readonly
Returns the value of attribute args.
-
#klass ⇒ Object
readonly
Returns the value of attribute klass.
-
#target ⇒ Object
Returns the value of attribute target.
Class Method Summary collapse
Instance Method Summary collapse
- #add_args(new_args) ⇒ Object
- #call(act, hints = {}) ⇒ Object
-
#initialize(klass, args) ⇒ Call
constructor
A new instance of Call.
- #instance_key ⇒ Object
- #merge_defaults(defaults) ⇒ Object
- #nickname ⇒ Object
- #validate_actions! ⇒ Object
Constructor Details
Instance Attribute Details
#actions ⇒ Object (readonly)
Returns the value of attribute actions.
4 5 6 |
# File 'lib/angry_mob/target/call.rb', line 4 def actions @actions end |
#args ⇒ Object (readonly)
Returns the value of attribute args.
4 5 6 |
# File 'lib/angry_mob/target/call.rb', line 4 def args @args end |
#klass ⇒ Object (readonly)
Returns the value of attribute klass.
4 5 6 |
# File 'lib/angry_mob/target/call.rb', line 4 def klass @klass end |
#target ⇒ Object
Returns the value of attribute target.
5 6 7 |
# File 'lib/angry_mob/target/call.rb', line 5 def target @target end |
Class Method Details
Instance Method Details
#add_args(new_args) ⇒ Object
21 22 23 24 |
# File 'lib/angry_mob/target/call.rb', line 21 def add_args(new_args) @args = Arguments.parse(new_args).update_preserving_actions(args) validate_actions! end |
#call(act, hints = {}) ⇒ Object
30 31 32 33 34 35 36 37 |
# File 'lib/angry_mob/target/call.rb', line 30 def call(act, hints={}) target.act = act target.noticing_changes(args) { actions.each {|action| target.send(action) } } end |
#instance_key ⇒ Object
17 18 19 |
# File 'lib/angry_mob/target/call.rb', line 17 def instance_key self.class.instance_key(klass,args) end |
#merge_defaults(defaults) ⇒ Object
26 27 28 |
# File 'lib/angry_mob/target/call.rb', line 26 def merge_defaults(defaults) args.reverse_deep_merge!(defaults) end |
#nickname ⇒ Object
39 40 41 |
# File 'lib/angry_mob/target/call.rb', line 39 def nickname klass.nickname end |
#validate_actions! ⇒ Object
43 44 45 46 47 48 49 50 51 52 53 54 |
# File 'lib/angry_mob/target/call.rb', line 43 def validate_actions! @actions = args.actions extras = actions - klass.all_actions raise(ArgumentError, "#{nickname}() unknown actions #{extras.inspect} known=#{klass.all_actions.inspect}") unless extras.empty? || extras == ['nothing'] actions << klass.default_action_name if actions.empty? if actions.norm.empty? raise ArgumentError, "#{klass.nickname}() no actions selected, and no default action defined" end end |