Sha256: 20787a374ad7e60e58fb09f6a925bddca001697b9bdfffb67e912bcd76da14e2
Contents?: true
Size: 843 Bytes
Versions: 1
Compression:
Stored size: 843 Bytes
Contents
require 'rest_in_peace/errors' module RESTinPeace class TemplateSanitizer class IncompleteParams < RESTinPeace::DefaultError; end def initialize(url_template, params, attributes) @url_template = url_template @params = params.dup @attributes = attributes @url = nil end def url return @url if @url @url = @url_template.dup tokens.each do |token| param = @params.delete(token.to_sym) param ||= @attributes[token.to_sym] raise IncompleteParams, "Unknown parameter for token :#{token} found" unless param @url.sub!(%r{:#{token}}, param.to_s) end @url end def tokens @url_template.scan(%r{:([a-z_]+)}).flatten end def leftover_params @params.delete_if { |param| tokens.include?(param.to_s) } end end end
Version data entries
1 entries across 1 versions & 1 rubygems
Version | Path |
---|---|
rest-in-peace-4.1.0 | lib/rest_in_peace/template_sanitizer.rb |