Sha256: 2ab47e0dd53c1ddf6a41f7d5f508f7ce22c95d577812c51536ce9c1e87309b19
Contents?: true
Size: 1.27 KB
Versions: 2
Compression:
Stored size: 1.27 KB
Contents
module GrapeApiary class Route < SimpleDelegator # would like to rely on SimpleDelegator but Grape::Route uses # method_missing for these methods :'( delegate :route_namespace, :route_path, :route_method, to: '__getobj__' def route_params @route_params ||= begin __getobj__.route_params.stringify_keys.sort.map do |param| Parameter.new(self, *param) end end end def route_name route_namespace.split('/').last || route_path.match('\/(\w*?)[\.\/\(]').captures.first end def route_description "#{__getobj__.route_description} [#{route_method.upcase}]" end def route_path_without_format route_path.gsub(/\((.*?)\)/, '') end def route_model route_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 = route_method == 'POST' ? 201 : 200 "+ Response #{code} (application/json)" end def list? %w(GET POST).include?(route_method) && !route_path.include?(':id') end private def request_body? !%w(GET DELETE).include?(route_method) end end end
Version data entries
2 entries across 2 versions & 1 rubygems
Version | Path |
---|---|
grape-apiary-0.1.2 | lib/grape-apiary/route.rb |
grape-apiary-0.1.1 | lib/grape-apiary/route.rb |