Class: Hobo::Model::Lifecycles::DeclarationDSL

Inherits:
Object
  • Object
show all
Defined in:
lib/hobo/model/lifecycles.rb

Instance Method Summary collapse

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, options={}, &block)
  @lifecycle.def_creator(name, block, options)
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)
  options = args.extract_options!
  names = args
  states = names.map {|name| @lifecycle.def_state(name, block) }
  if options[: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, options={}, &block)
  change.each do |k,v|
		    @lifecycle.def_transition(name, Array(k), v, block, options)
  end
end