Class: Baleen::Validation::Common
- Inherits:
-
Object
- Object
- Baleen::Validation::Common
- Defined in:
- lib/baleen/validator.rb
Instance Method Summary collapse
- #attributes ⇒ Object
-
#initialize(yaml) ⇒ Common
constructor
A new instance of Common.
- #validate ⇒ Object
Constructor Details
#initialize(yaml) ⇒ Common
Returns a new instance of Common.
22 23 24 25 |
# File 'lib/baleen/validator.rb', line 22 def initialize(yaml) @section = self.class.to_s.split("::").last.downcase.to_sym @project = yaml[@section] end |
Instance Method Details
#attributes ⇒ Object
27 28 29 |
# File 'lib/baleen/validator.rb', line 27 def attributes mandatory_attributes + optional_attributes end |
#validate ⇒ Object
31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 |
# 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 |