Sha256: f4e4ce11f09b23f442951c589353efa55d5a345b33f0ffe864d72f6aa71d1f5f

Contents?: true

Size: 485 Bytes

Versions: 5

Compression:

Stored size: 485 Bytes

Contents

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

  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

  private

  def all
    @model.all.to_json
  end

  def one(id)
    @model.find(id).to_json
  end

  def find_id(path)
    path[path.rindex('/') + 1, path.size]
  end
end

Version data entries

5 entries across 5 versions & 1 rubygems

Version Path
scrapify-0.0.9 lib/jsonify.rb
scrapify-0.0.8 lib/jsonify.rb
scrapify-0.0.7 lib/jsonify.rb
scrapify-0.0.6 lib/jsonify.rb
scrapify-0.0.5 lib/jsonify.rb