lib/grape/validations/coerce.rb in grape-0.6.0 vs lib/grape/validations/coerce.rb in grape-0.6.1
- old
+ new
@@ -1,26 +1,27 @@
module Grape
class API
- Boolean = Virtus::Attribute::Boolean
+ Boolean = Virtus::Attribute::Boolean # rubocop:disable ConstantName
end
module Validations
class CoerceValidator < SingleOptionValidator
def validate_param!(attr_name, params)
new_value = coerce_value(@option, params[attr_name])
if valid_type?(new_value)
params[attr_name] = new_value
else
- raise Grape::Exceptions::Validation, :param => @scope.full_name(attr_name), :message_key => :coerce
+ raise Grape::Exceptions::Validation, param: @scope.full_name(attr_name), message_key: :coerce
end
end
class InvalidValue; end
- private
+ private
+
def _valid_array_type?(type, values)
values.all? do |val|
_valid_single_type?(type, val)
end
end
@@ -44,14 +45,14 @@
_valid_single_type?(@option, val)
end
end
def coerce_value(type, val)
- converter = Virtus::Attribute.build(:a, type)
+ converter = Virtus::Attribute.build(type)
converter.coerce(val)
# not the prettiest but some invalid coercion can currently trigger
- # errors in Virtus (see coerce_spec.rb)
+ # errors in Virtus (see coerce_spec.rb:75)
rescue
InvalidValue.new
end
end