scopy 0.0.4 → 0.2.0
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.
- checksums.yaml +4 -4
- data/README.md +5 -3
- data/lib/scopy/created_at_scopes.rb +17 -13
- data/lib/scopy/version.rb +1 -1
- metadata +2 -2
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 7adea3693cdd368e2a320d2f7ef180798aeffb2b
|
4
|
+
data.tar.gz: 1fed5b1b4e34423016f2290860c181d7022a6a2a
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: e42bfa28540f1e1dc915cd180c21b388b24726f8a2dd530d60fc1553feb4e5d6ad610fea3867c20885270688efdb618c63202ade383d97d765d48aa4d0329f4f
|
7
|
+
data.tar.gz: 2ca35f9ee99634787b2984dca3ef048254295a30a176ce39c7b1559207efca5577981215f0b7112dec0d887e3e06f5e4144501cdd2d8bf7354b69bdd1635a802
|
data/README.md
CHANGED
@@ -3,7 +3,7 @@
|
|
3
3
|
[](http://rubygems.org/gems/scopy)
|
4
4
|
[](https://travis-ci.org/neighborland/scopy)
|
5
5
|
|
6
|
-
Scopy provides common ActiveRecord
|
6
|
+
Scopy provides common ActiveRecord scopes as ActiveSupport model concerns.
|
7
7
|
|
8
8
|
Common scopes for the following attributes are provided:
|
9
9
|
|
@@ -58,8 +58,11 @@ Dog.created_on_day(1.day.ago)
|
|
58
58
|
Dog.created_in_week(Date.parse("31/10/2013"))
|
59
59
|
# => dogs created in the week Sunday-Saturday around October 31, 2013
|
60
60
|
|
61
|
-
Dog.created_in_month(
|
61
|
+
Dog.created_in_month(Time.new(2013, 1))
|
62
62
|
# => dogs created in January 2013
|
63
|
+
|
64
|
+
Dog.created_in_year(Time.new(2013))
|
65
|
+
# => dogs created in 2013
|
63
66
|
```
|
64
67
|
|
65
68
|
##### Scopy::IdScopes
|
@@ -90,4 +93,3 @@ Dog.name_starts_with('snOOp')
|
|
90
93
|
Dog.name_starts_with('Snoop', case_sensitive: true)
|
91
94
|
# => dogs with names starting with 'Snoop' (case sensitive)
|
92
95
|
```
|
93
|
-
|
@@ -1,35 +1,39 @@
|
|
1
1
|
module Scopy
|
2
2
|
module CreatedAtScopes
|
3
3
|
extend ActiveSupport::Concern
|
4
|
-
|
4
|
+
|
5
5
|
included do
|
6
|
-
scope :newest, ->{ order("#{self.table_name}.created_at DESC") }
|
7
|
-
scope :oldest, ->{ order("#{self.table_name}.created_at") }
|
8
|
-
|
9
|
-
scope :created_since, ->(since) do
|
10
|
-
where("#{self.table_name}.created_at
|
6
|
+
scope :newest, -> { order("#{ self.table_name }.created_at DESC") }
|
7
|
+
scope :oldest, -> { order("#{ self.table_name }.created_at") }
|
8
|
+
|
9
|
+
scope :created_since, -> (since) do
|
10
|
+
where("#{ self.table_name }.created_at >= ?", since)
|
11
11
|
end
|
12
12
|
|
13
|
-
scope :created_before, ->(before) do
|
14
|
-
where("#{self.table_name}.created_at
|
13
|
+
scope :created_before, -> (before) do
|
14
|
+
where("#{ self.table_name }.created_at <= ?", before)
|
15
15
|
end
|
16
16
|
|
17
|
-
scope :created_between, ->(from, to) do
|
17
|
+
scope :created_between, -> (from, to) do
|
18
18
|
created_since(from).created_before(to)
|
19
19
|
end
|
20
20
|
|
21
|
-
scope :created_on_day, ->(date) do
|
21
|
+
scope :created_on_day, -> (date) do
|
22
22
|
created_between date.beginning_of_day, date.end_of_day
|
23
23
|
end
|
24
24
|
|
25
|
-
scope :created_in_week, ->(date, day_of_week
|
25
|
+
scope :created_in_week, -> (date, day_of_week = :sunday) do
|
26
26
|
created_between date.beginning_of_week(day_of_week), date.end_of_week(day_of_week)
|
27
27
|
end
|
28
28
|
|
29
|
-
scope :created_in_month, ->(date) do
|
29
|
+
scope :created_in_month, -> (date) do
|
30
30
|
created_between date.beginning_of_month, date.end_of_month
|
31
31
|
end
|
32
|
+
|
33
|
+
scope :created_in_year, -> (date) do
|
34
|
+
created_between date.beginning_of_year, date.end_of_year
|
35
|
+
end
|
32
36
|
end
|
33
37
|
|
34
38
|
end
|
35
|
-
end
|
39
|
+
end
|
data/lib/scopy/version.rb
CHANGED
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: scopy
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.0
|
4
|
+
version: 0.2.0
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Tee Parham
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date: 2015-
|
11
|
+
date: 2015-02-26 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: activerecord
|