daily_affirmation 1.0.0 → 1.1.0

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: 1cc1e1ce0b58bfda7c7d73f8d28f03e1e5e74756
4
- data.tar.gz: bbb527d49af075c5512336fbde9a1139f85c840f
3
+ metadata.gz: f7ba5e00c6949914c9cfd4e9cbf88ccac79a0cb7
4
+ data.tar.gz: 7023bf3b10fbc9caa76c59553f899ba06f7f8580
5
5
  SHA512:
6
- metadata.gz: 08ce5f23b0c2911bd124818fd1a71ab052db502027d8d72f146c5980b0c07ad2d9ceb42e0761488dc93674bd6df083d97a1a58dc4f16826d30a4736e2bfbb172
7
- data.tar.gz: 02eff11856d22c91fc861630c34210f5b02e4b40d7adcf520853ff657f82971d3e8cb8ae303628e59d1a785ea13c957d9692898ad93c89554a1a276200a73e56
6
+ metadata.gz: 7f34c62e82ca717e3389d6afb7b2c54de266a754d5d33a2938e41c8d00111e3744e0bf7ebc96f7a799258428e2a6947ae1ccf7b64f50765f27572395b8de94c3
7
+ data.tar.gz: fc852275569a2b97e0ce079c63a93f2cd3a7b5ac147ec084e5ab92d992d0834bd153049cea77eb891192888674c59e11aea41dee6b9c0cecd51f279a52387561
data/README.md CHANGED
@@ -8,7 +8,7 @@
8
8
  [![Dependency Status](https://gemnasium.com/teamsnap/daily_affirmation.png)](https://gemnasium.com/teamsnap/daily_affirmation)
9
9
  [![License](http://img.shields.io/license/MIT.png?color=green)](http://opensource.org/licenses/MIT)
10
10
 
11
- [Documentation](http://www.rubydoc.info/github/teamsnap/daily_affirmation)
11
+ [Documentation](http://www.rubydoc.info/gems/daily_affirmation)
12
12
 
13
13
  A simple library for external validations of POROs
14
14
 
@@ -6,7 +6,7 @@ class ProcessAffirmationEvaluator
6
6
  end
7
7
 
8
8
  def process?
9
- if_statement_passes? && allow_nil_passes?
9
+ if_statement_passes? && process_non_nil_value? && process_non_blank_value?
10
10
  end
11
11
 
12
12
  private
@@ -21,11 +21,36 @@ class ProcessAffirmationEvaluator
21
21
  end
22
22
  end
23
23
 
24
- def allow_nil_passes?
25
- if args.include?(:allow_nil)
26
- object.send(attribute)
24
+ def process_non_blank_value?
25
+ !(allow_blank_values? && object_is_blank?)
26
+ end
27
+
28
+ def allow_blank_values?
29
+ args.include?(:allow_blank)
30
+ end
31
+
32
+ def object_is_blank?
33
+ blank?(object.send(attribute))
34
+ end
35
+
36
+ def blank?(val)
37
+ case val
38
+ when String
39
+ val !~ /[^[:space:]]/
27
40
  else
28
- true
41
+ val.respond_to?(:empty?) ? val.empty? : !val
29
42
  end
30
43
  end
44
+
45
+ def object_is_nil?
46
+ object.send(attribute).nil?
47
+ end
48
+
49
+ def allow_nil_values?
50
+ args.include?(:allow_nil)
51
+ end
52
+
53
+ def process_non_nil_value?
54
+ !(allow_nil_values? && object_is_nil?)
55
+ end
31
56
  end
@@ -1,3 +1,3 @@
1
1
  module DailyAffirmation
2
- VERSION = "1.0.0"
2
+ VERSION = "1.1.0"
3
3
  end
@@ -154,6 +154,23 @@ describe DailyAffirmation do
154
154
  expect(affirmation2).to_not be_valid
155
155
  end
156
156
 
157
+ it "skips an affirmation for an :allow_blank option" do
158
+ cls = Class.new do
159
+ include DailyAffirmation.affirmations
160
+
161
+ affirms_inclusion_of :name, :list => ["name1"], :allow_blank => true
162
+ end
163
+
164
+ obj1 = double(:name => "")
165
+ obj2 = double(:name => "name2")
166
+
167
+ affirmation1 = cls.new(obj1)
168
+ affirmation2 = cls.new(obj2)
169
+
170
+ expect(affirmation1).to be_valid
171
+ expect(affirmation2).to_not be_valid
172
+ end
173
+
157
174
  it "allows each affirmation to be inverted via an :inverse option" do
158
175
  cls = Class.new do
159
176
  include DailyAffirmation.affirmations
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: 1.0.0
4
+ version: 1.1.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: 2015-01-15 00:00:00.000000000 Z
11
+ date: 2015-04-01 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: bundler
@@ -134,7 +134,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
134
134
  version: '0'
135
135
  requirements: []
136
136
  rubyforge_project:
137
- rubygems_version: 2.2.2
137
+ rubygems_version: 2.4.6
138
138
  signing_key:
139
139
  specification_version: 4
140
140
  summary: A simple library for external validations of POROs