Module: AASM::ClassMethods

Defined in:
lib/aasm/aasm.rb

Instance Method Summary collapse

Instance Method Details

#aasm_event(name, options = {}, &block) ⇒ Object



53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
# File 'lib/aasm/aasm.rb', line 53

def aasm_event(name, options = {}, &block)
  sm = AASM::StateMachine[self]

  unless sm.events.has_key?(name)
    sm.events[name] = AASM::SupportingClasses::Event.new(name, options, &block)
  end

  define_method("#{name.to_s}!") do |*args|
    aasm_fire_event(name, true, *args)
  end

  define_method("#{name.to_s}") do |*args|
    aasm_fire_event(name, false, *args)
  end
end

#aasm_eventsObject



73
74
75
# File 'lib/aasm/aasm.rb', line 73

def aasm_events
  AASM::StateMachine[self].events
end

#aasm_initial_state(set_state = nil) ⇒ Object



31
32
33
34
35
36
37
# File 'lib/aasm/aasm.rb', line 31

def aasm_initial_state(set_state=nil)
  if set_state
    AASM::StateMachine[self].initial_state = set_state
  else
    AASM::StateMachine[self].initial_state
  end
end

#aasm_initial_state=(state) ⇒ Object



39
40
41
# File 'lib/aasm/aasm.rb', line 39

def aasm_initial_state=(state)
  AASM::StateMachine[self].initial_state = state
end

#aasm_state(name, options = {}) ⇒ Object



43
44
45
46
47
48
49
50
51
# File 'lib/aasm/aasm.rb', line 43

def aasm_state(name, options={})
  sm = AASM::StateMachine[self]
  sm.create_state(name, options)
  sm.initial_state = name unless sm.initial_state

  define_method("#{name.to_s}?") do
    aasm_current_state == name
  end
end

#aasm_statesObject



69
70
71
# File 'lib/aasm/aasm.rb', line 69

def aasm_states
  AASM::StateMachine[self].states
end

#aasm_states_for_selectObject



77
78
79
# File 'lib/aasm/aasm.rb', line 77

def aasm_states_for_select
  AASM::StateMachine[self].states.map { |state| state.for_select }
end

#inherited(klass) ⇒ Object



26
27
28
29
# File 'lib/aasm/aasm.rb', line 26

def inherited(klass)
  AASM::StateMachine[klass] = AASM::StateMachine[self].clone
  super
end