class Addressable::Template

def generate(params={}, recall={}, options={})

Other tags:
    Api: - private

Parameters:
  • options (Hash) -- Either a `:processor` or a `:parameterize` block.
  • recall (Hash) -- Default parameters used to expand the template.
  • params (Hash) -- The set of parameters used to expand the template.
def generate(params={}, recall={}, options={})
  merged = recall.merge(params)
  if options[:processor]
    processor = options[:processor]
  elsif options[:parameterize]
    # TODO: This is sending me into fits trying to shoe-horn this into
    # the existing API. I think I've got this backwards and processors
    # should be a set of 4 optional blocks named :validate, :transform,
    # :match, and :restore. Having to use a singleton here is a huge
    # code smell.
    processor = Object.new
    class <<processor
      attr_accessor :block
      def transform(name, value)
        block.call(name, value)
      end
    end
    processor.block = options[:parameterize]
  else
    processor = nil
  end
  result = self.expand(merged, processor)
  result.to_s if result
end