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
15
# File 'lib/grape-swagger/doc_methods/operation_id.rb', line 7

def build(route, path = nil)
  if route.options[:nickname]
    route.options[:nickname]
  else
    verb = route.request_method.to_s.downcase
    operation = manipulate(path) unless path.nil?
    "#{verb}#{operation}"
  end
end

.manipulate(path) ⇒ Object



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

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