date_range_scopes 0.0.3 → 0.0.5

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.
Files changed (2) hide show
  1. data/lib/date_range_scopes.rb +36 -31
  2. metadata +7 -7
@@ -19,48 +19,53 @@ module DateRangeScopes
19
19
  # > #{updated}_today -> same as #{updated}_on(Date.today)
20
20
  # > today(date) -> same as created_on(date)
21
21
  included do
22
- date_columns = column_names.select { |col| col =~ /((_at)|(_on))\z/ }
23
-
24
- date_columns.each do |col|
25
- key = col.slice(0..-4)
26
- full_name = "#{table_name}.#{col}"
27
- date_column = col =~ /_on\z/
22
+ begin
23
+ date_columns = column_names.select { |col| col =~ /((_at)|(_on))\z/ }
28
24
 
29
- scope "#{key}_on", lambda { |time=nil|
30
- time ||= Time.zone.now
31
- time = time.respond_to?(:to_time_in_current_zone) ?
32
- time.to_time_in_current_zone : time
33
-
34
- starts_at = time.beginning_of_day
35
- ends_at = time.end_of_day
36
- if date_column
37
- starts_at = starts_at.to_date
38
- ends_at = ends_at.to_date
39
- end
40
-
41
- where "#{full_name} >= ? AND #{full_name} <= ?", starts_at, ends_at
42
- }
43
-
44
- scope "#{key}_today", send("#{key}_on")
45
-
46
- %w( week month year ).each do |period|
47
- scope "#{key}_in_#{period}", lambda { |time=nil|
25
+ date_columns.each do |col|
26
+ key = col.slice(0..-4)
27
+ full_name = "#{table_name}.#{col}"
28
+ date_column = col =~ /_on\z/
29
+
30
+ scope "#{key}_on", lambda { |time=nil|
48
31
  time ||= Time.zone.now
49
32
  time = time.respond_to?(:to_time_in_current_zone) ?
50
33
  time.to_time_in_current_zone : time
51
-
52
- starts_at = time.send("beginning_of_#{period}")
53
- ends_at = time.send("end_of_#{period}")
34
+
35
+ starts_at = time.beginning_of_day
36
+ ends_at = time.end_of_day
54
37
  if date_column
55
38
  starts_at = starts_at.to_date
56
39
  ends_at = ends_at.to_date
57
40
  end
58
-
41
+
59
42
  where "#{full_name} >= ? AND #{full_name} <= ?", starts_at, ends_at
60
43
  }
61
-
62
- scope "#{key}_this_#{period}", send("#{key}_in_#{period}")
44
+
45
+ scope "#{key}_today", send("#{key}_on")
46
+
47
+ %w( week month year ).each do |period|
48
+ scope "#{key}_in_#{period}", lambda { |time=nil|
49
+ time ||= Time.zone.now
50
+ time = time.respond_to?(:to_time_in_current_zone) ?
51
+ time.to_time_in_current_zone : time
52
+
53
+ starts_at = time.send("beginning_of_#{period}")
54
+ ends_at = time.send("end_of_#{period}")
55
+ if date_column
56
+ starts_at = starts_at.to_date
57
+ ends_at = ends_at.to_date
58
+ end
59
+
60
+ where "#{full_name} >= ? AND #{full_name} <= ?", starts_at, ends_at
61
+ }
62
+
63
+ scope "#{key}_this_#{period}", send("#{key}_in_#{period}")
64
+ end
63
65
  end
66
+
67
+ rescue
68
+ puts "Columns not available for date_range_scopes"
64
69
  end
65
70
  end
66
71
 
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: date_range_scopes
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.0.3
4
+ version: 0.0.5
5
5
  prerelease:
6
6
  platform: ruby
7
7
  authors:
@@ -9,11 +9,11 @@ authors:
9
9
  autorequire:
10
10
  bindir: bin
11
11
  cert_chain: []
12
- date: 2011-09-21 00:00:00.000000000Z
12
+ date: 2012-03-20 00:00:00.000000000 Z
13
13
  dependencies:
14
14
  - !ruby/object:Gem::Dependency
15
15
  name: rails
16
- requirement: &70186309036160 !ruby/object:Gem::Requirement
16
+ requirement: &70251478339160 !ruby/object:Gem::Requirement
17
17
  none: false
18
18
  requirements:
19
19
  - - ~>
@@ -21,10 +21,10 @@ dependencies:
21
21
  version: '3'
22
22
  type: :runtime
23
23
  prerelease: false
24
- version_requirements: *70186309036160
24
+ version_requirements: *70251478339160
25
25
  - !ruby/object:Gem::Dependency
26
26
  name: sqlite3
27
- requirement: &70186309035600 !ruby/object:Gem::Requirement
27
+ requirement: &70251476248320 !ruby/object:Gem::Requirement
28
28
  none: false
29
29
  requirements:
30
30
  - - ! '>='
@@ -32,7 +32,7 @@ dependencies:
32
32
  version: '0'
33
33
  type: :development
34
34
  prerelease: false
35
- version_requirements: *70186309035600
35
+ version_requirements: *70251476248320
36
36
  description: Automatically add scopes for day, week, month and year ranges to Active
37
37
  Record models.
38
38
  email: nick.ragaz@gmail.com
@@ -64,7 +64,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
64
64
  version: '0'
65
65
  requirements: []
66
66
  rubyforge_project:
67
- rubygems_version: 1.8.6
67
+ rubygems_version: 1.8.11
68
68
  signing_key:
69
69
  specification_version: 3
70
70
  summary: Automatically add scopes for day, week, month and year ranges to Active Record