Sha256: 8575fafd4f37ad56ed455b5918ccf837e66c5938ea11779388fd31e5f67d90ab

Contents?: true

Size: 918 Bytes

Versions: 2

Compression:

Stored size: 918 Bytes

Contents

module Unidom::Accession::Concerns::AsPostFulfilled

  extend ActiveSupport::Concern

  included do |includer|

    has_many :post_fulfillments, class_name: 'Unidom::Accession::PostFulfillment', as:     :fulfilled
    has_many :fulfiller_people,  through:    :post_fulfillments,                   source: :fulfiller, source_type: 'Unidom::Party::Person'

    def is_fulfilled_as_post!(by: nil, at: Time.now)
      raise ArgumentError.new('The by argument is required.') if by.blank?
      raise ArgumentError.new('The at argument is required.') if at.blank?
      post_fulfillments.create! fulfiller: by, opened_at: at
    end

    def is_fulfilled_as_post?(by: nil, at: Time.now)
      raise ArgumentError.new('The by argument is required.') if by.blank?
      raise ArgumentError.new('The at argument is required.') if at.blank?
      post_fulfillments.fulfilled_by(by).valid_at(now: at).exists?
    end

  end

end

Version data entries

2 entries across 2 versions & 1 rubygems

Version Path
unidom-accession-2.2 app/models/unidom/accession/concerns/as_post_fulfilled.rb
unidom-accession-2.1 app/models/unidom/accession/concerns/as_post_fulfilled.rb