class Restspec::Endpoints::URLBuilder
Constants
- PARAM_INTERPOLATION_REGEX
Attributes
path[RW]
query_params[RW]
url_params[RW]
Public Class Methods
new(path = '', url_params = {}, query_params = {})
click to toggle source
# File lib/restspec/endpoints/url_builder.rb, line 8 def initialize(path = '', url_params = {}, query_params = {}) self.path = path self.url_params = unbox_url_params(url_params) self.query_params = query_params end
Public Instance Methods
full_url()
click to toggle source
# File lib/restspec/endpoints/url_builder.rb, line 14 def full_url base_url + path_from_params + query_string end
Private Instance Methods
base_url()
click to toggle source
# File lib/restspec/endpoints/url_builder.rb, line 29 def base_url @base_url ||= (Restspec.config.base_url || '') end
fill_query_string(query_string)
click to toggle source
# File lib/restspec/endpoints/url_builder.rb, line 37 def fill_query_string(query_string) query_string.present? ? "?#{query_string}" : "" end
path_from_params()
click to toggle source
# File lib/restspec/endpoints/url_builder.rb, line 23 def path_from_params path.gsub(PARAM_INTERPOLATION_REGEX) do url_params[$1] || url_params[$1.to_sym] end end
query_string()
click to toggle source
# File lib/restspec/endpoints/url_builder.rb, line 33 def query_string @query_string ||= fill_query_string(query_params.to_param) end
unbox_url_params(raw_url_params)
click to toggle source
# File lib/restspec/endpoints/url_builder.rb, line 41 def unbox_url_params(raw_url_params) params = raw_url_params.inject({}) do |hash, (key, value)| real_value = value.respond_to?(:call) ? value.call : value hash.merge(key.to_sym => real_value) end Restspec::Values::SuperHash.new(params) end