Sha256: 64868f712f1cb407f39cf8d5f104bda1c950568657ac8113d68d64c8ba2b8c95

Contents?: true

Size: 434 Bytes

Versions: 3

Compression:

Stored size: 434 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))
    [200, {"Content-Type" => "application/json"}, [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

3 entries across 3 versions & 1 rubygems

Version Path
scrapify-0.0.4 lib/jsonify.rb
scrapify-0.0.3 lib/jsonify.rb
scrapify-0.0.2 lib/jsonify.rb