Module: Jet::Core::InstanceRegistry
- Defined in:
- lib/jet/core/instance_registry.rb
Class Method Summary collapse
Instance Method Summary collapse
- #[](obj) ⇒ Object
- #[]=(key, obj) ⇒ Object
- #fetch(*args) ⇒ Object
- #freeze ⇒ Object
- #register(hash) ⇒ Object
- #to_h ⇒ Object
- #type(type = nil) ⇒ Object
Class Method Details
.extended(base) ⇒ Object
6 7 8 9 |
# File 'lib/jet/core/instance_registry.rb', line 6 def self.extended(base) super base.instance_variable_set(:@registry, {}) end |
Instance Method Details
#[](obj) ⇒ Object
11 12 13 |
# File 'lib/jet/core/instance_registry.rb', line 11 def [](obj) @registry[obj] end |
#[]=(key, obj) ⇒ Object
15 16 17 18 |
# File 'lib/jet/core/instance_registry.rb', line 15 def []=(key, obj) raise "no `type` for registry has been set yet" unless @type @registry[Jet.type_check!("`key`", key, Symbol)] = Jet.type_check!("`obj`", obj, @type) end |
#fetch(*args) ⇒ Object
20 21 22 |
# File 'lib/jet/core/instance_registry.rb', line 20 def fetch(*args) @registry.fetch(*args) end |
#freeze ⇒ Object
24 25 26 27 |
# File 'lib/jet/core/instance_registry.rb', line 24 def freeze @registry.freeze super end |
#register(hash) ⇒ Object
29 30 31 32 |
# File 'lib/jet/core/instance_registry.rb', line 29 def register(hash) hash.each { |key, obj| self[key] = obj } self end |
#to_h ⇒ Object
34 35 36 |
# File 'lib/jet/core/instance_registry.rb', line 34 def to_h @registry.dup end |
#type(type = nil) ⇒ Object
38 39 40 41 42 43 |
# File 'lib/jet/core/instance_registry.rb', line 38 def type(type = nil) return @type unless type raise "`type` cannot be changed once set" if @type Jet.type_check!("`type`", type, Class, Module) @type = type end |