Sha256: 306e4ef91119860c91e3aff8d917d7744fa4748bec479aa7bce482414edf0bd0

Contents?: true

Size: 1.15 KB

Versions: 49

Compression:

Stored size: 1.15 KB

Contents

require 'subj_models/concerns/comprising_external_id'
require 'subj_models/concerns/shared_scopes'

module SubjModels

  module BrandLineModule

    def self.included(including_class)

      including_class.class_eval do

        include SubjModels::SharedScopes
        include SubjModels::ComprisingExternalId

        belongs_to :brand
        belongs_to :document_file

        has_many :nomenclatures

        validates :name, presence: true

        scope :brand_id, -> (brand) do
          return all unless brand.present?
          parent_id_scope("brand", brand)
        end

        scope :to_show, -> () { where(show_on_index: true) }
        scope :is_recommended, -> (condition) { where(is_recommended: condition) }

        scope :category_id, -> (category) do
          return all unless category.present?
          joins(:brand, nomenclatures: :category).where('categories.id' => category)
        end

        scope :brand_ids, -> (brand_ids_string) do
          unless brand_ids_string.blank?
            joins(:brand).where('brands.id' => brand_ids_string.split(','))
          end
        end

      end

    end

    def to_s
      name
    end

  end

end

Version data entries

49 entries across 49 versions & 2 rubygems

Version Path
subj_sub_models-0.0.3.29 lib/subj_models/brand_line.rb
subj_sub_models-0.0.3.28 lib/subj_models/brand_line.rb
subj_sub_models-0.0.3.27 lib/subj_models/brand_line.rb
subj_sub_models-0.0.3.26 lib/subj_models/brand_line.rb
subj_sub_models-0.0.3.25 lib/subj_models/brand_line.rb
subj_sub_models-0.0.3.24 lib/subj_models/brand_line.rb
subj_sub_models-0.0.3.23 lib/subj_models/brand_line.rb
subj_sub_models-0.0.3.22 lib/subj_models/brand_line.rb
subj_sub_models-0.0.3.21 lib/subj_models/brand_line.rb
subj_sub_models-0.0.3.20 lib/subj_models/brand_line.rb
subj_sub_models-0.0.3.19 lib/subj_models/brand_line.rb
subj_sub_models-0.0.3.18 lib/subj_models/brand_line.rb
subj_sub_models-0.0.3.17 lib/subj_models/brand_line.rb
subj_sub_models-0.0.3.16 lib/subj_models/brand_line.rb
subj_sub_models-0.0.3.15 lib/subj_models/brand_line.rb
subj_sub_models-0.0.3.14 lib/subj_models/brand_line.rb
subj_sub_models-0.0.3.13 lib/subj_models/brand_line.rb
subj_sub_models-0.0.3.12 lib/subj_models/brand_line.rb
subj_sub_models-0.0.3.11 lib/subj_models/brand_line.rb
subj_sub_models-0.0.3.10 lib/subj_models/brand_line.rb