Module: Bsm::Constrainable::Registry
Instance Method Summary collapse
-
#new(kind, *args) ⇒ Object
Create a new object of a certain kind.
-
#register(klass) ⇒ Object
Register a class.
-
#registered?(kind) ⇒ Boolean
Returns true if kind was already registered, else false.
-
#registry ⇒ Object
Returns the current registry Hash.
Instance Method Details
#new(kind, *args) ⇒ Object
Create a new object of a certain kind.
15 16 17 18 |
# File 'lib/bsm/constrainable/registry.rb', line 15 def new(kind, *args) raise ArgumentError, "Invalid kind #{kind}" unless registered?(kind) registry[kind.to_sym].new(*args) end |
#register(klass) ⇒ Object
Register a class
9 10 11 12 |
# File 'lib/bsm/constrainable/registry.rb', line 9 def register(klass) raise ArgumentError, "Already registered kind: #{klass.kind}" if registered?(klass.kind) registry[klass.kind] = klass end |
#registered?(kind) ⇒ Boolean
Returns true if kind was already registered, else false
21 22 23 |
# File 'lib/bsm/constrainable/registry.rb', line 21 def registered?(kind) registry.key?(kind.to_sym) end |
#registry ⇒ Object
Returns the current registry Hash
4 5 6 |
# File 'lib/bsm/constrainable/registry.rb', line 4 def registry @registry ||= {} end |