Class: Configuration::OutputImage

Inherits:
Object
  • Object
show all
Includes:
ClassLogging
Defined in:
lib/httpimagestore/configuration/output.rb

Class Method Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(name, cache_control) ⇒ OutputImage

Returns a new instance of OutputImage.



137
138
139
140
# File 'lib/httpimagestore/configuration/output.rb', line 137

def initialize(name, cache_control)
	@name = name
	@cache_control = cache_control
end

Class Method Details

.match(node) ⇒ Object



126
127
128
# File 'lib/httpimagestore/configuration/output.rb', line 126

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

.parse(configuration, node) ⇒ Object



130
131
132
133
134
135
# File 'lib/httpimagestore/configuration/output.rb', line 130

def self.parse(configuration, node)
	configuration.output and raise StatementCollisionError.new(node, 'output')
	image_name = node.grab_values('image name').first
	cache_control = node.grab_attributes('cache-control').first
	configuration.output = OutputImage.new(image_name, cache_control)
end

Instance Method Details

#realize(request_state) ⇒ Object



142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
# File 'lib/httpimagestore/configuration/output.rb', line 142

def realize(request_state)
	image = request_state.images[@name]
	mime_type =
		if image.mime_type
			image.mime_type
		else
			log.warn "image '#{@name}' has no mime type; sending 'application/octet-stream' content type"
			'application/octet-stream'
		end

	cache_control = @cache_control
	request_state.output do
		res['Cache-Control'] = cache_control if cache_control
		write 200, mime_type, image.data
	end
end