Module: Ey::Core::Mock::Params
- Included in:
- Client::Mock
- Defined in:
- lib/ey-core/mock/params.rb
Instance Method Summary collapse
Instance Method Details
#extract_url_params!(params) ⇒ Object
18 19 20 21 22 23 24 25 26 27 28 29 |
# File 'lib/ey-core/mock/params.rb', line 18 def extract_url_params!(params) if url = params.delete("url") @logger.debug('request.params') { "Extracted params from url: #{path_params(url).inspect}" } path_params(url).each do |resource,id| next unless id && ! id.empty? params[resource.to_s.gsub(/s$/, '').gsub("-", "_")] = url_for("/#{resource}/#{id}") end params.merge!(url_params(url)) end end |
#path_params(url) ⇒ Object
10 11 12 13 14 15 16 |
# File 'lib/ey-core/mock/params.rb', line 10 def path_params(url) parts = URI.parse(url).path.split("/").rotate if parts.size % 2 == 1 parts.pop end Hash[*parts].reject {|key,val| val.nil? || val.empty? } end |
#url_params(url) ⇒ Object
3 4 5 6 7 8 |
# File 'lib/ey-core/mock/params.rb', line 3 def url_params(url) uri = URI.parse(url) query = uri.query || "" query.split("&").inject({}){|r,e| k,v = e.split("="); r.merge(k => v)} end |