Sha256: 2fee0dc710586c4529938716bdadfa57d4cae732af25f2e2a2871de0fc0a4c2f

Contents?: true

Size: 1011 Bytes

Versions: 6

Compression:

Stored size: 1011 Bytes

Contents

module Unidom::ArticleNumber::Concerns::AsBarcode

  extend ActiveSupport::Concern

  included do |includer|

    has_many :markings,        class_name: 'Unidom::ArticleNumber::Marking', as:     :barcode
    has_many :marked_products, through:    :markings,                        source: :marked, source_type: 'Unidom::Product::Product'

    def mark!(marked, by: nil, at: Time.now)
      raise ArgumentError.new('The marked argument is required.') if marked.blank?
      raise ArgumentError.new('The by argument is required.'    ) if by.blank?
      raise ArgumentError.new('The at argument is required.'    ) if at.blank?
      markings.create! marked: marked, marker: by, opened_at: at
    end

    def mark?(marked, at: Time.now)
      raise ArgumentError.new('The marked argument is required.') if marked.blank?
      raise ArgumentError.new('The at argument is required.'    ) if at.blank?
      markings.marked_is(marked).valid_at(now: at).alive.exists?
    end

  end

  module ClassMethods
  end

end

Version data entries

6 entries across 6 versions & 1 rubygems

Version Path
unidom-article_number-2.2.1 app/models/unidom/article_number/concerns/as_barcode.rb
unidom-article_number-2.2 app/models/unidom/article_number/concerns/as_barcode.rb
unidom-article_number-2.1 app/models/unidom/article_number/concerns/as_barcode.rb
unidom-article_number-2.0.2 app/models/unidom/article_number/concerns/as_barcode.rb
unidom-article_number-2.0.1 app/models/unidom/article_number/concerns/as_barcode.rb
unidom-article_number-2.0 app/models/unidom/article_number/concerns/as_barcode.rb