Module: YaKassa::V3::Concerns::Validatable

Included in:
BaseRequest
Defined in:
lib/ya_kassa/v3/concerns/validatable.rb

Defined Under Namespace

Modules: ClassMethods

Constant Summary collapse

VALIDATORS =
{
  present: 'Present',
  is_a: "IsA",
  is_a_boolean: 'IsABoolean',
  float_or_nil: 'FloatOrNil'
}

Class Method Summary collapse

Instance Method Summary collapse

Class Method Details

.included(klass) ⇒ Object



30
31
32
# File 'lib/ya_kassa/v3/concerns/validatable.rb', line 30

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

Instance Method Details

#errorsObject



45
46
47
# File 'lib/ya_kassa/v3/concerns/validatable.rb', line 45

def errors
  @errors.select { |k, v| v.any? }
end

#valid?Boolean

Returns:

  • (Boolean)


34
35
36
37
38
39
40
41
42
43
# File 'lib/ya_kassa/v3/concerns/validatable.rb', line 34

def valid?
  @errors = {}
  valid_arr = validators.map do |opts|
    validator = create_validator(opts)
    validator.validate
    collect_errors(validator)
    validator.valid?
  end
  valid_arr.select { |v| v == false }.empty?
end