daily_affirmation 0.5.0 → 0.6.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 +2 -1
- data/lib/daily_affirmation.rb +1 -0
- data/lib/daily_affirmation/affirmations.rb +1 -7
- data/lib/daily_affirmation/process_affirmation_evaluator.rb +31 -0
- data/lib/daily_affirmation/version.rb +1 -1
- data/spec/daily_affirmation_spec.rb +17 -0
- data/spec/spec_helper.rb +2 -0
- 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: f9de5dd78a0bef74b3651afb803f155368e25584
|
4
|
+
data.tar.gz: 09f91e14d2dbb1b5792f6e839f33df8652060294
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 274adb6724f09c22837e088d1b05c879114d9cfbc1a76ba1b7055d8e8dfd9d0adb1761514d9ad2af20916bb96cfa7ecbb657009773fc5d40f820b764c5415068
|
7
|
+
data.tar.gz: 9ac90e5455aa763cba07ef3c6c062a72bd7f6a4267ac4efb4163d79f5866c9281077e10e76dcc3ae16e9f94da53222c09009a49b240227e3f34688240ec3bcea
|
data/README.md
CHANGED
@@ -1,7 +1,8 @@
|
|
1
1
|
# DailyAffirmation
|
2
2
|
|
3
|
+
[ ](https://www.codeship.io/projects/24759)
|
4
|
+
|
3
5
|
[](http://badge.fury.io/rb/daily_affirmation)
|
4
|
-
[](https://semaphoreapp.com/minter/daily_affirmation)
|
5
6
|
[](https://codeclimate.com/github/teamsnap/daily_affirmation)
|
6
7
|
[](https://coveralls.io/r/teamsnap/daily_affirmation?branch=master)
|
7
8
|
[](https://gemnasium.com/teamsnap/daily_affirmation)
|
data/lib/daily_affirmation.rb
CHANGED
@@ -37,13 +37,7 @@ module DailyAffirmation
|
|
37
37
|
attribute = affirmation[:attribute]
|
38
38
|
args = affirmation.reject { |k, _| [:type, :attribute].include?(k) }
|
39
39
|
|
40
|
-
|
41
|
-
instance_eval(&args[:if])
|
42
|
-
else
|
43
|
-
true
|
44
|
-
end
|
45
|
-
|
46
|
-
if process_validation
|
40
|
+
if ProcessAffirmationEvaluator.new(object, attribute, args).process?
|
47
41
|
validator = Object.const_get(
|
48
42
|
"DailyAffirmation::Validators::#{type.to_s.capitalize}Validator"
|
49
43
|
)
|
@@ -0,0 +1,31 @@
|
|
1
|
+
class ProcessAffirmationEvaluator
|
2
|
+
def initialize(object, attribute, args)
|
3
|
+
self.object = object
|
4
|
+
self.attribute = attribute
|
5
|
+
self.args = args
|
6
|
+
end
|
7
|
+
|
8
|
+
def process?
|
9
|
+
if_statement_passes? && allow_nil_passes?
|
10
|
+
end
|
11
|
+
|
12
|
+
private
|
13
|
+
|
14
|
+
attr_accessor :object, :attribute, :args
|
15
|
+
|
16
|
+
def if_statement_passes?
|
17
|
+
if args.include?(:if)
|
18
|
+
instance_eval(&args[:if])
|
19
|
+
else
|
20
|
+
true
|
21
|
+
end
|
22
|
+
end
|
23
|
+
|
24
|
+
def allow_nil_passes?
|
25
|
+
if args.include?(:allow_nil)
|
26
|
+
object.send(attribute)
|
27
|
+
else
|
28
|
+
true
|
29
|
+
end
|
30
|
+
end
|
31
|
+
end
|
@@ -135,6 +135,23 @@ describe DailyAffirmation do
|
|
135
135
|
expect(affirmation2).to_not be_valid
|
136
136
|
end
|
137
137
|
|
138
|
+
it "skips an affirmation for an :allow_nil option" do
|
139
|
+
cls = Class.new do
|
140
|
+
include DailyAffirmation.affirmations
|
141
|
+
|
142
|
+
affirms_format_of :name, :regex => /^\D+$/, :allow_nil => true
|
143
|
+
end
|
144
|
+
|
145
|
+
obj1 = double(:name => nil)
|
146
|
+
obj2 = double(:name => "name1")
|
147
|
+
|
148
|
+
affirmation1 = cls.new(obj1)
|
149
|
+
affirmation2 = cls.new(obj2)
|
150
|
+
|
151
|
+
expect(affirmation1).to be_valid
|
152
|
+
expect(affirmation2).to_not be_valid
|
153
|
+
end
|
154
|
+
|
138
155
|
it "allows each affirmation to be inverted via an :inverse option" do
|
139
156
|
cls = Class.new do
|
140
157
|
include DailyAffirmation.affirmations
|
data/spec/spec_helper.rb
CHANGED
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.
|
4
|
+
version: 0.6.0
|
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-06
|
11
|
+
date: 2014-08-06 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
|
- daily_affirmation.gemspec
|
82
82
|
- lib/daily_affirmation.rb
|
83
83
|
- lib/daily_affirmation/affirmations.rb
|
84
|
+
- lib/daily_affirmation/process_affirmation_evaluator.rb
|
84
85
|
- lib/daily_affirmation/validator.rb
|
85
86
|
- lib/daily_affirmation/validators/absence_validator.rb
|
86
87
|
- lib/daily_affirmation/validators/acceptance_validator.rb
|