Strelka::App::

Presenters

module
Included Modules
Strelka::Constants
Extended With
Strelka::Plugin

Presentation layer plugin for Strelka service apps.

Attributes

presenter[R]

The configured Yaks presenter object

Public Class Methods

anchor
configure_block( app, &block )

Set a block passed to plugin to the presenter library when it's configured.

# File lib/strelka/app/presenters.rb, line 41
def self::configure_block( app, &block )
        app.plugin( :negotiation )
        app.presenter_config_block = block
end
anchor
included( object )

Extension callback – extend the HTTPResponse classes with presenter logic when the plugin is loaded.

# File lib/strelka/app/presenters.rb, line 33
def self::included( object )
        Strelka::HTTPResponse.include( Strelka::HTTPResponse::Presenters )
        super
end
anchor
new( * )

Set up the presenters when the app is created.

# File lib/strelka/app/presenters.rb, line 48
def initialize( * )
        super
        @presenter = self.setup_presentation_layer
end

Public Instance Methods

anchor
handle_request( req )

Set up the presenter when the response has returned.

# File lib/strelka/app/presenters.rb, line 64
def handle_request( req )
        self.log.debug "[:negotiation] Wrapping response with hypermedia presentation."

        response = super
        response.presenter = self.presenter

        return response
end
anchor
setup_presentation_layer()

Configure and return the presenter.

# File lib/strelka/app/presenters.rb, line 75
def setup_presentation_layer
        self.log.debug "Setting up presenters using %s" %
                [ self.class.presenter_config_block&.inspect || 'defaults' ]
        config_block = self.class.presenter_config_block || Proc.new {}
        return Yaks.new( &config_block )
end