Sha256: 02236ec19936fbfedd6718a32e4a0531c01087289a3abdc6bc96dd0a92ee5e14

Contents?: true

Size: 1.01 KB

Versions: 6

Compression:

Stored size: 1.01 KB

Contents

module Qa::Authorities
  module Local
    class Registry
      def initialize
        @hash = {}
        yield self if block_given?
      end

      def keys
        @hash.keys
      end

      def instance_for(key)
        fetch(key).instance
      end

      def fetch(key)
        @hash.fetch(key)
      end

      def self.logger
        @logger ||= ::Rails.logger if defined? Rails && Rails.respond_to?(:logger)
      end

      class << self
        attr_writer :logger
      end

      def add(subauthority, class_name)
        Registry.logger.debug "Registering Local QA authority: #{subauthority} - #{class_name}"
        @hash[subauthority] = RegistryEntry.new(subauthority, class_name)
      end

      class RegistryEntry
        def initialize(subauthority, class_name)
          @subauthority = subauthority
          @class_name = class_name
        end

        def klass
          @class_name.constantize
        end

        def instance
          klass.new(@subauthority)
        end
      end
    end
  end
end

Version data entries

6 entries across 6 versions & 1 rubygems

Version Path
qa-5.14.0 lib/qa/authorities/local/registry.rb
qa-5.13.0 lib/qa/authorities/local/registry.rb
qa-5.12.0 lib/qa/authorities/local/registry.rb
qa-5.11.0 lib/qa/authorities/local/registry.rb
qa-5.10.0 lib/qa/authorities/local/registry.rb
qa-5.9.0 lib/qa/authorities/local/registry.rb