Class: Kangaru::Validation::AttributeValidator

Inherits:
Object
  • Object
show all
Defined in:
lib/kangaru/validation/attribute_validator.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(model:, attribute:) ⇒ AttributeValidator

Returns a new instance of AttributeValidator.



8
9
10
11
# File 'lib/kangaru/validation/attribute_validator.rb', line 8

def initialize(model:, attribute:)
  @model = model
  @attribute = attribute
end

Instance Attribute Details

#attributeObject (readonly)

Returns the value of attribute attribute.



6
7
8
# File 'lib/kangaru/validation/attribute_validator.rb', line 6

def attribute
  @attribute
end

#modelObject (readonly)

Returns the value of attribute model.



6
7
8
# File 'lib/kangaru/validation/attribute_validator.rb', line 6

def model
  @model
end

Instance Method Details

#validate!(**validations) ⇒ Object



13
14
15
16
17
18
19
# File 'lib/kangaru/validation/attribute_validator.rb', line 13

def validate!(**validations)
  validations.each do |validator, params|
    params = {} if params == true

    load_validator(validator:, **params).validate
  end
end