class ControllerValidator::Validator
Nearly entirely lifted from the example code in the Rails Documentation. See: www.rubydoc.info/docs/rails/ActiveModel/Errors
Attributes
errors[R]
Public Class Methods
human_attribute_name(attr, options = {})
click to toggle source
# File lib/controller_validator/validator.rb, line 33 def self.human_attribute_name(attr, options = {}) attr.to_s.humanize end
lookup_ancestors()
click to toggle source
# File lib/controller_validator/validator.rb, line 37 def self.lookup_ancestors [self] end
new(*args)
click to toggle source
# File lib/controller_validator/validator.rb, line 11 def initialize(*args) @errors = ::ActiveModel::Errors.new(self) end
Public Instance Methods
read_attribute_for_validation(attr)
click to toggle source
The following methods are needed to be minimally implemented
# File lib/controller_validator/validator.rb, line 29 def read_attribute_for_validation(attr) send(attr) end
validate()
click to toggle source
# File lib/controller_validator/validator.rb, line 23 def validate raise RuntimeError, 'Must be defined in subclass of ControllerValidator' end
validate_and_push_errors_to(instance:)
click to toggle source
# File lib/controller_validator/validator.rb, line 15 def validate_and_push_errors_to(instance:) unless self.validate! self.errors.full_messages.each do |message| instance.errors.add(:base, message) end end end