Class: R2OAS::Routing::PathComponent
- Inherits:
-
BaseComponent
- Object
- Base
- Base
- BaseComponent
- R2OAS::Routing::PathComponent
- Defined in:
- lib/r2-oas/routing/components/path_component.rb
Constant Summary collapse
- FORMAT_PATH_PARAMETER_REGEXP =
/\(.+\)/.freeze
- SYMBOL_PATH_PARAMETER_REGEXP =
/:(.\w+)/.freeze
- BRACE_PATH_PARAMETER_REGEXP =
/\{(.\w+)\}/.freeze
Instance Method Summary collapse
- #exist_path_parameters? ⇒ Boolean
-
#initialize(path) ⇒ PathComponent
constructor
A new instance of PathComponent.
- #path_excluded_path_parameters ⇒ Object
- #path_parameters ⇒ Object
- #path_parameters_data ⇒ Object
- #symbol_to_brace ⇒ Object
- #to_s ⇒ Object
Constructor Details
#initialize(path) ⇒ PathComponent
Returns a new instance of PathComponent.
12 13 14 15 |
# File 'lib/r2-oas/routing/components/path_component.rb', line 12 def initialize(path) super() @path = path end |
Instance Method Details
#exist_path_parameters? ⇒ Boolean
49 50 51 |
# File 'lib/r2-oas/routing/components/path_component.rb', line 49 def exist_path_parameters? path_parameters.present? end |
#path_excluded_path_parameters ⇒ Object
42 43 44 45 46 47 |
# 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 ⇒ Object
53 54 55 56 |
# 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 ⇒ Object
29 30 31 32 33 34 35 36 37 38 39 40 |
# 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 ⇒ Object
21 22 23 24 25 26 27 |
# 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 ⇒ Object
17 18 19 |
# File 'lib/r2-oas/routing/components/path_component.rb', line 17 def to_s without_format.to_s end |