duck_record 0.0.23 → 0.0.24
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/lib/duck_record/validations/subset.rb +12 -3
- data/lib/duck_record/version.rb +1 -1
- metadata +1 -1
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: cabf3726f7d003f3207bd5da1a536d1a4cc4b0ea
|
4
|
+
data.tar.gz: 61604634b3ae7ad953172a00d190012a37c430a0
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 6a3e6595e975d36d0e70e162b1b986e564831f8b42240c1d9e09a164518bb7ee32ccbd4acf95d89370a0e29f89ed4ef598c5369f9d48ecc45e9ff42798e774be
|
7
|
+
data.tar.gz: b868f9688ce9fbabdd37ea6069f4636a5fa31f68eda6684d0072ad4b2dd2d51970a4664c0f5e3e7f6728bd7a57e5918dac4f1c0110c19b1f8f6bb89ca074b4c3
|
@@ -1,11 +1,16 @@
|
|
1
1
|
# frozen_string_literal: true
|
2
2
|
|
3
|
-
require "active_model/validations/clusivity"
|
4
|
-
|
5
3
|
module DuckRecord
|
6
4
|
module Validations
|
7
5
|
class SubsetValidator < ActiveModel::EachValidator # :nodoc:
|
8
|
-
include
|
6
|
+
ERROR_MESSAGE = "An object with the method #include? or a proc, lambda or symbol is required, " \
|
7
|
+
"and must be supplied as the :in (or :within) option of the configuration hash"
|
8
|
+
|
9
|
+
def check_validity!
|
10
|
+
unless delimiter.respond_to?(:include?) || delimiter.respond_to?(:call) || delimiter.respond_to?(:to_sym)
|
11
|
+
raise ArgumentError, ERROR_MESSAGE
|
12
|
+
end
|
13
|
+
end
|
9
14
|
|
10
15
|
def validate_each(record, attribute, value)
|
11
16
|
unless subset?(record, value)
|
@@ -15,6 +20,10 @@ module DuckRecord
|
|
15
20
|
|
16
21
|
private
|
17
22
|
|
23
|
+
def delimiter
|
24
|
+
@delimiter ||= options[:in] || options[:within]
|
25
|
+
end
|
26
|
+
|
18
27
|
def subset?(record, value)
|
19
28
|
return false unless value.respond_to?(:to_a)
|
20
29
|
|
data/lib/duck_record/version.rb
CHANGED