Class: AASM::SupportingClasses::State

Inherits:
Object
  • Object
show all
Defined in:
lib/aasm/state.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(name, options = {}) ⇒ State

Returns a new instance of State.



6
7
8
# File 'lib/aasm/state.rb', line 6

def initialize(name, options={})
  @name, @options = name, options
end

Instance Attribute Details

#nameObject (readonly)

Returns the value of attribute name.



4
5
6
# File 'lib/aasm/state.rb', line 4

def name
  @name
end

#optionsObject (readonly)

Returns the value of attribute options.



4
5
6
# File 'lib/aasm/state.rb', line 4

def options
  @options
end

Instance Method Details

#==(state) ⇒ Object



10
11
12
13
14
15
16
# File 'lib/aasm/state.rb', line 10

def ==(state)
  if state.is_a? Symbol
    name == state
  else
    name == state.name
  end
end

#call_action(action, record) ⇒ Object



18
19
20
21
22
23
24
25
26
27
28
# File 'lib/aasm/state.rb', line 18

def call_action(action, record)
  action = @options[action]
  case action
  when Symbol, String
    record.send(action)
  when Proc
    action.call(record)
  when Array
    action.each { |a| record.send(a) }
  end
end

#for_selectObject



30
31
32
# File 'lib/aasm/state.rb', line 30

def for_select
  [name.to_s.gsub(/_/, ' ').capitalize, name.to_s]
end