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 CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: 655a4fd3e168dccb141486694c27d97cebbcf45b
4
- data.tar.gz: e49a6fa4c16e13327124a8988367063ecc5dd99f
3
+ metadata.gz: e41e4d7a1eeed5e84e2fd0cda7254154d4f0b3e8
4
+ data.tar.gz: cbd399798cdcf795b4a06a6b5b531056dc47aa0a
5
5
  SHA512:
6
- metadata.gz: 70c9cc82bd5a4dc1c6056cf9d74e6a9185eac24d82565a65d07522983d5317780b7c28b56caaadb3664eb2858b19ec7279c533023b771f6d30531b52a9e3d0df
7
- data.tar.gz: 165ecd5a0169d009807a2e3d7a567dc6297cc015670821e2f01935cc1ed900bd18353fe69071147cade904c1be7062823303f6c3d27327034c21ba1c675806f4
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
@@ -1,5 +1,5 @@
1
1
  module Unidom
2
2
  module Category
3
- VERSION = '1.0'.freeze
3
+ VERSION = '1.1'.freeze
4
4
  end
5
5
  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.0'
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-15 00:00:00.000000000 Z
11
+ date: 2016-08-29 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: unidom-common