Sha256: 2eb414c9adfb928e40e358d1e7e530318d9c8b7dfa135bde00c71091325281dd

Contents?: true

Size: 1.21 KB

Versions: 15

Compression:

Stored size: 1.21 KB

Contents

module Honeybadger
  class Dependency
    class << self
      @@instances = []

      def instances
        @@instances
      end

      def register
        instances << new.tap { |d| d.instance_eval(&Proc.new) }
      end

      def inject!
        instances.each do |dependency|
          dependency.inject! if dependency.ok?
        end
      end

      def reset!
        instances.each(&:reset!)
      end
    end

    def initialize
      @injected     = false
      @requirements = []
      @injections   = []
    end

    def requirement
      @requirements << Proc.new
    end

    def injection
      @injections << Proc.new
    end

    def ok?
      !@injected && @requirements.all?(&:call)
    rescue => e
      Honeybadger.write_verbose_log("Exception caught while verifying dependency: #{e.class} -- #{e.message}", :error)
      false
    end

    def inject!
      @injections.each(&:call)
    rescue => e
      Honeybadger.write_verbose_log("Exception caught while injecting dependency: #{e.class} -- #{e.message}", :error)
      false
    ensure
      @injected = true
    end

    def reset!
      @injected = false
    end

    def injected?
      @injected
    end

    attr_reader :requirements, :injections
  end
end

Version data entries

15 entries across 15 versions & 1 rubygems

Version Path
honeybadger-1.16.7 lib/honeybadger/dependency.rb
honeybadger-1.16.6 lib/honeybadger/dependency.rb
honeybadger-1.16.5 lib/honeybadger/dependency.rb
honeybadger-1.16.4 lib/honeybadger/dependency.rb
honeybadger-1.16.3 lib/honeybadger/dependency.rb
honeybadger-1.16.2 lib/honeybadger/dependency.rb
honeybadger-1.16.1 lib/honeybadger/dependency.rb
honeybadger-1.16.0 lib/honeybadger/dependency.rb
honeybadger-1.15.3 lib/honeybadger/dependency.rb
honeybadger-1.15.2 lib/honeybadger/dependency.rb
honeybadger-1.15.1 lib/honeybadger/dependency.rb
honeybadger-1.15.0 lib/honeybadger/dependency.rb
honeybadger-1.14.0 lib/honeybadger/dependency.rb
honeybadger-1.12.0.beta3 lib/honeybadger/dependency.rb
honeybadger-1.12.0.beta2 lib/honeybadger/dependency.rb