Class: Generator::Path

Inherits:
Object
  • Object
show all
Includes:
Utils
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

Methods included from Utils

#pascalcase, #snakecase

Constructor Details

#initialize(path, methods) ⇒ Path

Returns a new instance of Path.



14
15
16
17
# File 'lib/generator/path.rb', line 14

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

Instance Attribute Details

#methodsObject (readonly)

Returns the value of attribute methods.



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

def methods
  @methods
end

Instance Method Details

#has_dynamic_sandbox?Boolean

Returns:

  • (Boolean)


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

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

#operationsObject



19
20
21
22
23
# File 'lib/generator/path.rb', line 19

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

#parametersObject



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

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

#pathObject



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

def path
  @path.gsub(/\{([^}]+)\}/) do
    "\#{#{snakecase(Regexp.last_match(1))}}"
  end
end

#sandbox_only?Boolean

Returns:

  • (Boolean)


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

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

#to_sObject



25
26
27
# File 'lib/generator/path.rb', line 25

def to_s
  path
end