Module: NubeFact::Validator

Included in:
Document, Document::Item
Defined in:
lib/util/validator.rb

Defined Under Namespace

Modules: ClassMethods

Class Method Summary collapse

Instance Method Summary collapse

Class Method Details

.included(klass) ⇒ Object

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



4
5
6
# File 'lib/util/validator.rb', line 4

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

Instance Method Details

#validate!Object



24
25
26
27
28
29
30
31
32
# 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