Sha256: 776f270fc118f9104fcb77cb4181a0492646f1bdbd41437214658c921e7a3ea6
Contents?: true
Size: 1.29 KB
Versions: 3
Compression:
Stored size: 1.29 KB
Contents
require 'forwardable' module ServiceContract module Avro class Endpoint < AbstractEndpoint extend Forwardable def_delegators :definition, :name, :response, :request def description [request_method, path].join(" ") end def doc definition.respond_to?(:doc) ? definition.doc : nil end def response_type Type.build(response) end def parameters request.fields.map{|field| Parameter.new(field) } end protected def request_method case name when "create" "POST" when "update" "PUT" when "destroy" "DELETE" else "GET" end end def path case name when "index", "create" protocol.path when "show", "destroy", "update" File.join(protocol.path, ":id") else if member? File.join(protocol.path, ":id", name) else File.join(protocol.path, name) end end end # seems kinda hacky def member? first_field_type = request.fields.first.type first_field_type.is_a?(::Avro::Schema::RecordSchema) && first_field_type.name == protocol.main_type end end end end
Version data entries
3 entries across 3 versions & 1 rubygems
Version | Path |
---|---|
service_contract-0.0.7 | lib/service_contract/avro/endpoint.rb |
service_contract-0.0.6 | lib/service_contract/avro/endpoint.rb |
service_contract-0.0.5 | lib/service_contract/avro/endpoint.rb |