Sha256: f2781fbefb9619142778785917b885f130715d593aa24553c2469d8976699175
Contents?: true
Size: 719 Bytes
Versions: 1
Compression:
Stored size: 719 Bytes
Contents
# frozen_string_literal: true module HasStates module Stateable extend ActiveSupport::Concern included do has_many :states, class_name: 'HasStates::Base', as: :stateable, dependent: :destroy end # Instance methods for managing states def add_state(type, status: 'pending', metadata: {}, state_class: HasStates::State) states.create!(type: state_class.name, state_type: type, status: status, metadata: metadata) end def current_state(type) states.where(state_type: type).order(created_at: :desc).first end def current_states(type) states.where(state_type: type).order(created_at: :desc) end end end
Version data entries
1 entries across 1 versions & 1 rubygems
Version | Path |
---|---|
stateful_models-0.0.3 | lib/has_states/stateable.rb |