Class: Generator::Path

Inherits:
Object
  • Object
show all
Defined in:
lib/generator/parsers/path.rb

Constant Summary collapse

HTTP_METHODS =
["delete", "get", "patch", "post", "put"].freeze

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(path, methods) ⇒ Path

Returns a new instance of Path.



12
13
14
15
# File 'lib/generator/parsers/path.rb', line 12

def initialize(path, methods)
  @path = path
  @methods = methods
end

Instance Attribute Details

#methodsObject (readonly)

Returns the value of attribute methods.



10
11
12
# File 'lib/generator/parsers/path.rb', line 10

def methods
  @methods
end

Instance Method Details

#has_dynamic_sandbox?Boolean

Returns:

  • (Boolean)


39
40
41
# File 'lib/generator/parsers/path.rb', line 39

def has_dynamic_sandbox?
  !!methods.dig("x-amzn-api-sandbox", "dynamic")
end

#operations(api_name_with_version) ⇒ Object



17
18
19
20
21
# File 'lib/generator/parsers/path.rb', line 17

def operations(api_name_with_version)
  methods.select { |k, _| HTTP_METHODS.include?(k) }.map do |method, operation|
    Operation.new(self, method, operation, api_name_with_version)
  end
end

#parametersObject



35
36
37
# File 'lib/generator/parsers/path.rb', line 35

def parameters
  methods.fetch("parameters", [])
end

#pathObject



27
28
29
30
31
32
33
# File 'lib/generator/parsers/path.rb', line 27

def path
  # Use atomic grouping (?>...) to prevent ReDoS
  @path.gsub(/\{(?>([^}]+))\}/) do
    match = Regexp.last_match(1) or raise("No match found")
    "\#{percent_encode(#{Naming.parameter_name(match)})}"
  end
end

#sandbox_only?Boolean

Returns:

  • (Boolean)


43
44
45
# File 'lib/generator/parsers/path.rb', line 43

def sandbox_only?
  methods.key?("x-amzn-api-sandbox-only")
end

#to_sObject



23
24
25
# File 'lib/generator/parsers/path.rb', line 23

def to_s
  path
end