Module: ParamValidator::Controller

Defined in:
lib/param_validator/controller.rb

Defined Under Namespace

Modules: ClassMethods

Class Method Summary collapse

Instance Method Summary collapse

Class Method Details

.included(other_module) ⇒ Object



4
5
6
# File 'lib/param_validator/controller.rb', line 4

def self.included( other_module )
  other_module.extend ClassMethods
end

Instance Method Details

#validate_parametersObject



16
17
18
19
20
21
22
23
24
25
26
27
28
# File 'lib/param_validator/controller.rb', line 16

def validate_parameters
  klass_name = [self.class.name.gsub( /Controller/, '' ), "#{action_name.titlecase}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