Class: ParamsChecker::ParamChecker::ArrParamChecker

Inherits:
BaseParamChecker show all
Includes:
SimpleCommand
Defined in:
lib/params_checker/param_checker.rb

Instance Attribute Summary

Attributes inherited from BaseParamChecker

#fields, #key, #opts

Instance Method Summary collapse

Methods inherited from BaseParamChecker

#add_error, #initialize

Constructor Details

This class inherits a constructor from ParamsChecker::ParamChecker::BaseParamChecker

Instance Method Details

#callObject



102
103
104
105
106
# File 'lib/params_checker/param_checker.rb', line 102

def call
    return nil if fields[key][:allow_nil] && opts[key].nil?

    check_type && check_allow_empty && opts[key]
end

#check_allow_emptyObject



114
115
116
117
118
# File 'lib/params_checker/param_checker.rb', line 114

def check_allow_empty
    valid =!(!fields[key][:allow_empty] && opts[key].empty?)
    add_error('This field cannot be empty.') unless valid
    valid
end

#check_typeObject



108
109
110
111
112
# File 'lib/params_checker/param_checker.rb', line 108

def check_type
    valid =opts[key].is_a? Array
    add_error("This field's type must be array.") unless valid
    valid
end