Class: Configuration::OutputMultiBase::OutputSpec

Inherits:
HandlerStatement show all
Includes:
ConditionalInclusion, GlobalConfiguration, ImageName, LocalConfiguration, PathSpec
Defined in:
lib/httpimagestore/configuration/output.rb

Instance Method Summary collapse

Methods inherited from Scope

node_parsers, #parse, register_node_parser

Constructor Details

#initialize(global, image_name, scheme, host, port, path_spec) ⇒ OutputSpec

Returns a new instance of OutputSpec.



27
28
29
30
31
32
33
34
# File 'lib/httpimagestore/configuration/output.rb', line 27

def initialize(global, image_name, scheme, host, port, path_spec)
	with_global_configuration(global)
	with_image_name(image_name)
	with_path_spec(path_spec)
	@scheme = scheme && scheme.to_template
	@host = host && host.to_template
	@port = port && port.to_template
end

Instance Method Details

#store_path(request_state) ⇒ Object



36
37
38
39
40
41
# File 'lib/httpimagestore/configuration/output.rb', line 36

def store_path(request_state)
	store_path = request_state.images[@image_name].store_path or raise StorePathNotSetForImage.new(@image_name)
	return store_path unless @path_spec

	path_template.render(request_state.with_locals(local_configuration, path: store_path))
end

#store_url(request_state) ⇒ Object



43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
# File 'lib/httpimagestore/configuration/output.rb', line 43

def store_url(request_state)
	url = request_state.images[@image_name].store_url or raise StoreURLNotSetForImage.new(@image_name)
	url = url.dup
	store_path = request_state.images[@image_name].store_path or raise StorePathNotSetForImage.new(@image_name)

	request_locals = {
		path: store_path,
		url: url.to_s
	}
	request_locals[:scheme] = url.scheme if url.scheme
	request_locals[:host] = url.host if url.host
	request_locals[:port] = url.port if url.port

	request_state = request_state.with_locals(local_configuration, request_locals)

	# optional rewrites
	url.scheme = @scheme.render(request_state) if @scheme
	url.host = @host.render(request_state) if @host
	(url.host ||= 'localhost'; url.port = @port.render(request_state).to_i) if @port
	url.path = path_template.render(request_state).to_uri if @path_spec

	url.normalize
end