Module: ActionDirector::Directable

Included in:
Directive
Defined in:
lib/action_director/directable.rb

Instance Method Summary collapse

Instance Method Details

#alike(so, *args) ⇒ Object

derives a key from the subject (so), only passes succeeding arguments (args)



53
54
55
# File 'lib/action_director/directable.rb', line 53

def alike so, *args                    # derives a key from the subject (so), only passes succeeding arguments (args)

  as key_like(so), *args               # similar to as() method, passing no key they are alike :P

end

#as(key, *args) ⇒ Object

of the eight(8) calling methods, is the most straight forward (direct) way of calling a stored action block



20
21
22
23
24
25
26
27
# File 'lib/action_director/directable.rb', line 20

def as key, *args                      # of the eight(8) calling methods, is the most straight forward (direct) way of calling a stored action block

  stored = actions[key]                # use one (1) calling method for different directables instead of many on the same directable (Directive)

  if stored
    stored.call *args                  # here only the succeeding arguments (args) are passed (excluding key)

  else
    raise ArgumentError, "#{key.inspect}:#{key.class} did not match any condition"
  end
end

#by(key, *args) ⇒ Object

passes a key plus (optional) arguments



29
30
31
# File 'lib/action_director/directable.rb', line 29

def by key, *args                      # passes a key plus (optional) arguments

  as key, key, *args
end

#conditionsObject

list block keys



57
58
59
# File 'lib/action_director/directable.rb', line 57

def conditions                         # list block keys

  actions.keys
end

#for(subject, condition) ⇒ Object

evaluates second argument (condition) instead of the first (subject), ideal for hash conditions



45
46
47
# File 'lib/action_director/directable.rb', line 45

def for subject, condition             # evaluates second argument (condition) instead of the first (subject), ideal for hash conditions

  alike condition, subject, condition  # accepts only two (2) arguments and passes both

end

#from(source) ⇒ Object

matches (keys) and passes the subject (with matching key)



37
38
39
# File 'lib/action_director/directable.rb', line 37

def from source                        # matches (keys) and passes the subject (with matching key)

  of key_like(source), source          # accepts only one (1) argument (source), passes two (2) to the block

end

#like(so, &block) ⇒ Object

matches and passes the subject (so)



49
50
51
# File 'lib/action_director/directable.rb', line 49

def like so, &block                    # matches and passes the subject (so)

  alike so, so, block                  # accepts only one (1) argument (so)

end

#of(key, subject) ⇒ Object

passes the subject with the key



33
34
35
# File 'lib/action_director/directable.rb', line 33

def of key, subject                    # passes the subject with the key

  as key, subject, key                 # accepts only two (2) arguments

end

#otherwise(&block) ⇒ Object

assigns a default callback for when none of the conditions are met



15
16
17
18
# File 'lib/action_director/directable.rb', line 15

def otherwise &block                   # assigns a default callback for when none of the conditions are met

  actions.default = block
  self
end

#to(destination, *args) ⇒ Object

matches (keys) and passes the subject (without a key) plus (optional) arguments



41
42
43
# File 'lib/action_director/directable.rb', line 41

def to destination, *args              # matches (keys) and passes the subject (without a key) plus (optional) arguments

  alike destination, destination, *args
end

#with(*_conditions, &block) ⇒ Object

assign conditions (keys) on the same callback (block)



5
6
7
8
# File 'lib/action_director/directable.rb', line 5

def with *_conditions, &block          # assign conditions (keys) on the same callback (block)

  _conditions.each do |key| actions[key] = block end
  self
end

#without(*_conditions) ⇒ Object

removes actions



10
11
12
13
# File 'lib/action_director/directable.rb', line 10

def without *_conditions               # removes actions

  _conditions.each do |key| actions.delete key end
  self
end