Class: Configuration::OutputMultiBase::OutputSpec

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

Instance Attribute Summary

Attributes inherited from HandlerStatement

#config_locals

Instance Method Summary collapse

Methods inherited from HandlerStatement

#config_local, #path_template

Constructor Details

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

Returns a new instance of OutputSpec.



72
73
74
75
76
77
# File 'lib/httpimagestore/configuration/output.rb', line 72

def initialize(global, image_name, scheme, host, port, path_spec, matcher)
	super(global, image_name, path_spec, matcher)
	@scheme = scheme && scheme.to_template
	@host = host && host.to_template
	@port = port && port.to_template
end

Instance Method Details

#store_path(request_state) ⇒ Object



79
80
81
82
83
84
# File 'lib/httpimagestore/configuration/output.rb', line 79

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(config_locals, path: store_path))
end

#store_url(request_state) ⇒ Object



86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
# File 'lib/httpimagestore/configuration/output.rb', line 86

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(config_locals, 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