Sha256: 4a06c3b5abbe20ecd298309219839831297de491b0aaba0b0538c9beed21c143
Contents?: true
Size: 808 Bytes
Versions: 7
Compression:
Stored size: 808 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(klass, **kw) Registry.instance.register(klass, **kw) end end
Version data entries
7 entries across 7 versions & 1 rubygems