class PINS::Handler

Public Class Methods

add(&block) click to toggle source

Call as often as necessary to add handlers; each call creates a PINS::Handler object

# File lib/postmark-inbound/handler.rb, line 25
def self.add(&block)
  @handlers ||= []
  @handlers << Handler.new(&block)
  PINS.logger.debug("Added handler: #{@handlers.last}")
end
autoload() click to toggle source

Load handlers from directories designated in config

# File lib/postmark-inbound/handler.rb, line 10
def self.autoload
  PINS.config.handler_paths.each { |path|
    load_from_path(path)
  }
end
handlers() click to toggle source

@return [Array] containing all the handlers

# File lib/postmark-inbound/handler.rb, line 32
def self.handlers
  @handlers
end
load_from_path(path) click to toggle source

Load handlers from a directory @param path [String] directory name

# File lib/postmark-inbound/handler.rb, line 18
def self.load_from_path(path)
  Dir.chdir(path) {
    Dir.foreach('.') { |f| load f unless File.directory?(f) }
  }
end
new(&block) click to toggle source
# File lib/postmark-inbound/handler.rb, line 44
def initialize(&block)
  @block = block
end
run_handlers(pin) click to toggle source

Run the handlers, typically called by the server @param pin [Hash] from Postmark inbound webhook JSON

# File lib/postmark-inbound/handler.rb, line 38
def self.run_handlers(pin)
  PINS.logger.info('Running handlers...')
  @handlers.each { |h| h.run(pin) }
  PINS.logger.info('Done running handlers.')
end

Public Instance Methods

run(obj) click to toggle source
# File lib/postmark-inbound/handler.rb, line 48
def run(obj)
  PINS.logger.warn("No block to execute for handler: #{self}") unless @block
  PINS.logger.debug("Running handler: #{self}")
  @block.call(obj)
end