Module: RSchema::Rails::Controller::InstanceMethods

Defined in:
lib/rschema/rails.rb

Overview

Instance methods added to ActionController classes

Instance Method Summary collapse

Instance Method Details

#param_schema(&schema_block) ⇒ Object


21
22
23
# File 'lib/rschema/rails.rb', line 21

def param_schema(&schema_block)
  self.class.param_schema(&schema_block)
end

#validate_params(schema = nil, &schema_block) ⇒ Object


25
26
27
28
# File 'lib/rschema/rails.rb', line 25

def validate_params(schema = nil, &schema_block)
  schema ||= param_schema(&schema_block)
  schema.validate(request.parameters.to_hash)
end

#validate_params!(*args, &block) ⇒ Object

Raises:


30
31
32
33
34
# File 'lib/rschema/rails.rb', line 30

def validate_params!(*args, &block)
  result = validate_params(*args, &block)
  raise InvalidParams.new(result.error) if result.invalid?
  result.value
end