daily_affirmation 0.3.5 → 0.4.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/lib/daily_affirmation/affirmations.rb +6 -0
- data/lib/daily_affirmation/validators/custom_validator.rb +17 -0
- data/lib/daily_affirmation/version.rb +1 -1
- data/lib/daily_affirmation.rb +1 -0
- data/spec/daily_affirmation_spec.rb +3 -0
- data/spec/validators/custom_validator_spec.rb +35 -0
- metadata +6 -3
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: c59c90a22d3f3dcc889c34407b064f4f92efd24b
|
4
|
+
data.tar.gz: 1b002616ee6ef2b5d8c2098181c0c3bcfb891f93
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 005eee3d03c5d14da30bad1cb1ed4553f8a5af1020e67a185e09ce528eeb7777b60230bda60f1c2c2e0a4a434821049cc580d49e59e18160df2bbf9f11be9fcc
|
7
|
+
data.tar.gz: a2e18647e4120221fa5431b32083ce6403af960bb0686c67ad9ff9c330a40d7f6dc3c26d84a9c20540d5d5b33db13051e6fed7acd291e7ec1b385ed2761bda42
|
@@ -118,6 +118,12 @@ module DailyAffirmation
|
|
118
118
|
}.merge(opts)
|
119
119
|
end
|
120
120
|
|
121
|
+
def affirms(attribute, opts = {})
|
122
|
+
affirmations << {
|
123
|
+
:attribute => attribute, :type => :custom
|
124
|
+
}.merge(opts)
|
125
|
+
end
|
126
|
+
|
121
127
|
def affirmations
|
122
128
|
@affirmations ||= []
|
123
129
|
end
|
@@ -0,0 +1,17 @@
|
|
1
|
+
require_relative "../validator"
|
2
|
+
|
3
|
+
module DailyAffirmation
|
4
|
+
module Validators
|
5
|
+
class CustomValidator < Validator
|
6
|
+
def valid?
|
7
|
+
@valid ||= opts[:proc].call(object)
|
8
|
+
end
|
9
|
+
|
10
|
+
def error_message
|
11
|
+
@error_message ||= i18n_error_message(
|
12
|
+
:custom, :default => "#{attribute} is invalid"
|
13
|
+
)
|
14
|
+
end
|
15
|
+
end
|
16
|
+
end
|
17
|
+
end
|
data/lib/daily_affirmation.rb
CHANGED
@@ -2,6 +2,7 @@ require_relative "daily_affirmation/affirmations"
|
|
2
2
|
require_relative "daily_affirmation/validators/absence_validator"
|
3
3
|
require_relative "daily_affirmation/validators/acceptance_validator"
|
4
4
|
require_relative "daily_affirmation/validators/confirmation_validator"
|
5
|
+
require_relative "daily_affirmation/validators/custom_validator"
|
5
6
|
require_relative "daily_affirmation/validators/exclusion_validator"
|
6
7
|
require_relative "daily_affirmation/validators/format_validator"
|
7
8
|
require_relative "daily_affirmation/validators/inclusion_validator"
|
@@ -0,0 +1,35 @@
|
|
1
|
+
require_relative "../spec_helper"
|
2
|
+
require_relative "../../lib/daily_affirmation/validators/custom_validator"
|
3
|
+
|
4
|
+
describe "CustomValidator" do
|
5
|
+
subject { DailyAffirmation::Validators::CustomValidator }
|
6
|
+
|
7
|
+
it "passes validation if the proc returns true" do
|
8
|
+
obj = double(:name => "Bobby Tabbles")
|
9
|
+
|
10
|
+
validator = subject.new(obj, :name, :proc => Proc.new { |object|
|
11
|
+
object.name == "Bobby Tabbles"
|
12
|
+
})
|
13
|
+
expect(validator).to be_valid
|
14
|
+
end
|
15
|
+
|
16
|
+
it "fails validation if the proc returns false" do
|
17
|
+
obj = double(:name => "Bobby Tabbles")
|
18
|
+
|
19
|
+
validator = subject.new(obj, :name, :proc => Proc.new { |object|
|
20
|
+
object.name == "Robert Tabbles"
|
21
|
+
})
|
22
|
+
expect(validator).to_not be_valid
|
23
|
+
end
|
24
|
+
|
25
|
+
it "has the correct error message" do
|
26
|
+
obj = double(:name => "Bobby Tabbles")
|
27
|
+
|
28
|
+
validator = subject.new(obj, :name, :proc => Proc.new { |object|
|
29
|
+
object.name == "Robert Tabbles"
|
30
|
+
})
|
31
|
+
expect(validator.error_message).to eq(
|
32
|
+
"name is invalid"
|
33
|
+
)
|
34
|
+
end
|
35
|
+
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.
|
4
|
+
version: 0.4.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-
|
11
|
+
date: 2014-06-17 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: bundler
|
@@ -85,6 +85,7 @@ files:
|
|
85
85
|
- lib/daily_affirmation/validators/absence_validator.rb
|
86
86
|
- lib/daily_affirmation/validators/acceptance_validator.rb
|
87
87
|
- lib/daily_affirmation/validators/confirmation_validator.rb
|
88
|
+
- lib/daily_affirmation/validators/custom_validator.rb
|
88
89
|
- lib/daily_affirmation/validators/exclusion_validator.rb
|
89
90
|
- lib/daily_affirmation/validators/format_validator.rb
|
90
91
|
- lib/daily_affirmation/validators/inclusion_validator.rb
|
@@ -101,6 +102,7 @@ files:
|
|
101
102
|
- spec/validators/absence_validator_spec.rb
|
102
103
|
- spec/validators/acceptance_validator_spec.rb
|
103
104
|
- spec/validators/confirmation_validator_spec.rb
|
105
|
+
- spec/validators/custom_validator_spec.rb
|
104
106
|
- spec/validators/exclusion_validator_spec.rb
|
105
107
|
- spec/validators/format_validator_spec.rb
|
106
108
|
- spec/validators/inclusion_validator_spec.rb
|
@@ -127,7 +129,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
|
|
127
129
|
version: '0'
|
128
130
|
requirements: []
|
129
131
|
rubyforge_project:
|
130
|
-
rubygems_version: 2.2.
|
132
|
+
rubygems_version: 2.2.2
|
131
133
|
signing_key:
|
132
134
|
specification_version: 4
|
133
135
|
summary: A simple library for external validations of POROs
|
@@ -141,6 +143,7 @@ test_files:
|
|
141
143
|
- spec/validators/absence_validator_spec.rb
|
142
144
|
- spec/validators/acceptance_validator_spec.rb
|
143
145
|
- spec/validators/confirmation_validator_spec.rb
|
146
|
+
- spec/validators/custom_validator_spec.rb
|
144
147
|
- spec/validators/exclusion_validator_spec.rb
|
145
148
|
- spec/validators/format_validator_spec.rb
|
146
149
|
- spec/validators/inclusion_validator_spec.rb
|