Sha256: e16ec17f5577369b95f18e6e0e10e353c6813f8c123d2c3a151cc6c922741d48
Contents?: true
Size: 790 Bytes
Versions: 7
Compression:
Stored size: 790 Bytes
Contents
require 'singleton' # Regstiry Pattern - https://www.martinfowler.com/eaaCatalog/registry.html # A well-known object that other objects can use to find common objects and services. module Yao::Plugins class Registry include Singleton def initialize @types = {} end # @type type [Symbol] # @return [Object] def [](type) @types[type] end # @param klass [*] # @param type [Symbol] # @param name [Symbol] def register(klass, type: nil, name: :default) raise("Plugin registration requires both type and name.") if !type or !name @types[type] ||= {} @types[type][name] = klass end end # @param [*] # @param [Symbol] # @param [Symbol] def self.register(*a) Registry.instance.register(*a) end end
Version data entries
7 entries across 7 versions & 1 rubygems