class RFlow::Configuration::DataExtensionCollection
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.
Public Class Methods
new()
click to toggle source
# File lib/rflow/configuration.rb, line 19 def initialize # TODO: choose a different data structure ... @extensions_for = Hash.new {|hash, key| hash[key] = []} end
Public Instance Methods
[](key)
click to toggle source
Return an array of all of the values that have keys that are prefixes of the lookup key. @return [Array]
# File lib/rflow/configuration.rb, line 27 def [](key) @extensions_for. find_all {|data_type, _| key.to_s.start_with?(data_type) }. flat_map {|_, extensions| extensions } end
add(data_type, extension)
click to toggle source
Adds a data extension for a given data type to the collection @return [void]
# File lib/rflow/configuration.rb, line 35 def add(data_type, extension) @extensions_for[data_type.to_s] << extension end
clear()
click to toggle source
Remove all elements from the collection. Useful for testing, not much else @return [void]
# File lib/rflow/configuration.rb, line 42 def clear @extensions_for.clear end