Sha256: d290412f26baa76e3226b010685ed9db873ed99100a4a9752d831f0c3c15426f

Contents?: true

Size: 989 Bytes

Versions: 3

Compression:

Stored size: 989 Bytes

Contents

module GrapeSwagger
  module DocMethods
    class OperationId
      class << self
        def build(route, path = nil)
          if route.options[:nickname]
            operation_id = route.options[:nickname]
          else
            verb = route.request_method.to_s.downcase

            operation = manipulate(path) unless path.nil?

            operation_id = "#{verb}#{operation}"
          end

          operation_id
        end

        def manipulate(path)
          operation = path.split('/').map(&:capitalize).join
          operation.gsub!(/\-(\w)/, &:upcase).delete!('-') if operation.include?('-')
          operation.gsub!(/\_(\w)/, &:upcase).delete!('_') if operation.include?('_')
          operation.gsub!(/\.(\w)/, &:upcase).delete!('.') if operation.include?('.')
          if path.include?('{')
            operation.gsub!(/\{(\w)/, &:upcase)
            operation.delete!('{').delete!('}')
          end

          operation
        end
      end
    end
  end
end

Version data entries

3 entries across 3 versions & 1 rubygems

Version Path
grape-swagger-0.26.1 lib/grape-swagger/doc_methods/operation_id.rb
grape-swagger-0.26.0 lib/grape-swagger/doc_methods/operation_id.rb
grape-swagger-0.25.3 lib/grape-swagger/doc_methods/operation_id.rb