Sha256: 5212344f63fcb8ce2adebba02c2d7b8f24c73a765608d10d65df52ebeaab71e3
Contents?: true
Size: 1.21 KB
Versions: 2
Compression:
Stored size: 1.21 KB
Contents
module GrapeApiary class Route < SimpleDelegator # would like to rely on SimpleDelegator but Grape::Route uses # method_missing for these methods :'( delegate :namespace, :path, :request_method, to: '__getobj__' def params @params ||= begin __getobj__.params.stringify_keys.sort.map do |param| Parameter.new(self, *param) end end end def route_name namespace.split('/').last || path.match('\/(\w*?)[\.\/\(]').captures.first end def description "#{__getobj__.description} [#{request_method.upcase}]" end def path_without_format path.gsub(/\((.*?)\)/, '') end def route_model namespace.split('/').last.singularize end def route_type list? ? 'collection' : 'single' end def request_description "+ Request #{'(application/json)' if request_body?}" end def response_description code = request_method == 'POST' ? 201 : 200 "+ Response #{code} (application/json)" end def list? %w(GET POST).include?(request_method) && !path.include?(':id') end private def request_body? !%w(GET DELETE).include?(request_method) end end end
Version data entries
2 entries across 2 versions & 1 rubygems
Version | Path |
---|---|
grape-apiary-1.0.0 | lib/grape-apiary/route.rb |
grape-apiary-0.2.0 | lib/grape-apiary/route.rb |