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 CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: 14ba902afe4fe1b37986e39469d170fb7d8222db
4
- data.tar.gz: 6deb23cd6ec76f510fc30e3478e249e06b0bedff
3
+ metadata.gz: 8e0c66e1e302ebb2e68c7789ee0b49731b08f0a2
4
+ data.tar.gz: b2f79c55e993bbd294d86deadbcad0e77d009979
5
5
  SHA512:
6
- metadata.gz: 19937a336bd5df579cce48b946f2071c6347ef1d03876b01b50b12dcc9956c3af8b2d2eca00a7d8ebf7795ced5f94e1f6713a9f42c39515905a9908931e9b84a
7
- data.tar.gz: 1cdc28b8dfd71fad4933d0507d691823b1f1d461c918d4f8960068d3d04ee6c7b0ccb86f7cfa52650900dca3e99733072c60ec6d28064bbb89d5758973a64919
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
- MyModel.created_before(Time.now)
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
- MyModel.updated_before(DateTime.now)
39
- MyModel.updated_after('01-01-2015')
40
- MyModel.updated_between(Time.now - 1.week, Time.now)
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, <insert-more-here>)
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/[my-github-username]/season/fork )
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 Scopes
1
+ module Season
2
+ module Scopes
2
3
 
3
- def self.included(base)
4
- base.class_eval do
5
- def self.created_before(date)
6
- where("#{table_name}.created_at < ?", date)
7
- end
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
- def self.created_between(start_date, end_date)
10
- where("#{table_name}.created_at > ? AND #{table_name}.created_at < ?", start_date, end_date)
11
- end
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
- def self.created_after(date)
14
- where("#{table_name}.created_at > ?", date)
15
- end
14
+ def self.created_after(date)
15
+ where("#{table_name}.created_at > ?", date)
16
+ end
16
17
 
17
18
 
18
- def self.updated_before(date)
19
- where("#{table_name}.updated_at < ?", date)
20
- end
19
+ def self.updated_before(date)
20
+ where("#{table_name}.updated_at < ?", date)
21
+ end
21
22
 
22
- def self.updated_between(start_date, end_date)
23
- where("#{table_name}.updated_at > ? AND #{table_name}.updated_at < ?", start_date, end_date)
24
- end
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
- def self.updated_after(date)
27
- where("#{table_name}.updated_at > ?", date)
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
@@ -1,3 +1,3 @@
1
1
  module Season
2
- VERSION = "0.0.1"
2
+ VERSION = "0.0.2"
3
3
  end
data/lib/season.rb CHANGED
@@ -1,6 +1,3 @@
1
1
  require "season/version"
2
+ require "season/configuration"
2
3
  require "season/active_record/scopes" if defined? ActiveRecord
3
-
4
- module Season
5
-
6
- end
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.1
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-01-31 00:00:00.000000000 Z
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