require 'rack/core-data' class Helios::Backend::Data < Sinatra::Base use Rack::PostBodyContentTypeParser def initialize(xcdatamodel) super(Rack::CoreData(xcdatamodel)) @model = Rack::CoreData::DataModel.new(xcdatamodel) end before do content_type :json end helpers Sinatra::Param options '/' do pass unless settings.frontend rescue false links = [] @model.entities.each do |entity| links << %{; rel="resource"} end response['Link'] = links.join("\n") @model.entities.collect{ |entity| { name: entity.name, url: "/#{entity.name.downcase.pluralize}", attributes: Hash[entity.attributes.collect{|attribute| [attribute.name, attribute.type]}] } }.to_json end end