Class: Plz::ResponseRenderer

Inherits:
Object
  • Object
show all
Defined in:
lib/plz/response_renderer.rb

Class Method Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(status: nil, headers: nil, body: nil, response_header: nil, response_body: nil, color: nil) ⇒ ResponseRenderer

Returns a new instance of ResponseRenderer.

Parameters:

  • status (Fixnum) (defaults to: nil)

    Status code

  • headers (Hash) (defaults to: nil)

    Response header fields

  • body (Array, Hash) (defaults to: nil)

    JSON decoded response body

  • response_header (true, false) (defaults to: nil)

    Flag to show response header

  • response_body (true, false) (defaults to: nil)

    Flag to show response body

  • color (true, false) (defaults to: nil)

    Flag to color response body



14
15
16
17
18
19
20
21
# File 'lib/plz/response_renderer.rb', line 14

def initialize(status: nil, headers: nil, body: nil, response_header: nil, response_body: nil, color: nil)
  @status = status
  @headers = headers
  @body = body
  @show_response_header = response_header
  @show_response_body = response_body
  @color_response = color
end

Class Method Details

.call(*args) ⇒ Object

Shortcut for #call method



4
5
6
# File 'lib/plz/response_renderer.rb', line 4

def self.call(*args)
  new(*args).call
end

Instance Method Details

#callString

Renders response with given options

Returns:

  • (String)

    Rendered output



25
26
27
28
29
30
31
# File 'lib/plz/response_renderer.rb', line 25

def call
  template % {
    status: status,
    headers: headers,
    body: body,
  }
end