Class: ResourceKit::EndpointResolver

Inherits:
Object
  • Object
show all
Defined in:
lib/resource_kit/endpoint_resolver.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(options = {}) ⇒ EndpointResolver

Returns a new instance of EndpointResolver.



7
8
9
10
# File 'lib/resource_kit/endpoint_resolver.rb', line 7

def initialize(options = {})
  @path = options[:path]
  @query_param_keys = options[:query_param_keys] || []
end

Instance Attribute Details

#pathObject (readonly)

Returns the value of attribute path.



5
6
7
# File 'lib/resource_kit/endpoint_resolver.rb', line 5

def path
  @path
end

#query_param_keysObject (readonly)

Returns the value of attribute query_param_keys.



5
6
7
# File 'lib/resource_kit/endpoint_resolver.rb', line 5

def query_param_keys
  @query_param_keys
end

Instance Method Details

#resolve(values = {}) ⇒ Object



12
13
14
15
16
17
18
19
20
# File 'lib/resource_kit/endpoint_resolver.rb', line 12

def resolve(values = {})
  uri = Addressable::URI.parse(path)
  new_path = generated_path(uri.path, values)

  uri.path = normalized_path_components(new_path)
  uri.query = append_query_values(uri, values) unless query_param_keys.empty?

  uri.to_s
end