Class: Doze::URITemplate::WithPrefix

Inherits:
Composite show all
Defined in:
lib/doze/uri_template.rb

Overview

A simple case of Composite where a template is prefixed by a string. This allows the same compiled URI template to be used with many different prefixes without having to re-compile the expand method for each of them, or use the slower default implementation

Instance Attribute Summary

Attributes inherited from Composite

#parts

Instance Method Summary collapse

Methods inherited from Composite

#expand_code_fragment, #partially_expand, #regexp_fragment, #to_s, #variables

Methods inherited from Doze::URITemplate

#+, #anchored_regexp, compile, #compile_expand!, #inspect, #match, #match_with_trailing, #parts, #start_anchored_regexp, #with_prefix

Constructor Details

#initialize(template, prefix) ⇒ WithPrefix

Returns a new instance of WithPrefix.



206
207
208
209
210
# File 'lib/doze/uri_template.rb', line 206

def initialize(template, prefix)
  @template = template
  @prefix = prefix
  @parts = [String.new(prefix.to_s), *@template.parts]
end

Instance Method Details

#expand(vars) ⇒ Object



212
213
214
# File 'lib/doze/uri_template.rb', line 212

def expand(vars)
  "#{@prefix}#{@template.expand(vars)}"
end