class Conferrable::FileUtilities

Extra utilities that help, but do not define the domain.

Constants

ERB_EXTENSION
FILE_MATCHER

Public Class Methods

read(filename) click to toggle source
# File lib/conferrable/file_utilities.rb, line 22
def read(filename)
  file_content = IO.read(filename)

  pre_processed_content =
    filename.downcase.end_with?(ERB_EXTENSION) ? ERB.new(file_content).result : file_content

  YAML.safe_load(pre_processed_content)
end
resolve(filenames) click to toggle source
# File lib/conferrable/file_utilities.rb, line 14
def resolve(filenames)
  Array(filenames).flatten.map do |filename|
    next unless filename && filename.to_s.length.positive?

    list(filename)
  end.flatten
end

Private Class Methods

glob_files_only(filename) click to toggle source
# File lib/conferrable/file_utilities.rb, line 47
def glob_files_only(filename)
  dir_glob = File.join(filename, '**/*')
  Dir.glob(dir_glob).grep(FILE_MATCHER).reject { |f| File.directory?(f) }
end
list(filename) click to toggle source
# File lib/conferrable/file_utilities.rb, line 37
def list(filename)
  if File.exist?(filename) && File.directory?(filename)
    glob_files_only(filename)
  elsif File.exist?(filename)
    filename
  else
    raise ArgumentError, "Cannot find file: #{filename} => #{File.expand_path(filename)}"
  end
end