Processor

class
Superclass
Object
Extended With
Pluggability

Thingfish asset processor base class.

Public Class Methods

anchor
handled_types( *mediatypes )

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

anchor
handled_path?( request )

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
anchor
handled_type?( type )

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?
anchor
is_handled_type?( type )
Alias for: handled_type?
anchor
on_request( request )

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
anchor
on_response( response )

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
anchor
process_request( request )

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
anchor
process_response( response )

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