Sha256: c962359cc8753dc2ff26d2ca4e495e506a94ff9f2673d052e859d3e6d985b687

Contents?: true

Size: 1.08 KB

Versions: 4

Compression:

Stored size: 1.08 KB

Contents

require 'ostruct'

module Chillout
  class Error

    attr_reader :exception
    attr_reader :environment

    def initialize(exception, environment = {})
      @exception   = exception
      @environment = environment
      @nullObject  = OpenStruct.new
    end

    def exception_class
      exception.class.name
    end

    def message
      exception.message
    end

    def backtrace
      exception.backtrace
    end

    def file
      backtrace.first.split(":").first rescue nil
    end

    def controller
      environment['action_controller.instance'] || @nullObject
    end

    def controller_name
      controller.controller_name
    end

    def controller_action
      controller.action_name
    end

    def current_user
      environment['current_user'] || @nullObject
    end

    def current_user_id
      current_user.id if current_user.respond_to?(:id)
    end

    def current_user_email
      current_user.email if current_user.respond_to?(:email)
    end

    def current_user_full_name
      current_user.full_name if current_user.respond_to?(:full_name)
    end

  end
end

Version data entries

4 entries across 4 versions & 1 rubygems

Version Path
chillout-0.2.3 lib/chillout/error.rb
chillout-0.2.2 lib/chillout/error.rb
chillout-0.2.1 lib/chillout/error.rb
chillout-0.2.0 lib/chillout/error.rb