Class: Configuration::Identify
- Inherits:
-
HandlerStatement
show all
- Extended by:
- Stats
- Includes:
- ClassLogging, ConditionalInclusion, GlobalConfiguration, ImageName, LocalConfiguration, PerfStats
- Defined in:
- lib/httpimagestore/configuration/identify.rb
Class Method Summary
collapse
Instance Method Summary
collapse
Methods inherited from Scope
node_parsers, #parse, register_node_parser
Constructor Details
#initialize(global, image_name) ⇒ Identify
Returns a new instance of Identify.
36
37
38
39
|
# File 'lib/httpimagestore/configuration/identify.rb', line 36
def initialize(global, image_name)
with_global_configuration(global)
with_image_name(image_name)
end
|
Class Method Details
.match(node) ⇒ Object
20
21
22
|
# File 'lib/httpimagestore/configuration/identify.rb', line 20
def self.match(node)
node.name == 'identify'
end
|
.parse(configuration, node) ⇒ Object
24
25
26
27
28
29
30
31
32
33
34
|
# File 'lib/httpimagestore/configuration/identify.rb', line 24
def self.parse(configuration, node)
image_name = node.grab_values('image name').first
conditions, remaining = *ConditionalInclusion.grab_conditions_with_remaining(node.attributes)
remaining.empty? or raise UnexpectedAttributesError.new(node, remaining)
iden = self.new(configuration.global, image_name)
iden.with_conditions(conditions)
configuration.processors << iden
end
|
Instance Method Details
#realize(request_state) ⇒ Object
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
|
# File 'lib/httpimagestore/configuration/identify.rb', line 41
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 = measure "identifying", @image_name do
client.(request_state.).identify(image.data)
end
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
|