Module: Hanami::Components Private
- Defined in:
- lib/hanami/components.rb,
lib/hanami/commands/apps.rb,
lib/hanami/components/app/view.rb,
lib/hanami/components/component.rb,
lib/hanami/components/app/assets.rb,
lib/hanami/components/app/logger.rb,
lib/hanami/components/app/routes.rb,
lib/hanami/components/components.rb,
lib/hanami/components/app/controller.rb,
lib/hanami/components/routes_inspector.rb
Overview
This module is part of a private API. You should avoid using this module if possible, as it may be removed or be changed in the future.
Registered components
Defined Under Namespace
Modules: App Classes: Component, RoutesInspector
Class Method Summary collapse
-
.[](name) ⇒ Object
private
Return the value of an already resolved component.
-
.component(name) ⇒ Object
private
Return a registered component.
-
.register(name, &blk) ⇒ Object
private
Register a component.
-
.resolve(*names) ⇒ Object
private
Ask to resolve a component.
-
.resolved(name, value = nil, &blk) ⇒ Object
private
Mark a component as resolved by providing a value or a block.
Class Method Details
.[](name) ⇒ Object
This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.
Return the value of an already resolved component.
98 99 100 101 102 |
# File 'lib/hanami/components.rb', line 98 def self.[](name) @_resolved.fetch(name) do raise ArgumentError.new("Component not resolved: `#{name}'.\nResolved components are: #{@_resolved.keys.join(', ')}") end end |
.component(name) ⇒ Object
This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.
Return a registered component
47 48 49 50 51 |
# File 'lib/hanami/components.rb', line 47 def self.component(name) @_components.fetch(name) do raise ArgumentError.new("Component not found: `#{name}'.\nAvailable components are: #{@_components.keys.join(', ')}") end end |
.register(name, &blk) ⇒ Object
This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.
Register a component
35 36 37 |
# File 'lib/hanami/components.rb', line 35 def self.register(name, &blk) @_components[name] = Component.new(name, &blk) end |
.resolve(*names) ⇒ Object
This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.
Ask to resolve a component.
This is used as dependency mechanism. For instance ‘model` component depends on `model.configuration`. Before to resolve `model`, `Components` uses this method to resolve that dependency first.
81 82 83 84 85 86 87 88 |
# File 'lib/hanami/components.rb', line 81 def self.resolve(*names) Array(names).flatten.each do |name| @_resolved.fetch_or_store(name) do component = @_components.fetch(name) component.call(Hanami.configuration) end end end |
.resolved(name, value = nil, &blk) ⇒ Object
This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.
Mark a component as resolved by providing a value or a block. In the latter case, the returning value of the block is associated with the component.
63 64 65 66 67 68 69 |
# File 'lib/hanami/components.rb', line 63 def self.resolved(name, value = nil, &blk) if block_given? @_resolved.fetch_or_store(name, &blk) else @_resolved.compute_if_absent(name) { value } end end |