Class: Torikago::Configuration
- Inherits:
-
Object
- Object
- Torikago::Configuration
- Defined in:
- lib/torikago/configuration.rb
Overview
Stores module definitions declared by the host application. Other runtime objects treat this as the source of truth for module roots and boot options.
Defined Under Namespace
Classes: Definition
Instance Method Summary collapse
- #each_definition(&block) ⇒ Object
- #fetch(name) ⇒ Object
-
#initialize ⇒ Configuration
constructor
A new instance of Configuration.
- #register(name, root:, entrypoint: nil, setup: nil, gemfile: nil) ⇒ Object
- #registered?(name) ⇒ Boolean
Constructor Details
#initialize ⇒ Configuration
Returns a new instance of Configuration.
9 10 11 |
# File 'lib/torikago/configuration.rb', line 9 def initialize @definitions = {} end |
Instance Method Details
#each_definition(&block) ⇒ Object
31 32 33 34 35 |
# File 'lib/torikago/configuration.rb', line 31 def each_definition(&block) return @definitions.each_value unless block @definitions.each_value(&block) end |
#fetch(name) ⇒ Object
37 38 39 40 41 42 43 |
# File 'lib/torikago/configuration.rb', line 37 def fetch(name) normalized_name = name.to_sym @definitions.fetch(normalized_name) do raise KeyError, "module not registered: #{name}" end end |
#register(name, root:, entrypoint: nil, setup: nil, gemfile: nil) ⇒ Object
13 14 15 16 17 18 19 20 21 22 23 24 25 |
# File 'lib/torikago/configuration.rb', line 13 def register(name, root:, entrypoint: nil, setup: nil, gemfile: nil) if @definitions.key?(name.to_sym) raise ArgumentError, "module already registered: #{name}" end @definitions[name.to_sym] = Definition.new( name: name.to_sym, root: Pathname(root), entrypoint: entrypoint, setup: setup, gemfile: gemfile ) end |
#registered?(name) ⇒ Boolean
27 28 29 |
# File 'lib/torikago/configuration.rb', line 27 def registered?(name) @definitions.key?(name.to_sym) end |