Sha256: 2c05bac9c1182f6251331dccac30c661908ad5d4949e50e614e930ee061e8c0c

Contents?: true

Size: 1.11 KB

Versions: 9

Compression:

Stored size: 1.11 KB

Contents

module Unidom::Action::Concerns::AsObsolescerParty

  extend  ActiveSupport::Concern
  include Unidom::Common::Concerns::ArgumentValidation

  included do |includer|

    has_many :obsolesced_obsolescings, class_name: 'Unidom::Action::Obsolescing', as: :obsolescer_party

    def obsolesce!(it, obsolescence_code: 'OBSL', due_to: nil, via: nil, at: Time.now)

      assert_present! :it, it

      obsolesced_obsolescings.create! obsolesced: it, obsolescence_code: 'OBSL', obsolescer_visitor: via, reason: due_to, opened_at: at

    end

    def obsolesce?(it, obsolescence_code: 'OBSL', due_to: nil, via: nil, at: Time.now)
      query = obsolesced_obsolescings
      query = query.obsolesced_is         it                if it.present?
      query = query.obsolesced_via        via               if via.present?
      query = query.caused_by             due_to            if due_to.present?
      query = query.obsolescence_coded_as obsolescence_code if obsolescence_code.present?
      query = query.valid_at              now: at           if at.present?
      query.alive.exists?
    end

  end

  module ClassMethods
  end

end

Version data entries

9 entries across 9 versions & 1 rubygems

Version Path
unidom-action-2.0 app/models/unidom/action/concerns/as_obsolescer_party.rb
unidom-action-1.17.18 app/models/unidom/action/concerns/as_obsolescer_party.rb
unidom-action-1.17.17 app/models/unidom/action/concerns/as_obsolescer_party.rb
unidom-action-1.17.16 app/models/unidom/action/concerns/as_obsolescer_party.rb
unidom-action-1.17.15 app/models/unidom/action/concerns/as_obsolescer_party.rb
unidom-action-1.17.13 app/models/unidom/action/concerns/as_obsolescer_party.rb
unidom-action-1.17.14 app/models/unidom/action/concerns/as_obsolescer_party.rb
unidom-action-1.17.12 app/models/unidom/action/concerns/as_obsolescer_party.rb
unidom-action-1.17.11 app/models/unidom/action/concerns/as_obsolescer_party.rb