Class: Yodatra::ApiFormatter

Inherits:
Object
  • Object
show all
Defined in:
lib/yodatra/api_formatter.rb

Instance Method Summary collapse

Constructor Details

#initialize(app, &block) ⇒ ApiFormatter

Returns a new instance of ApiFormatter.



4
5
6
7
# File 'lib/yodatra/api_formatter.rb', line 4

def initialize(app, &block)
  @app = app
  @block = block if block_given?
end

Instance Method Details

#_call(env) ⇒ Object



13
14
15
16
17
18
19
20
21
# File 'lib/yodatra/api_formatter.rb', line 13

def _call(env)
  status, headers, response = @app.call(env)

  status, headers, response = @block.yield(status, headers, response) unless @block.nil?

  headers['Content-Length'] = response.first.bytes.count.to_s unless response.nil? || !response.respond_to?(:first) || response.first.nil?

  [status, headers, response]
end

#call(env) ⇒ Object



9
10
11
# File 'lib/yodatra/api_formatter.rb', line 9

def call(env)
  dup._call(env)
end