Class: Configuration::OutputImage

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

Direct Known Subclasses

OutputDataURIImage

Class Method Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(name, cache_control) ⇒ OutputImage

Returns a new instance of OutputImage.


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

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

Class Method Details

.match(node) ⇒ Object


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

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

.parse(configuration, node) ⇒ Object


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

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 = self.new(image_name, cache_control)
end

Instance Method Details

#realize(request_state) ⇒ Object


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

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