daily_affirmation 0.8.1 → 0.8.2

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: 324f16541c789eee4d66b3c7986f53c0a21590a0
4
- data.tar.gz: b602bca65f7b876b598af6af81a1b32180a65f2c
3
+ metadata.gz: 5d6a05019e18b5074eb228e2cd9e42ae8302cb00
4
+ data.tar.gz: f33966b9dc5669032db433ed3034aeacce539fd8
5
5
  SHA512:
6
- metadata.gz: a91d08b3c6a0596a6d644c3483938cab4c79f45b9ed6e8eef023eefe814d448d38ba1afa1e4b997dd062ce7efde4b0bd1a5af6eb7d3ddf9e6ad19cdd4fc07411
7
- data.tar.gz: e73cf19e62430dfa2ba3e81ce23cf533376d074e4b089734b2cc23851b57d5f1d4d76387d6efa3e8a05b4f143883a152cc8d866644f59324bf1ba46faebbbafd
6
+ metadata.gz: 2af4d1fd5b8bd6334e837aa1aa2842ed9c4dcbc8adb6200171313e26ebd7a54778548bc6ff37dd51a448fe1b52ce23cb34d235a52f642b9428bcd5de3c6a20bd
7
+ data.tar.gz: 1158c66ad417f70e3117573b8b51b9ed2d744f8b2e246a676548abe6be32b478ae3eaaab7f59d0d1bc583696b3e1e7797b57cad5e29ca31235ce0c67fd202696
@@ -3,6 +3,11 @@ require_relative "../validator"
3
3
  module DailyAffirmation
4
4
  module Validators
5
5
  class DateValidator < Validator
6
+ class NullDateLike
7
+ def <(val); true; end
8
+ def >(val); true; end
9
+ end
10
+
6
11
  def valid?
7
12
  @valid ||= parseable? && before? && after?
8
13
  end
@@ -25,20 +30,26 @@ module DailyAffirmation
25
30
  opts.fetch(:as, :date)
26
31
  end
27
32
 
33
+ def before
34
+ @before ||= -> {
35
+ val = opts.fetch(:before, NullDateLike.new)
36
+ val.respond_to?(:call) ? val.call : val
37
+ }.call
38
+ end
39
+
28
40
  def before?
29
- if opts[:before]
30
- value < opts[:before]
31
- else
32
- true
33
- end
41
+ before > value
42
+ end
43
+
44
+ def after
45
+ @after ||= -> {
46
+ val = opts.fetch(:after, NullDateLike.new)
47
+ val.respond_to?(:call) ? val.call : val
48
+ }.call
34
49
  end
35
50
 
36
51
  def after?
37
- if opts[:after]
38
- value > opts[:after]
39
- else
40
- true
41
- end
52
+ after < value
42
53
  end
43
54
 
44
55
  def klass
@@ -1,3 +1,3 @@
1
1
  module DailyAffirmation
2
- VERSION = "0.8.1"
2
+ VERSION = "0.8.2"
3
3
  end
@@ -145,6 +145,14 @@ describe "DateValidator" do
145
145
  validator = subject.new(obj, :created_at, :before => Date.today.prev_year)
146
146
  expect(validator).to_not be_valid
147
147
  end
148
+
149
+ it "allows a proc to be passed into before" do
150
+ obj = double(:created_at => Date.today.prev_year(2))
151
+ validator = subject.new(
152
+ obj, :created_at, :before => ->{ Date.today.prev_year }
153
+ )
154
+ expect(validator).to be_valid
155
+ end
148
156
  end
149
157
 
150
158
  context "the :after option is passed" do
@@ -159,5 +167,13 @@ describe "DateValidator" do
159
167
  validator = subject.new(obj, :created_at, :after => Date.today.prev_year)
160
168
  expect(validator).to be_valid
161
169
  end
170
+
171
+ it "allows a proc to be passed into after" do
172
+ obj = double(:created_at => Date.today)
173
+ validator = subject.new(
174
+ obj, :created_at, :after => ->{ Date.today.prev_year }
175
+ )
176
+ expect(validator).to be_valid
177
+ end
162
178
  end
163
179
  end
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: daily_affirmation
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.8.1
4
+ version: 0.8.2
5
5
  platform: ruby
6
6
  authors:
7
7
  - Shane Emmons
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2014-09-30 00:00:00.000000000 Z
11
+ date: 2014-10-01 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: bundler