Sha256: 558510cc6d59a9ca3b6f49f0c92f0754f660db2a645c37b5e4abcbf4ccd2a070

Contents?: true

Size: 832 Bytes

Versions: 1

Compression:

Stored size: 832 Bytes

Contents

require 'rack/core-data'
require 'sinatra/param'

class Helios::Backend::Data < Sinatra::Base
  helpers Sinatra::Param

  def initialize(app, options = {})
    super(Rack::CoreData(options[:model]))

    @model = Rack::CoreData::DataModel.new(options[:model])
  end

  before do
    content_type :json
  end

  helpers Sinatra::Param

  options '/' do
    pass unless self.class < Helios::Administerable

    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

1 entries across 1 versions & 1 rubygems

Version Path
helios-0.2.0 ./lib/helios/backend/data.rb