Class: Thingfish::Processor

Inherits:
Object
  • Object
show all
Extended by:
Pluggability
Defined in:
lib/thingfish/processor.rb

Overview

Thingfish asset processor base class.

Direct Known Subclasses

SHA256

Defined Under Namespace

Classes: SHA256

Class Method Summary collapse

Instance Method Summary collapse

Class Method Details

.handled_types(*mediatypes) ⇒ Object

Get/set the list of media types this processor can handle.



19
20
21
22
23
24
25
26
27
28
29
# File 'lib/thingfish/processor.rb', line 19

def self::handled_types( *mediatypes )
	if mediatypes.empty?
		@handled_types ||= []
	else
		@handled_types = mediatypes.collect do |type|
			Strelka::HTTPRequest::MediaType.parse(type)
		end
	end

	return @handled_types
end

Instance Method Details

#handled_path?(request) ⇒ Boolean

Returns true if the given request‘s path is one that should be processed.

Returns:

  • (Boolean)


74
75
76
# File 'lib/thingfish/processor.rb', line 74

def handled_path?( request )
	return ! request.path.match( %r|^/?[\w\-]+/metadata| )
end

#handled_type?(type) ⇒ Boolean Also known as: is_handled_type?

Returns true if the given media type is one the processor handles.

Returns:

  • (Boolean)


65
66
67
68
# File 'lib/thingfish/processor.rb', line 65

def handled_type?( type )
	return true if self.class.handled_types.empty?
	self.class.handled_types.find {|handled_type| type =~ handled_type }
end

#on_request(request) ⇒ Object

Process the data and/or metadata in the request.



43
44
45
# File 'lib/thingfish/processor.rb', line 43

def on_request( request )
	# No-op by default
end

#on_response(response) ⇒ Object

Process the data and/or metadata in the response.



59
60
61
# File 'lib/thingfish/processor.rb', line 59

def on_response( response )
	# No-op by default
end

#process_request(request) ⇒ Object

Filter hook for request, pass to processor if it is able to handle the request content type.



34
35
36
37
38
39
# File 'lib/thingfish/processor.rb', line 34

def process_request( request )
	return unless self.handled_path?( request )
	if self.handled_type?( request.content_type )
		on_request( request )
	end
end

#process_response(response) ⇒ Object

Filter hook for response, pass to processor if it is able to handle the response content type.



50
51
52
53
54
55
# File 'lib/thingfish/processor.rb', line 50

def process_response( response )
	return unless self.handled_path?( response.request )
	if self.handled_type?( response.content_type )
		on_response( response )
	end
end