Class: Zodra::ScalarRegistry
- Inherits:
-
Object
- Object
- Zodra::ScalarRegistry
- Defined in:
- lib/zodra/scalar_registry.rb
Class Method Summary collapse
Instance Method Summary collapse
- #clear! ⇒ Object
- #exists?(name) ⇒ Boolean
- #find(name) ⇒ Object
-
#initialize ⇒ ScalarRegistry
constructor
A new instance of ScalarRegistry.
- #register(name, base:, coercer:) ⇒ Object
Constructor Details
#initialize ⇒ ScalarRegistry
Returns a new instance of ScalarRegistry.
9 10 11 |
# File 'lib/zodra/scalar_registry.rb', line 9 def initialize @store = {} end |
Class Method Details
.global ⇒ Object
5 6 7 |
# File 'lib/zodra/scalar_registry.rb', line 5 def self.global @global ||= new end |
Instance Method Details
#clear! ⇒ Object
28 29 30 |
# File 'lib/zodra/scalar_registry.rb', line 28 def clear! @store.clear end |
#exists?(name) ⇒ Boolean
24 25 26 |
# File 'lib/zodra/scalar_registry.rb', line 24 def exists?(name) @store.key?(name.to_sym) end |
#find(name) ⇒ Object
20 21 22 |
# File 'lib/zodra/scalar_registry.rb', line 20 def find(name) @store[name.to_sym] end |
#register(name, base:, coercer:) ⇒ Object
13 14 15 16 17 18 |
# File 'lib/zodra/scalar_registry.rb', line 13 def register(name, base:, coercer:) name = name.to_sym raise DuplicateTypeError, "Scalar type :#{name} is already registered" if @store.key?(name) @store[name] = ScalarType.new(name:, base:, coercer:) end |