Thingfish asset processor base class.
Get/set the list of media types this processor can handle.
# File lib/thingfish/processor.rb, line 18
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
Returns true
if the given request
's path is
one that should be processed.
# File lib/thingfish/processor.rb, line 73
def handled_path?( request )
return ! request.path.match( %r|^/?[\w\-]+/metadata| )
end
Returns true
if the given media type
is one the
processor handles.
# File lib/thingfish/processor.rb, line 64
def handled_type?( type )
return true if self.class.handled_types.empty?
self.class.handled_types.find {|handled_type| type =~ handled_type }
end
Process the data and/or metadata in the request
.
# File lib/thingfish/processor.rb, line 42
def on_request( request )
# No-op by default
end
Process the data and/or metadata in the response
.
# File lib/thingfish/processor.rb, line 58
def on_response( response )
# No-op by default
end
Filter hook for request, pass to processor if it is able to handle the
request
content type.
# File lib/thingfish/processor.rb, line 33
def process_request( request )
return unless self.handled_path?( request )
if self.handled_type?( request.content_type )
on_request( request )
end
end
Filter hook for response, pass to processor if it is able to handle the
response
content type.
# File lib/thingfish/processor.rb, line 49
def process_response( response )
return unless self.handled_path?( response.request )
if self.handled_type?( response.content_type )
on_response( response )
end
end