Sha256: bf1ea9d50eb7d07aec95ae3d3e8af4069737f9fca37a2a7d72d8cf4fc43f880f

Contents?: true

Size: 694 Bytes

Versions: 1

Compression:

Stored size: 694 Bytes

Contents

# frozen_string_literal: true

module Flexdot
  class Index
    def initialize(index)
      @index = index
    end

    def each(&block)
      index.each do |root, descendants|
        fetch_descendants(descendants, paths: [root], &block)
      end
    end

    private

    attr_reader :index

    def fetch_descendants(descendants, paths:, &block)
      descendants.each do |k, v|
        dotfile_path = paths + [k]
        case v
        when String
          block.call(dotfile_path: File.join(*dotfile_path), target_path: v)
        when Hash
          fetch_descendants(v, paths: dotfile_path, &block)
        else
          raise ArgumentError, v
        end
      end
    end
  end
end

Version data entries

1 entries across 1 versions & 1 rubygems

Version Path
flexdot-1.0.2 lib/flexdot/index.rb