Class: HttpStub::Server::Stub::Match::Rule::SchemaBody

Inherits:
Object
  • Object
show all
Defined in:
lib/http_stub/server/stub/match/rule/schema_body.rb

Class Method Summary collapse

Class Method Details

.create(schema) ⇒ Object


15
16
17
18
19
20
21
22
23
# File 'lib/http_stub/server/stub/match/rule/schema_body.rb', line 15

def create(schema)
  validate(schema)
  begin
    body_class = HttpStub::Server::Stub::Match::Rule.const_get("#{schema[:type].capitalize}SchemaBody")
    body_class.new(schema[:definition])
  rescue NameError
    raise "Stub request body schema #{schema} is invalid: #{schema[:type]} schema is not supported"
  end
end

.validate(schema) ⇒ Object


25
26
27
28
29
# File 'lib/http_stub/server/stub/match/rule/schema_body.rb', line 25

def validate(schema)
  MANDATORY_ELEMENT_NAMES.each do |name|
    raise "Stub request body schema #{schema} is invalid: #{name} expected" unless schema[name]
  end
end