module Sanctum::Command::PathsHelper

Public Instance Methods

build_path(hash, path = []) click to toggle source
# File lib/sanctum/command/paths_helper.rb, line 21
def build_path(hash, path = [])
  build_path_helper(hash, path).each_slice(2).to_h
end
get_local_paths(paths) click to toggle source
# File lib/sanctum/command/paths_helper.rb, line 47
def get_local_paths(paths)
  tmp_array = Array.new
  Find.find(paths) do |path|
    if FileTest.file?(path)
      tmp_array << path
      if File.basename(path).start_with?(?.)
        Find.prune
      else
        next
      end
    end
  end
  tmp_array
end
join_path(hash, config_file) click to toggle source
# File lib/sanctum/command/paths_helper.rb, line 25
def join_path(hash, config_file)
  config_file = Pathname.new(config_file)
  tmp_hash = Hash.new

  hash.each do |p, v|
    p = config_file.dirname + Pathname.new(p.join("/"))
    tmp_hash["#{p}"] = v
  end
  tmp_hash
end
read_local_files(paths) click to toggle source
# File lib/sanctum/command/paths_helper.rb, line 36
def read_local_files(paths)
  tmp_hash = Hash.new
  paths.each do |k,v|
    if File.file?(k)
      v = File.read(k)
      tmp_hash["#{k}"] = v
    end
  end
  tmp_hash
end

Private Instance Methods

build_path_helper(hash, path = []) click to toggle source

Helper methods for building, reading and joining paths

# File lib/sanctum/command/paths_helper.rb, line 10
def build_path_helper(hash, path = [])
  if hash.values.any? { |k| !k.is_a?(Hash) }
    [path, hash]
  else
    hash.flat_map do |(key,value)|
      build_path_helper(value, path+[key])
    end
  end
end