by_star 1.0.1 → 2.0.0.beta1

Sign up to get free protection for your applications and to get access to all the features.
data/.travis.yml ADDED
@@ -0,0 +1,23 @@
1
+ before_script:
2
+ - "mysql -e 'create database by_star_test;'"
3
+ - "psql -c 'create database by_star_test;' -U postgres"
4
+
5
+ env:
6
+ - DB=sqlite
7
+ - DB=mysql
8
+ - DB=postgres
9
+
10
+ script: "DISPLAY=:99.0 bundle exec rspec spec/by_star"
11
+
12
+ notifications:
13
+ email:
14
+ - radarlistener@gmail.com
15
+
16
+ branches:
17
+ only:
18
+ - master
19
+
20
+ rvm:
21
+ - 1.8.7
22
+ - 1.9.3
23
+ - 1.9.2
data/Gemfile CHANGED
@@ -1,10 +1,4 @@
1
- source :gemcutter
2
-
3
- group :test do
4
- gem 'rspec', '~> 2.6.0'
5
- gem 'mysql'
6
- gem 'sqlite3-ruby'
7
- end
1
+ source "http://rubygems.org"
8
2
 
9
3
  # Specify your gem's dependencies in by_star.gemspec
10
4
  gemspec
data/Gemfile.lock CHANGED
@@ -1,39 +1,85 @@
1
1
  PATH
2
2
  remote: .
3
3
  specs:
4
- by_star (1.0.0)
4
+ by_star (2.0.0.beta)
5
5
  activerecord (>= 2.0.0)
6
6
  chronic
7
7
 
8
8
  GEM
9
9
  remote: http://rubygems.org/
10
10
  specs:
11
- activemodel (3.0.7)
12
- activesupport (= 3.0.7)
13
- builder (~> 2.1.2)
14
- i18n (~> 0.5.0)
15
- activerecord (3.0.7)
16
- activemodel (= 3.0.7)
17
- activesupport (= 3.0.7)
18
- arel (~> 2.0.2)
19
- tzinfo (~> 0.3.23)
20
- activesupport (3.0.7)
21
- arel (2.0.10)
22
- builder (2.1.2)
23
- chronic (0.3.0)
24
- diff-lcs (1.1.2)
25
- i18n (0.5.0)
26
- mysql (2.8.1)
27
- rspec (2.6.0)
28
- rspec-core (~> 2.6.0)
29
- rspec-expectations (~> 2.6.0)
30
- rspec-mocks (~> 2.6.0)
31
- rspec-core (2.6.3)
32
- rspec-expectations (2.6.0)
11
+ actionpack (3.2.1)
12
+ activemodel (= 3.2.1)
13
+ activesupport (= 3.2.1)
14
+ builder (~> 3.0.0)
15
+ erubis (~> 2.7.0)
16
+ journey (~> 1.0.1)
17
+ rack (~> 1.4.0)
18
+ rack-cache (~> 1.1)
19
+ rack-test (~> 0.6.1)
20
+ sprockets (~> 2.1.2)
21
+ activemodel (3.2.1)
22
+ activesupport (= 3.2.1)
23
+ builder (~> 3.0.0)
24
+ activerecord (3.2.1)
25
+ activemodel (= 3.2.1)
26
+ activesupport (= 3.2.1)
27
+ arel (~> 3.0.0)
28
+ tzinfo (~> 0.3.29)
29
+ activesupport (3.2.1)
30
+ i18n (~> 0.6)
31
+ multi_json (~> 1.0)
32
+ arel (3.0.0)
33
+ builder (3.0.0)
34
+ chronic (0.6.7)
35
+ diff-lcs (1.1.3)
36
+ erubis (2.7.0)
37
+ hike (1.2.1)
38
+ i18n (0.6.0)
39
+ journey (1.0.1)
40
+ json (1.6.5)
41
+ multi_json (1.0.4)
42
+ mysql2 (0.3.11)
43
+ pg (0.13.1)
44
+ rack (1.4.1)
45
+ rack-cache (1.1)
46
+ rack (>= 0.4)
47
+ rack-ssl (1.3.2)
48
+ rack
49
+ rack-test (0.6.1)
50
+ rack (>= 1.0)
51
+ railties (3.2.1)
52
+ actionpack (= 3.2.1)
53
+ activesupport (= 3.2.1)
54
+ rack-ssl (~> 1.3.2)
55
+ rake (>= 0.8.7)
56
+ rdoc (~> 3.4)
57
+ thor (~> 0.14.6)
58
+ rake (0.9.2.2)
59
+ rdoc (3.12)
60
+ json (~> 1.4)
61
+ rspec (2.8.0)
62
+ rspec-core (~> 2.8.0)
63
+ rspec-expectations (~> 2.8.0)
64
+ rspec-mocks (~> 2.8.0)
65
+ rspec-core (2.8.0)
66
+ rspec-expectations (2.8.0)
33
67
  diff-lcs (~> 1.1.2)
34
- rspec-mocks (2.6.0)
35
- sqlite3-ruby (1.3.1)
36
- tzinfo (0.3.27)
68
+ rspec-mocks (2.8.0)
69
+ rspec-rails (2.8.1)
70
+ actionpack (>= 3.0)
71
+ activesupport (>= 3.0)
72
+ railties (>= 3.0)
73
+ rspec (~> 2.8.0)
74
+ sprockets (2.1.2)
75
+ hike (~> 1.2)
76
+ rack (~> 1.0)
77
+ tilt (~> 1.1, != 1.3.0)
78
+ sqlite3 (1.3.5)
79
+ thor (0.14.6)
80
+ tilt (1.3.3)
81
+ timecop (0.3.5)
82
+ tzinfo (0.3.31)
37
83
 
38
84
  PLATFORMS
39
85
  ruby
@@ -41,6 +87,8 @@ PLATFORMS
41
87
  DEPENDENCIES
42
88
  bundler (>= 1.0.0)
43
89
  by_star!
44
- mysql
45
- rspec (~> 2.6.0)
46
- sqlite3-ruby
90
+ mysql2
91
+ pg
92
+ rspec-rails (~> 2.8)
93
+ sqlite3
94
+ timecop (~> 0.3)
data/README.markdown CHANGED
@@ -1,7 +1,7 @@
1
1
  # by_*
2
2
 
3
3
 
4
- by_* (byStar) is a plugin that allows you to find ActiveRecord objects given certain date objects. This was originally crafted for only finding objects within a given month, but now has extended out to much more. It now supports finding objects for:
4
+ by_* (by_star) is a plugin that allows you to find ActiveRecord objects given certain date objects. This was originally crafted for only finding objects within a given month, but now has extended out to much more. It now supports finding objects for:
5
5
 
6
6
  * A given year
7
7
  * A given month
@@ -14,8 +14,6 @@ by_* (byStar) is a plugin that allows you to find ActiveRecord objects given cer
14
14
  * The Past
15
15
  * The Future
16
16
  * Between certain times
17
- * As of a certain time
18
- * Up to a certain time
19
17
  * Before a specific record
20
18
  * After a specific record
21
19
 
@@ -23,47 +21,32 @@ All methods return scopes. I love these. You love these. Everybody loves these.
23
21
 
24
22
  It also allows you to do nested finds on the records returned which I personally think is the coolest feature of the whole plugin:
25
23
 
26
- Post.by_month(1) do
27
- { :include => "tags", :conditions => ["tags.name = ?", 'ruby'] }
28
- end
24
+ Post.by_month(1).include(:tags).where("tags.name" => "ruby")
29
25
 
30
26
  If you're not using the standard `created_at` field: don't worry! I've covered that scenario too.
31
27
 
32
28
  ## Scoping the find
33
29
 
34
- You can treat all `by_*` methods exactly how you would treat `named_scope`s: they are effectively scopes in their own right. This means you are able to call them like this:
30
+ You can treat all `by_*` methods exactly how you would treat normal, every-day ActiveRecord scopes. This is because all `by_*` methods return `ActiveRecord::Relation` objects, with the exception of `previous` and `next`, which return a single record. You can call them like this:
35
31
 
36
- Post.by_month.my_special_scope
32
+ Post.by_month.your_scope
37
33
 
38
34
  Where `my_special_scope` is a `named_scope` you have specified.
39
35
 
40
- All the `by_*` methods, with the exception of `previous` and `next`, take a block which will then scope the find based on the options passed into it. You can also specify these options for each method, but the syntax may differ. The supported options are the same options that are supported by `find` from ActiveRecord. Please note that if you want to use conditions you *have* to use this syntax:
41
-
42
- Post.by_month(1) { { :include => "tags", :conditions => ["tags.name = ?", 'ruby'] } }
43
-
44
- or the lengthened:
45
-
46
- Post.by_month(1) do
47
- { :include => "tags", :conditions => ["tags.name = ?", 'ruby'] }
48
- end
49
-
50
- An alternative syntax to this is:
36
+ You can also call typical `ActiveRecord::Relation` methods on the `by_*` methods (like I showed before):
51
37
 
52
- Post.by_month(1, { :include => "tags", :conditions => ["tags.name = ?", 'ruby'] })
38
+ Post.by_month.include(:tags).where("tags.name" => "ruby")
53
39
 
40
+ Want to count records? Simple:
54
41
 
55
- ## count_by* methods
42
+ Post.by_month.count
56
43
 
57
- `count_by` methods can be scoped to only count those records which have a specific field set, and you do this by specifying the symbol version of the name of the field, e.g;
58
44
 
59
- Invoice.count_by_year(:value)
60
-
61
- If you want to specify further arguments but do not care about the scoped field:
45
+ ## By Year (`by_year`)
62
46
 
63
- Invoice.count_by_year(:all, 2009)
47
+ To find records from the current year, simply call the method without any arguments:
64
48
 
65
-
66
- ## By Year (`by_year`)
49
+ Post.by_year
67
50
 
68
51
  To find records based on a year you can pass it a two or four digit number:
69
52
 
@@ -80,36 +63,6 @@ You can also specify the full year:
80
63
  Post.by_year(2009)
81
64
  Post.by_year(1999)
82
65
 
83
- When you specify a year *less than* 1902 and *greater than* 2039 using specific versions of Ruby (i.e. 1.8.6p114) an `ArgumentError` will be raised. We recommend you upgrade Ruby to *at least* 1.8.7 to stop this problem occuring.
84
-
85
- ## Sum By Year (`sum_by_year`)
86
-
87
- To sum records for the current year based on a field:
88
-
89
- Invoice.sum_by_year(:value)
90
-
91
- To sum records for a year based on a field:
92
-
93
- Invoice.sum_by_year(:value, 09)
94
-
95
- You can also pass it a full year:
96
-
97
- Invoice.sum_by_year(:value, 2009)
98
-
99
- ## Count By Year (`count_by_year`)
100
-
101
- To count the records in the current year regardless of field:
102
-
103
- Invoice.count_by_year
104
-
105
- To count records in the current year where only a specific field is set:
106
-
107
- Invoice.count_by_year(:value)
108
-
109
- To count records in a different year regardless of field:
110
-
111
- Invoice.count_by_year(:all, :year => 2009)
112
-
113
66
  ## By Month (`by_month`)
114
67
 
115
68
  If you know the number of the month you want:
@@ -136,52 +89,9 @@ This will perform a find using the column you've specified.
136
89
 
137
90
  If you have a Time object you can use it to find the posts:
138
91
 
139
- Post.by_month(Time.local(2008, 11, 24))
140
-
141
- This will find all the posts in November 2008.
142
-
143
- When you specify a year *less than* 1902 and *greater than* 2039 using specific versions of Ruby (i.e. 1.8.6p114) an `ArgumentError` will be raised. We recommend you upgrade Ruby to *at least* 1.8.7 to stop this problem occuring.
144
-
145
-
146
- ## Sum By Month (`sum_by_month`)
147
-
148
- To sum records for the current month:
149
-
150
- Invoice.sum_by_month
151
-
152
- To sum records for a numbered month based on a field:
153
-
154
- Invoice.sum_by_month(:value, 9)
155
-
156
- You can also specify the name of the month:
157
-
158
- Invoice.sum_by_month(:value, "September")
159
-
160
- You can also lookup on a different year:
161
-
162
- Invoice.sum_by_year(:value, 9, :year => "2009")
163
-
164
- ## Count By Month (`count_by_month`)
92
+ Post.by_month(Time.local(2012, 11, 24))
165
93
 
166
- To count records for the current month regardless of field:
167
-
168
- Invoice.count_by_month
169
-
170
- To count records for the current month where only a specific field is set:
171
-
172
- Invoice.count_by_month(:value)
173
-
174
- To count records for a different month regardless of field:
175
-
176
- Invoice.count_by_month(:all, 9)
177
-
178
- To count records for a different month in the current year:
179
-
180
- Invoice.count_by_month(:number, 9)
181
-
182
- To count records for a different month in a different year:
183
-
184
- Invoice.count_by_month(:number, 9, :year => 2008)
94
+ This will find all the posts in November 2012.
185
95
 
186
96
  ## By Fortnight (`by_fortnight`)
187
97
 
@@ -197,13 +107,13 @@ To find records based on a fortnight, you can pass in a number (representing the
197
107
 
198
108
  This will return all posts in the 18th fortnight of the current year.
199
109
 
200
- Post.by_fortnight(18, :year => 2008)
110
+ Post.by_fortnight(18, :year => 2012)
201
111
 
202
- This will return all posts in the 18th fortnight week of 2008.
112
+ This will return all posts in the 18th fortnight week of 2012.
203
113
 
204
- Post.by_fortnight(Time.local(2008,1,1))
114
+ Post.by_fortnight(Time.local(2012,1,1))
205
115
 
206
- This will return all posts from the first fortnight of 2008.
116
+ This will return all posts from the first fortnight of 2012.
207
117
 
208
118
  ## By Week (`by_week`)
209
119
 
@@ -219,13 +129,13 @@ To find records based on a week, you can pass in a number (representing the week
219
129
 
220
130
  This will return all posts in the 36th week of the current year.
221
131
 
222
- Post.by_week(36, :year => 2008)
132
+ Post.by_week(36, :year => 2012)
223
133
 
224
- This will return all posts in the 36th week of 2008.
134
+ This will return all posts in the 36th week of 2012.
225
135
 
226
- Post.by_week(Time.local(2008,1,1))
136
+ Post.by_week(Time.local(2012,1,1))
227
137
 
228
- This will return all posts from the first week of 2008.
138
+ This will return all posts from the first week of 2012.
229
139
 
230
140
  ## By Weekend (`by_weekend`)
231
141
 
@@ -242,7 +152,7 @@ To find records for today:
242
152
 
243
153
  To find records for a certain day:
244
154
 
245
- Post.by_day(Time.local(2008, 1, 1))
155
+ Post.by_day(Time.local(2012, 1, 1))
246
156
 
247
157
  You can also pass a string:
248
158
 
@@ -250,33 +160,9 @@ You can also pass a string:
250
160
 
251
161
  This will return all posts for the given day.
252
162
 
253
- ## Sum By Day (`sum_by_day`)
254
-
255
-
256
- To sum records for the current day:
257
-
258
- Event.sum_by_day
259
-
260
- The `sum_by_day` method's second argument works in the same was as `by_day`, accepting Time, String, Date and chronicable strings:
261
-
262
- Event.sum_by_day(:value, Time.now)
263
- Event.sum_by_day(:value, Date.today)
264
-
265
-
266
- ## Current Weekend (`by_current_weekend`)
267
-
268
- If you are currently in a weekend (between 3pm Friday and 3am Monday) this will find all records starting at 3pm the previous Friday up until 3am, Monday.
269
-
270
- If you are not in a weekend (between 3am Monday and 3pm Friday) this will find all records from the next Friday 3pm to the following Monday 3am.
271
-
272
- ## Current Work Week (`by_current_work_week`)
273
-
274
- If you are currently in a work week (between 3am Monday and 3pm Friday) this will find all records in that range. If you are currently in a weekend (between 3pm Friday and 3am Monday) this will return all records in the upcoming work week.
275
-
276
-
277
163
  ## Tomorrow (`tomorrow`)
278
164
 
279
- *This method has been shown to be shifty when passed a `Date` object, it is recommended that you pass it a `Time` object instead.*
165
+ *This method has been shown to be shifty when passed a `Date` object, it is recommended that you pass it an `ActiveSupport::TimeWithZone` object instead.*
280
166
 
281
167
  To find all posts from the day after the current date:
282
168
 
@@ -293,7 +179,7 @@ You can also pass a string:
293
179
 
294
180
  ## Yesterday (`yesterday`)
295
181
 
296
- *This method has been shown to be shifty when passed a `Date` object, it is recommended that you pass it a `Time` object instead.*
182
+ *This method has been shown to be shifty when passed a `Date` object, it is recommended that you pass it an `ActiveSupport::TimeWithZone` object instead.*
297
183
 
298
184
  To find all posts from the day before the current date:
299
185
 
@@ -348,24 +234,6 @@ Also works with dates:
348
234
 
349
235
  Post.between(date1, date2)
350
236
 
351
- And with strings:
352
-
353
- Post.between("last tuesday", "next wednesday")
354
-
355
- ## As of (`as_of_<dynamic>`)
356
-
357
- To find records as of a certain date up until the current time:
358
-
359
- Post.as_of_2_weeks_ago
360
-
361
- This uses the Chronic "human mind reading" (read: it's really good at determining what time you mean using written English) library to work it out.
362
-
363
- ## Up to (`up_to_<dynamic>`)
364
-
365
- To find records up to a certain time from the current time:
366
-
367
- Post.up_to_6_weeks_from_now
368
-
369
237
  ## Previous (`previous`)
370
238
 
371
239
  To find the record prior to this one call `previous` on any model instance:
@@ -400,29 +268,17 @@ Or if you're doing it all the time on your model, then it's best to use `by_star
400
268
  by_star_field :something_else
401
269
  end
402
270
 
403
- ## Ordering records
404
-
405
- To order the returned set of records you may specify an `:order` option which works the same was as a standard AR `:order` option:
406
-
407
- Item.by_month(1, :order => "position DESC")
408
-
409
-
410
- ## "Chronicable string"
411
-
412
- This means a string that can be parsed with the Chronic gem.
413
-
414
271
  ## Collaborators
415
272
 
416
- Unfortunately I forget who exactly prompted me to write the plugin, but I would like to thank #rubyonrails for their support and the following people:
273
+ Thanks to Thomas Sinclair for the original bump for implementing it. I would like to thank #rubyonrails for their support and the following people:
417
274
 
418
275
  * Mislav Marohnic
419
276
  * August Lilleas (leethal)
420
277
  * gte351s
421
- * Thomase Sinclair (anathematic)
422
- * Sam Elliott (lenaryg)
423
- * The dude(s) & gal(s) who created Chronic
278
+ * Sam Elliott (lenary)
279
+ * The people who created Chronic
424
280
  * Erik Fonselius
425
281
 
426
282
  ## Suggestions?
427
283
 
428
- If you have suggestions, please contact me at radarlistener@gmail.com
284
+ If you have suggestions, please contact me at radarlistener@gmail.com