Class: Configuration::Identify

Inherits:
HandlerStatement show all
Extended by:
Stats
Includes:
ClassLogging, ConditionalInclusion, ImageName
Defined in:
lib/httpimagestore/configuration/identify.rb

Instance Attribute Summary

Attributes inherited from HandlerStatement

#config_locals

Class Method Summary collapse

Instance Method Summary collapse

Methods inherited from HandlerStatement

#config_local, #path_template

Constructor Details

#initialize(global, image_name, matcher = nil) ⇒ Identify

Returns a new instance of Identify.



31
32
33
# File 'lib/httpimagestore/configuration/identify.rb', line 31

def initialize(global, image_name, matcher = nil)
  super(global, image_name, matcher)
end

Class Method Details

.match(node) ⇒ Object



15
16
17
# File 'lib/httpimagestore/configuration/identify.rb', line 15

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

.parse(configuration, node) ⇒ Object



19
20
21
22
23
24
25
26
# File 'lib/httpimagestore/configuration/identify.rb', line 19

def self.parse(configuration, node)
  image_name = node.grab_values('image name').first
  if_image_name_on = node.grab_attributes('if-image-name-on').first

  matcher = InclusionMatcher.new(image_name, if_image_name_on) if if_image_name_on

  configuration.processors << self.new(configuration.global, image_name, matcher)
end

Instance Method Details

#realize(request_state) ⇒ Object



35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
# File 'lib/httpimagestore/configuration/identify.rb', line 35

def realize(request_state)
  client = @global.thumbnailer or fail 'thumbnailer configuration'
  image = request_state.images[@image_name]

  log.info "identifying '#{@image_name}'"

  Identify.stats.incr_total_identify_requests
  Identify.stats.incr_total_identify_requests_bytes image.data.bytesize

  id = client.with_headers(request_state.headers).identify(image.data)

  image.mime_type = id.mime_type if id.mime_type
  image.width = id.width if id.width
  image.height = id.height if id.height
  log.info "image '#{@image_name}' identified as '#{id.mime_type}' #{image.width}x#{image.height}"
end