Sha256: 7fed9b89bf9b5f0fba97f60a73d3ee2645e79a1ba68fa1702e9ec4ffd0df5fe6

Contents?: true

Size: 846 Bytes

Versions: 26

Compression:

Stored size: 846 Bytes

Contents

module Quebert
  module Support
    class Registry < Hash
      def register(key, val)
        self[key.to_sym] = val
      end
    
      def unregister(key)
        self.delete(key.to_sym)
      end
    end
    
    # Stores classes at retreives a key for class and subclasses.
    # TODO 
    #   * make this thing match on most specific subclass
    class ClassRegistry < Registry
      # Returns a class from a given instance
      def[](key)
        case key
        when Class
          # Find the class key based on the class or subclass of the incoming key/klass
          if klass = keys.map{|klass| Support.constantize(klass) }.find{|k| k >= key}
            # If we find a matching class/subclass then pull this out
            super klass.name.to_sym
          end
        else
          super
        end
      end
    end
  end
end

Version data entries

26 entries across 26 versions & 1 rubygems

Version Path
quebert-3.3.0 lib/quebert/support/registry.rb
quebert-3.2.1 lib/quebert/support/registry.rb
quebert-3.2.0 lib/quebert/support/registry.rb
quebert-3.0.3 lib/quebert/support/registry.rb
quebert-3.0.2 lib/quebert/support/registry.rb
quebert-3.0.1 lib/quebert/support/registry.rb
quebert-3.0.0 lib/quebert/support/registry.rb
quebert-2.0.4 lib/quebert/support/registry.rb
quebert-2.0.3 lib/quebert/support/registry.rb
quebert-2.0.2 lib/quebert/support/registry.rb
quebert-2.0.1 lib/quebert/support/registry.rb
quebert-2.0.0 lib/quebert/support/registry.rb
quebert-1.12.0 lib/quebert/support/registry.rb
quebert-1.11.0 lib/quebert/support/registry.rb
quebert-1.0.9 lib/quebert/support/registry.rb
quebert-1.0.8 lib/quebert/support/registry.rb
quebert-1.0.7 lib/quebert/support/registry.rb
quebert-1.0.6 lib/quebert/support/registry.rb
quebert-1.0.5 lib/quebert/support/registry.rb
quebert-1.0.4 lib/quebert/support/registry.rb