poro_validator 0.1.2 → 0.2.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: 9b208b1870698a602feb0e169d24e98d18adce92
4
- data.tar.gz: eb7553305d2c920e2f17f5d53b39db5a736948da
3
+ metadata.gz: 7b4d11e09f822043d4a06bf638d63d1340203a0b
4
+ data.tar.gz: a3190629a9fcd8f330cb3b9305b84f75a07a6c79
5
5
  SHA512:
6
- metadata.gz: e5e56fcf3b6f187bfda5f3694bdcd68ded5be9eb50c440f14d1d02e71d5fcaafc888a09021f8f2e7c1e993c13ce5ae1fb38bf6a7f2ad26abe590d1a086ab866e
7
- data.tar.gz: f407bc281ab3901ffed0c4b8ecc5d9c10857d92e6a609e368a1e405628b3f706ad9ac213fa87e047824c2749917705652ec85d73f56467516df064085b7401ae
6
+ metadata.gz: 131f42ab7e0cd7e2df6ab86e2d6227680107e2b0b62f08690e32b1b5204b296b7bcd0bd579821a7dce6d295b86ee5bdb9ed72e8710282bf3672de71ea85ebf47
7
+ data.tar.gz: c9fc039ac60eb4cc055e95411627f60be31bac40f66ab59e45c997ba84e93429f1d6db2e387f6866050b7e4f0494e980c4587e5ae4b6d45044dbd0fb0fe5ebe2
@@ -9,8 +9,9 @@ module PoroValidator
9
9
  PoroValidator.const_get(klass).new(attr_name, options)
10
10
  rescue NameError => e
11
11
  raise(::PoroValidator::ValidatorNotFound.new(
12
- "Validator not found: ::PoroValidator::#{klass} exception: #{e}"
13
- ))
12
+ "Validator not found: ::PoroValidator::#{klass} exception: #{e}"
13
+ )
14
+ )
14
15
  end
15
16
  end
16
17
 
@@ -11,9 +11,11 @@ module PoroValidator
11
11
  # e.g, message:, on:, etc.
12
12
  def self.build(attr_name, validator, options)
13
13
  b = new(attr_name, validator, options)
14
- b = Factory::Validators.set_validator(b.attr_name,
15
- b.validator,
16
- b.options)
14
+ b = Factory::Validators.set_validator(
15
+ b.attr_name,
16
+ b.validator,
17
+ b.options
18
+ )
17
19
  b
18
20
  end
19
21
 
@@ -1,3 +1,3 @@
1
1
  module PoroValidator
2
- VERSION = "0.1.2"
2
+ VERSION = "0.2.0"
3
3
  end
@@ -19,8 +19,12 @@ module PoroValidator
19
19
  mod
20
20
  end
21
21
 
22
+ def self.configure(&block)
23
+ yield(configuration)
24
+ end
25
+
22
26
  def self.configuration
23
- @configuration || Configuration.new
27
+ @configuration ||= Configuration.new
24
28
  end
25
29
  end
26
30
 
@@ -68,6 +68,7 @@ Gem::Specification.new do |spec|
68
68
  lib/poro_validator/version.rb
69
69
  poro_validator.gemspec
70
70
  spec/features/composable_validations_spec.rb
71
+ spec/features/configurable_error_messages_spec.rb
71
72
  spec/features/inheritable_spec.rb
72
73
  spec/features/nested_validations_spec.rb
73
74
  spec/features/validate_hash_object_spec.rb
@@ -0,0 +1,35 @@
1
+ require 'spec_helper'
2
+
3
+ RSpec.describe "Allow configuration for error messages", type: :feature do
4
+ let(:custom_message) { proc { "manbearpig" } }
5
+
6
+ before(:each) do
7
+ ::PoroValidator.configure do |config|
8
+ config.message.set(:integer, custom_message)
9
+ end
10
+ end
11
+
12
+ it "customize existing validator messages" do
13
+ validator = Class.new do
14
+ include PoroValidator.validator
15
+
16
+ validates :amount, integer: true
17
+ end.new
18
+
19
+ entity = OpenStruct.new(amount: 'abc')
20
+ validator.valid?(entity)
21
+ expect(validator.errors.on(:amount)).to eq(
22
+ [custom_message.call]
23
+ )
24
+ end
25
+
26
+ after(:each) do
27
+ # reset the custom messages
28
+ # if this is not done, there will be flapping test wherever
29
+ # the integer validator is used and it's default error message
30
+ # matched
31
+ ::PoroValidator.configure do |config|
32
+ config.message.instance_variable_set(:@messages, {})
33
+ end
34
+ end
35
+ end
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: poro_validator
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.1.2
4
+ version: 0.2.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - Kareem Gan
8
8
  autorequire:
9
9
  bindir: exe
10
10
  cert_chain: []
11
- date: 2016-01-17 00:00:00.000000000 Z
11
+ date: 2016-01-21 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: bundler
@@ -147,6 +147,7 @@ files:
147
147
  - lib/poro_validator/version.rb
148
148
  - poro_validator.gemspec
149
149
  - spec/features/composable_validations_spec.rb
150
+ - spec/features/configurable_error_messages_spec.rb
150
151
  - spec/features/inheritable_spec.rb
151
152
  - spec/features/nested_validations_spec.rb
152
153
  - spec/features/validate_hash_object_spec.rb