mongoid_max_denormalize 0.0.6 → 0.0.7

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.
data/README.md CHANGED
@@ -31,7 +31,9 @@ Or install with RubyGems:
31
31
 
32
32
  Add `include Mongoid::Max::Denormalize` in your model and also:
33
33
 
34
- denormalize relation, field_1, field_2 ... field_n, options
34
+ ```ruby
35
+ denormalize :relation, :field_1, :field_2 ... :field_n, :options_1 => :value, :options_2 => :value
36
+ ```
35
37
 
36
38
 
37
39
  ### Warming up
@@ -49,39 +51,43 @@ Note: you can't warm up from both sides of the relation. Only the most efficient
49
51
 
50
52
  #### Example:
51
53
 
52
- class Post
53
- include Mongoid::Document
54
+ ```ruby
55
+ class Post
56
+ include Mongoid::Document
54
57
 
55
- field :title
58
+ field :title
56
59
 
57
- def slug
58
- title.try(:parameterize)
59
- end
60
+ def slug
61
+ title.try(:parameterize)
62
+ end
60
63
 
61
- has_many :comments
62
- end
64
+ has_many :comments
65
+ end
63
66
 
64
- class Comment
65
- include Mongoid::Document
66
- include Mongoid::Max::Denormalize
67
+ class Comment
68
+ include Mongoid::Document
69
+ include Mongoid::Max::Denormalize
67
70
 
68
- belongs_to :post
69
- denormalize :post, :title, :slug
70
- end
71
+ belongs_to :post
72
+ denormalize :post, :title, :slug
73
+ end
71
74
 
72
- @post = Post.create(:title => "Mush from the Wimp")
73
- @comment = @post.comments.create
74
- @comment.post_title #=> "Mush from the Wimp"
75
- @comment.post_slug #=> "mush-from-the-wimp"
75
+ @post = Post.create(:title => "Mush from the Wimp")
76
+ @comment = @post.comments.create
77
+ @comment.post_title #=> "Mush from the Wimp"
78
+ @comment.post_slug #=> "mush-from-the-wimp"
76
79
 
77
- @post.update_attributes(:title => "All Must Share The Burden")
78
- @comment.reload # to reload the comment from the DB
79
- @comment.post_title #=> "All Must Share The Burden"
80
- @comment.post_slug #=> "all-must-share-the-burden"
80
+ @post.update_attributes(:title => "All Must Share The Burden")
81
+ @comment.reload # to reload the comment from the DB
82
+ @comment.post_title #=> "All Must Share The Burden"
83
+ @comment.post_slug #=> "all-must-share-the-burden"
84
+ ```
81
85
 
82
86
  To warm up the denormalization for an existing collection:
83
87
 
84
- Post.denormalize_to_comments!
88
+ ```ruby
89
+ Post.denormalize_to_comments!
90
+ ```
85
91
 
86
92
  **Tips :** In your views, do not use `@comment.post` but `@comment.post_id` or `@comment.post_id?`
87
93
  to avoid a query that checks/retrieve for the post. We want to avoid it, don't we ?
@@ -105,6 +111,7 @@ This is better :
105
111
  </div>
106
112
 
107
113
 
114
+
108
115
  ### Many to One
109
116
 
110
117
  **Supported fields:** only normal Mongoid fields, no methods *(optionnal)*
@@ -116,64 +123,72 @@ This is better :
116
123
 
117
124
  #### Example:
118
125
 
119
- class Post
120
- include Mongoid::Document
121
- include Mongoid::Max::Denormalize
126
+ ```ruby
127
+ class Post
128
+ include Mongoid::Document
129
+ include Mongoid::Max::Denormalize
122
130
 
123
- has_many :comments
124
- denormalize :comments, :rating, :stuff, :count => true
125
- end
131
+ has_many :comments
132
+ denormalize :comments, :rating, :stuff, :count => true
133
+ end
126
134
 
127
- class Comment
128
- include Mongoid::Document
135
+ class Comment
136
+ include Mongoid::Document
129
137
 
130
- belongs_to :post
138
+ belongs_to :post
131
139
 
132
- field :rating
133
- field :stuff
134
- end
140
+ field :rating
141
+ field :stuff
142
+ end
135
143
 
136
- @post = Post.create
137
- @comment = @post.comments.create(:rating => 5, :stuff => "A")
138
- @comment = @post.comments.create(:rating => 3, :stuff => "B")
139
- @post.reload
140
- @post.comments_count #=> 2
141
- @post.comments_rating #=> [5, 3]
142
- @post.comments_stuff #=> ["A", "B"]
144
+ @post = Post.create
145
+ @comment = @post.comments.create(:rating => 5, :stuff => "A")
146
+ @comment = @post.comments.create(:rating => 3, :stuff => "B")
147
+ @post.reload
148
+ @post.comments_count #=> 2
149
+ @post.comments_rating #=> [5, 3]
150
+ @post.comments_stuff #=> ["A", "B"]
151
+ ```
143
152
 
144
153
  To warm up the denormalization for an existing collection:
145
154
 
146
- Post.denormalize_from_comments!
155
+ ```ruby
156
+ Post.denormalize_from_comments!
157
+ ```
147
158
 
148
159
  You can see that each denormalized field in stored in a separate array. This is wanted.
149
160
  An option `:group` will come to allow the way below (and maybe permit methods denormalization) :
150
161
 
151
- @post.comments_fields #=> [{:rating => 5, :stuff => "A"}, {:rating => 5, :stuff => "B"}]
162
+ ```ruby
163
+ @post.comments_fields #=> [{:rating => 5, :stuff => "A"}, {:rating => 5, :stuff => "B"}]
164
+ ```
152
165
 
153
166
  #### Example 2: only count
154
167
 
155
- class Post
156
- include Mongoid::Document
157
- include Mongoid::Max::Denormalize
168
+ ```ruby
169
+ class Post
170
+ include Mongoid::Document
171
+ include Mongoid::Max::Denormalize
158
172
 
159
- has_many :comments
160
- denormalize :comments, :count => true
161
- end
173
+ has_many :comments
174
+ denormalize :comments, :count => true
175
+ end
162
176
 
163
- class Comment
164
- include Mongoid::Document
177
+ class Comment
178
+ include Mongoid::Document
165
179
 
166
- belongs_to :post
167
- end
180
+ belongs_to :post
181
+ end
168
182
 
169
- @post = Post.create
170
- @comment = @post.comments.create
171
- @comment = @post.comments.create
172
- @post.reload
173
- @post.comments_count #=> 2
183
+ @post = Post.create
184
+ @comment = @post.comments.create
185
+ @comment = @post.comments.create
186
+ @post.reload
187
+ @post.comments_count #=> 2
188
+ ```
174
189
 
175
190
 
176
- ### Many to One
191
+ ### Many to Many
177
192
 
178
193
  To come...
179
194
 
@@ -61,7 +61,7 @@ module Mongoid
61
61
  to_set[:"#{relation}_\#{field}"] = send(field)
62
62
  end
63
63
 
64
- #{inverse_relation}.update to_set
64
+ #{inverse_relation}.update_all(to_set) unless to_set.empty?
65
65
  end
66
66
  EOM
67
67
 
@@ -89,7 +89,7 @@ module Mongoid
89
89
  to_set[:"#{relation}_\#{field}"] = nil
90
90
  end
91
91
 
92
- #{inverse_relation}.update(to_set) unless to_set.empty?
92
+ #{inverse_relation}.update_all(to_set) unless to_set.empty?
93
93
  end
94
94
  EOM
95
95
  end
@@ -4,7 +4,7 @@ module Mongoid
4
4
  module Denormalize
5
5
  module Version
6
6
 
7
- STRING = '0.0.6'
7
+ STRING = '0.0.7'
8
8
 
9
9
  end
10
10
  end
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: mongoid_max_denormalize
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.0.6
4
+ version: 0.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-06-15 00:00:00.000000000 Z
12
+ date: 2012-10-01 00:00:00.000000000 Z
13
13
  dependencies:
14
14
  - !ruby/object:Gem::Dependency
15
15
  name: mongoid
@@ -87,19 +87,19 @@ files:
87
87
  - README.md
88
88
  - LICENSE
89
89
  - lib/mongoid_max_denormalize.rb
90
- - lib/mongoid/max/denormalize/one_to_many.rb
91
- - lib/mongoid/max/denormalize/config_error.rb
90
+ - lib/mongoid/max/denormalize.rb
91
+ - lib/mongoid/max/denormalize/base.rb
92
92
  - lib/mongoid/max/denormalize/version.rb
93
93
  - lib/mongoid/max/denormalize/many_to_one.rb
94
- - lib/mongoid/max/denormalize/base.rb
95
- - lib/mongoid/max/denormalize.rb
94
+ - lib/mongoid/max/denormalize/config_error.rb
95
+ - lib/mongoid/max/denormalize/one_to_many.rb
96
96
  - spec/lib/mongoid_max_denormalize_spec.rb
97
- - spec/cases/city_and_inhabitants_spec.rb
98
- - spec/cases/song_and_ratings_spec.rb
99
- - spec/cases/existing_models_spec.rb
97
+ - spec/spec_helper.rb
100
98
  - spec/cases/contact_and_addresses_spec.rb
99
+ - spec/cases/song_and_ratings_spec.rb
101
100
  - spec/cases/post_and_comments_spec.rb
102
- - spec/spec_helper.rb
101
+ - spec/cases/city_and_inhabitants_spec.rb
102
+ - spec/cases/existing_models_spec.rb
103
103
  homepage: http://github.com/maximeg/mongoid_max_denormalize
104
104
  licenses: []
105
105
  post_install_message:
@@ -112,18 +112,12 @@ required_ruby_version: !ruby/object:Gem::Requirement
112
112
  - - ! '>='
113
113
  - !ruby/object:Gem::Version
114
114
  version: '0'
115
- segments:
116
- - 0
117
- hash: -1176296074452929639
118
115
  required_rubygems_version: !ruby/object:Gem::Requirement
119
116
  none: false
120
117
  requirements:
121
118
  - - ! '>='
122
119
  - !ruby/object:Gem::Version
123
120
  version: '0'
124
- segments:
125
- - 0
126
- hash: -1176296074452929639
127
121
  requirements: []
128
122
  rubyforge_project:
129
123
  rubygems_version: 1.8.24
@@ -132,9 +126,9 @@ specification_version: 3
132
126
  summary: MaxMapper, polyvalent ORM for Rails
133
127
  test_files:
134
128
  - spec/lib/mongoid_max_denormalize_spec.rb
135
- - spec/cases/city_and_inhabitants_spec.rb
136
- - spec/cases/song_and_ratings_spec.rb
137
- - spec/cases/existing_models_spec.rb
129
+ - spec/spec_helper.rb
138
130
  - spec/cases/contact_and_addresses_spec.rb
131
+ - spec/cases/song_and_ratings_spec.rb
139
132
  - spec/cases/post_and_comments_spec.rb
140
- - spec/spec_helper.rb
133
+ - spec/cases/city_and_inhabitants_spec.rb
134
+ - spec/cases/existing_models_spec.rb