Sha256: d608dcb51b13881f8287e055dbf9893b736aacf8ac9a2a771634c342b2b46ea5

Contents?: true

Size: 973 Bytes

Versions: 18

Compression:

Stored size: 973 Bytes

Contents

require 'singleton'

module Frodo
  # Provides a registry for keeping track of various property types used by
  # Frodo.
  class PropertyRegistry
    include Singleton

    # Add a property type to the registry
    #
    # @param type_name [String] property type name to register
    # @param klass [Class] Ruby class to use for the specified type
    def add(type_name, klass)
      properties[type_name] = klass
    end

    # Lookup a property by name and get the Ruby class to use for its instances
    #
    # @param type_name [String] the type name to lookup
    # @return [Class, nil] the proper class or nil
    def [](type_name)
      properties[type_name]
    end

    # (see #add)
    def self.add(type_name, klass)
      Frodo::PropertyRegistry.instance.add(type_name, klass)
    end

    # (see #[])
    def self.[](type_name)
      Frodo::PropertyRegistry.instance[type_name]
    end

    private

    def properties
      @properties ||= {}
    end
  end
end

Version data entries

18 entries across 18 versions & 1 rubygems

Version Path
frodo-0.12.8 lib/frodo/property_registry.rb
frodo-0.12.7 lib/frodo/property_registry.rb
frodo-0.12.6 lib/frodo/property_registry.rb
frodo-0.12.5 lib/frodo/property_registry.rb
frodo-0.12.4 lib/frodo/property_registry.rb
frodo-0.12.2 lib/frodo/property_registry.rb
frodo-0.12.1 lib/frodo/property_registry.rb
frodo-0.12.0 lib/frodo/property_registry.rb
frodo-0.11.0 lib/frodo/property_registry.rb
frodo-0.10.8 lib/frodo/property_registry.rb
frodo-0.10.7 lib/frodo/property_registry.rb
frodo-0.10.6 lib/frodo/property_registry.rb
frodo-0.10.5 lib/frodo/property_registry.rb
frodo-0.10.4 lib/frodo/property_registry.rb
frodo-0.10.3 lib/frodo/property_registry.rb
frodo-0.10.2 lib/frodo/property_registry.rb
frodo-0.10.1 lib/frodo/property_registry.rb
frodo-0.10.0 lib/frodo/property_registry.rb