Module: Sinatra::ParamValidator::Rule::Common

Included in:
AllOrNoneOf, AnyOf, OneOf
Defined in:
lib/sinatra/param_validator/rule/common.rb

Overview

Common validation methods shared between rules

Instance Attribute Summary collapse

Instance Method Summary collapse

Instance Attribute Details

#errorsObject (readonly)

Returns the value of attribute errors.



8
9
10
# File 'lib/sinatra/param_validator/rule/common.rb', line 8

def errors
  @errors
end

Instance Method Details

#countObject



18
19
20
# File 'lib/sinatra/param_validator/rule/common.rb', line 18

def count
  @count ||= (@fields & @params.keys.map(&:to_sym)).count
end

#initialize(params, *fields, **_kwargs) ⇒ Object



10
11
12
13
14
15
16
# File 'lib/sinatra/param_validator/rule/common.rb', line 10

def initialize(params, *fields, **_kwargs)
  @errors = []
  @params = params
  @fields = fields

  validate
end

#passes?Boolean

Returns:

  • (Boolean)


22
23
24
# File 'lib/sinatra/param_validator/rule/common.rb', line 22

def passes?
  @errors.empty?
end