Sha256: f8bcf4eb54e2e2092c77dfe59bbd727fc410a8d3a41800c43a52b6a90f62dd43

Contents?: true

Size: 1.43 KB

Versions: 1

Compression:

Stored size: 1.43 KB

Contents

# frozen_string_literal: true

module RShade
  class Config
    class Registry
      include Singleton
      attr_reader :map, :mutex

      DEFAULT_EVENT_STORE = :event_store_default
      DEFAULT_STACK_STORE = :stack_store_default

      def initialize
        @map = {}
        @mutex = Mutex.new
        defaults
      end

      def default_stack_config
        val = nil
        mutex.synchronize do
          val = map[DEFAULT_STACK_STORE]
        end
        val
      end

      def stack_config(&block)
        val = nil
        mutex.synchronize do
          val = ::RShade::Config::StackStore.new
          block.call(val)
          map[DEFAULT_STACK_STORE] = val
        end
        val
      end

      def default_trace_config
        val = nil
        mutex.synchronize do
          val = map[DEFAULT_EVENT_STORE]
        end
        val
      end

      def trace_config(&block)
        val = nil
        mutex.synchronize do
          val = ::RShade::Config::EventStore.new
          block.call(val)
          map[DEFAULT_EVENT_STORE] = val
        end
        val
      end

      def defaults
        mutex.synchronize do
          stack_store = ::RShade::Config::StackStore.new
          stack_store.exclude_gems!
          map[DEFAULT_STACK_STORE] = stack_store

          event_store = ::RShade::Config::EventStore.new
          event_store.exclude_gems!
          map[DEFAULT_EVENT_STORE] = event_store
        end
      end
    end
  end
end

Version data entries

1 entries across 1 versions & 1 rubygems

Version Path
rshade-0.2.2 lib/rshade/config/registry.rb