date_scopable 0.0.2 → 0.0.3

Sign up to get free protection for your applications and to get access to all the features.
@@ -13,6 +13,7 @@ module DateScopable
13
13
  # User.on Date.parse("4/7/2011")
14
14
  # User.last_7_days
15
15
  # User.last_month
16
+ # User.in_month_year(12,1999)
16
17
  # User.between(Date.parse("4/1/2011"), Date.parse("4/5/2011"))
17
18
  #
18
19
  # Usage: Ensure that the path to this module is autoloadable in
@@ -32,42 +33,49 @@ module DateScopable
32
33
  # Show all objects created today
33
34
  #
34
35
  scope :today, lambda {
35
- where("created_at > ?", Time.now.beginning_of_day)
36
+ where("created_at >= ?", Time.now.beginning_of_day)
36
37
  }
37
38
 
38
39
  ##
39
40
  # Show all objects created yesterday
40
41
  #
41
42
  scope :yesterday, lambda {
42
- where("created_at > ? AND created_at < ?", Date.yesterday.beginning_of_day, Date.yesterday.end_of_day)
43
+ where("created_at >= ? AND created_at <= ?", Date.yesterday.beginning_of_day, Date.yesterday.end_of_day)
43
44
  }
44
45
 
45
46
  ##
46
47
  # Show all objects created on a specific day
47
48
  #
48
49
  scope :on, lambda { |day|
49
- where("created_at > ? AND created_At < ?", day.beginning_of_day, day.end_of_day)
50
+ where("created_at >= ? AND created_at <= ?", day.beginning_of_day, day.end_of_day)
50
51
  }
51
52
 
52
53
  ##
53
54
  # Show all objects created in the last seven days
54
55
  #
55
56
  scope :last_7_days, lambda {
56
- where("created_at > ?", 1.week.ago.beginning_of_day)
57
+ where("created_at >= ?", 1.week.ago.beginning_of_day)
57
58
  }
58
59
 
59
60
  ##
60
61
  # Show all objects created last month
61
62
  #
62
63
  scope :last_month, lambda {
63
- where("created_at > ?", 1.month.ago.beginning_of_day)
64
+ where("created_at >= ?", 1.month.ago.beginning_of_day)
65
+ }
66
+
67
+ ##
68
+ # Show all objects created in month
69
+ #
70
+ scope :in_month_year, lambda { |month, year|
71
+ where("created_at > ? AND created_at < ?", Date.new(year, month, 1).beginning_of_day, (Date.new(year, month, 1).next_month-1).end_of_day)
64
72
  }
65
73
 
66
74
  ##
67
75
  # show all objects created between two specific days
68
76
  #
69
77
  scope :between, lambda { |start, finish|
70
- where("created_at > ? AND created_at < ?", start.beginning_of_day, finish.end_of_day)
78
+ where("created_at >= ? AND created_at <= ?", start.beginning_of_day, finish.end_of_day)
71
79
  }
72
80
  end
73
81
 
@@ -1,3 +1,3 @@
1
1
  module DateScopable
2
- VERSION = "0.0.2"
2
+ VERSION = "0.0.3"
3
3
  end
data/readme.md CHANGED
@@ -7,6 +7,7 @@ DateScopable provides convenient scopes for Rails ActiveRecord models:
7
7
  User.on Date.parse("4/7/2011")
8
8
  User.last_7_days
9
9
  User.last_month
10
+ User.in_month_year(12,1999)
10
11
  User.between(Date.parse("4/1/2011"), Date.parse("4/5/2011"))
11
12
 
12
13
  ## Usage
metadata CHANGED
@@ -1,13 +1,13 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: date_scopable
3
3
  version: !ruby/object:Gem::Version
4
- hash: 27
4
+ hash: 25
5
5
  prerelease:
6
6
  segments:
7
7
  - 0
8
8
  - 0
9
- - 2
10
- version: 0.0.2
9
+ - 3
10
+ version: 0.0.3
11
11
  platform: ruby
12
12
  authors:
13
13
  - Anton Zolotov
@@ -15,7 +15,7 @@ autorequire:
15
15
  bindir: bin
16
16
  cert_chain: []
17
17
 
18
- date: 2011-05-25 00:00:00 -04:00
18
+ date: 2011-06-29 00:00:00 -04:00
19
19
  default_executable:
20
20
  dependencies: []
21
21