unidom-category 1.0 → 1.1
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/README.md +14 -1
- data/app/models/unidom/category/category.rb +6 -0
- data/lib/unidom/category/version.rb +1 -1
- metadata +2 -2
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: e41e4d7a1eeed5e84e2fd0cda7254154d4f0b3e8
|
4
|
+
data.tar.gz: cbd399798cdcf795b4a06a6b5b531056dc47aa0a
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 107829d2a32ade295954b14eb752dc3330a362c0fb4489a283599aab99a41649e5252476b4c373256afe1bfa248232f9aadc0d1eb1426cf4421838f6f1ed4300
|
7
|
+
data.tar.gz: e7512d4c70d4a17194c887933689477b895fea5e7d11db676c24f419345a4f970f7fab2e6e2f957037038b9dcb0435ee6f520aa17b373f02259245f29e0c7009
|
data/README.md
CHANGED
@@ -23,8 +23,21 @@ The migration versions start with 200003.
|
|
23
23
|
|
24
24
|
## Call the Model
|
25
25
|
```ruby
|
26
|
-
Unidom::Category::Category.coded_as('x1').scheme_is(scheme).valid_at.alive.first
|
26
|
+
@category = Unidom::Category::Category.coded_as('x1').scheme_is(scheme).valid_at.alive.first
|
27
27
|
Unidom::Category::Categorizing.categorize! product, into: category, at: Time.now
|
28
28
|
|
29
29
|
Unidom::Category::CategoryRollup.roll_up! child_category, into: parent_category, at: Time.now
|
30
|
+
|
31
|
+
# Add the @product into the @category.
|
32
|
+
@category.categorize! @product, primary: true
|
30
33
|
```
|
34
|
+
|
35
|
+
## Include the Concerns
|
36
|
+
```ruby
|
37
|
+
include Unidom::Category::Concerns::AsCategorized
|
38
|
+
```
|
39
|
+
|
40
|
+
### As Categorized concern
|
41
|
+
The As Categorized concern do the following tasks for the includer automatically:
|
42
|
+
1. Define the has_many :categorizings macro as: ``has_many :categorizings, class_name: 'Unidom::Category::Categorizing', as: :categorized``
|
43
|
+
2. Define the has_many :categories macro as: ``has_many :categories, through: :categorizings, source: :category``
|
@@ -23,4 +23,10 @@ class Unidom::Category::Category < ActiveRecord::Base
|
|
23
23
|
scope :code_length_is, ->(length) { where 'LENGTH(code) = :code_length', code_length: length }
|
24
24
|
scope :code_starting_with, ->(prefix) { where 'code LIKE :prefix_expression', prefix_expression: prefix+'%' }
|
25
25
|
|
26
|
+
def categorize!(categorized, primary: false, at: Time.now)
|
27
|
+
raise ArgumentError('The categorized argument is required.') if categorized.blank?
|
28
|
+
raise ArgumentError('The at argument is required.' ) if at.blank?
|
29
|
+
categorizings.create! categorized: categorized, elemental: primary, opened_at: at
|
30
|
+
end
|
31
|
+
|
26
32
|
end
|
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: unidom-category
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: '1.
|
4
|
+
version: '1.1'
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Topbit Du
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date: 2016-08-
|
11
|
+
date: 2016-08-29 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: unidom-common
|