Class: AngryMob::Target::Call

Inherits:
Object
  • Object
show all
Defined in:
lib/angry_mob/target/call.rb

Instance Attribute Summary collapse

Class Method Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(klass, args) ⇒ Call

Returns a new instance of Call.



7
8
9
10
11
# File 'lib/angry_mob/target/call.rb', line 7

def initialize(klass,args)
  @klass = klass
  @args  = Arguments.parse(args)
  validate_actions!
end

Instance Attribute Details

#actionsObject (readonly)

Returns the value of attribute actions.



4
5
6
# File 'lib/angry_mob/target/call.rb', line 4

def actions
  @actions
end

#argsObject (readonly)

Returns the value of attribute args.



4
5
6
# File 'lib/angry_mob/target/call.rb', line 4

def args
  @args
end

#klassObject (readonly)

Returns the value of attribute klass.



4
5
6
# File 'lib/angry_mob/target/call.rb', line 4

def klass
  @klass
end

#targetObject

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_key(klass, args) ⇒ Object



13
14
15
# File 'lib/angry_mob/target/call.rb', line 13

def self.instance_key(klass,args)
  klass.instance_key(Arguments.parse(args))
end

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_keyObject



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

#nicknameObject



39
40
41
# File 'lib/angry_mob/target/call.rb', line 39

def nickname
  klass.nickname
end

#validate_actions!Object

Raises:

  • (ArgumentError)


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