Module: Hanami::Components Private
- Defined in:
- lib/hanami/components.rb,
lib/hanami/components/app/view.rb,
lib/hanami/components/component.rb,
lib/hanami/components/app/assets.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.
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.
-
.release ⇒ Object
private
Release all the resolved components.
-
.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. Or raise error for not resolved component.
127 128 129 130 131 |
# File 'lib/hanami/components.rb', line 127 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
70 71 72 73 74 |
# File 'lib/hanami/components.rb', line 70 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
58 59 60 |
# File 'lib/hanami/components.rb', line 58 def self.register(name, &blk) @_components[name] = Component.new(name, &blk) end |
.release ⇒ 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.
Release all the resolved components. This is used for code reloading.
NOTE: this MUST NOT be used unless you know what you’re doing.
149 150 151 |
# File 'lib/hanami/components.rb', line 149 def self.release @_resolved.clear 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.
104 105 106 107 108 109 110 111 |
# File 'lib/hanami/components.rb', line 104 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.
86 87 88 89 90 91 92 |
# File 'lib/hanami/components.rb', line 86 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 |