mongoid_taggable_with_context 1.1.3 → 1.1.4

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,7 +1,15 @@
1
1
  ---
2
- SHA1:
3
- metadata.gz: 186f1d14401b1a4813ba9f0a59bf5ecc6747379d
4
- data.tar.gz: 42ea2145a014a4cc59c4bfb3b18b353dadc4fdfd
2
+ !binary "U0hBMQ==":
3
+ metadata.gz: !binary |-
4
+ YzBkNGIxYzNiZTIyMTQxMGVlY2Q4NThlOWZhYzA1NDA1ZTM2ZjZhNA==
5
+ data.tar.gz: !binary |-
6
+ NWNiOTU2ZWE2MzQ5ZDNiMDY3YTY5M2FiNDk4ZWE5NzhmOThiOTViOQ==
5
7
  SHA512:
6
- metadata.gz: 3e06dede604cb1fdf85110065a3c537411e937fa29eaf41ae55afb73052cfea5e0857930d24460f1098eb4a93ea9267f22e5f1ffc03b086bb51932bb3215f276
7
- data.tar.gz: 42bdc3e64da2950a37ad4e8947aff8a1804bc075ac791653b833916d9759c8b0720b5ba242cc12882ce615c4cef2e0fa4726476226c5ecd6669a0965724836d1
8
+ metadata.gz: !binary |-
9
+ YzJhZDQyMGJjZDM5M2MwMTc2NzNlYmY1ODA2YTZkYTViMWVkYWE4MTUyN2Fm
10
+ NjIzZjY1MmQwOWRiMmI5YWZjMTVkODdmYWM2YmQ0MGQwYWQ1YWE5ZjMxYTky
11
+ NzIyZDgzOWQzNmE5NmFhYTU2MzQwYWU1OGM3MDg1YmY3NTBiZTM=
12
+ data.tar.gz: !binary |-
13
+ MTlkMDQ5YTkxNmI1MDEyZTFlODAwZDJjNTA0NmEwMWU0ODM2NjhlNjUxYmFj
14
+ NzBmN2NiMmVlNWM5YzJjZmI5N2RhOTM4ZjdiNzJjMTZiYTk1YTMyYTY1M2My
15
+ MGU1MGQwZDgyNGFjMTAzOGZlMTNkM2RjMWZhMWQxMGJiMDI2N2M=
data/.document CHANGED
@@ -1,5 +1,5 @@
1
- lib/**/*.rb
2
- bin/*
3
- -
4
- features/**/*.feature
5
- LICENSE.txt
1
+ lib/**/*.rb
2
+ bin/*
3
+ -
4
+ features/**/*.feature
5
+ LICENSE.txt
@@ -1,7 +1,7 @@
1
- language: ruby
2
- bundler_args: --without development
3
- rvm:
4
- - 1.9.3
5
- - 2.0.0
6
- services:
7
- - mongodb
1
+ language: ruby
2
+ bundler_args: --without development
3
+ rvm:
4
+ - 1.9.3
5
+ - 2.0.0
6
+ services:
7
+ - mongodb
data/Gemfile CHANGED
@@ -1,12 +1,12 @@
1
- source 'http://rubygems.org'
2
-
3
- gem 'mongoid', '>= 3.0.0'
4
-
5
- group :test, :development do
6
- gem 'rake'
7
- gem 'rspec'
8
- gem 'yard'
9
- gem 'bundler', '>= 1.0.0'
10
- gem 'jeweler'
11
- end
12
-
1
+ source 'http://rubygems.org'
2
+
3
+ gem 'mongoid', '>= 3.0.0'
4
+
5
+ group :test, :development do
6
+ gem 'rake'
7
+ gem 'rspec'
8
+ gem 'yard'
9
+ gem 'bundler', '>= 1.0.0'
10
+ gem 'jeweler'
11
+ end
12
+
@@ -1,20 +1,20 @@
1
- Copyright (c) 2011 Aaron Qian
2
-
3
- Permission is hereby granted, free of charge, to any person obtaining
4
- a copy of this software and associated documentation files (the
5
- "Software"), to deal in the Software without restriction, including
6
- without limitation the rights to use, copy, modify, merge, publish,
7
- distribute, sublicense, and/or sell copies of the Software, and to
8
- permit persons to whom the Software is furnished to do so, subject to
9
- the following conditions:
10
-
11
- The above copyright notice and this permission notice shall be
12
- included in all copies or substantial portions of the Software.
13
-
14
- THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
15
- EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
16
- MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
17
- NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
18
- LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
19
- OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
20
- WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
1
+ Copyright (c) 2011 Aaron Qian
2
+
3
+ Permission is hereby granted, free of charge, to any person obtaining
4
+ a copy of this software and associated documentation files (the
5
+ "Software"), to deal in the Software without restriction, including
6
+ without limitation the rights to use, copy, modify, merge, publish,
7
+ distribute, sublicense, and/or sell copies of the Software, and to
8
+ permit persons to whom the Software is furnished to do so, subject to
9
+ the following conditions:
10
+
11
+ The above copyright notice and this permission notice shall be
12
+ included in all copies or substantial portions of the Software.
13
+
14
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
15
+ EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
16
+ MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
17
+ NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
18
+ LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
19
+ OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
20
+ WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
data/README.md CHANGED
@@ -1,223 +1,223 @@
1
- mongoid_taggable_with_context
2
- =============================
3
-
4
- [![Build Status](https://secure.travis-ci.org/lgs/mongoid_taggable_with_context.png?branch=master)](http://travis-ci.org/lgs/mongoid_taggable_with_context) [![Dependency Status](https://gemnasium.com/lgs/mongoid_taggable_with_context.png?travis)](https://gemnasium.com/lgs/mongoid_taggable_with_context)
5
- [![Code Climate](https://codeclimate.com/github/lgs/mongoid_taggable_with_context.png)](https://codeclimate.com/github/lgs/mongoid_taggable_with_context)
6
-
7
- A tagging lib for Mongoid that allows for custom tagging along dynamic contexts. This gem was originally based on [mongoid_taggable](https://github.com/ches/mongoid_taggable) by Wilker Lúcio and Ches Martin. It has evolved substantially since that point, but all credit goes to them for the initial tagging functionality.
8
-
9
- For instance, in a social network, a user might have tags that are called skills, interests, sports, and more. There is no real way to differentiate between tags and so an implementation of this type is not possible with `mongoid_taggable`.
10
-
11
- Another example, aggregation such as counting tag occurrences was achieved by map-reduce with `mongoid_taggable`. It was ok for small amount of tags, but when the amount of tags and documents grow, the original `mongoid_taggable` won't be able to scale to real-time statistics demand.
12
-
13
- Enter `mongoid_taggable_with_context`. Rather than tying functionality to a specific keyword (namely "tags"), `mongoid_taggable_with_context` allows you to specify an arbitrary number of *tag contexts* that can be used locally or in combination in the same way `mongoid_taggable` was used.
14
-
15
- `mongoid_taggable_with_context` also provides flexibility on aggregation strategy. In addition to the map-reduce strategy, this gem also comes with real-time strategy. By using real-time strategy, your document can quickly adjusts the aggregation collection whenever tags are inserted or removed with $inc operator. So performance won't be impacted as the number of tags and documents grow.
16
-
17
- Installation
18
- ------------
19
-
20
- You can simply install from rubygems:
21
-
22
- ```
23
- gem install mongoid_taggable_with_context
24
- ```
25
-
26
- or in Gemfile:
27
-
28
- ```ruby
29
- gem 'mongoid_taggable_with_context'
30
- ```
31
-
32
-
33
- The "taggable" Macro Function
34
- -----------------------------
35
-
36
- Use the `taggable` macro function in your model to
37
- declare a tags field. Specify `field name`
38
- for tags, and `options` for tagging behavior.
39
-
40
- Example:
41
-
42
- ```ruby
43
- class Article
44
- include Mongoid::Document
45
- include Mongoid::TaggableWithContext
46
- taggable :keywords, separator: ' ', default: ['foobar']
47
- end
48
- ```
49
-
50
- * `@param [ Symbol ] field`
51
-
52
- (Optional) The name of the field for tags. Defaults to "tags"
53
-
54
-
55
- * `@param [ Hash ] options`
56
-
57
- (Optional) Options for taggable behavior.
58
-
59
-
60
- * `@option [ String ] :separator`
61
-
62
- The delimiter used when converting the tags to and from String format. Defaults to " "
63
-
64
-
65
- * `@option [ :Symbol ] :group_by_field`
66
-
67
- The Mongoid field to group by when RealTimeGroupBy aggregation is used.
68
-
69
-
70
- * `@option [ <various> ] :default, :as, :localize, etc.`
71
-
72
- Options for Mongoid #field method will be automatically passed
73
- to the underlying Array field (with the exception of `:type`,
74
- which is coerced to `Array`).
75
-
76
-
77
- Example Usage
78
- -------------
79
-
80
- To make a document taggable you need to include Mongoid::TaggableOnContext
81
- into your document and call the *taggable* macro with optional arguments:
82
-
83
- ```ruby
84
- class Post
85
- include Mongoid::Document
86
- include Mongoid::TaggableWithContext
87
-
88
- field :title
89
- field :content
90
-
91
- # default context is 'tags'.
92
- # This creates #tags, #tags=, #tag_string instance methods
93
- # separator is " " by default
94
- # #tags method returns an array of tags
95
- # #tags= methods accepts an array of tags or a separated string
96
- # #tag_string method returns a separated string
97
- taggable
98
-
99
- # tagging for 'skills' context.
100
- # This creates #skills, #skills=, #skills_string instance methods
101
- # changing tag separator to "," (Default is " ")
102
- taggable :skills, separator: ','
103
-
104
- # aliased context tagging.
105
- # This creates #interests, #interests=, #interests_string instance methods
106
- # The tags will be stored in a database field called 'ints'
107
- taggable :ints, as: :interests
108
- end
109
- ```
110
-
111
- Then in your form, for example:
112
-
113
- ```rhtml
114
- <% form_for @post do |f| %>
115
- <p>
116
- <%= f.label :title %><br />
117
- <%= f.text_field :title %>
118
- </p>
119
- <p>
120
- <%= f.label :content %><br />
121
- <%= f.text_area :content %>
122
- </p>
123
- <p>
124
- <%= f.label :tags %><br />
125
- <%= text_field_tag 'post[tags]' %>
126
- </p>
127
- <p>
128
- <%= f.label :interests %><br />
129
- <%= text_field_tag 'post[interests]' %>
130
- </p>
131
- <p>
132
- <%= f.label :skills %><br />
133
- <%= text_field_tag 'post[skills]' %>
134
- </p>
135
- <p>
136
- <button type="submit">Send</button>
137
- </p>
138
- <% end %>
139
- ```
140
-
141
-
142
- Aggregation Strategies
143
- ----------------------
144
-
145
- By including an aggregation strategy in your document, tag aggregations will be automatically available to you.
146
- This lib presents the following aggregation strategies:
147
-
148
- * MapReduce
149
- * RealTime
150
- * RealTimeGroupBy
151
-
152
- The following document will automatically aggregate counts on all tag contexts.
153
-
154
- ```ruby
155
- class Post
156
- include Mongoid::Document
157
- include Mongoid::TaggableWithContext
158
-
159
- # automatically adds real time aggregations to all tag contexts
160
- include Mongoid::TaggableWithContext::AggregationStrategy::RealTime
161
-
162
- # alternatively for map-reduce
163
- # include Mongoid::TaggableWithContext::AggregationStrategy::MapReduce
164
-
165
- field :title
166
- field :content
167
-
168
- taggable
169
- taggable :skills, separator: ','
170
- taggable :ints, as: interests
171
- end
172
- ```
173
-
174
- When you include an aggregation strategy, your document also gains a few extra methods to retrieve aggregation data.
175
- In the case of previous example the following methods are included:
176
-
177
- ```ruby
178
- Post.tags
179
- Post.tags_with_weight
180
- Post.interests
181
- Post.interests_with_weight
182
- Post.skills
183
- Post.skills_with_weight
184
- ```
185
-
186
- Here is how to use these methods in more detail:
187
-
188
- ```ruby
189
- Post.create!(tags: "food,ant,bee")
190
- Post.create!(tags: "juice,food,bee,zip")
191
- Post.create!(tags: "honey,strip,food")
192
-
193
- Post.tags # will retrieve ["ant", "bee", "food", "honey", "juice", "strip", "zip"]
194
- Post.tags_with_weight # will retrieve:
195
- # [
196
- # ['ant', 1],
197
- # ['bee', 2],
198
- # ['food', 3],
199
- # ['honey', 1],
200
- # ['juice', 1],
201
- # ['strip', 1],
202
- # ['zip', 1]
203
- # ]
204
- ```
205
-
206
-
207
- Contributing to mongoid_taggable_with_context
208
- -----------------------------------------------
209
-
210
- * Check out the latest master to make sure the feature hasn't been implemented or the bug hasn't been fixed yet
211
- * Check out the issue tracker to make sure someone already hasn't requested it and/or contributed it
212
- * Fork the project
213
- * Start a feature/bugfix branch
214
- * Commit and push until you are happy with your contribution
215
- * Make sure to add tests for it. This is important so I don't break it in a future version unintentionally.
216
- * Please try not to mess with the Rakefile, version, or history. If you want to have your own version, or is otherwise necessary, that is fine, but please isolate to its own commit so I can cherry-pick around it.
217
-
218
-
219
- Copyright
220
- ---------
221
-
222
- Copyright (c) 2011 Aaron Qian. See LICENSE.txt for
223
- further details.
1
+ mongoid_taggable_with_context
2
+ =============================
3
+
4
+ [![Build Status](https://secure.travis-ci.org/lgs/mongoid_taggable_with_context.png?branch=master)](http://travis-ci.org/lgs/mongoid_taggable_with_context) [![Dependency Status](https://gemnasium.com/lgs/mongoid_taggable_with_context.png?travis)](https://gemnasium.com/lgs/mongoid_taggable_with_context)
5
+ [![Code Climate](https://codeclimate.com/github/lgs/mongoid_taggable_with_context.png)](https://codeclimate.com/github/lgs/mongoid_taggable_with_context)
6
+
7
+ A tagging lib for Mongoid that allows for custom tagging along dynamic contexts. This gem was originally based on [mongoid_taggable](https://github.com/ches/mongoid_taggable) by Wilker Lúcio and Ches Martin. It has evolved substantially since that point, but all credit goes to them for the initial tagging functionality.
8
+
9
+ For instance, in a social network, a user might have tags that are called skills, interests, sports, and more. There is no real way to differentiate between tags and so an implementation of this type is not possible with `mongoid_taggable`.
10
+
11
+ Another example, aggregation such as counting tag occurrences was achieved by map-reduce with `mongoid_taggable`. It was ok for small amount of tags, but when the amount of tags and documents grow, the original `mongoid_taggable` won't be able to scale to real-time statistics demand.
12
+
13
+ Enter `mongoid_taggable_with_context`. Rather than tying functionality to a specific keyword (namely "tags"), `mongoid_taggable_with_context` allows you to specify an arbitrary number of *tag contexts* that can be used locally or in combination in the same way `mongoid_taggable` was used.
14
+
15
+ `mongoid_taggable_with_context` also provides flexibility on aggregation strategy. In addition to the map-reduce strategy, this gem also comes with real-time strategy. By using real-time strategy, your document can quickly adjusts the aggregation collection whenever tags are inserted or removed with $inc operator. So performance won't be impacted as the number of tags and documents grow.
16
+
17
+ Installation
18
+ ------------
19
+
20
+ You can simply install from rubygems:
21
+
22
+ ```
23
+ gem install mongoid_taggable_with_context
24
+ ```
25
+
26
+ or in Gemfile:
27
+
28
+ ```ruby
29
+ gem 'mongoid_taggable_with_context'
30
+ ```
31
+
32
+
33
+ The "taggable" Macro Function
34
+ -----------------------------
35
+
36
+ Use the `taggable` macro function in your model to
37
+ declare a tags field. Specify `field name`
38
+ for tags, and `options` for tagging behavior.
39
+
40
+ Example:
41
+
42
+ ```ruby
43
+ class Article
44
+ include Mongoid::Document
45
+ include Mongoid::TaggableWithContext
46
+ taggable :keywords, separator: ' ', default: ['foobar']
47
+ end
48
+ ```
49
+
50
+ * `@param [ Symbol ] field`
51
+
52
+ (Optional) The name of the field for tags. Defaults to "tags"
53
+
54
+
55
+ * `@param [ Hash ] options`
56
+
57
+ (Optional) Options for taggable behavior.
58
+
59
+
60
+ * `@option [ String ] :separator`
61
+
62
+ The delimiter used when converting the tags to and from String format. Defaults to " "
63
+
64
+
65
+ * `@option [ :Symbol ] :group_by_field`
66
+
67
+ The Mongoid field to group by when RealTimeGroupBy aggregation is used.
68
+
69
+
70
+ * `@option [ <various> ] :default, :as, :localize, etc.`
71
+
72
+ Options for Mongoid #field method will be automatically passed
73
+ to the underlying Array field (with the exception of `:type`,
74
+ which is coerced to `Array`).
75
+
76
+
77
+ Example Usage
78
+ -------------
79
+
80
+ To make a document taggable you need to include Mongoid::TaggableOnContext
81
+ into your document and call the *taggable* macro with optional arguments:
82
+
83
+ ```ruby
84
+ class Post
85
+ include Mongoid::Document
86
+ include Mongoid::TaggableWithContext
87
+
88
+ field :title
89
+ field :content
90
+
91
+ # default context is 'tags'.
92
+ # This creates #tags, #tags=, #tag_string instance methods
93
+ # separator is " " by default
94
+ # #tags method returns an array of tags
95
+ # #tags= methods accepts an array of tags or a separated string
96
+ # #tag_string method returns a separated string
97
+ taggable
98
+
99
+ # tagging for 'skills' context.
100
+ # This creates #skills, #skills=, #skills_string instance methods
101
+ # changing tag separator to "," (Default is " ")
102
+ taggable :skills, separator: ','
103
+
104
+ # aliased context tagging.
105
+ # This creates #interests, #interests=, #interests_string instance methods
106
+ # The tags will be stored in a database field called 'ints'
107
+ taggable :ints, as: :interests
108
+ end
109
+ ```
110
+
111
+ Then in your form, for example:
112
+
113
+ ```rhtml
114
+ <% form_for @post do |f| %>
115
+ <p>
116
+ <%= f.label :title %><br />
117
+ <%= f.text_field :title %>
118
+ </p>
119
+ <p>
120
+ <%= f.label :content %><br />
121
+ <%= f.text_area :content %>
122
+ </p>
123
+ <p>
124
+ <%= f.label :tags %><br />
125
+ <%= text_field_tag 'post[tags]' %>
126
+ </p>
127
+ <p>
128
+ <%= f.label :interests %><br />
129
+ <%= text_field_tag 'post[interests]' %>
130
+ </p>
131
+ <p>
132
+ <%= f.label :skills %><br />
133
+ <%= text_field_tag 'post[skills]' %>
134
+ </p>
135
+ <p>
136
+ <button type="submit">Send</button>
137
+ </p>
138
+ <% end %>
139
+ ```
140
+
141
+
142
+ Aggregation Strategies
143
+ ----------------------
144
+
145
+ By including an aggregation strategy in your document, tag aggregations will be automatically available to you.
146
+ This lib presents the following aggregation strategies:
147
+
148
+ * MapReduce
149
+ * RealTime
150
+ * RealTimeGroupBy
151
+
152
+ The following document will automatically aggregate counts on all tag contexts.
153
+
154
+ ```ruby
155
+ class Post
156
+ include Mongoid::Document
157
+ include Mongoid::TaggableWithContext
158
+
159
+ # automatically adds real time aggregations to all tag contexts
160
+ include Mongoid::TaggableWithContext::AggregationStrategy::RealTime
161
+
162
+ # alternatively for map-reduce
163
+ # include Mongoid::TaggableWithContext::AggregationStrategy::MapReduce
164
+
165
+ field :title
166
+ field :content
167
+
168
+ taggable
169
+ taggable :skills, separator: ','
170
+ taggable :ints, as: interests
171
+ end
172
+ ```
173
+
174
+ When you include an aggregation strategy, your document also gains a few extra methods to retrieve aggregation data.
175
+ In the case of previous example the following methods are included:
176
+
177
+ ```ruby
178
+ Post.tags
179
+ Post.tags_with_weight
180
+ Post.interests
181
+ Post.interests_with_weight
182
+ Post.skills
183
+ Post.skills_with_weight
184
+ ```
185
+
186
+ Here is how to use these methods in more detail:
187
+
188
+ ```ruby
189
+ Post.create!(tags: "food,ant,bee")
190
+ Post.create!(tags: "juice,food,bee,zip")
191
+ Post.create!(tags: "honey,strip,food")
192
+
193
+ Post.tags # will retrieve ["ant", "bee", "food", "honey", "juice", "strip", "zip"]
194
+ Post.tags_with_weight # will retrieve:
195
+ # [
196
+ # ['ant', 1],
197
+ # ['bee', 2],
198
+ # ['food', 3],
199
+ # ['honey', 1],
200
+ # ['juice', 1],
201
+ # ['strip', 1],
202
+ # ['zip', 1]
203
+ # ]
204
+ ```
205
+
206
+
207
+ Contributing to mongoid_taggable_with_context
208
+ -----------------------------------------------
209
+
210
+ * Check out the latest master to make sure the feature hasn't been implemented or the bug hasn't been fixed yet
211
+ * Check out the issue tracker to make sure someone already hasn't requested it and/or contributed it
212
+ * Fork the project
213
+ * Start a feature/bugfix branch
214
+ * Commit and push until you are happy with your contribution
215
+ * Make sure to add tests for it. This is important so I don't break it in a future version unintentionally.
216
+ * Please try not to mess with the Rakefile, version, or history. If you want to have your own version, or is otherwise necessary, that is fine, but please isolate to its own commit so I can cherry-pick around it.
217
+
218
+
219
+ Copyright
220
+ ---------
221
+
222
+ Copyright (c) 2011 Aaron Qian. See LICENSE.txt for
223
+ further details.