Sha256: 2e5626fe5b34ee5e60b2d5b98dc5ed5313edc3ca5606a10a7b8613d5b1d0e1e8

Contents?: true

Size: 909 Bytes

Versions: 16

Compression:

Stored size: 909 Bytes

Contents

module Unidom::Category::Concerns::AsAncestorCategory

  extend ActiveSupport::Concern

  included do |includer|

    has_many :descendant_category_rollups, class_name: 'Unidom::Category::CategoryRollup', foreign_key: :ancestor_category_id, source: :ancestor_category
    has_many :descendant_categories,       class_name: 'Unidom::Category::Category',       through:     :descendant_category_rollups

    def roll_up!(it, at: Time.now, primary: true)
      rollup = descendant_category_rollups.descendant_category_is(it).valid_at(now: at).alive.first_or_create! elemental: primary, opened_at: at
      rollup.elemental = primary if rollup.elemental!=primary
      rollup.save!
      rollup
    end

    def roll_up?(it, at: Time.now, primary: true)
      descendant_category_rollups.descendant_category_is(it).primary(primary).valid_at(now: at).alive.exists?
    end

  end

  module ClassMethods
  end

end

Version data entries

16 entries across 16 versions & 1 rubygems

Version Path
unidom-category-2.0 app/models/unidom/category/concerns/as_ancestor_category.rb
unidom-category-1.6.8 app/models/unidom/category/concerns/as_ancestor_category.rb
unidom-category-1.6.7 app/models/unidom/category/concerns/as_ancestor_category.rb
unidom-category-1.6.6 app/models/unidom/category/concerns/as_ancestor_category.rb
unidom-category-1.6.5 app/models/unidom/category/concerns/as_ancestor_category.rb
unidom-category-1.6.4 app/models/unidom/category/concerns/as_ancestor_category.rb
unidom-category-1.6.3 app/models/unidom/category/concerns/as_ancestor_category.rb
unidom-category-1.6.2 app/models/unidom/category/concerns/as_ancestor_category.rb
unidom-category-1.6.1 app/models/unidom/category/concerns/as_ancestor_category.rb
unidom-category-1.6 app/models/unidom/category/concerns/as_ancestor_category.rb
unidom-category-1.5.5 app/models/unidom/category/concerns/as_ancestor_category.rb
unidom-category-1.5.4 app/models/unidom/category/concerns/as_ancestor_category.rb
unidom-category-1.5.3 app/models/unidom/category/concerns/as_ancestor_category.rb
unidom-category-1.5.2 app/models/unidom/category/concerns/as_ancestor_category.rb
unidom-category-1.5.1 app/models/unidom/category/concerns/as_ancestor_category.rb
unidom-category-1.5 app/models/unidom/category/concerns/as_ancestor_category.rb