Commit 528e7f04 by PiYa

use check_param_presence? method to check default param

parent 8f3c9b43
......@@ -15,12 +15,11 @@ module RailsParam
def param!(name, type, options = {}, &block)
name = name.to_s unless name.is_a? Integer # keep index for validating elements
return unless params.member?(name) || (not options[:default].nil?) || options[:required]
return unless params.member?(name) || check_param_presence?(options[:default]) || options[:required]
begin
params[name] = coerce(params[name], type, options)
params[name] = (options[:default].call if options[:default].respond_to?(:call)) || options[:default] if params[name].nil? and (not options[:default].nil?)
params[name] = (options[:default].call if options[:default].respond_to?(:call)) || options[:default] if params[name].nil? and check_param_presence?(options[:default])
params[name] = options[:transform].to_proc.call(params[name]) if params[name] and options[:transform]
validate!(params[name], options)
......@@ -66,6 +65,10 @@ module RailsParam
private
def check_param_presence? param
not param.nil?
end
def recurse(params, index = nil)
raise InvalidParameterError, 'no block given' unless block_given?
controller = RailsParam::Param::MockController.new
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment