Class: Hobo::Model::Lifecycles::DeclarationDSL
- Inherits:
-
Object
- Object
- Hobo::Model::Lifecycles::DeclarationDSL
- Defined in:
- lib/hobo/model/lifecycles.rb
Instance Method Summary collapse
- #create(name, options = {}, &block) ⇒ Object
-
#initialize(lifecycle) ⇒ DeclarationDSL
constructor
A new instance of DeclarationDSL.
- #invariant(&block) ⇒ Object
- #state(*args, &block) ⇒ Object
- #transition(name, change, options = {}, &block) ⇒ Object
Constructor Details
#initialize(lifecycle) ⇒ DeclarationDSL
Returns a new instance of DeclarationDSL.
87 88 89 |
# File 'lib/hobo/model/lifecycles.rb', line 87 def initialize(lifecycle) @lifecycle = lifecycle end |
Instance Method Details
#create(name, options = {}, &block) ⇒ Object
101 102 103 |
# File 'lib/hobo/model/lifecycles.rb', line 101 def create(name, ={}, &block) @lifecycle.def_creator(name, block, ) end |
#invariant(&block) ⇒ Object
111 112 113 |
# File 'lib/hobo/model/lifecycles.rb', line 111 def invariant(&block) @lifecycle.invariants << block end |
#state(*args, &block) ⇒ Object
91 92 93 94 95 96 97 98 99 |
# File 'lib/hobo/model/lifecycles.rb', line 91 def state(*args, &block) = args. names = args states = names.map {|name| @lifecycle.def_state(name, block) } if [:default] raise ArgumentError, "you must define one state if you give the :default option" unless states.length == 1 @lifecycle.default_state = states.first end end |
#transition(name, change, options = {}, &block) ⇒ Object
105 106 107 108 109 |
# File 'lib/hobo/model/lifecycles.rb', line 105 def transition(name, change, ={}, &block) change.each do |k,v| @lifecycle.def_transition(name, Array(k), v, block, ) end end |