activemodel-behavior_validator 0.0.1 → 0.0.2

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: 373144806bd7fd0470a5b5764b1cf862f6ad576f
4
- data.tar.gz: 4f1c003a2da2f5208730d64f6143d021e231cd72
3
+ metadata.gz: 95e39de4761601fc6a4688f2ddf20e88d79a81e2
4
+ data.tar.gz: 5a542853207a721590e3d116cb7f0a0fe5f8711c
5
5
  SHA512:
6
- metadata.gz: d7d9a8811fab322f7f229be06bf7552c0941c0550d31931cfbdc3560e230a058a3e479ecab75a9e2472d21c4d4927742129316becbfe346b38203b43d7463a49
7
- data.tar.gz: bec71dc50270f0c4a1f41e3cb28926bdaa258daf1a1a992c2528898a076b1bd3c358324cd519da6402eee68a19b6e5cc37e98883dc3fd945cdd931ecf9d60abb
6
+ metadata.gz: 027580b1fb8ad37c0c588c5181705c215ed2f9d332369c31a5e8003b1546277b756058edd449779901742a034b9f98f122af08ee8ba4b042dc60a6f5a9d93181
7
+ data.tar.gz: 7e63c4d455cfdd03a8b6971e48322681597aa5ca89f7c5bc3e428fc1e31c36c152832bbf327d890bb6c033b85ac6174251db69791356fd93e7b9d7c9ecf8b890
@@ -3,14 +3,12 @@ class BehaviorValidator < ActiveModel::EachValidator
3
3
  def valid?(value, options = {})
4
4
  options = options.reject { |option| reserved_options.include?(option) }
5
5
  options.each_pair.all? do |method, expected_result|
6
- value.__send__(method) == expected_result
6
+ value.respond_do?(method) && value.__send__(method) == expected_result
7
7
  end
8
- rescue NoMethodError
9
- false
10
8
  end
11
9
 
12
10
  def reserved_options
13
- [:allow_nil, :allow_blank, :message, :on]
11
+ [:allow_nil, :allow_blank, :message, :on, :if, :unless]
14
12
  end
15
13
  end
16
14
 
@@ -1,3 +1,3 @@
1
1
  class BehaviorValidator
2
- VERSION = '0.0.1'
2
+ VERSION = '0.0.2'
3
3
  end
@@ -88,7 +88,9 @@ describe BehaviorValidator do
88
88
  # Reserved by ActiveModel.
89
89
  allow_nil: true,
90
90
  allow_blank: true,
91
- message: 'hello'
91
+ message: 'hello',
92
+ if: -> { true },
93
+ unless: -> { false }
92
94
  # on: :create
93
95
  }
94
96
  end
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: activemodel-behavior_validator
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.0.1
4
+ version: 0.0.2
5
5
  platform: ruby
6
6
  authors:
7
7
  - Yuku Takahashi
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2015-02-07 00:00:00.000000000 Z
11
+ date: 2015-02-08 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: activemodel