Class: AASM::SupportingClasses::State
- Inherits:
-
Object
- Object
- AASM::SupportingClasses::State
- Defined in:
- lib/alexrevin-aasm_numerical/state.rb
Instance Attribute Summary collapse
-
#name ⇒ Object
readonly
Returns the value of attribute name.
-
#options ⇒ Object
readonly
Returns the value of attribute options.
Instance Method Summary collapse
- #==(state) ⇒ Object
- #call_action(action, record) ⇒ Object
- #display_name ⇒ Object
- #for_select ⇒ Object
-
#initialize(name, options = {}) ⇒ State
constructor
A new instance of State.
- #update(options = {}) ⇒ Object
Constructor Details
#initialize(name, options = {}) ⇒ State
Returns a new instance of State.
4 5 6 7 |
# File 'lib/alexrevin-aasm_numerical/state.rb', line 4 def initialize(name, ={}) @name = name update() end |
Instance Attribute Details
#name ⇒ Object (readonly)
Returns the value of attribute name.
2 3 4 |
# File 'lib/alexrevin-aasm_numerical/state.rb', line 2 def name @name end |
#options ⇒ Object (readonly)
Returns the value of attribute options.
2 3 4 |
# File 'lib/alexrevin-aasm_numerical/state.rb', line 2 def @options end |
Instance Method Details
#==(state) ⇒ Object
9 10 11 12 13 14 15 |
# File 'lib/alexrevin-aasm_numerical/state.rb', line 9 def ==(state) if state.is_a? Symbol name == state else name == state.name end end |
#call_action(action, record) ⇒ Object
17 18 19 20 21 22 23 24 |
# File 'lib/alexrevin-aasm_numerical/state.rb', line 17 def call_action(action, record) action = @options[action] catch :halt_aasm_chain do action.is_a?(Array) ? action.each {|a| _call_action(a, record)} : _call_action(action, record) end end |
#display_name ⇒ Object
26 27 28 |
# File 'lib/alexrevin-aasm_numerical/state.rb', line 26 def display_name @display_name ||= name.to_s.gsub(/_/, ' ').capitalize end |
#for_select ⇒ Object
30 31 32 |
# File 'lib/alexrevin-aasm_numerical/state.rb', line 30 def for_select [display_name, name.to_s] end |
#update(options = {}) ⇒ Object
34 35 36 37 38 39 40 |
# File 'lib/alexrevin-aasm_numerical/state.rb', line 34 def update( = {}) if .key?(:display) then @display_name = .delete(:display) end @options = self end |