Class: Jerry::Config Abstract
- Inherits:
-
Object
- Object
- Jerry::Config
- Defined in:
- lib/jerry/config.rb
Overview
Subclass to define a config
Base class for all jerry configs.
A config is a class that tells jerry about a set of available components and how those should be created
Instance Attribute Summary collapse
-
#jerry ⇒ Object
writeonly
Jerry instance the config is part of.
Class Method Summary collapse
-
.component(name, options = {}) { ... } ⇒ Object
Defines a component.
-
.components ⇒ Array<Symbol>
List of the components defined by the config.
Instance Method Summary collapse
-
#cache ⇒ Object
protected
Used internally to cache single instance components.
-
#components ⇒ Array<Symbol>
List of components defined by the config.
-
#knows?(component) ⇒ Boolean
protected
Check if given component exists.
-
#rig(component) ⇒ Object
protected
Creates a component.
Instance Attribute Details
#jerry=(value) ⇒ Object (writeonly)
Jerry instance the config is part of
This gets set by Jerry when it loads a config
62 63 64 |
# File 'lib/jerry/config.rb', line 62 def jerry=(value) @jerry = value end |
Class Method Details
.component(name, options = {}) { ... } ⇒ Object
Defines a component
33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 |
# File 'lib/jerry/config.rb', line 33 def component(name, ={}, &block) raise Jerry::ComponentError, "could not define component #{name}, block is missing" if block.nil? scope = [:scope] || :single unless [:single, :instance].include? scope raise Jerry::ComponentError, "could not define component #{name}, scope #{scope} is unknown" end define_method name do case scope when :single cache[name] ||= instance_eval(&block) when :instance instance_eval(&block) end end components << name end |
.components ⇒ Array<Symbol>
Returns list of the components defined by the config.
19 20 21 |
# File 'lib/jerry/config.rb', line 19 def components @components ||= [] end |
Instance Method Details
#cache ⇒ Object (protected)
Used internally to cache single instance components
81 82 83 |
# File 'lib/jerry/config.rb', line 81 def cache @cache ||= {} end |
#components ⇒ Array<Symbol>
Returns list of components defined by the config.
55 56 57 |
# File 'lib/jerry/config.rb', line 55 def components self.class.components end |
#knows?(component) ⇒ Boolean (protected)
Check if given component exists
This should be used inside the block passed to Config::component
76 77 78 |
# File 'lib/jerry/config.rb', line 76 def knows?(component) @jerry.knows? component end |
#rig(component) ⇒ Object (protected)
Creates a component
This should be used inside the block passed to Config::component
69 70 71 |
# File 'lib/jerry/config.rb', line 69 def rig(component) @jerry.rig component end |