Class: Configuration::Path

Inherits:
RubyStringTemplate show all
Defined in:
lib/httpimagestore/configuration/path.rb

Defined Under Namespace

Classes: RenderedPath

Class Method Summary collapse

Instance Method Summary collapse

Methods inherited from RubyStringTemplate

#add_missing_resolver, #initialize_copy, #to_template, #with_missing_resolver

Methods inherited from String

#to_template

Constructor Details

#initialize(path_name, template) ⇒ Path

Returns a new instance of Path.



53
54
55
56
57
58
59
60
61
# File 'lib/httpimagestore/configuration/path.rb', line 53

def initialize(path_name, template)
	super(template) do |locals, name|
		begin
			locals[name]
		rescue ConfigurationError => error
			raise PathRenderingError.new(path_name, template, error.message)
		end or raise NoValueForPathTemplatePlaceholerError.new(path_name, template, name)
	end
end

Class Method Details

.match(node) ⇒ Object



33
34
35
# File 'lib/httpimagestore/configuration/path.rb', line 33

def self.match(node)
	node.name == 'path'
end

.parse(configuration, node) ⇒ Object



41
42
43
44
45
46
47
48
49
50
51
# File 'lib/httpimagestore/configuration/path.rb', line 41

def self.parse(configuration, node)
	nodes = []
	nodes << node unless node.values.empty?
	nodes |= node.children

	nodes.empty? and raise NoValueError.new(node, 'path name')
	nodes.each do |node|
		path_name, template = *node.grab_values('path name', 'path template')
		configuration.paths[path_name] = Path.new(path_name, template)
	end
end

.pre(configuration) ⇒ Object



37
38
39
# File 'lib/httpimagestore/configuration/path.rb', line 37

def self.pre(configuration)
	configuration.paths ||= Hash.new{|hash, path_name| raise PathNotDefinedError.new(path_name)}
end

Instance Method Details

#render(locals = {}) ⇒ Object



63
64
65
# File 'lib/httpimagestore/configuration/path.rb', line 63

def render(locals = {})
	RenderedPath.new(super)
end