Class: GrapeSwagger::DocMethods::OperationId

Inherits:
Object
  • Object
show all
Defined in:
lib/grape-swagger/doc_methods/operation_id.rb

Class Method Summary collapse

Class Method Details

.build(route, path = nil) ⇒ Object



7
8
9
10
11
12
13
14
# File 'lib/grape-swagger/doc_methods/operation_id.rb', line 7

def build(route, path = nil)
  nickname = route.nickname
  return nickname if nickname

  verb = route.request_method.to_s.downcase
  operation = manipulate(path) unless path.nil?
  "#{verb}#{operation}"
end

.manipulate(path) ⇒ Object



16
17
18
19
20
21
22
23
24
25
26
27
# File 'lib/grape-swagger/doc_methods/operation_id.rb', line 16

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

  operation
end