Class: OasRails::Builders::ParameterBuilder

Inherits:
Object
  • Object
show all
Defined in:
lib/oas_rails/builders/parameter_builder.rb

Instance Method Summary collapse

Constructor Details

#initialize(specification) ⇒ ParameterBuilder

Returns a new instance of ParameterBuilder.



4
5
6
7
# File 'lib/oas_rails/builders/parameter_builder.rb', line 4

def initialize(specification)
  @specification = specification
  @parameter = Spec::Parameter.new(specification)
end

Instance Method Details

#buildObject



23
24
25
# File 'lib/oas_rails/builders/parameter_builder.rb', line 23

def build
  @parameter
end

#extract_word_before(string, param) ⇒ Object



17
18
19
20
21
# File 'lib/oas_rails/builders/parameter_builder.rb', line 17

def extract_word_before(string, param)
  regex = %r{/(\w+)/\{#{param}\}}
  match = string.match(regex)
  match ? match[1] : nil
end

#from_path(path, param) ⇒ Object



9
10
11
12
13
14
15
# File 'lib/oas_rails/builders/parameter_builder.rb', line 9

def from_path(path, param)
  @parameter.name = param
  @parameter.in = 'path'
  @parameter.description = "#{param.split('_')[-1].titleize} of existing #{extract_word_before(path, param).singularize}."

  self
end