categoryz3 0.8.4 → 0.9.0
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/README.rdoc +2 -0
- data/app/models/categoryz3/item.rb +1 -1
- data/lib/categoryz3/categorizable.rb +30 -5
- data/lib/categoryz3/version.rb +1 -1
- metadata +5 -5
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 69526af5ee6719afe5a192596c08e14854349b0d
|
4
|
+
data.tar.gz: 2f3ceeec6fba79a8632aceb7828f5eb0841457e4
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 908aa26903456b8323248feac36cfc39e3aaba3ca6778d8976806cc62455697916e55854e38ba2e020b248f8bcfb43d2501da29c4fca2383f837406bc54a0a5a
|
7
|
+
data.tar.gz: a111b9674dbe7e13f7f8708298d8fce57aa36cb8bb31c0c2598ca7b50a0aa1ae5793982988b550f812080a51563f5acecb12614ad6eca3ba6be6b1b797b66021
|
data/README.rdoc
CHANGED
@@ -2,6 +2,8 @@
|
|
2
2
|
{<img src="https://secure.travis-ci.org/tscolari/categoryz3.png" />}[http://travis-ci.org/tscolari/categoryz3]
|
3
3
|
{<img src="https://codeclimate.com/badge.png" />}[https://codeclimate.com/github/tscolari/categoryz3]
|
4
4
|
|
5
|
+
__Version 0.9+ is rails4 compatible__
|
6
|
+
|
5
7
|
Simple categorization to ActiveRecord models.
|
6
8
|
|
7
9
|
Works like a simple tagging system, but instead of tags it has categories, and categories may have an ilimited level of subcategories.
|
@@ -21,7 +21,7 @@ module Categoryz3
|
|
21
21
|
# Private: Creates a child item for the category
|
22
22
|
#
|
23
23
|
def create_child_item_for_category(category)
|
24
|
-
category.child_items.
|
24
|
+
category.child_items.find_or_create_by(categorizable_type: self.categorizable.class.base_class.name, categorizable_id: self.categorizable.id, master_item_id: self.id)
|
25
25
|
end
|
26
26
|
|
27
27
|
# Private: Create a child_item for each subcategory the category from this item have
|
@@ -14,11 +14,36 @@ module Categoryz3
|
|
14
14
|
module Categorizable
|
15
15
|
extend ActiveSupport::Concern
|
16
16
|
included do
|
17
|
-
has_many :direct_category_items
|
18
|
-
|
19
|
-
|
20
|
-
|
21
|
-
|
17
|
+
has_many :direct_category_items,
|
18
|
+
class_name: 'Categoryz3::Item',
|
19
|
+
as: :categorizable,
|
20
|
+
inverse_of: :categorizable
|
21
|
+
|
22
|
+
has_many :child_category_items,
|
23
|
+
class_name: 'Categoryz3::ChildItem',
|
24
|
+
as: :categorizable,
|
25
|
+
inverse_of: :categorizable
|
26
|
+
|
27
|
+
has_many :categories,
|
28
|
+
through: :direct_category_items,
|
29
|
+
source: 'category',
|
30
|
+
class_name: 'Categoryz3::Category'
|
31
|
+
|
32
|
+
has_many :all_categories,
|
33
|
+
through: :child_category_items,
|
34
|
+
source: 'category',
|
35
|
+
class_name: 'Categoryz3::Category'
|
36
|
+
|
37
|
+
has_many :root_categories,
|
38
|
+
through: :child_category_items,
|
39
|
+
source: 'category',
|
40
|
+
class_name: 'Categoryz3::Category',
|
41
|
+
conditions: { parent_id: nil }
|
42
|
+
|
43
|
+
scope :inside_category ,
|
44
|
+
->(category) { joins(:child_category_items).where('categoryz3_child_items.category_id = ?' , category.id) }
|
45
|
+
scope :having_category ,
|
46
|
+
->(category) { joins(:direct_category_items).where('categoryz3_items.category_id = ?' , category.id) }
|
22
47
|
end
|
23
48
|
|
24
49
|
# Public: Removes a category, or categories, from the model
|
data/lib/categoryz3/version.rb
CHANGED
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: categoryz3
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.
|
4
|
+
version: 0.9.0
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Tiago Scolari
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date: 2013-
|
11
|
+
date: 2013-10-27 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: rails
|
@@ -16,14 +16,14 @@ dependencies:
|
|
16
16
|
requirements:
|
17
17
|
- - '>='
|
18
18
|
- !ruby/object:Gem::Version
|
19
|
-
version:
|
19
|
+
version: 4.0.0
|
20
20
|
type: :runtime
|
21
21
|
prerelease: false
|
22
22
|
version_requirements: !ruby/object:Gem::Requirement
|
23
23
|
requirements:
|
24
24
|
- - '>='
|
25
25
|
- !ruby/object:Gem::Version
|
26
|
-
version:
|
26
|
+
version: 4.0.0
|
27
27
|
- !ruby/object:Gem::Dependency
|
28
28
|
name: rspec-rails
|
29
29
|
requirement: !ruby/object:Gem::Requirement
|
@@ -126,7 +126,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
|
|
126
126
|
version: '0'
|
127
127
|
requirements: []
|
128
128
|
rubyforge_project:
|
129
|
-
rubygems_version: 2.0.
|
129
|
+
rubygems_version: 2.0.3
|
130
130
|
signing_key:
|
131
131
|
specification_version: 4
|
132
132
|
summary: Simple categorization to ActiveRecord models.
|