Sha256: 88e71d3b4f7bf88491184cff72339a98493c683e8ff222b1fc9279b5545af900

Contents?: true

Size: 1.01 KB

Versions: 35

Compression:

Stored size: 1.01 KB

Contents

module Unidom::Action::Concerns::AsStateTransitorParty

  extend ActiveSupport::Concern

  included do |includer|

    has_many :transited_state_transitions, class_name: 'Unidom::Action::StateTransition', as: :transitor_party

    def transit!(it, from: nil, thru: nil, due_to: nil, via: nil, at: Time.now)
      transited_state_transitions.create! subject: it, from_state: from, thru_state: thru, transitor_visitor: via, reason: due_to, opened_at: at
    end

    def transit?(it, from: nil, thru: nil, due_to: nil, via: nil, at: Time.now)
      query = transited_state_transitions
      query = query.subject_is        it      if it.present?
      query = query.transited_via     via     if via.present?
      query = query.from_transited_to from    if from.present?
      query = query.thru_transited_to thru    if thru.present?
      query = query.caused_by         due_to  if due_to.present?
      query = query.valid_at          now: at if at.present?
      query.alive.exists?
    end

  end

  module ClassMethods
  end

end

Version data entries

35 entries across 35 versions & 1 rubygems

Version Path
unidom-action-2.0 app/models/unidom/action/concerns/as_state_transitor_party.rb
unidom-action-1.17.18 app/models/unidom/action/concerns/as_state_transitor_party.rb
unidom-action-1.17.17 app/models/unidom/action/concerns/as_state_transitor_party.rb
unidom-action-1.17.16 app/models/unidom/action/concerns/as_state_transitor_party.rb
unidom-action-1.17.15 app/models/unidom/action/concerns/as_state_transitor_party.rb
unidom-action-1.17.13 app/models/unidom/action/concerns/as_state_transitor_party.rb
unidom-action-1.17.14 app/models/unidom/action/concerns/as_state_transitor_party.rb
unidom-action-1.17.12 app/models/unidom/action/concerns/as_state_transitor_party.rb
unidom-action-1.17.11 app/models/unidom/action/concerns/as_state_transitor_party.rb
unidom-action-1.17.10 app/models/unidom/action/concerns/as_state_transitor_party.rb
unidom-action-1.17.9 app/models/unidom/action/concerns/as_state_transitor_party.rb
unidom-action-1.17.8 app/models/unidom/action/concerns/as_state_transitor_party.rb
unidom-action-1.17.7 app/models/unidom/action/concerns/as_state_transitor_party.rb
unidom-action-1.17.6 app/models/unidom/action/concerns/as_state_transitor_party.rb
unidom-action-1.17.5 app/models/unidom/action/concerns/as_state_transitor_party.rb
unidom-action-1.17.4 app/models/unidom/action/concerns/as_state_transitor_party.rb
unidom-action-1.17.3 app/models/unidom/action/concerns/as_state_transitor_party.rb
unidom-action-1.17.2 app/models/unidom/action/concerns/as_state_transitor_party.rb
unidom-action-1.17.1 app/models/unidom/action/concerns/as_state_transitor_party.rb
unidom-action-1.17 app/models/unidom/action/concerns/as_state_transitor_party.rb