Module: Spider::Model::StateMachine::ClassMethods

Defined in:
lib/spiderfw/model/mixins/state_machine.rb

Defined Under Namespace

Classes: StateEvent

Instance Attribute Summary collapse

Instance Method Summary collapse

Instance Attribute Details

#state_eventsObject (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

#element_association?(name, ass) ⇒ Boolean

Returns:

  • (Boolean)


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

#inherited(sub) ⇒ Object



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

#state(name, type, attributes = {}, &proc) ⇒ Object



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

#state_event(element_name) {|ev| ... } ⇒ Object

Yields:

  • (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