Sha256: b9c24155389604e65d152760f30ab5d56c8abedb90f84060360945f6362d9232

Contents?: true

Size: 1.08 KB

Versions: 30

Compression:

Stored size: 1.08 KB

Contents

# frozen_string_literal: true

module GrapeSwagger
  module DocMethods
    class PathString
      class << self
        def build(route, options = {})
          path = route.path.dup
          # always removing format
          path.sub!(/\(\.\w+?\)$/, '')
          path.sub!('(.:format)', '')

          # ... format path params
          path.gsub!(/:(\w+)/, '{\1}')

          # set item from path, this could be used for the definitions object
          path_name = path.gsub(%r{/{(.+?)}}, '').split('/').last
          item = path_name.present? ? path_name.singularize.underscore.camelize : 'Item'

          if route.version && options[:add_version]
            version = GrapeSwagger::DocMethods::Version.get(route)
            version = version.first while version.is_a?(Array)
            path.sub!('{version}', version.to_s)
          else
            path.sub!('/{version}', '')
          end

          path = "#{OptionalObject.build(:base_path, options)}#{path}" if options[:add_base_path]

          [item, path.start_with?('/') ? path : "/#{path}"]
        end
      end
    end
  end
end

Version data entries

30 entries across 30 versions & 1 rubygems

Version Path
grape-swagger-2.1.1 lib/grape-swagger/doc_methods/path_string.rb
grape-swagger-2.0.3 lib/grape-swagger/doc_methods/path_string.rb
grape-swagger-2.0.2 lib/grape-swagger/doc_methods/path_string.rb
grape-swagger-2.0.1 lib/grape-swagger/doc_methods/path_string.rb
grape-swagger-2.0.0 lib/grape-swagger/doc_methods/path_string.rb
grape-swagger-1.6.1 lib/grape-swagger/doc_methods/path_string.rb
grape-swagger-1.6.0 lib/grape-swagger/doc_methods/path_string.rb
grape-swagger-1.5.0 lib/grape-swagger/doc_methods/path_string.rb
grape-swagger-1.4.2 lib/grape-swagger/doc_methods/path_string.rb
grape-swagger-1.4.1 lib/grape-swagger/doc_methods/path_string.rb
grape-swagger-1.4.0 lib/grape-swagger/doc_methods/path_string.rb
grape-swagger-1.3.1 lib/grape-swagger/doc_methods/path_string.rb
grape-swagger-1.3.0 lib/grape-swagger/doc_methods/path_string.rb
grape-swagger-1.2.1 lib/grape-swagger/doc_methods/path_string.rb
grape-swagger-1.2.0 lib/grape-swagger/doc_methods/path_string.rb
grape-swagger-1.1.0 lib/grape-swagger/doc_methods/path_string.rb
grape-swagger-1.0.0 lib/grape-swagger/doc_methods/path_string.rb
grape-swagger-0.34.2 lib/grape-swagger/doc_methods/path_string.rb
grape-swagger-0.34.1 lib/grape-swagger/doc_methods/path_string.rb
grape-swagger-0.34.0 lib/grape-swagger/doc_methods/path_string.rb