Class: RestMyCase::Context::SchemaValidator::Base
- Inherits:
-
Object
- Object
- RestMyCase::Context::SchemaValidator::Base
- Defined in:
- lib/rest_my_case/context/schema_validator/base.rb,
lib/rest_my_case/context/schema_validator/compel.rb
Instance Method Summary collapse
-
#initialize(context) ⇒ Base
constructor
A new instance of Base.
- #validate(schema) ⇒ Object
Constructor Details
#initialize(context) ⇒ Base
Returns a new instance of Base.
7 8 9 |
# File 'lib/rest_my_case/context/schema_validator/base.rb', line 7 def initialize(context) @context = context end |
Instance Method Details
#validate(schema) ⇒ Object
11 12 13 14 15 16 17 18 19 20 21 |
# File 'lib/rest_my_case/context/schema_validator/base.rb', line 11 def validate(schema) errors = {} schema.each do |required_attribute| if Helpers.blank?(@context.send(required_attribute)) errors[required_attribute] = 'is required' end end Helpers.blank?(errors) ? nil : errors end |