Class: RFlow::Configuration::DataExtensionCollection
- Inherits:
-
Object
- Object
- RFlow::Configuration::DataExtensionCollection
- Defined in:
- lib/rflow/configuration.rb
Overview
A collection class for data extensions that supports a naive prefix-based ‘inheritance’ on lookup. When looking up a key with [] all existing keys will be examined to determine if the existing key is a string prefix of the lookup key. All the results are consolidated into a single, flattened array.
Instance Method Summary collapse
-
#[](key) ⇒ Object
Return an array of all of the values that have keys that are prefixes of the lookup key.
-
#add(data_type, extension) ⇒ Object
Adds a data extension for a given data type to the collection.
-
#clear ⇒ Object
Remove all elements from the collection.
-
#initialize ⇒ DataExtensionCollection
constructor
A new instance of DataExtensionCollection.
Constructor Details
#initialize ⇒ DataExtensionCollection
Returns a new instance of DataExtensionCollection.
19 20 21 22 |
# File 'lib/rflow/configuration.rb', line 19 def initialize # TODO: choose a different data structure ... @extensions_for = Hash.new {|hash, key| hash[key] = []} end |
Instance Method Details
#[](key) ⇒ Object
Return an array of all of the values that have keys that are prefixes of the lookup key.
26 27 28 29 30 |
# File 'lib/rflow/configuration.rb', line 26 def [](key) @extensions_for. find_all {|data_type, _| key.to_s.start_with?(data_type) }. flat_map {|_, extensions| extensions } end |
#add(data_type, extension) ⇒ Object
Adds a data extension for a given data type to the collection
33 34 35 |
# File 'lib/rflow/configuration.rb', line 33 def add(data_type, extension) @extensions_for[data_type.to_s] << extension end |
#clear ⇒ Object
Remove all elements from the collection. Useful for testing, not much else
39 40 41 |
# File 'lib/rflow/configuration.rb', line 39 def clear @extensions_for.clear end |