Class: RestMyCase::Context::SchemaValidator::Base

Inherits:
Object
  • Object
show all
Defined in:
lib/rest_my_case/context/schema_validator/base.rb,
lib/rest_my_case/context/schema_validator/compel.rb

Instance Method Summary collapse

Constructor Details

#initialize(context) ⇒ Base

Returns a new instance of Base.



5
6
7
# File 'lib/rest_my_case/context/schema_validator/base.rb', line 5

def initialize(context)
  @context = context
end

Instance Method Details

#validate(schema) ⇒ Object



9
10
11
12
13
14
15
16
17
18
19
# File 'lib/rest_my_case/context/schema_validator/base.rb', line 9

def validate(schema)
  errors = {}

  schema.each do |required_attribute|
    if @context.send(required_attribute).nil?
      errors[required_attribute] = 'is required'
    end
  end

  Helpers.blank?(errors) ? nil : errors
end