Sha256: a0a15651369d63b53c21b462f7837b90d9164fe6d975f7b8663704bda7e34b31
Contents?: true
Size: 826 Bytes
Versions: 6
Compression:
Stored size: 826 Bytes
Contents
require 'core_data' require 'sequel' require 'rack/scaffold' require 'sinatra/base' require 'sinatra/param' class Helios::Backend::Data < Sinatra::Base helpers Sinatra::Param def initialize(app, options = {}) super(Rack::Scaffold.new(options)) @model = CoreData::DataModel.new(options[:model]) rescue nil end before do content_type :json end options '/resources' do links = [] @model.entities.each do |entity| links << %{</#{entity.name.downcase.pluralize}>; 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
Version data entries
6 entries across 6 versions & 1 rubygems