Module: SubjModels::BrandLineModule

Defined in:
lib/subj_models/brand_line.rb

Class Method Summary collapse

Instance Method Summary collapse

Class Method Details

.included(including_class) ⇒ Object



8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
# File 'lib/subj_models/brand_line.rb', line 8

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

Instance Method Details

#to_sObject



45
46
47
# File 'lib/subj_models/brand_line.rb', line 45

def to_s
  name
end