Module: HasStates::Stateable
- Extended by:
- ActiveSupport::Concern
- Defined in:
- lib/has_states/stateable.rb
Instance Method Summary collapse
-
#add_state(type, status: 'pending', metadata: {}, state_class: HasStates::State) ⇒ Object
Instance methods for managing states.
- #current_state(type) ⇒ Object
- #current_states(type) ⇒ Object
Instance Method Details
#add_state(type, status: 'pending', metadata: {}, state_class: HasStates::State) ⇒ Object
Instance methods for managing states
14 15 16 |
# File 'lib/has_states/stateable.rb', line 14 def add_state(type, status: 'pending', metadata: {}, state_class: HasStates::State) states.create!(type: state_class.name, state_type: type, status: status, metadata: ) end |
#current_state(type) ⇒ Object
18 19 20 |
# File 'lib/has_states/stateable.rb', line 18 def current_state(type) states.where(state_type: type).order(created_at: :desc).first end |
#current_states(type) ⇒ Object
22 23 24 |
# File 'lib/has_states/stateable.rb', line 22 def current_states(type) states.where(state_type: type).order(created_at: :desc) end |