Class: RFlow::Configuration::DataExtensionCollection

Inherits:
Object
  • Object
show all
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

Constructor Details

#initializeDataExtensionCollection

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) ⇒ Array

Return an array of all of the values that have keys that are prefixes of the lookup key.

Returns:

  • (Array)


27
28
29
30
31
# 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) ⇒ void

This method returns an undefined value.

Adds a data extension for a given data type to the collection



35
36
37
# File 'lib/rflow/configuration.rb', line 35

def add(data_type, extension)
  @extensions_for[data_type.to_s] << extension
end

#clearvoid

This method returns an undefined value.

Remove all elements from the collection. Useful for testing, not much else



42
43
44
# File 'lib/rflow/configuration.rb', line 42

def clear
  @extensions_for.clear
end