simple_date_scopes 0.1.0 → 0.1.1

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
@@ -71,6 +71,9 @@ We can now also take a field to use instead of :created\_at:
71
71
 
72
72
  # Changes
73
73
 
74
+ ## 0.1.1
75
+ * Refactoring to use a common private method instead of 3 almost identical methods
76
+
74
77
  ## 0.1.0
75
78
  * Renamed to simple\_date\_scopes so we can push to rubygems
76
79
 
@@ -10,34 +10,31 @@ module SimpleDateScopes
10
10
 
11
11
  base_class.extend(InstanceMethods)
12
12
 
13
- scope :in_week_of, ->(d,field = 'created_at') { where("#{field} BETWEEN ? AND ?",
14
- d.beginning_of_week.beginning_of_day,
15
- d.end_of_week.end_of_day ) }
13
+ scope :in_week_of, ->(d,field = 'created_at') { in_x_of(d, field, :week) }
16
14
  scope :last_week, ->(f = 'created_at') { in_week_of(Date.today - 7.days, f) }
17
15
  scope :this_week, ->(f = 'created_at') { in_week_of(Date.today, f) }
18
16
  scope :next_week, ->(f = 'created_at') { in_week_of(Date.today + 7.days, f) }
19
17
 
20
- scope :in_month_of, ->(d,field = 'created_at') { where("#{field} BETWEEN ? AND ?",
21
- d.beginning_of_month.beginning_of_day,
22
- d.end_of_month.end_of_day ) }
18
+ scope :in_month_of, ->(d,field = 'created_at') { in_x_of(d, field, :month) }
23
19
  scope :last_month, ->(f = 'created_at') { in_month_of(Date.today - 1.months, f) }
24
20
  scope :this_month, ->(f = 'created_at') { in_month_of(Date.today, f) }
25
21
  scope :next_month, ->(f = 'created_at') { in_month_of(Date.today + 1.months, f) }
26
22
 
27
- scope :in_year_of, ->(d,field = 'created_at') { where("#{field} BETWEEN ? AND ?",
28
- d.beginning_of_year.beginning_of_day,
29
- d.end_of_year.end_of_day ) }
23
+ scope :in_year_of, ->(d,field = 'created_at') { in_x_of(d, field, :year) }
30
24
  scope :last_year, ->(f = 'created_at') { in_year_of(Date.today - 1.years, f) }
31
25
  scope :this_year, ->(f = 'created_at') { in_year_of(Date.today, f) }
32
26
  scope :next_year, ->(f = 'created_at') { in_year_of(Date.today + 1.years, f) }
33
27
 
34
- private
35
- def in_x_of(date, field, method)
36
- end
37
28
  end
38
29
  end
39
30
 
40
31
  module ClassMethods
32
+ private
33
+ def in_x_of(date, field, method)
34
+ where("#{field} BETWEEN ? AND ?",
35
+ date.send("beginning_of_#{method.to_s}".to_sym).beginning_of_day,
36
+ date.send("end_of_#{method.to_s}".to_sym).end_of_day)
37
+ end
41
38
  end
42
39
 
43
40
  module InstanceMethods
@@ -11,7 +11,7 @@ shared_examples_for 'simple date scopes' do
11
11
  @new_item = kind.last
12
12
  end
13
13
 
14
- it "should have 4 items" do
14
+ it 'should have 4 items' do
15
15
  kind.count.should eq(4)
16
16
  end
17
17
 
@@ -1,3 +1,3 @@
1
1
  module SimpleDateScopes
2
- VERSION = '0.1.0'
2
+ VERSION = '0.1.1'
3
3
  end
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: simple_date_scopes
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.1.0
4
+ version: 0.1.1
5
5
  prerelease:
6
6
  platform: ruby
7
7
  authors:
@@ -160,7 +160,7 @@ required_ruby_version: !ruby/object:Gem::Requirement
160
160
  version: '0'
161
161
  segments:
162
162
  - 0
163
- hash: -2259891919373961889
163
+ hash: 2204942028803521934
164
164
  required_rubygems_version: !ruby/object:Gem::Requirement
165
165
  none: false
166
166
  requirements:
@@ -169,7 +169,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
169
169
  version: '0'
170
170
  segments:
171
171
  - 0
172
- hash: -2259891919373961889
172
+ hash: 2204942028803521934
173
173
  requirements: []
174
174
  rubyforge_project:
175
175
  rubygems_version: 1.8.23