Class: Configuration::Identify

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

Class Method Summary collapse

Instance Method Summary collapse

Methods included from ConditionalInclusion

#excluded?, #included?, #inclusion_matcher

Constructor Details

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

Returns a new instance of Identify.



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

def initialize(global, image_name, matcher = nil)
  @global = global
  @image_name = image_name
  inclusion_matcher matcher if matcher
end

Class Method Details

.match(node) ⇒ Object



17
18
19
# File 'lib/httpimagestore/configuration/identify.rb', line 17

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

.parse(configuration, node) ⇒ Object



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

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



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

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