categoryz3 0.6 → 0.7

Sign up to get free protection for your applications and to get access to all the features.
data/README.rdoc CHANGED
@@ -16,12 +16,12 @@ Fetches items in any level of subcategories with a single join.
16
16
  action_category = Categoryz3::Category.create(name: 'horror', parent: genres_category)
17
17
 
18
18
  horror_movie = Movie.find(1)
19
- horror_movie.category = cult_horror_category
19
+ horror_movie.categories << cult_horror_category
20
20
  horror_movie.categories
21
21
  #=> [cult_horror_category]
22
22
 
23
23
  action_movie = Movie.find(2)
24
- action_movie.category = action_category
24
+ action_movie.categories << action_category
25
25
 
26
26
  Movie.inside_category(genres_category).all
27
27
  #=> [horror_movie, action_movie]
@@ -54,7 +54,7 @@ Include the categorizable module in the models you want to categorize:
54
54
 
55
55
  === Listing categories from an object
56
56
 
57
- You can use the method `categories` to list all categories from a model:
57
+ You can use the relation `categories` to list all categories from a model:
58
58
 
59
59
  model.categories
60
60
  #=> [category1, category2]
@@ -68,16 +68,9 @@ You can also use the `categories_list`, this will return the categories ids:
68
68
 
69
69
  There are 2 ways for adding categories to an object:
70
70
 
71
- model.category = category
72
- model.category = [category1, category2, category3]
73
- # alias_method :categories=, :category=
74
-
75
- Replaces the object categories for the given ones.
76
-
71
+ model.categories << category
77
72
  model.categories_list = "1, 2, 3"
78
73
 
79
- Replaces the object categories for the ones with ids 1, 2 and 3.
80
-
81
74
  === Removing categories from an object
82
75
 
83
76
  To remove a category from the model, you can use the `remove_category` method:
@@ -16,35 +16,11 @@ module Categoryz3
16
16
  included do
17
17
  has_many :direct_category_items , class_name: 'Categoryz3::Item' , as: :categorizable
18
18
  has_many :child_category_items , class_name: 'Categoryz3::ChildItem' , as: :categorizable
19
+ has_many :categories, through: :direct_category_items, as: :categorizable, class_name: 'Categoryz3::Category'
19
20
  scope :inside_category , ->(category) { joins(:child_category_items).where('categoryz3_child_items.category_id = ?' , category.id) }
20
21
  scope :having_category , ->(category) { joins(:direct_category_items).where('categoryz3_items.category_id = ?' , category.id) }
21
22
  end
22
23
 
23
- # Public: List all object categories
24
- # Categories are retrieved from direct_category_items association, no subcategories included
25
- #
26
- def categories
27
- return @categories if @categories
28
- category_ids = direct_category_items.all.map { |category| category.id }
29
- @categories = Categoryz3::Category.where(id: category_ids)
30
- end
31
-
32
- # Public: Adds a category, or categories, to the model
33
- #
34
- # Examples:
35
- #
36
- # categorizable_object.category = dummy_category
37
- # categorizable_object.categories = [dummy_category1, dummy_category2]
38
- #
39
- def category=(categories)
40
- self.direct_category_items.destroy_all
41
- [categories].flatten.each do |category|
42
- category.direct_items.create(categorizable: self) if category
43
- end
44
- @categories = nil
45
- end
46
- alias_method :categories=, :category=
47
-
48
24
  # Public: Removes a category, or categories, from the model
49
25
  #
50
26
  # Examples:
@@ -1,3 +1,3 @@
1
1
  module Categoryz3
2
- VERSION = "0.6"
2
+ VERSION = "0.7"
3
3
  end
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: categoryz3
3
3
  version: !ruby/object:Gem::Version
4
- version: '0.6'
4
+ version: '0.7'
5
5
  prerelease:
6
6
  platform: ruby
7
7
  authors:
@@ -9,7 +9,7 @@ authors:
9
9
  autorequire:
10
10
  bindir: bin
11
11
  cert_chain: []
12
- date: 2012-11-02 00:00:00.000000000 Z
12
+ date: 2012-11-07 00:00:00.000000000 Z
13
13
  dependencies:
14
14
  - !ruby/object:Gem::Dependency
15
15
  name: rails
@@ -132,7 +132,7 @@ required_ruby_version: !ruby/object:Gem::Requirement
132
132
  version: '0'
133
133
  segments:
134
134
  - 0
135
- hash: 4499004963160732104
135
+ hash: 3253231323559020203
136
136
  required_rubygems_version: !ruby/object:Gem::Requirement
137
137
  none: false
138
138
  requirements:
@@ -141,7 +141,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
141
141
  version: '0'
142
142
  segments:
143
143
  - 0
144
- hash: 4499004963160732104
144
+ hash: 3253231323559020203
145
145
  requirements: []
146
146
  rubyforge_project:
147
147
  rubygems_version: 1.8.24