Class: Respect::Rails::ResponseDef

Inherits:
Object
  • Object
show all
Defined in:
lib/respect/rails/response_def.rb

Class Method Summary (collapse)

Instance Method Summary (collapse)

Constructor Details

- (ResponseDef) initialize(*args)

A new instance of ResponseDef



11
12
13
# File 'lib/respect/rails/response_def.rb', line 11

def initialize(*args)
  @response_schema = ResponseSchema.new(*args)
end

Class Method Details

+ (Object) eval(*args, &block)



6
7
8
# File 'lib/respect/rails/response_def.rb', line 6

def eval(*args, &block)
  new(*args).eval(&block)
end

Instance Method Details

- (Object) body(options = {}, &block)

Define the schema of the response body.

Parameters:

  • options (Hash) (defaults to: {})

    a customizable set of options

Options Hash (options):

  • hash (Boolean) — default: true

    whether the body is hash schema.



22
23
24
25
26
27
28
29
30
# File 'lib/respect/rails/response_def.rb', line 22

def body(options = {}, &block)
  @response_schema.body = (
    if options.fetch(:hash, true)
      HashSchema.define(&block)
    else
      Schema.define(&block)
    end
    )
end

- (Object) documentation(text)

Set the documentation to text.



37
38
39
# File 'lib/respect/rails/response_def.rb', line 37

def documentation(text)
  @response_schema.documentation = text
end

- (Object) eval(&block)



15
16
17
18
# File 'lib/respect/rails/response_def.rb', line 15

def eval(&block)
  block.call(self)
  @response_schema
end

- (Object) headers(options = {}, &block)



32
33
34
# File 'lib/respect/rails/response_def.rb', line 32

def headers(options = {}, &block)
  @response_schema.headers = HashSchema.define(options, &block)
end