Sha256: ca0a8c2c91dd49fc3ffa30a1b7d6f129139781acaae6526a56247b91283cec69

Contents?: true

Size: 842 Bytes

Versions: 18

Compression:

Stored size: 842 Bytes

Contents

# frozen_string_literal: true

module Anyway
  module Ext
    # Convert Hash with mixed array and hash values to an
    # array of paths.
    module FlattenNames
      refine ::Array do
        def flatten_names(prefix, buf)
          if empty?
            buf << :"#{prefix}"
            return buf
          end

          each_with_object(buf) do |name, acc|
            if name.is_a?(::Symbol)
              acc << :"#{prefix}.#{name}"
            else
              name.flatten_names(prefix, acc)
            end
          end
        end
      end

      refine ::Hash do
        def flatten_names(prefix = nil, buf = [])
          each_with_object(buf) do |(k, v), acc|
            parent = prefix ? "#{prefix}.#{k}" : k
            v.flatten_names(parent, acc)
          end
        end
      end

      using self
    end
  end
end

Version data entries

18 entries across 18 versions & 2 rubygems

Version Path
anyway_config-2.6.4 lib/anyway/ext/flatten_names.rb
anyway_config-2.6.3 lib/anyway/ext/flatten_names.rb
anyway_config-2.6.2 lib/anyway/ext/flatten_names.rb
anyway_config-2.6.1 lib/anyway/ext/flatten_names.rb
anyway_config-2.6.0 lib/anyway/ext/flatten_names.rb
runger_config-3.0.1 lib/anyway/ext/flatten_names.rb
runger_config-3.0.0 lib/anyway/ext/flatten_names.rb
runger_config-2.7.0 lib/anyway/ext/flatten_names.rb
runger_config-2.6.1 lib/anyway/ext/flatten_names.rb
runger_config-2.6.0 lib/anyway/ext/flatten_names.rb
anyway_config-2.5.4 lib/anyway/ext/flatten_names.rb
anyway_config-2.5.3 lib/anyway/ext/flatten_names.rb
anyway_config-2.5.2 lib/anyway/ext/flatten_names.rb
anyway_config-2.5.1 lib/anyway/ext/flatten_names.rb
anyway_config-2.5.0 lib/anyway/ext/flatten_names.rb
anyway_config-2.4.2 lib/anyway/ext/flatten_names.rb
anyway_config-2.4.1 lib/anyway/ext/flatten_names.rb
anyway_config-2.4.0 lib/anyway/ext/flatten_names.rb