10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
|
# File 'lib/hash_params/binding_validator.rb', line 10
def var(var_name, type, opts={})
raise 'Variable name must be a string or symbol' unless (var_name.is_a?(String) || var_name.is_a?(Symbol))
value = @binding.local_variable_get var_name
new_value = if value.is_a?(Hash)
if block_given?
HashParams::HashValidator.new.validate_hash(value, opts, &Proc.new)
else
HashParams::HashValidator.new.validate_hash(value, opts)
end
else
HashParams.validate value, type, opts
end
@binding.local_variable_set var_name, new_value
end
|