Class: Pling::Middleware::Base

Inherits:
Object
  • Object
show all
Includes:
Configurable
Defined in:
lib/pling/middleware/base.rb

Overview

This is the base class to implement custom middleware for pling.

Middleware should inherit from this base class and implement a #deliver method. To call the next middleware on the stack this method must yield passing the given message and device.

Examples:


class Pling::Middleware::TimeFilter < Pling::Middleware::Base
  def deliver(message, device)
    yield(message, device) if configuration[:range].include? Time.now.hour
  end

  protected

    def default_configuration
      super.merge({
        :range => 8..22
      })
    end
end

Instance Method Summary collapse

Constructor Details

#initialize(configuration = {}) ⇒ Base

Initializes a new middleware instance

Parameters:

  • configuration (Hash) (defaults to: {})


32
33
34
# File 'lib/pling/middleware/base.rb', line 32

def initialize(configuration = {})
  setup_configuration(configuration)
end

Instance Method Details

#deliver(message, device) {|message, device| ... } ⇒ Object

Processes the given message and device and passes it to the next middleware on the stack.

Yields:

  • (message, device)

    Call the next middleware on the stack



41
42
43
# File 'lib/pling/middleware/base.rb', line 41

def deliver(message, device)
  yield(message, device)
end