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 CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: 63dddf98c1338f2c348cfc44c6f1e1325c17c3a1
4
- data.tar.gz: 1be0d8af0b511c753aad20cca49d85185653c3a3
3
+ metadata.gz: f9de5dd78a0bef74b3651afb803f155368e25584
4
+ data.tar.gz: 09f91e14d2dbb1b5792f6e839f33df8652060294
5
5
  SHA512:
6
- metadata.gz: 626d8b7867e06308262c2e8f5f2e9401137d1c81b649dd932c0555e9486f7a58cba29c38b3d3ec6c201d5f8c6aa55261cd60ff34b3aa67ac60634b19090f8ebe
7
- data.tar.gz: 5d50e83ac7694ee5972d8240a9f8b99a51003333d9d82dce37be5d90ac74cc71b5254ae7cd21ba5f426836c96a42e38a8a83c6f5703486ea8462d9974108894c
6
+ metadata.gz: 274adb6724f09c22837e088d1b05c879114d9cfbc1a76ba1b7055d8e8dfd9d0adb1761514d9ad2af20916bb96cfa7ecbb657009773fc5d40f820b764c5415068
7
+ data.tar.gz: 9ac90e5455aa763cba07ef3c6c062a72bd7f6a4267ac4efb4163d79f5866c9281077e10e76dcc3ae16e9f94da53222c09009a49b240227e3f34688240ec3bcea
data/README.md CHANGED
@@ -1,7 +1,8 @@
1
1
  # DailyAffirmation
2
2
 
3
+ [ ![Codeship Status for teamsnap/daily_affirmation](https://www.codeship.io/projects/70727b30-de01-0131-af05-5236ebb52643/status)](https://www.codeship.io/projects/24759)
4
+
3
5
  [![Gem Version](https://badge.fury.io/rb/daily_affirmation.png)](http://badge.fury.io/rb/daily_affirmation)
4
- [![Semaphore](https://semaphoreapp.com/api/v1/projects/7268def52c792e50bfc60e1b1a6e905ed4e2a80d/118940/shields_badge.png)](https://semaphoreapp.com/minter/daily_affirmation)
5
6
  [![Code Climate](https://codeclimate.com/github/teamsnap/daily_affirmation.png)](https://codeclimate.com/github/teamsnap/daily_affirmation)
6
7
  [![Coverage Status](https://coveralls.io/repos/teamsnap/daily_affirmation/badge.png?branch=master)](https://coveralls.io/r/teamsnap/daily_affirmation?branch=master)
7
8
  [![Dependency Status](https://gemnasium.com/teamsnap/daily_affirmation.png)](https://gemnasium.com/teamsnap/daily_affirmation)
@@ -1,3 +1,4 @@
1
+ require_relative "daily_affirmation/process_affirmation_evaluator"
1
2
  require_relative "daily_affirmation/affirmations"
2
3
  require_relative "daily_affirmation/validators/absence_validator"
3
4
  require_relative "daily_affirmation/validators/acceptance_validator"
@@ -37,13 +37,7 @@ module DailyAffirmation
37
37
  attribute = affirmation[:attribute]
38
38
  args = affirmation.reject { |k, _| [:type, :attribute].include?(k) }
39
39
 
40
- process_validation = if args.include?(:if)
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
@@ -1,3 +1,3 @@
1
1
  module DailyAffirmation
2
- VERSION = "0.5.0"
2
+ VERSION = "0.6.0"
3
3
  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
@@ -1,4 +1,6 @@
1
1
  require "coveralls"
2
+ require "pry"
3
+
2
4
  Coveralls.wear!
3
5
 
4
6
  RSpec.configure do |config|
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.5.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-18 00:00:00.000000000 Z
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