Class: Jsonify

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

Instance Method Summary collapse

Constructor Details

#initialize(route, model) ⇒ Jsonify

Returns a new instance of Jsonify.



2
3
4
5
# File 'lib/jsonify.rb', line 2

def initialize(route, model)
  @route = route
  @model = model
end

Instance Method Details

#call(env) ⇒ Object



7
8
9
10
11
12
# File 'lib/jsonify.rb', line 7

def call(env)
  path = env['REQUEST_PATH']
  response = path == @route ? all : one(find_id(path))
  header = @model.http_cache_header.merge("Content-Type" => "application/json")
  [200, header, [response]]
end