subj_models 0.3.6 → 0.3.7
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- checksums.yaml +4 -4
- data/lib/subj_models.rb +2 -0
- data/lib/subj_models/brand.rb +63 -0
- data/lib/subj_models/brand_line.rb +51 -0
- data/lib/subj_models/document_file.rb +2 -2
- data/lib/subj_models/version.rb +1 -1
- metadata +3 -1
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 48471a7c556f02bb0bccac66dd2623634751f9ff
|
4
|
+
data.tar.gz: 0468ce59403329aa385750a4aa42059a97d661cf
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: a9e6fab46ffcbbf3457d9d3bff072dc74ff6ec93bc7ebf03cdd3a2b9675a372549a4533b1759bf87aa33ae661ac735211dac1db896c43dde94132756825930be
|
7
|
+
data.tar.gz: 0e5085f1a165dc9861e99321bcf184124b4db105f42b438933f379677b6269ee8860f702da65d9563eaeea043c375e98684ee3b7f785587c0eed5764e096199e
|
data/lib/subj_models.rb
CHANGED
@@ -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
|
-
|
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
|
-
|
22
|
+
has_many :brands
|
23
23
|
|
24
24
|
mount_uploader :file_data, PhotoUploader
|
25
25
|
mount_uploader :alternative_file_data, PhotoUploader
|
data/lib/subj_models/version.rb
CHANGED
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.
|
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
|