unidom-category 1.1 → 1.2

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 CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: e41e4d7a1eeed5e84e2fd0cda7254154d4f0b3e8
4
- data.tar.gz: cbd399798cdcf795b4a06a6b5b531056dc47aa0a
3
+ metadata.gz: 93576c414117bd512f8cc34e2f744098d23f4306
4
+ data.tar.gz: 17bae303105dae01da620ec1f3a43d9ed7f96e9d
5
5
  SHA512:
6
- metadata.gz: 107829d2a32ade295954b14eb752dc3330a362c0fb4489a283599aab99a41649e5252476b4c373256afe1bfa248232f9aadc0d1eb1426cf4421838f6f1ed4300
7
- data.tar.gz: e7512d4c70d4a17194c887933689477b895fea5e7d11db676c24f419345a4f970f7fab2e6e2f957037038b9dcb0435ee6f520aa17b373f02259245f29e0c7009
6
+ metadata.gz: e98a45ffb2ce9c06fcdadbc17ef584de584bd21f71f856dd2bdefce3c0757691aed825f671f83f72df4ec6da0c6416ed8256a285ae508ef47b730afb47a6b6d2
7
+ data.tar.gz: 15decf5e34ddb8572a3069179f82b5838cd47deca2a65e2701e0daf29cc78b4df05be965033f601446c26f7d947b68f6056f64156cfaceee85b9345ee05e70de
data/README.md CHANGED
@@ -35,9 +35,18 @@ Unidom::Category::CategoryRollup.roll_up! child_category, into: parent_category,
35
35
  ## Include the Concerns
36
36
  ```ruby
37
37
  include Unidom::Category::Concerns::AsCategorized
38
+ include Unidom::Category::Concerns::AsCategory
38
39
  ```
39
40
 
41
+ ### As Category concern
42
+ The As Category concern do the following tasks for the includer automatically:
43
+ 1. Define the has_many :categorizings macro as: ``has_many :categorizings, class_name: 'Category::Categorizing'``
44
+ 2. Define the #categorize! method as: ``categorize!(categorized, at: Time.now, primary: true)``
45
+ 3. Define the #categorize? method as: ``categorize?(categorized, at: Time.now, primary: true)``
46
+
40
47
  ### As Categorized concern
41
48
  The As Categorized concern do the following tasks for the includer automatically:
42
49
  1. Define the has_many :categorizings macro as: ``has_many :categorizings, class_name: 'Unidom::Category::Categorizing', as: :categorized``
43
50
  2. Define the has_many :categories macro as: ``has_many :categories, through: :categorizings, source: :category``
51
+ 3. Define the #is_categorized! method as: ``is_categorized!(into: nil, at: Time.now, primary: true)``
52
+ 4. Define the #is_categorized? method as: ``is_categorized?(into: nil, at: Time.now, primary: true)``
@@ -17,7 +17,7 @@ class Unidom::Category::Categorizing < ActiveRecord::Base
17
17
  #end
18
18
 
19
19
  def self.categorize!(categorized, into: nil, at: Time.now)
20
- self.categorized_is(categorized).category_is(into).valid_at.alive.first_or_create! elemental: true, opened_at: at
20
+ categorized_is(categorized).category_is(into).valid_at.alive.first_or_create! elemental: true, opened_at: at
21
21
  end
22
22
 
23
23
  end
@@ -5,6 +5,7 @@ class Unidom::Category::Category < ActiveRecord::Base
5
5
  self.table_name = 'unidom_categories'
6
6
 
7
7
  include Unidom::Common::Concerns::ModelExtension
8
+ include Unidom::Category::Concerns::AsCategory
8
9
 
9
10
  validates :name, presence: true, length: { in: 2..self.columns_hash['name'].limit }
10
11
  validates :abbreviation, allow_blank: true, length: { in: 2..self.columns_hash['abbreviation'].limit }
@@ -17,16 +18,8 @@ class Unidom::Category::Category < ActiveRecord::Base
17
18
  has_many :descendant_category_rollups, class_name: 'Unidom::Category::CategoryRollup', foreign_key: :ancestor_category_id, source: :ancestor_category
18
19
  has_many :descendant_categories, class_name: 'Unidom::Category::Category', through: :descendant_category_rollups
19
20
 
20
- has_many :categorizings, class_name: 'Category::Categorizing'
21
-
22
21
  scope :scheme_is, ->(scheme) { where scheme_id: (scheme.respond_to?(:id) ? scheme.id : scheme ) }
23
22
  scope :code_length_is, ->(length) { where 'LENGTH(code) = :code_length', code_length: length }
24
23
  scope :code_starting_with, ->(prefix) { where 'code LIKE :prefix_expression', prefix_expression: prefix+'%' }
25
24
 
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
-
32
25
  end
@@ -2,11 +2,29 @@ module Unidom::Category::Concerns::AsCategorized
2
2
 
3
3
  extend ActiveSupport::Concern
4
4
 
5
- self.included do |includer|
5
+ included do |includer|
6
6
 
7
7
  has_many :categorizings, class_name: 'Unidom::Category::Categorizing', as: :categorized
8
8
  has_many :categories, through: :categorizings, source: :category
9
9
 
10
+ def is_categorized!(into: nil, at: Time.now, primary: true)
11
+
12
+ raise ArgumentError('The into argument is required.') if into.blank?
13
+ raise ArgumentError('The at argument is required.' ) if at.blank?
14
+
15
+ categorizings.category_is(into).valid_at(now: at).alive.first_or_create! elemental: primary, opened_at: at
16
+
17
+ end
18
+
19
+ def is_categorized?(into: nil, at: Time.now, primary: true)
20
+
21
+ raise ArgumentError('The into argument is required.') if into.blank?
22
+ raise ArgumentError('The at argument is required.' ) if at.blank?
23
+
24
+ categorizings.category_is(into).valid_at(now: at).alive.primary(primary).exists?
25
+
26
+ end
27
+
10
28
  end
11
29
 
12
30
  end
@@ -0,0 +1,29 @@
1
+ module Unidom::Category::Concerns::AsCategory
2
+
3
+ extend ActiveSupport::Concern
4
+
5
+ included do |includer|
6
+
7
+ has_many :categorizings, class_name: 'Category::Categorizing'
8
+
9
+ def categorize!(categorized, at: Time.now, primary: true)
10
+
11
+ raise ArgumentError('The categorized argument is required.') if categorized.blank?
12
+ raise ArgumentError('The at argument is required.' ) if at.blank?
13
+
14
+ categorizings.categorized_is(categorized).valid_at(now: at).alive.first_or_create! elemental: primary, opened_at: at
15
+
16
+ end
17
+
18
+ def categorize?(categorized, at: Time.now, primary: true)
19
+
20
+ raise ArgumentError('The categorized argument is required.') if categorized.blank?
21
+ raise ArgumentError('The at argument is required.' ) if at.blank?
22
+
23
+ categorizings.categorized_is(categorized).valid_at(now: at).alive.primary(primary).exists?
24
+
25
+ end
26
+
27
+ end
28
+
29
+ end
@@ -1,5 +1,5 @@
1
1
  module Unidom
2
2
  module Category
3
- VERSION = '1.1'.freeze
3
+ VERSION = '1.2'.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.1'
4
+ version: '1.2'
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-29 00:00:00.000000000 Z
11
+ date: 2016-09-09 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: unidom-common
@@ -45,6 +45,7 @@ files:
45
45
  - app/models/unidom/category/category_rollup.rb
46
46
  - app/models/unidom/category/category_scheme.rb
47
47
  - app/models/unidom/category/concerns/as_categorized.rb
48
+ - app/models/unidom/category/concerns/as_category.rb
48
49
  - app/views/layouts/unidom/category/application.html.erb
49
50
  - config/routes.rb
50
51
  - db/migrate/20000301000000_create_unidom_category_schemes.rb