Sha256: 47f245ffe494a61fc68aa585cecf6df94d0347c73129af1570bd4643d8822c1f
Contents?: true
Size: 1.89 KB
Versions: 1
Compression:
Stored size: 1.89 KB
Contents
require 'sinatra/base' require 'sinatra/json' require 'slim' module ServiceContract module Avro class Documentation < Sinatra::Base get '/:version/:protocol' do version = service.find(params[:version]) protocol = version.protocol(params[:protocol]) if request_json? content_type "application/json" send_file File.join(service.data_dir, version.version, "compiled", "#{protocol.name}.avpr") else slim :protocol, locals: { version: version, protocol: protocol } end end get '/:version' do version = service.find(params[:version]) if version if request_json? json version: { version: version.version, protocols: version.protocols.map { |protocol| { name: protocol.name, link: "/#{version.version}/#{protocol.name}" } } } else slim :version, locals: { version: version } end else status 404 end end get '/' do if request_json? json contract: { name: service.name, title: service.title, description: service.description, release_version: release_version, versions: service.all.map { |version| { version: version.version, link: "/#{version.version}" } } } else slim :homepage end end helpers do def service raise :not_implemented end def request_json? request.accept.map(&:entry).include?("application/json") end def release_version service.const_defined?("VERSION") ? service.const_get("VERSION") : "" end end end end end
Version data entries
1 entries across 1 versions & 1 rubygems
Version | Path |
---|---|
service_contract-0.6.0 | lib/service_contract/avro/documentation.rb |