module ParamValidator::Controller

Public Class Methods

included( other_module ) click to toggle source
# File lib/param_validator/controller.rb, line 4
def self.included( other_module )
  other_module.extend ClassMethods
end

Public Instance Methods

validate_parameters() click to toggle source
# File lib/param_validator/controller.rb, line 16
def validate_parameters
  klass_name = [self.class.name.gsub( /Controller/, '' ), "#{action_name.camelize}ParamValidator"].join( '::' )
  klass = klass_name.constantize
  validator = klass.new( params )
  unless validator.valid?
    raise ParamValidator::InvalidParameters.new( validator.full_errors.join( ', '))
  end
rescue NameError => e
  raise if e.is_a?( NoMethodError )
  raise NotImplementedError,
        "please implement #{klass_name} param validator"
        e.backtrace
end