Method: Grape::Validations::Validators::Base#initialize

Defined in:
lib/grape/validations/validators/base.rb

#initialize(attrs, options, required, scope, opts) ⇒ Base

Creates a new Validator from options specified by a requires or optional directive during parameter definition.

Parameters:

  • attrs (Array)

    names of attributes to which the Validator applies

  • options (Object)

    implementation-dependent Validator options; deep-frozen on assignment

  • required (Boolean)

    attribute(s) are required or optional

  • scope (ParamsScope)

    parent scope for this Validator

  • opts (Hash)

    additional validation options



56
57
58
59
60
61
62
63
64
# File 'lib/grape/validations/validators/base.rb', line 56

def initialize(attrs, options, required, scope, opts)
  @attrs = Array(attrs).freeze
  @options = Grape::Util::DeepFreeze.deep_freeze(options)
  @option = @options # TODO: remove in next major release
  @required = required
  @scope = scope
  @fail_fast, @allow_blank = opts.values_at(:fail_fast, :allow_blank)
  @exception_message = message(self.class.default_message_key) if self.class.default_message_key
end