Class: Generator::Path

Inherits:
Object
  • Object
show all
Defined in:
lib/generator/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.



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

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

Instance Attribute Details

#methodsObject (readonly)

Returns the value of attribute methods.



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

def methods
  @methods
end

Instance Method Details

#has_dynamic_sandbox?Boolean

Returns:

  • (Boolean)


37
38
39
# File 'lib/generator/path.rb', line 37

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

#operations(api_name_with_version = nil, specification = nil) ⇒ Object



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

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

#parametersObject



33
34
35
# File 'lib/generator/path.rb', line 33

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

#pathObject



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

def path
  # Use atomic grouping (?>...) to prevent ReDoS
  @path.gsub(/\{(?>([^}]+))\}/) do
    "\#{percent_encode(#{Regexp.last_match(1).underscore})}"
  end
end

#sandbox_only?Boolean

Returns:

  • (Boolean)


41
42
43
# File 'lib/generator/path.rb', line 41

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

#to_sObject



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

def to_s
  path
end