activerecord_time_scopes 0.0.1
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 +7 -0
- data/LICENSE +20 -0
- data/README.md +29 -0
- data/lib/activerecord_time_scopes.rb +103 -0
- data/lib/activerecord_time_scopes/railtie.rb +4 -0
- data/lib/activerecord_time_scopes/version.rb +3 -0
- metadata +75 -0
checksums.yaml
ADDED
@@ -0,0 +1,7 @@
|
|
1
|
+
---
|
2
|
+
SHA256:
|
3
|
+
metadata.gz: 4c6671317cb9d850c7c65a8c0fc7c6c55598d0776191548b2b6da62b5d26fc45
|
4
|
+
data.tar.gz: fcdb767ae005a935719e948638002cd9f09455220378ff58bb1dfa0d7b04ac1e
|
5
|
+
SHA512:
|
6
|
+
metadata.gz: 853739a584c0cda3a97d09b85ca3d4f4244e54132a8a9825499c1055274923b70d7ea8b9aa13f320f36648620034e6837e88e09b2e730aafe27a15a73565aa9f
|
7
|
+
data.tar.gz: 8283a53d59632ad3a2dba91f020fca7be920c177dcaa1b4c1b16b76c65f8bb54723ed086d979bd00679ddf71ab12e918d5a496142cfc74e82e9c100313fa1085
|
data/LICENSE
ADDED
@@ -0,0 +1,20 @@
|
|
1
|
+
Copyright 2019 Matthew Schultz
|
2
|
+
|
3
|
+
Permission is hereby granted, free of charge, to any person obtaining
|
4
|
+
a copy of this software and associated documentation files (the
|
5
|
+
"Software"), to deal in the Software without restriction, including
|
6
|
+
without limitation the rights to use, copy, modify, merge, publish,
|
7
|
+
distribute, sublicense, and/or sell copies of the Software, and to
|
8
|
+
permit persons to whom the Software is furnished to do so, subject to
|
9
|
+
the following conditions:
|
10
|
+
|
11
|
+
The above copyright notice and this permission notice shall be
|
12
|
+
included in all copies or substantial portions of the Software.
|
13
|
+
|
14
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
|
15
|
+
EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
|
16
|
+
MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
|
17
|
+
NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
|
18
|
+
LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
|
19
|
+
OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
|
20
|
+
WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
|
data/README.md
ADDED
@@ -0,0 +1,29 @@
|
|
1
|
+
# Activerecord Time Scopes
|
2
|
+
Short description and motivation.
|
3
|
+
|
4
|
+
## Installation
|
5
|
+
Add this line to your application's Gemfile:
|
6
|
+
|
7
|
+
```ruby
|
8
|
+
gem 'activerecord_time_scopes'
|
9
|
+
```
|
10
|
+
|
11
|
+
And then execute:
|
12
|
+
```bash
|
13
|
+
$ bundle
|
14
|
+
```
|
15
|
+
|
16
|
+
Or install it yourself as:
|
17
|
+
```bash
|
18
|
+
$ gem install activerecord_time_scopes
|
19
|
+
```
|
20
|
+
|
21
|
+
## Usage
|
22
|
+
This plugin enables the following methods:
|
23
|
+
|
24
|
+
[created | updated] _ [before | after | between | today | yesterday | this_week | last_week | this_month | last_month | this_year | last_year]
|
25
|
+
|
26
|
+
You can pass either datetime objects or ActiveRecord objects - if you pass an activerecord object, the relevant method (created/updated_at) will be used to search.
|
27
|
+
|
28
|
+
## License
|
29
|
+
The gem is available as open source under the terms of the [MIT License](https://opensource.org/licenses/MIT).
|
@@ -0,0 +1,103 @@
|
|
1
|
+
require "activerecord_time_scopes/railtie"
|
2
|
+
|
3
|
+
module ActiverecordTimeScopes
|
4
|
+
extend ActiveSupport::Concern
|
5
|
+
|
6
|
+
module ClassMethods
|
7
|
+
def created_before(time)
|
8
|
+
time = time.created_at if time.is_a?(ActiveRecord::Base)
|
9
|
+
where('created_at < ?', time)
|
10
|
+
end
|
11
|
+
|
12
|
+
def created_after(time)
|
13
|
+
time = time.created_at if time.is_a?(ActiveRecord::Base)
|
14
|
+
where('created_at > ?', time)
|
15
|
+
end
|
16
|
+
|
17
|
+
def created_between(time, time2)
|
18
|
+
created_after(time).created_before(time2)
|
19
|
+
end
|
20
|
+
|
21
|
+
def created_today
|
22
|
+
created_after(Time.zone.now.beginning_of_day)
|
23
|
+
end
|
24
|
+
|
25
|
+
def created_yesterday
|
26
|
+
created_between(Time.zone.now.beginning_of_day - 1.days,Time.zone.now.beginning_of_day)
|
27
|
+
end
|
28
|
+
|
29
|
+
def created_this_week
|
30
|
+
created_after(Time.zone.now.beginning_of_week)
|
31
|
+
end
|
32
|
+
|
33
|
+
def created_last_week
|
34
|
+
created_between(Time.zone.now.beginning_of_week - 1.week, Time.zone.now.beginning_of_week)
|
35
|
+
end
|
36
|
+
|
37
|
+
def created_this_month
|
38
|
+
created_after(Time.zone.now.beginning_of_month)
|
39
|
+
end
|
40
|
+
|
41
|
+
def created_last_month
|
42
|
+
# This is different, since months can be different lengths:
|
43
|
+
created_between((Time.zone.now.beginning_of_month - 1.day).beginning_of_month, Time.zone.now.beginning_of_month)
|
44
|
+
end
|
45
|
+
|
46
|
+
def created_this_year
|
47
|
+
created_after(Time.zone.now.beginning_of_year)
|
48
|
+
end
|
49
|
+
|
50
|
+
def created_last_year
|
51
|
+
created_between(Time.zone.now.beginning_of_year - 1.years, Time.zone.now.beginning_of_year)
|
52
|
+
end
|
53
|
+
|
54
|
+
def updated_before(time)
|
55
|
+
time = time.updated_at if time.is_a?(ActiveRecord::Base)
|
56
|
+
where('updated_at < ?', time)
|
57
|
+
end
|
58
|
+
|
59
|
+
def updated_after(time)
|
60
|
+
time = time.updated_at if time.is_a?(ActiveRecord::Base)
|
61
|
+
where('updated_at > ?', time)
|
62
|
+
end
|
63
|
+
|
64
|
+
def updated_between(time, time2)
|
65
|
+
updated_after(time).updated_before(time2)
|
66
|
+
end
|
67
|
+
|
68
|
+
def updated_today
|
69
|
+
updated_after(Time.zone.now.beginning_of_day)
|
70
|
+
end
|
71
|
+
|
72
|
+
def updated_yesterday
|
73
|
+
updated_between(Time.zone.now.beginning_of_day - 1.days,Time.zone.now.beginning_of_day)
|
74
|
+
end
|
75
|
+
|
76
|
+
def updated_this_week
|
77
|
+
updated_after(Time.zone.now.beginning_of_week)
|
78
|
+
end
|
79
|
+
|
80
|
+
def updated_last_week
|
81
|
+
updated_between(Time.zone.now.beginning_of_week - 1.week, Time.zone.now.beginning_of_week)
|
82
|
+
end
|
83
|
+
|
84
|
+
def updated_this_month
|
85
|
+
updated_after(Time.zone.now.beginning_of_month)
|
86
|
+
end
|
87
|
+
|
88
|
+
def updated_last_month
|
89
|
+
# This is different, since months can be different lengths:
|
90
|
+
updated_between((Time.zone.now.beginning_of_month - 1.day).beginning_of_month, Time.zone.now.beginning_of_month)
|
91
|
+
end
|
92
|
+
|
93
|
+
def updated_this_year
|
94
|
+
updated_after(Time.zone.now.beginning_of_year)
|
95
|
+
end
|
96
|
+
|
97
|
+
def updated_last_year
|
98
|
+
updated_between(Time.zone.now.beginning_of_year - 1.years, Time.zone.now.beginning_of_year)
|
99
|
+
end
|
100
|
+
end
|
101
|
+
end
|
102
|
+
|
103
|
+
ActiveRecord::Base.send :include, ActiverecordTimeScopes
|
metadata
ADDED
@@ -0,0 +1,75 @@
|
|
1
|
+
--- !ruby/object:Gem::Specification
|
2
|
+
name: activerecord_time_scopes
|
3
|
+
version: !ruby/object:Gem::Version
|
4
|
+
version: 0.0.1
|
5
|
+
platform: ruby
|
6
|
+
authors:
|
7
|
+
- Matthew Schultz
|
8
|
+
autorequire:
|
9
|
+
bindir: bin
|
10
|
+
cert_chain: []
|
11
|
+
date: 2019-07-25 00:00:00.000000000 Z
|
12
|
+
dependencies:
|
13
|
+
- !ruby/object:Gem::Dependency
|
14
|
+
name: rails
|
15
|
+
requirement: !ruby/object:Gem::Requirement
|
16
|
+
requirements:
|
17
|
+
- - "~>"
|
18
|
+
- !ruby/object:Gem::Version
|
19
|
+
version: 5.2.3
|
20
|
+
type: :runtime
|
21
|
+
prerelease: false
|
22
|
+
version_requirements: !ruby/object:Gem::Requirement
|
23
|
+
requirements:
|
24
|
+
- - "~>"
|
25
|
+
- !ruby/object:Gem::Version
|
26
|
+
version: 5.2.3
|
27
|
+
- !ruby/object:Gem::Dependency
|
28
|
+
name: sqlite3
|
29
|
+
requirement: !ruby/object:Gem::Requirement
|
30
|
+
requirements:
|
31
|
+
- - ">="
|
32
|
+
- !ruby/object:Gem::Version
|
33
|
+
version: '0'
|
34
|
+
type: :development
|
35
|
+
prerelease: false
|
36
|
+
version_requirements: !ruby/object:Gem::Requirement
|
37
|
+
requirements:
|
38
|
+
- - ">="
|
39
|
+
- !ruby/object:Gem::Version
|
40
|
+
version: '0'
|
41
|
+
description: A collection of time scopes for activerecord, including created_after/created_before/updated_after/etc
|
42
|
+
email:
|
43
|
+
executables: []
|
44
|
+
extensions: []
|
45
|
+
extra_rdoc_files: []
|
46
|
+
files:
|
47
|
+
- LICENSE
|
48
|
+
- README.md
|
49
|
+
- lib/activerecord_time_scopes.rb
|
50
|
+
- lib/activerecord_time_scopes/railtie.rb
|
51
|
+
- lib/activerecord_time_scopes/version.rb
|
52
|
+
homepage: https://github.com/MatthewSchultz/activerecord_time_scopes
|
53
|
+
licenses:
|
54
|
+
- MIT
|
55
|
+
metadata: {}
|
56
|
+
post_install_message:
|
57
|
+
rdoc_options: []
|
58
|
+
require_paths:
|
59
|
+
- lib
|
60
|
+
required_ruby_version: !ruby/object:Gem::Requirement
|
61
|
+
requirements:
|
62
|
+
- - ">="
|
63
|
+
- !ruby/object:Gem::Version
|
64
|
+
version: '0'
|
65
|
+
required_rubygems_version: !ruby/object:Gem::Requirement
|
66
|
+
requirements:
|
67
|
+
- - ">="
|
68
|
+
- !ruby/object:Gem::Version
|
69
|
+
version: '0'
|
70
|
+
requirements: []
|
71
|
+
rubygems_version: 3.0.3
|
72
|
+
signing_key:
|
73
|
+
specification_version: 4
|
74
|
+
summary: A collection of time scopes for activerecord, including created_after/created_before/updated_after/etc
|
75
|
+
test_files: []
|