Class: ActionDirector::Directive

Inherits:
SimpleDelegator
  • Object
show all
Includes:
Directable
Defined in:
lib/action_director/directive.rb

Instance Method Summary collapse

Methods included from Directable

#alike, #as, #by, #conditions, #for, #from, #like, #of, #otherwise, #to, #with, #without

Constructor Details

#initialize(directed = nil, name = nil) ⇒ Directive

Returns a new instance of Directive.



7
8
9
10
11
# File 'lib/action_director/directive.rb', line 7

def initialize directed = nil, name = nil
  super @directed = directed
  @name = name
  @actions = {}
end

Instance Method Details

#[](condition) ⇒ Object



34
35
36
# File 'lib/action_director/directive.rb', line 34

def [](condition)
  @actions[key_like condition]
end

#accept?(condition) ⇒ Boolean

Returns:

  • (Boolean)


26
27
28
# File 'lib/action_director/directive.rb', line 26

def accept? condition
  otherwise? || recognize?(condition)
end

#inspectObject



13
14
15
# File 'lib/action_director/directive.rb', line 13

def inspect
  [@name, 'Directive'].join ' '
end

#otherwise?Boolean

Returns:

  • (Boolean)


22
23
24
# File 'lib/action_director/directive.rb', line 22

def otherwise?
  !@actions.default.nil?
end

#recognize?(condition) ⇒ Boolean

Returns:

  • (Boolean)


30
31
32
# File 'lib/action_director/directive.rb', line 30

def recognize? condition
  key_like(condition) != nil
end

#setup(&block) ⇒ Object



17
18
19
20
# File 'lib/action_director/directive.rb', line 17

def setup &block
  block.arity < 1 ? instance_eval(&block) : block.call(self) unless block.nil?
  self
end