module LuckyParam
An easy and extendable controller validator helper for Rails.
Constants
- CHECKER
- VERSION
Public Instance Methods
optional(column, checker_type)
click to toggle source
# File lib/lucky_param.rb, line 20 def optional(column, checker_type) return if params[column].blank? check_param_format(column, checker_type) end
required(column, checker_type)
click to toggle source
# File lib/lucky_param.rb, line 14 def required(column, checker_type) raise ParamMissError.new("Missing Params: #{column}") if params[column].blank? check_param_format(column, checker_type) end
Private Instance Methods
check_param_format(column, checker_type)
click to toggle source
# File lib/lucky_param.rb, line 28 def check_param_format(column, checker_type) checker = CUSTOM_CHECKER[checker_type] if LuckyParam.const_defined?(:CUSTOM_CHECKER) checker ||= CHECKER.fetch(checker_type) do raise UnknownCheckerError.new("Unknown checker `#{checker_type}`, try to define checker with const `LuckyParam::CUSTOM_CHECKER`") end result = checker[0].call(params, column) raise ParamFormatError.new("Wrong Params Format: #{column} #{checker[1]}") unless result end