class RailsParam::Validator

Constants

VALIDATABLE_OPTIONS

Attributes

parameter[R]

Public Class Methods

new(parameter) click to toggle source
# File lib/rails_param/validator.rb, line 24
def initialize(parameter)
  @parameter = parameter
end

Public Instance Methods

valid!() click to toggle source
# File lib/rails_param/validator.rb, line 37
def valid!
  return if valid_value?

  raise InvalidParameterError.new(
    error_message,
    param: name,
    options: options
  )
end
validate!() click to toggle source
# File lib/rails_param/validator.rb, line 28
def validate!
  options.each_key do |key|
    next unless VALIDATABLE_OPTIONS.include? key

    class_name = camelize(key)
    Validator.const_get(class_name).new(parameter).valid!
  end
end

Private Instance Methods

camelize(term) click to toggle source
# File lib/rails_param/validator.rb, line 49
def camelize(term)
  string = term.to_s
  string.split('_').collect(&:capitalize).join
end
error_message() click to toggle source
# File lib/rails_param/validator.rb, line 54
def error_message
  nil
end
valid_value?() click to toggle source
# File lib/rails_param/validator.rb, line 58
def valid_value?
  # Should be overwritten in subclass
  false
end