Class: Dotcrypt::Flattener
- Inherits:
-
Object
- Object
- Dotcrypt::Flattener
- Defined in:
- lib/dotcrypt/flattener.rb
Constant Summary collapse
- SCALARS =
[String, Numeric, NilClass].freeze
Class Method Summary collapse
Instance Method Summary collapse
- #call ⇒ Object
-
#initialize(config, prefixes: [], accumulator: {}, separator: "_") ⇒ Flattener
constructor
A new instance of Flattener.
Constructor Details
#initialize(config, prefixes: [], accumulator: {}, separator: "_") ⇒ Flattener
Returns a new instance of Flattener.
8 9 10 11 12 13 |
# File 'lib/dotcrypt/flattener.rb', line 8 def initialize(config, prefixes: [], accumulator: {}, separator: "_") @config = config @prefixes = prefixes @accumulator = accumulator @separator = separator end |
Class Method Details
.call ⇒ Object
6 |
# File 'lib/dotcrypt/flattener.rb', line 6 def self.call(...) = new(...).call |
Instance Method Details
#call ⇒ Object
15 16 17 18 19 20 21 22 23 24 |
# File 'lib/dotcrypt/flattener.rb', line 15 def call case config when *SCALARS then save(@config) when Hash then config.each { |k, v| self.class.call(v, prefixes: prefixes + [k], accumulator:, separator:) } when Array then flatten_array else raise TypeError, "unknown type: #{config.class}" end accumulator end |