hash_params 2.0.0 → 2.0.1
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/lib/hash_params.rb +1 -1
- data/lib/hash_params/validator.rb +3 -2
- 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: 18b9b33c318505732f31be28490a86c21f71fbb8
|
4
|
+
data.tar.gz: 85bea6b4b4586a471628133ca29f3fafdd184b78
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 6cb584ef9c38be540b5f63183f44d265f58f4d7d9b9517da8aa4e5372114b54d3afa97ebbddce2e309b81feb9fa95cbf97a18b73dbb85928a52c80269b048a2a
|
7
|
+
data.tar.gz: dcabb95cc3e9b7e8e46672a3e5c2693b5bac428e14c09c65de93cc6c2af2ad51531d9f3f0f8f89a894daf97d30db16de7b8e7c456f6ae837bf1341916bebeb33
|
data/lib/hash_params.rb
CHANGED
@@ -8,7 +8,7 @@ require_relative 'hash_params/binding_validator'
|
|
8
8
|
|
9
9
|
module HashParams
|
10
10
|
ENVIRONMENT = ENV['HASH_PARAMS_ENV'] || (defined?(Rails) && Rails.env) || ENV['RAILS_ENV'] || ENV['RACK_ENV'] || 'development'
|
11
|
-
VERSION = '2.0.
|
11
|
+
VERSION = '2.0.1'
|
12
12
|
extend HashParams::Validator
|
13
13
|
end
|
14
14
|
|
@@ -11,7 +11,7 @@ module HashParams
|
|
11
11
|
BindingValidator.new.with_binding(&code)
|
12
12
|
end
|
13
13
|
|
14
|
-
def validate(param, type, validations={})
|
14
|
+
def validate(param, type=nil, validations={})
|
15
15
|
|
16
16
|
coercions = Array(validations[:coerce]) << type
|
17
17
|
|
@@ -77,7 +77,7 @@ module HashParams
|
|
77
77
|
|
78
78
|
private
|
79
79
|
|
80
|
-
def coerce(val, type, opts={})
|
80
|
+
def coerce(val, type=nil, opts={})
|
81
81
|
|
82
82
|
# exceptions bubble up
|
83
83
|
#order is important
|
@@ -104,6 +104,7 @@ module HashParams
|
|
104
104
|
return type.call(val) if type.respond_to?(:call)
|
105
105
|
#nothing but simple types left
|
106
106
|
return val if val.is_a?(type)
|
107
|
+
return val.to_s.to_sym if type == Symbol
|
107
108
|
return Integer(val) if type == Integer
|
108
109
|
return Float(val) if type == Float
|
109
110
|
return String(val) if type == String
|