Sha256: 02a59c0a0aacb7d30a6b0fa81d5238d4cdd0957bc2ce9f890b1ca1787415dae8

Contents?: true

Size: 1.12 KB

Versions: 1

Compression:

Stored size: 1.12 KB

Contents

module Unidom
  module Category
    module Concerns
      module AsCategorized

        extend ActiveSupport::Concern

        included do |includer|

          has_many :categorizings, class_name: 'Unidom::Category::Categorizing', as:     :categorized
          has_many :categories,    through:    :categorizings,                   source: :category

          def is_categorized!(into: nil, at: Time.now, primary: true)

            raise ArgumentError('The into argument is required.') if into.blank?
            raise ArgumentError('The at argument is required.'  ) if at.blank?

            categorizings.category_is(into).valid_at(now: at).alive.first_or_create! elemental: primary, opened_at: at

          end

          def is_categorized?(into: nil, at: Time.now, primary: true)

            raise ArgumentError('The into argument is required.') if into.blank?
            raise ArgumentError('The at argument is required.'  ) if at.blank?

            categorizings.category_is(into).valid_at(now: at).alive.primary(primary).exists?

          end

        end

        module ClassMethods
        end

      end
    end
  end
end

Version data entries

1 entries across 1 versions & 1 rubygems

Version Path
unidom-category-2.0.1 app/models/unidom/category/concerns/as_categorized.rb