class Plugg::DispatchResponder

Attributes

meta[R]
plugin[R]

Public Class Methods

new(plugin = nil) click to toggle source
# File lib/plugg.rb, line 66
def initialize(plugin = nil)
  @meta = OpenStruct.new

  @meta.start_time = Time.now
  @meta.plugin     = plugin
  @meta.response   = nil
  @meta.runtime    = nil
  @meta.error      = nil
end

Public Instance Methods

error() click to toggle source
# File lib/plugg.rb, line 98
def error
  @meta.error
end
finalize() click to toggle source
# File lib/plugg.rb, line 88
def finalize
  if @meta.plugin.respond_to?(:after)
    @meta.plugin.send(:after) 
  end
end
ok?() click to toggle source
# File lib/plugg.rb, line 94
def ok? 
  @meta.error.nil?
end
to_h() click to toggle source
# File lib/plugg.rb, line 102
def to_h
  defaults = {
    plugin:   @meta.plugin.to_s,
    runtime:  @meta.runtime,
    response: @meta.error,
    success:  ok?
  }

  defaults
end
trap(timeout = 5) { || ... } click to toggle source
# File lib/plugg.rb, line 76
def trap(timeout = 5)
  Timeout::timeout(timeout) {
    begin  
      @meta.response = yield
    rescue Exception => e
      @meta.error = e
    end
  }

  @meta.runtime = (Time.now - @start_time) * 1000
end