Class: AASM::Core::State
- Inherits:
-
Object
- Object
- AASM::Core::State
- Defined in:
- lib/aasm/core/state.rb
Instance Attribute Summary collapse
-
#name ⇒ Object
readonly
Returns the value of attribute name.
-
#options ⇒ Object
readonly
Returns the value of attribute options.
-
#state_machine ⇒ Object
readonly
Returns the value of attribute state_machine.
Instance Method Summary collapse
- #<=>(state) ⇒ Object
- #==(state) ⇒ Object
- #display_name ⇒ Object
- #fire_callbacks(action, record, *args) ⇒ Object
- #for_select ⇒ Object
-
#initialize(name, klass, state_machine, options = {}) ⇒ State
constructor
A new instance of State.
- #localized_name ⇒ Object (also: #human_name)
- #to_s ⇒ Object
Constructor Details
#initialize(name, klass, state_machine, options = {}) ⇒ State
Returns a new instance of State.
5 6 7 8 9 10 |
# File 'lib/aasm/core/state.rb', line 5 def initialize(name, klass, state_machine, ={}) @name = name @klass = klass @state_machine = state_machine update() end |
Instance Attribute Details
#name ⇒ Object (readonly)
Returns the value of attribute name.
3 4 5 |
# File 'lib/aasm/core/state.rb', line 3 def name @name end |
#options ⇒ Object (readonly)
Returns the value of attribute options.
3 4 5 |
# File 'lib/aasm/core/state.rb', line 3 def end |
#state_machine ⇒ Object (readonly)
Returns the value of attribute state_machine.
3 4 5 |
# File 'lib/aasm/core/state.rb', line 3 def state_machine @state_machine end |
Instance Method Details
#<=>(state) ⇒ Object
20 21 22 23 24 25 26 |
# File 'lib/aasm/core/state.rb', line 20 def <=>(state) if state.is_a? Symbol name <=> state else name <=> state.name end end |
#==(state) ⇒ Object
12 13 14 15 16 17 18 |
# File 'lib/aasm/core/state.rb', line 12 def ==(state) if state.is_a? Symbol name == state else name == state.name end end |
#display_name ⇒ Object
41 42 43 44 45 46 47 48 49 |
# File 'lib/aasm/core/state.rb', line 41 def display_name @display_name ||= begin if Module.const_defined?(:I18n) localized_name else name.to_s.gsub(/_/, ' ').capitalize end end end |
#fire_callbacks(action, record, *args) ⇒ Object
32 33 34 35 36 37 38 39 |
# File 'lib/aasm/core/state.rb', line 32 def fire_callbacks(action, record, *args) action = [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 ⇒ Object
56 57 58 |
# File 'lib/aasm/core/state.rb', line 56 def for_select [display_name, name.to_s] end |
#localized_name ⇒ Object Also known as: human_name
51 52 53 |
# File 'lib/aasm/core/state.rb', line 51 def localized_name AASM::Localizer.new.human_state_name(@klass, self) end |
#to_s ⇒ Object
28 29 30 |
# File 'lib/aasm/core/state.rb', line 28 def to_s name.to_s end |