class Flexdot::Index

Attributes

index[R]

Public Class Methods

new(index) click to toggle source
# File lib/flexdot/index.rb, line 5
def initialize(index)
  @index = index
end

Public Instance Methods

each(&block) click to toggle source
# File lib/flexdot/index.rb, line 9
def each(&block)
  index.each do |root, descendants|
    fetch_descendants(descendants, paths: [root], &block)
  end
end

Private Instance Methods

fetch_descendants(descendants, paths:, &block) click to toggle source
# File lib/flexdot/index.rb, line 19
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), home_file_path: v)
    when Hash
      fetch_descendants(v, paths: dotfile_path, &block)
    else
      raise ArgumentError, v
    end
  end
end