Class: Rack::JsonSchema::Mock

Inherits:
Object
  • Object
show all
Defined in:
lib/rack/json_schema/mock.rb

Defined Under Namespace

Classes: Error, ExampleNotFound, RequestHandler, ResponseGenerator

Instance Method Summary collapse

Constructor Details

#initialize(app, schema: nil) ⇒ Mock

Behaves as a rack-middleware

Parameters:

  • app (Object)

    Rack application

  • schema (Hash) (defaults to: nil)

    Schema object written in JSON schema format

Raises:

  • (JsonSchema::SchemaError)

8
9
10
11
# File 'lib/rack/json_schema/mock.rb', line 8

def initialize(app, schema: nil)
  @app = app
  @schema = Schema.new(schema)
end

Instance Method Details

#call(env) ⇒ Object

Parameters:

  • env (Hash)

    Rack env


14
15
16
# File 'lib/rack/json_schema/mock.rb', line 14

def call(env)
  RequestHandler.call(app: @app, env: env, schema: @schema)
end