Class: Kangaru::Validator
- Inherits:
-
Object
- Object
- Kangaru::Validator
- Defined in:
- lib/kangaru/validator.rb
Direct Known Subclasses
Instance Attribute Summary collapse
-
#attribute ⇒ Object
readonly
Returns the value of attribute attribute.
-
#model ⇒ Object
readonly
Returns the value of attribute model.
-
#params ⇒ Object
readonly
Returns the value of attribute params.
-
#value ⇒ Object
readonly
Returns the value of attribute value.
Instance Method Summary collapse
- #add_error!(message) ⇒ Object
-
#initialize(model:, attribute:, **params) ⇒ Validator
constructor
A new instance of Validator.
- #validate ⇒ Object
Constructor Details
#initialize(model:, attribute:, **params) ⇒ Validator
Returns a new instance of Validator.
5 6 7 8 9 10 |
# File 'lib/kangaru/validator.rb', line 5 def initialize(model:, attribute:, **params) @model = model @attribute = attribute @params = params @value = model.public_send(attribute) end |
Instance Attribute Details
#attribute ⇒ Object (readonly)
Returns the value of attribute attribute.
3 4 5 |
# File 'lib/kangaru/validator.rb', line 3 def attribute @attribute end |
#model ⇒ Object (readonly)
Returns the value of attribute model.
3 4 5 |
# File 'lib/kangaru/validator.rb', line 3 def model @model end |
#params ⇒ Object (readonly)
Returns the value of attribute params.
3 4 5 |
# File 'lib/kangaru/validator.rb', line 3 def params @params end |
#value ⇒ Object (readonly)
Returns the value of attribute value.
3 4 5 |
# File 'lib/kangaru/validator.rb', line 3 def value @value end |
Instance Method Details
#add_error!(message) ⇒ Object
16 17 18 |
# File 'lib/kangaru/validator.rb', line 16 def add_error!() model.errors << Validation::Error.new(attribute:, message:) end |
#validate ⇒ Object
12 13 14 |
# File 'lib/kangaru/validator.rb', line 12 def validate raise NotImplementedError end |