Module: Teaspoon::Registry
- Defined in:
- lib/teaspoon/registry.rb,
lib/teaspoon/registry/has_default.rb
Defined Under Namespace
Modules: HasDefault
Class Method Summary collapse
Instance Method Summary collapse
- #available ⇒ Object
- #fetch(name) ⇒ Object
- #matches?(one, two) ⇒ Boolean
- #not_found_in_registry(klass) ⇒ Object
- #register(name, constant, path, options = {}) ⇒ Object
Class Method Details
.extended(host) ⇒ Object
3 4 5 6 |
# File 'lib/teaspoon/registry.rb', line 3 def self.extended(host) host.instance_variable_set(:@registry, {}) host.instance_variable_set(:@options, {}) end |
Instance Method Details
#available ⇒ Object
33 34 35 |
# File 'lib/teaspoon/registry.rb', line 33 def available @options end |
#fetch(name) ⇒ Object
21 22 23 24 25 26 27 |
# File 'lib/teaspoon/registry.rb', line 21 def fetch(name) if !(driver = @registry[normalize_name(name)]) raise not_found_exception.new(name: name, available: available.keys) end driver.call end |
#matches?(one, two) ⇒ Boolean
29 30 31 |
# File 'lib/teaspoon/registry.rb', line 29 def matches?(one, two) normalize_name(one) == normalize_name(two) end |
#not_found_in_registry(klass) ⇒ Object
8 9 10 |
# File 'lib/teaspoon/registry.rb', line 8 def not_found_in_registry(klass) @not_found_exception = klass end |
#register(name, constant, path, options = {}) ⇒ Object
12 13 14 15 16 17 18 19 |
# File 'lib/teaspoon/registry.rb', line 12 def register(name, constant, path, = {}) @registry[normalize_name(name)] = proc { require path constant.constantize } @options[normalize_name(name)] = end |