Module: MetaStates::Stateable

Extended by:
ActiveSupport::Concern
Defined in:
lib/meta_states/stateable.rb

Instance Method Summary collapse

Instance Method Details

#add_state(type, status: 'pending', metadata: {}, state_class: MetaStates::State) ⇒ Object

Instance methods for managing states



14
15
16
# File 'lib/meta_states/stateable.rb', line 14

def add_state(type, status: 'pending', metadata: {}, state_class: MetaStates::State)
  states.create!(type: state_class.name, state_type: type, status: status, metadata: )
end

#current_state(type) ⇒ Object



18
19
20
# File 'lib/meta_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/meta_states/stateable.rb', line 22

def current_states(type)
  states.where(state_type: type).order(created_at: :desc)
end