Class: Automatic::Config::Validator
- Inherits:
-
Object
- Object
- Automatic::Config::Validator
- Defined in:
- lib/config/validator.rb
Defined Under Namespace
Modules: ValidateRule Classes: InvalidException, ValidateResult
Instance Attribute Summary collapse
-
#config ⇒ Object
Returns the value of attribute config.
-
#result ⇒ Object
Returns the value of attribute result.
Instance Method Summary collapse
-
#initialize(config = nil) ⇒ Validator
constructor
A new instance of Validator.
- #validate(klass, config = nil) ⇒ Object
Constructor Details
#initialize(config = nil) ⇒ Validator
Returns a new instance of Validator.
17 18 19 20 |
# File 'lib/config/validator.rb', line 17 def initialize(config = nil) @config = config || {} @result = ValidateResult.new end |
Instance Attribute Details
#config ⇒ Object
Returns the value of attribute config.
13 14 15 |
# File 'lib/config/validator.rb', line 13 def config @config end |
#result ⇒ Object
Returns the value of attribute result.
13 14 15 |
# File 'lib/config/validator.rb', line 13 def result @result end |
Instance Method Details
#validate(klass, config = nil) ⇒ Object
22 23 24 25 26 27 28 29 30 31 |
# File 'lib/config/validator.rb', line 22 def validate(klass, config = nil) return true if config.nil? return true if not config.is_a?(Hash) return true if not klass.respond_to?(:rules) rules = klass.rules return true if not rules.is_a?(Hash) process(rules, config).result.valid? end |