season 0.0.1 → 0.0.2
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 +31 -8
- data/lib/season/active_record/scopes.rb +22 -23
- data/lib/season/configuration.rb +29 -0
- data/lib/season/version.rb +1 -1
- data/lib/season.rb +1 -4
- metadata +3 -2
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 8e0c66e1e302ebb2e68c7789ee0b49731b08f0a2
|
4
|
+
data.tar.gz: b2f79c55e993bbd294d86deadbcad0e77d009979
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 736c259aaeeab9042a84d37e2269f20bcef9febd48fb07a6cfc0ab5da821fffda3a654fe41212e82a079536c7046b4c7e4039016dca1f92f94ec57450853526e
|
7
|
+
data.tar.gz: 701160c347723fb7db232ddb565c6af9bdedd8bdc13c9c9055296c4da97a6739d9da0e62348cf4e668d7aaee058d11a1330ee924e66db02503a2392f74c47c8c
|
data/README.md
CHANGED
@@ -31,26 +31,49 @@ Right now, Season gives you the following helper methods:
|
|
31
31
|
```ruby
|
32
32
|
# You can pass instances of Time/DateTime/String as arguments
|
33
33
|
|
34
|
-
|
35
|
-
MyModel.created_after(DateTime.now)
|
36
|
-
MyModel.created_between(Time.now - 1.week, '31-01-2015')
|
34
|
+
class User < ActiveRecord::Base; end
|
37
35
|
|
38
|
-
|
39
|
-
|
40
|
-
|
36
|
+
User.created_before(Time.now)
|
37
|
+
User.created_after(DateTime.now)
|
38
|
+
User.created_between(Time.now - 1.week, '31-01-2015')
|
39
|
+
|
40
|
+
User.updated_before(DateTime.now)
|
41
|
+
User.updated_after('01-01-2015')
|
42
|
+
User.updated_between(Time.now - 1.week, Time.now)
|
43
|
+
```
|
44
|
+
|
45
|
+
## Configuration
|
46
|
+
|
47
|
+
The scopes are not included by default in your models. To use them you need to include it yourself:
|
48
|
+
|
49
|
+
```ruby
|
50
|
+
Class User < ActiveRecord::Base
|
51
|
+
include Season::Scopes
|
52
|
+
|
53
|
+
...
|
54
|
+
|
55
|
+
end
|
56
|
+
```
|
57
|
+
|
58
|
+
If you want them to be available on all of your models by default, add the following code within an initializer - `config/initializers/season.rb`:
|
59
|
+
|
60
|
+
```ruby
|
61
|
+
Season.configure do |config|
|
62
|
+
config.include_by_default = true
|
63
|
+
end
|
41
64
|
```
|
42
65
|
|
43
66
|
## To Do
|
44
67
|
|
45
68
|
- Tests!
|
46
|
-
- Support other ORMs (Mongoid,
|
69
|
+
- Support other ORMs (Mongoid, 'insert-more-here')
|
47
70
|
- Add Error Handling
|
48
71
|
- Support user-defined date/time columns (through configuration)
|
49
72
|
- Support configuration for enabling/disabling Season for all models
|
50
73
|
|
51
74
|
## Contributing
|
52
75
|
|
53
|
-
1. Fork it ( https://github.com/
|
76
|
+
1. Fork it ( https://github.com/joaodiogocosta/season/fork )
|
54
77
|
2. Create your feature branch (`git checkout -b my-new-feature`)
|
55
78
|
3. Commit your changes (`git commit -am 'Add some feature'`)
|
56
79
|
4. Push to the branch (`git push origin my-new-feature`)
|
@@ -1,34 +1,33 @@
|
|
1
|
-
module
|
1
|
+
module Season
|
2
|
+
module Scopes
|
2
3
|
|
3
|
-
|
4
|
-
|
5
|
-
|
6
|
-
|
7
|
-
|
4
|
+
def self.included(base)
|
5
|
+
base.class_eval do
|
6
|
+
def self.created_before(date)
|
7
|
+
where("#{table_name}.created_at < ?", date)
|
8
|
+
end
|
8
9
|
|
9
|
-
|
10
|
-
|
11
|
-
|
10
|
+
def self.created_between(start_date, end_date)
|
11
|
+
where("#{table_name}.created_at > ? AND #{table_name}.created_at < ?", start_date, end_date)
|
12
|
+
end
|
12
13
|
|
13
|
-
|
14
|
-
|
15
|
-
|
14
|
+
def self.created_after(date)
|
15
|
+
where("#{table_name}.created_at > ?", date)
|
16
|
+
end
|
16
17
|
|
17
18
|
|
18
|
-
|
19
|
-
|
20
|
-
|
19
|
+
def self.updated_before(date)
|
20
|
+
where("#{table_name}.updated_at < ?", date)
|
21
|
+
end
|
21
22
|
|
22
|
-
|
23
|
-
|
24
|
-
|
23
|
+
def self.updated_between(start_date, end_date)
|
24
|
+
where("#{table_name}.updated_at > ? AND #{table_name}.updated_at < ?", start_date, end_date)
|
25
|
+
end
|
25
26
|
|
26
|
-
|
27
|
-
|
27
|
+
def self.updated_after(date)
|
28
|
+
where("#{table_name}.updated_at > ?", date)
|
29
|
+
end
|
28
30
|
end
|
29
31
|
end
|
30
32
|
end
|
31
|
-
|
32
33
|
end
|
33
|
-
|
34
|
-
ActiveRecord::Base.send(:include, Scopes)
|
@@ -0,0 +1,29 @@
|
|
1
|
+
module Season
|
2
|
+
|
3
|
+
class Configuration
|
4
|
+
|
5
|
+
attr_accessor :include_by_default
|
6
|
+
|
7
|
+
def initialize
|
8
|
+
@include_by_default = false
|
9
|
+
end
|
10
|
+
|
11
|
+
end
|
12
|
+
|
13
|
+
def self.configuration
|
14
|
+
@configuration ||= Configuration.new
|
15
|
+
end
|
16
|
+
|
17
|
+
def self.configure
|
18
|
+
yield configuration
|
19
|
+
auto_include_scopes
|
20
|
+
end
|
21
|
+
|
22
|
+
private
|
23
|
+
|
24
|
+
def self.auto_include_scopes
|
25
|
+
if configuration.include_by_default
|
26
|
+
ActiveRecord::Base.send(:include, Season::Scopes) if defined? ActiveRecord
|
27
|
+
end
|
28
|
+
end
|
29
|
+
end
|
data/lib/season/version.rb
CHANGED
data/lib/season.rb
CHANGED
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: season
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.0.
|
4
|
+
version: 0.0.2
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Joao Diogo Costa
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date: 2015-
|
11
|
+
date: 2015-02-05 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: bundler
|
@@ -81,6 +81,7 @@ files:
|
|
81
81
|
- Rakefile
|
82
82
|
- lib/season.rb
|
83
83
|
- lib/season/active_record/scopes.rb
|
84
|
+
- lib/season/configuration.rb
|
84
85
|
- lib/season/version.rb
|
85
86
|
- season.gemspec
|
86
87
|
- spec/scopes.rb
|