datescope 0.0.4 → 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.
- data/lib/datescope.rb +4 -2
- data/lib/datescope/extension.rb +29 -0
- data/lib/datescope/intervals.rb +33 -0
- data/lib/datescope/version.rb +1 -1
- metadata +3 -2
- data/lib/datescope/base.rb +0 -33
data/lib/datescope.rb
CHANGED
@@ -0,0 +1,29 @@
|
|
1
|
+
module DateScope
|
2
|
+
|
3
|
+
module Extension
|
4
|
+
def today
|
5
|
+
where("created_at >= ?", Intervals.today[:start])
|
6
|
+
end
|
7
|
+
|
8
|
+
def this_week
|
9
|
+
where("created_at >= ?", Intervals.this_week[:start])
|
10
|
+
end
|
11
|
+
|
12
|
+
def this_month
|
13
|
+
where("created_at >= ?", Intervals.this_month[:start])
|
14
|
+
end
|
15
|
+
|
16
|
+
def last_month
|
17
|
+
where("created_at >= ? and created_at <= ?", Intervals.last_month[:start], Intervals.last_month[:end])
|
18
|
+
end
|
19
|
+
|
20
|
+
def month_before_last_month
|
21
|
+
where("created_at >= ? and created_at <= ?", Intervals.month_before_last_month[:start], Intervals.month_before_last_month[:end])
|
22
|
+
end
|
23
|
+
|
24
|
+
def this_year
|
25
|
+
where("created_at >= ?", Intervals.this_year[:start])
|
26
|
+
end
|
27
|
+
end
|
28
|
+
|
29
|
+
end
|
@@ -0,0 +1,33 @@
|
|
1
|
+
module DateScope
|
2
|
+
|
3
|
+
module Intervals
|
4
|
+
def self.today
|
5
|
+
{:start => 0.day.ago.beginning_of_day, :end => 0.day.ago.end_of_day}
|
6
|
+
end
|
7
|
+
|
8
|
+
def self.this_week
|
9
|
+
{:start => 0.week.ago.beginning_of_week, :end => 0.week.ago.end_of_week}
|
10
|
+
end
|
11
|
+
|
12
|
+
def self.this_month
|
13
|
+
{:start => 0.month.ago.beginning_of_month, :end => 0.month.ago.end_of_month}
|
14
|
+
end
|
15
|
+
|
16
|
+
def self.this_year
|
17
|
+
{:start => 0.year.ago.beginning_of_year, :end => 0.year.ago.end_of_year}
|
18
|
+
end
|
19
|
+
|
20
|
+
def self.last_month
|
21
|
+
{:start => 1.month.ago.beginning_of_month, :end => 1.month.ago.end_of_month}
|
22
|
+
end
|
23
|
+
|
24
|
+
def self.month_before_last_month
|
25
|
+
{:start => 2.month.ago.beginning_of_month, :end => 2.month.ago.end_of_month}
|
26
|
+
end
|
27
|
+
|
28
|
+
def self.all
|
29
|
+
{:start => Time.at(0), :end => Time.at(2**31-1)}
|
30
|
+
end
|
31
|
+
end
|
32
|
+
|
33
|
+
end
|
data/lib/datescope/version.rb
CHANGED
metadata
CHANGED
@@ -2,7 +2,7 @@
|
|
2
2
|
name: datescope
|
3
3
|
version: !ruby/object:Gem::Version
|
4
4
|
prerelease:
|
5
|
-
version: 0.0.
|
5
|
+
version: 0.0.5
|
6
6
|
platform: ruby
|
7
7
|
authors:
|
8
8
|
- Laszlo Papp
|
@@ -40,7 +40,8 @@ files:
|
|
40
40
|
- Rakefile
|
41
41
|
- datescope.gemspec
|
42
42
|
- lib/datescope.rb
|
43
|
-
- lib/datescope/
|
43
|
+
- lib/datescope/extension.rb
|
44
|
+
- lib/datescope/intervals.rb
|
44
45
|
- lib/datescope/version.rb
|
45
46
|
homepage: http://github.com/luciditydigital/datescope
|
46
47
|
licenses: []
|
data/lib/datescope/base.rb
DELETED
@@ -1,33 +0,0 @@
|
|
1
|
-
module DateScope
|
2
|
-
|
3
|
-
module Extension
|
4
|
-
def today
|
5
|
-
where("created_at >= ?", 0.day.ago.beginning_of_day)
|
6
|
-
end
|
7
|
-
|
8
|
-
def this_week
|
9
|
-
where("created_at >= ?", 0.week.ago.beginning_of_week)
|
10
|
-
end
|
11
|
-
|
12
|
-
def this_month
|
13
|
-
where("created_at >= ?", 0.month.ago.beginning_of_month)
|
14
|
-
end
|
15
|
-
|
16
|
-
def last_month
|
17
|
-
where("created_at >= ? and created_at <= ?", 1.month.ago.beginning_of_month, 1.month.ago.end_of_month)
|
18
|
-
end
|
19
|
-
|
20
|
-
def month_before_last_month
|
21
|
-
where("created_at >= ? and created_at <= ?", 2.month.ago.beginning_of_month, 2.month.ago.end_of_month)
|
22
|
-
end
|
23
|
-
|
24
|
-
def this_year
|
25
|
-
where("created_at >= ?", 0.year.ago.beginning_of_year)
|
26
|
-
end
|
27
|
-
end
|
28
|
-
|
29
|
-
end
|
30
|
-
|
31
|
-
ActiveRecord::Base.send(:extend, DateScope::Extension)
|
32
|
-
ActiveRecord::Relation.send(:include, DateScope::Extension)
|
33
|
-
|