subj_models 0.3.6 → 0.3.7

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: c843f988e51f84b29497255d3a9af5a626c51531
4
- data.tar.gz: 188a7cbeb1f6aa848488cc3ce0877b98bca787a3
3
+ metadata.gz: 48471a7c556f02bb0bccac66dd2623634751f9ff
4
+ data.tar.gz: 0468ce59403329aa385750a4aa42059a97d661cf
5
5
  SHA512:
6
- metadata.gz: 20829a94029368d69c5b2715cff1e8666aae013ad950076f8e6e403152772ab3d58ee39876f2c3ffa197aca7d2a934584d5fa1ae093f6b98f7917cfde11542d0
7
- data.tar.gz: 86c7aceda4732e98de19b7ef2218ba1a906d273520bd45b84d5337b306f7a92a065ad1a690e7e9bcc9f3ea1c90bf704a25cf5b409c2b781a8764ee1f25f9d32e
6
+ metadata.gz: a9e6fab46ffcbbf3457d9d3bff072dc74ff6ec93bc7ebf03cdd3a2b9675a372549a4533b1759bf87aa33ae661ac735211dac1db896c43dde94132756825930be
7
+ data.tar.gz: 0e5085f1a165dc9861e99321bcf184124b4db105f42b438933f379677b6269ee8860f702da65d9563eaeea043c375e98684ee3b7f785587c0eed5764e096199e
data/lib/subj_models.rb CHANGED
@@ -5,6 +5,8 @@ require 'subj_models/document_file'
5
5
  require 'subj_models/manager'
6
6
  require 'subj_models/event_schedule'
7
7
  require 'subj_models/event'
8
+ require 'subj_models/brand_line'
9
+ require 'subj_models/brand'
8
10
 
9
11
  module SubjModels
10
12
 
@@ -0,0 +1,63 @@
1
+ require 'subj_models/concerns/comprising_external_id'
2
+ require 'subj_models/concerns/shared_scopes'
3
+
4
+ module SubjModels
5
+
6
+ module Brand
7
+
8
+ def self.included(including_class)
9
+
10
+ including_class.class_eval do
11
+
12
+ include SubjModels::SharedScopes
13
+ include SubjModels::ComprisingExternalId
14
+
15
+ has_many :brand_lines, dependent: :destroy
16
+ #has_many :nomenclatures
17
+ #has_many :videos
18
+
19
+ #belongs_to :content_block1, class_name: "ContentBlock"
20
+ #belongs_to :content_block2, class_name: "ContentBlock"
21
+ #belongs_to :content_block3, class_name: "ContentBlock"
22
+ belongs_to :document_file
23
+
24
+ before_validation :set_first_letter, if: :name_changed?
25
+
26
+ validates :name, presence: true
27
+
28
+ scope :category_id, -> (category_id) do
29
+ return all if category_id.blank?
30
+ joins(brand_lines: [{ nomenclatures: :category}]).where('categories.id' => category_id)
31
+ end
32
+
33
+ scope :by_first_letters, -> (by_first_letters) do
34
+ unless by_first_letters.blank?
35
+ where(first_letter: by_first_letters)
36
+ end
37
+ end
38
+
39
+ end
40
+
41
+ end
42
+
43
+ def to_s
44
+ name
45
+ end
46
+
47
+ private
48
+
49
+ def self.searchable_fields
50
+ [:name, :hidden_name]
51
+ end
52
+
53
+ def order_params
54
+ [ :order_by_name, :order_by_popularity ]
55
+ end
56
+
57
+ def set_first_letter
58
+ self.first_letter = name[0].downcase
59
+ end
60
+
61
+ end
62
+
63
+ end
@@ -0,0 +1,51 @@
1
+ require 'subj_models/concerns/comprising_external_id'
2
+ require 'subj_models/concerns/shared_scopes'
3
+
4
+ module SubjModels
5
+
6
+ module BrandLine
7
+
8
+ def self.included(including_class)
9
+
10
+ including_class.class_eval do
11
+
12
+ include SubjModels::SharedScopes
13
+ include SubjModels::ComprisingExternalId
14
+
15
+ #belongs_to :brand
16
+ belongs_to :document_file
17
+
18
+ #has_many :nomenclatures
19
+
20
+ validates :name, presence: true
21
+
22
+ scope :brand_id, -> (brand) do
23
+ return all unless brand.present?
24
+ parent_id_scope("brand", brand)
25
+ end
26
+
27
+ scope :to_show, -> () { where(show_on_index: true) }
28
+ scope :is_recommended, -> (condition) { where(is_recommended: condition) }
29
+
30
+ scope :category_id, -> (category) do
31
+ return all unless category.present?
32
+ joins(:brand, nomenclatures: :category).where('categories.id' => category)
33
+ end
34
+
35
+ scope :brand_ids, -> (brand_ids_string) do
36
+ unless brand_ids_string.blank?
37
+ joins(:brand, nomenclatures: :specialist_activity).where('brands.id' => brand_ids_string.split(','))
38
+ end
39
+ end
40
+
41
+ end
42
+
43
+ end
44
+
45
+ def to_s
46
+ name
47
+ end
48
+
49
+ end
50
+
51
+ end
@@ -12,14 +12,14 @@ module SubjModels
12
12
 
13
13
  # has_one :nomenclature_photo
14
14
  # has_one :nomenclature_file
15
- # has_one :brand_line
15
+ has_one :brand_line
16
16
  has_one :user
17
17
  has_one :manager
18
18
  # has_one :user_specialization_approval
19
19
  has_one :event
20
20
 
21
21
  # has_many :videos
22
- # has_many :brands
22
+ has_many :brands
23
23
 
24
24
  mount_uploader :file_data, PhotoUploader
25
25
  mount_uploader :alternative_file_data, PhotoUploader
@@ -1,3 +1,3 @@
1
1
  module SubjModels
2
- VERSION = "0.3.6"
2
+ VERSION = "0.3.7"
3
3
  end
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: subj_models
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.3.6
4
+ version: 0.3.7
5
5
  platform: ruby
6
6
  authors:
7
7
  - Denys Dvoriashyn
@@ -57,6 +57,8 @@ files:
57
57
  - bin/console
58
58
  - bin/setup
59
59
  - lib/subj_models.rb
60
+ - lib/subj_models/brand.rb
61
+ - lib/subj_models/brand_line.rb
60
62
  - lib/subj_models/concerns/comprising_external_id.rb
61
63
  - lib/subj_models/concerns/shared_scopes.rb
62
64
  - lib/subj_models/document_file.rb