class AASM::Core::State

Attributes

default_display_name[R]
name[R]
options[R]
state_machine[R]

Public Class Methods

new(name, klass, state_machine, options={}) click to toggle source
# File lib/aasm/core/state.rb, line 7
def initialize(name, klass, state_machine, options={})
  @name = name
  @klass = klass
  @state_machine = state_machine
  @default_display_name = name.to_s.gsub(/_/, ' ').capitalize
  update(options)
end

Public Instance Methods

<=>(state) click to toggle source
# File lib/aasm/core/state.rb, line 36
def <=>(state)
  if state.is_a? Symbol
    name <=> state
  else
    name <=> state.name
  end
end
==(state) click to toggle source
# File lib/aasm/core/state.rb, line 28
def ==(state)
  if state.is_a? Symbol
    name == state
  else
    name == state.name
  end
end
display_name() click to toggle source
# File lib/aasm/core/state.rb, line 57
def display_name
  @display_name = begin
    if Module.const_defined?(:I18n)
      localized_name
    else
      @default_display_name
    end
  end
end
fire_callbacks(action, record, *args) click to toggle source
# File lib/aasm/core/state.rb, line 48
def fire_callbacks(action, record, *args)
  action = @options[action]
  catch :halt_aasm_chain do
    action.is_a?(Array) ?
            action.each {|a| _fire_callbacks(a, record, args)} :
            _fire_callbacks(action, record, args)
  end
end
for_select() click to toggle source
# File lib/aasm/core/state.rb, line 72
def for_select
  [display_name, name.to_s]
end
human_name()
Alias for: localized_name
initialize_copy(orig) click to toggle source

called internally by Ruby 1.9 after clone()

Calls superclass method
# File lib/aasm/core/state.rb, line 16
def initialize_copy(orig)
  super
  @options = {}
  orig.options.each_pair do |name, setting|
    @options[name] = if setting.is_a?(Hash) || setting.is_a?(Array)
                       setting.dup
                     else
                       setting
                     end
  end
end
localized_name() click to toggle source
# File lib/aasm/core/state.rb, line 67
def localized_name
  AASM::Localizer.new.human_state_name(@klass, self)
end
Also aliased as: human_name
to_s() click to toggle source
# File lib/aasm/core/state.rb, line 44
def to_s
  name.to_s
end

Private Instance Methods

_fire_callbacks(action, record, args) click to toggle source
# File lib/aasm/core/state.rb, line 86
def _fire_callbacks(action, record, args)
  Invoker.new(action, record, args).invoke
end
update(options = {}) click to toggle source
# File lib/aasm/core/state.rb, line 78
def update(options = {})
  if options.key?(:display)
    @default_display_name = options.delete(:display)
  end
  @options = options
  self
end