Module: Spider::Model::StateMachine::ClassMethods
- Defined in:
- lib/spiderfw/model/mixins/state_machine.rb
Defined Under Namespace
Classes: StateEvent
Instance Attribute Summary (collapse)
-
- (Object) state_events
readonly
Returns the value of attribute state_events.
Instance Method Summary (collapse)
- - (Boolean) element_association?(name, ass)
- - (Object) inherited(sub)
- - (Object) state(name, type, attributes = {}, &proc)
- - (Object) state_event(element_name) {|ev| ... }
Instance Attribute Details
- (Object) state_events (readonly)
Returns the value of attribute state_events
11 12 13 |
# File 'lib/spiderfw/model/mixins/state_machine.rb', line 11 def state_events @state_events end |
Instance Method Details
- (Boolean) element_association?(name, ass)
42 43 44 45 46 47 48 |
# File 'lib/spiderfw/model/mixins/state_machine.rb', line 42 def element_association?(name, ass) el_ass = elements[name].association if (el_ass == :state) return true if ass == :choice end return super end |
- (Object) inherited(sub)
13 14 15 16 17 |
# File 'lib/spiderfw/model/mixins/state_machine.rb', line 13 def inherited(sub) super sub.extend(Spider::Model::StateMachine::ClassMethods) sub.instance_variable_set("@state_events", @state_events.clone) if @state_events end |
- (Object) state(name, type, attributes = {}, &proc)
50 51 52 53 54 |
# File 'lib/spiderfw/model/mixins/state_machine.rb', line 50 def state(name, type, attributes={}, &proc) attributes[:association] = :state raise "States must be models with one primary key" unless type.is_a?(Hash) || !type.is_a?(Spider::Model::BaseModel) || type.primary_keys.length == 1 element(name, type, attributes, &proc) end |
- (Object) state_event(element_name) {|ev| ... }
56 57 58 59 60 61 62 |
# File 'lib/spiderfw/model/mixins/state_machine.rb', line 56 def state_event(element_name) ev = StateEvent.new yield ev @state_events ||= {} @state_events[element_name] ||= [] @state_events[element_name] << ev end |