class Baleen::Validation::Common

Public Class Methods

new(yaml) click to toggle source
# File lib/baleen/validator.rb, line 22
def initialize(yaml)
  @section = self.class.to_s.split("::").last.downcase.to_sym
  @project  = yaml[@section]
end

Public Instance Methods

attributes() click to toggle source
# File lib/baleen/validator.rb, line 27
def attributes
  mandatory_attributes + optional_attributes
end
validate() click to toggle source
# File lib/baleen/validator.rb, line 31
def validate
  unless @project
    hl_error "Your baleen.yml is missing the following mandatory section"
    hl_warn  " :#{@section}"
    raise Baleen::Error::Validator::MandatoryMissing
  end

  mandatory = mandatory_attributes
  @project.keys.each do |k|
    mandatory.delete k
    unless attributes.include? k
      hl_error "Your baleen.yml has the following invalid attribute at :#{@section} section"
      hl_warn " :#{k}"
      return false
    end
  end

  unless mandatory.empty?
    hl_error "Following attributes are mandatory at :#{@section} section of baleen.yml"
    mandatory.each {|m| hl_warn " :#{m}"}
    raise Baleen::Error::Validator::MandatoryMissing
  end

  true
end