class R2OAS::Routing::PathComponent

Constants

BRACE_PATH_PARAMETER_REGEXP
FORMAT_PATH_PARAMETER_REGEXP
SYMBOL_PATH_PARAMETER_REGEXP

Public Class Methods

new(path) click to toggle source
Calls superclass method R2OAS::Base::new
# File lib/r2-oas/routing/components/path_component.rb, line 12
def initialize(path)
  super()
  @path = path
end

Public Instance Methods

exist_path_parameters?() click to toggle source
# File lib/r2-oas/routing/components/path_component.rb, line 49
def exist_path_parameters?
  path_parameters.present?
end
path_excluded_path_parameters() click to toggle source
# File lib/r2-oas/routing/components/path_component.rb, line 42
def path_excluded_path_parameters
  excluded_path_parameters = path_parameters.each_with_object(symbol_to_brace) do |path_parameter, result|
    result.gsub!("{#{path_parameter}}", '')
  end
  excluded_path_parameters.split('/').delete_if(&:empty?).join('/')
end
path_parameters() click to toggle source
# File lib/r2-oas/routing/components/path_component.rb, line 53
def path_parameters
  result = without_format.scan(SYMBOL_PATH_PARAMETER_REGEXP) + without_format.scan(BRACE_PATH_PARAMETER_REGEXP)
  result.flatten
end
path_parameters_data() click to toggle source
# File lib/r2-oas/routing/components/path_component.rb, line 29
def path_parameters_data
  return {} unless exist_path_parameters?

  path_parameters.each_with_object({}) do |path_parameter, data|
    type = (path_parameter =~ /id/ ? 'integer' : 'string')
    data.merge!(
      "#{path_parameter}": {
        type: type
      }
    )
  end
end
symbol_to_brace() click to toggle source
# File lib/r2-oas/routing/components/path_component.rb, line 21
def symbol_to_brace
  return without_format unless exist_path_parameters?

  path_parameters.each_with_object(without_format) do |path_parameter, result|
    result.gsub!(":#{path_parameter}", "{#{path_parameter}}")
  end
end
to_s() click to toggle source
# File lib/r2-oas/routing/components/path_component.rb, line 17
def to_s
  without_format.to_s
end

Private Instance Methods

without_format() click to toggle source

e.x.) “/tasks(.:format)” => “/tasks” e.x.) “/:model_name/:id/show_in_app(.:format)” => “/{model_name}/{id}/show_in_app”

# File lib/r2-oas/routing/components/path_component.rb, line 62
def without_format
  @path.gsub(FORMAT_PATH_PARAMETER_REGEXP, '')
end