Module: Async::Enumerable::Configurable
- Included in:
- Async::Enumerable, Async::Enumerable
- Defined in:
- lib/async/enumerable/configurable.rb
Overview
Manages configuration and collection resolution for async enumerables. Provides a DSL for defining async enumerable sources and configuration.
Defined Under Namespace
Modules: ClassMethods Classes: Config
Class Method Summary collapse
Instance Method Summary collapse
-
#__async_enumerable_collection ⇒ Enumerable
Resolves the actual enumerable collection.
-
#__async_enumerable_collection_ref ⇒ Symbol?
Gets collection reference from class.
-
#__async_enumerable_config_ref ⇒ AtomicReference
Gets the config reference for this object.
-
#__async_enumerable_configure {|ConfigStruct| ... } ⇒ Config
(also: #__async_enumerable_config)
Gets or updates configuration with block.
-
#__async_enumerable_merge_all_config(config = nil) ⇒ Hash
Merges configs from all hierarchy levels.
Class Method Details
.included(base) ⇒ Object
28 29 30 31 32 33 |
# File 'lib/async/enumerable/configurable.rb', line 28 def included(base) unless base.instance_variable_get(:@__async_enumerable_config_ref) ref = Concurrent::AtomicReference.new base.instance_variable_set(:@__async_enumerable_config_ref, ref) end end |
Instance Method Details
#__async_enumerable_collection ⇒ Enumerable
Resolves the actual enumerable collection.
128 129 130 131 132 133 134 135 136 137 |
# File 'lib/async/enumerable/configurable.rb', line 128 def __async_enumerable_collection return self unless __async_enumerable_collection_ref.is_a?(Symbol) ref = __async_enumerable_collection_ref if ref.to_s.start_with?("@") instance_variable_get(ref) else send(ref) end end |
#__async_enumerable_collection_ref ⇒ Symbol?
Gets collection reference from class.
122 123 124 |
# File 'lib/async/enumerable/configurable.rb', line 122 def __async_enumerable_collection_ref self.class.__async_enumerable_collection_ref end |
#__async_enumerable_config_ref ⇒ AtomicReference
Gets the config reference for this object.
113 114 115 116 |
# File 'lib/async/enumerable/configurable.rb', line 113 def __async_enumerable_config_ref # First check for instance-level config ref @__async_enumerable_config_ref || Async::Enumerable.config_ref end |
#__async_enumerable_configure {|ConfigStruct| ... } ⇒ Config Also known as: __async_enumerable_config
Gets or updates configuration with block.
76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 |
# File 'lib/async/enumerable/configurable.rb', line 76 def __async_enumerable_configure # Get the current config (with hierarchy) if @__async_enumerable_config_ref current = @__async_enumerable_config_ref.get else # Build config from hierarchy current_hash = __async_enumerable_merge_all_config current = Config.new(**current_hash) end return current unless block_given? mutable = current.to_struct yield mutable final = __async_enumerable_merge_all_config(mutable.to_h) Config.new(**final).tap do |updated| @__async_enumerable_config_ref = Concurrent::AtomicReference.new(updated) end end |
#__async_enumerable_merge_all_config(config = nil) ⇒ Hash
Merges configs from all hierarchy levels.
101 102 103 104 105 106 107 108 109 |
# File 'lib/async/enumerable/configurable.rb', line 101 def __async_enumerable_merge_all_config(config = nil) [Async::Enumerable.config].tap do |arr| class_cfg = self.class.respond_to?(:__async_enumerable_config) ? self.class.__async_enumerable_config : nil arr << class_cfg arr << @__async_enumerable_config arr << config end.compact.map(&:to_h).reduce(&:merge) end |