class Thingfish::Processor
Thingfish
asset processor base class.
Public Class Methods
handled_types( *mediatypes )
click to toggle source
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
Public Instance Methods
handled_path?( request )
click to toggle source
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
handled_type?( type )
click to toggle source
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
Also aliased as: is_handled_type?
on_request( request )
click to toggle source
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
on_response( response )
click to toggle source
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
process_request( request )
click to toggle source
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
process_response( response )
click to toggle source
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