module ActionDirector::Directable
Public Instance Methods
alike(so, *args)
click to toggle source
# File lib/action_director/directable.rb, line 53 def alike so, *args # derives a key from the subject (so), only passes succeeding arguments (args), similar to as() method, passing no key they are alike :P as key_like(so), *args end
as(key, *args)
click to toggle source
# 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] if stored stored.call *args else raise ArgumentError, "#{key.inspect}:#{key.class} did not match any condition" end end
by(key, *args)
click to toggle source
# File lib/action_director/directable.rb, line 29 def by key, *args # passes a key plus (optional) arguments as key, key, *args end
conditions()
click to toggle source
# File lib/action_director/directable.rb, line 57 def conditions # list block keys actions.keys end
for(subject, condition)
click to toggle source
# File lib/action_director/directable.rb, line 45 def for subject, condition # evaluates second argument (condition) instead of the first (subject) alike condition, subject, condition end
from(source)
click to toggle source
# 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 end
like(so, &block)
click to toggle source
# File lib/action_director/directable.rb, line 49 def like so, &block # matches and passes the subject (so), accepts only one (1) argument (so) alike so, so, block end
of(key, subject)
click to toggle source
# File lib/action_director/directable.rb, line 33 def of key, subject # passes the subject with the key as key, subject, key end
otherwise(&block)
click to toggle source
# 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)
click to toggle source
# 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)
click to toggle source
# 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)
click to toggle source
# File lib/action_director/directable.rb, line 10 def without *_conditions # removes actions _conditions.each do |key| actions.delete key end self end
Protected Instance Methods
actions()
click to toggle source
# File lib/action_director/directable.rb, line 67 def actions # blocks store @actions ||= {} end
key_like(condition)
click to toggle source
# File lib/action_director/directable.rb, line 63 def key_like condition # returns a block key matching the argument conditions.find { |key| key === condition } end