datescope 0.0.4 → 0.0.5

Sign up to get free protection for your applications and to get access to all the features.
data/lib/datescope.rb CHANGED
@@ -1,4 +1,6 @@
1
1
  require "datescope/version"
2
- require "datescope/base.rb"
3
-
2
+ require "datescope/intervals.rb"
3
+ require "datescope/extension.rb"
4
4
 
5
+ ActiveRecord::Base.send(:extend, DateScope::Extension)
6
+ ActiveRecord::Relation.send(:include, DateScope::Extension)
@@ -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
@@ -1,3 +1,3 @@
1
1
  module Datescope
2
- VERSION = "0.0.4"
2
+ VERSION = "0.0.5"
3
3
  end
metadata CHANGED
@@ -2,7 +2,7 @@
2
2
  name: datescope
3
3
  version: !ruby/object:Gem::Version
4
4
  prerelease:
5
- version: 0.0.4
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/base.rb
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: []
@@ -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
-