module NubeFact::Validator

Public Class Methods

included(klass) click to toggle source

Following methods solve the issue of having required fields inherits from a base class

# File lib/util/validator.rb, line 4
def self.included(klass)
  klass.extend ClassMethods
end

Public Instance Methods

validate!() click to toggle source
# File lib/util/validator.rb, line 24
def validate!
  #ToDO change for a real validator like ActiveModel::Validations or Hanami::Validations
  self.class::required_fields.each do |field|
    if send(field).nil?
      raise NubeFact::ValidationError.new "#{field} it's a required field."
    end
  end
  true
end