lib/legion/settings/validator.rb in legion-settings-0.1.1 vs lib/legion/settings/validator.rb in legion-settings-0.2.0
- old
+ new
@@ -6,23 +6,16 @@
module Settings
class Validator
include Rules
include Validators
- # @!attribute [r] failures
- # @return [Array] validation failures.
attr_reader :failures
def initialize
@failures = []
end
- # Run the validator.
- #
- # @param settings [Hash] legion settings to validate.
- # @param service [String] legion service to validate for.
- # @return [Array] validation failures.
def run(settings, service = nil)
validate_legion(settings[:legion])
validate_transport(settings[:transport])
validate_categories(settings)
case service
@@ -44,14 +37,10 @@
end
alias reset reset!
private
- # Validate setting categories: checks, filters, mutators, and
- # handlers.
- #
- # @param settings [Hash] legion settings to validate.
def validate_categories(settings)
CATEGORIES.each do |category|
if is_a_hash?(settings[category])
validate_method = ('validate_' + category.to_s.chop).to_sym
settings[category].each do |name, details|
@@ -61,15 +50,9 @@
invalid(settings[category], "#{category} must be a hash")
end
end
end
- # Record an invalid object with a message.
- #
- # @param object [Object] invalid object.
- # @param message [String] message explaining why the object is
- # invalid.
- # @return [Array] current validation failures.
def invalid(object, message)
@failures << {
object: object,
message: message
}