Class: Smooth::Endpoint

Inherits:
Sinatra::Base
  • Object
show all
Defined in:
lib/smooth/endpoint.rb

Class Method Summary collapse

Class Method Details

.interface_for(model_class, options = {}) ⇒ Object



8
9
10
11
12
13
14
15
16
17
18
19
20
21
# File 'lib/smooth/endpoint.rb', line 8

def self.interface_for(model_class, options={})
  collection    = model_class.collection
  resource_name = options.fetch(:resource_name, collection.namespace)
  prefix        = options.fetch(:prefix, "/smooth/api/v1")

  get "#{ prefix }/#{ resource_name }" do
    json collection.query(params)
  end

  get "#{ prefix }/#{ resource_name }/:id" do
    json collection.show(params[:id])
  end

end