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_models-0.5.9 lib/subj_models/brand_line.rb
subj_models-0.5.8 lib/subj_models/brand_line.rb
subj_models-0.5.7 lib/subj_models/brand_line.rb
subj_models-0.5.6 lib/subj_models/brand_line.rb
subj_models-0.5.5 lib/subj_models/brand_line.rb
subj_models-0.5.4 lib/subj_models/brand_line.rb
subj_models-0.5.3 lib/subj_models/brand_line.rb
subj_models-0.5.2 lib/subj_models/brand_line.rb
subj_models-0.5.1 lib/subj_models/brand_line.rb