Class: Transitions::State
- Inherits:
-
Object
- Object
- Transitions::State
- Defined in:
- lib/transitions/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
- #==(other) ⇒ 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.
5 6 7 8 9 10 11 |
# File 'lib/transitions/state.rb', line 5 def initialize(name, = {}) @name = name if machine = .delete(:machine) define_state_query_method(machine) end update() end |
Instance Attribute Details
#name ⇒ Object (readonly)
Returns the value of attribute name.
3 4 5 |
# File 'lib/transitions/state.rb', line 3 def name @name end |
#options ⇒ Object (readonly)
Returns the value of attribute options.
3 4 5 |
# File 'lib/transitions/state.rb', line 3 def @options end |
Instance Method Details
#==(other) ⇒ Object
13 14 15 16 17 18 19 |
# File 'lib/transitions/state.rb', line 13 def ==(other) if other.is_a? Symbol name == other else name == other.name end end |
#call_action(action, record) ⇒ Object
21 22 23 24 25 26 27 28 29 |
# File 'lib/transitions/state.rb', line 21 def call_action(action, record) action = @options[action] case action when Symbol, String record.send(action) when Proc action.call(record) end end |
#display_name ⇒ Object
31 32 33 |
# File 'lib/transitions/state.rb', line 31 def display_name @display_name ||= name.to_s.tr('_', ' ').capitalize end |
#for_select ⇒ Object
35 36 37 |
# File 'lib/transitions/state.rb', line 35 def for_select [display_name, name.to_s] end |
#update(options = {}) ⇒ Object
39 40 41 42 43 |
# File 'lib/transitions/state.rb', line 39 def update( = {}) @display_name = .delete(:display) if .key?(:display) @options = self end |