class FeduxOrgStdlib::RecursiveFileFinder

Look for file recursively

Attributes

file_name[R]

Create a new instance of finder

It tries to find a file.

@param [String] file_name

The name of the file to be looked for

@param [String] working_directory

The directory where to start search

@return [RecursiveFileFinder]

The config instance. If the resulting data structure created by the
config_engine does not respond to `:[]` an empty config object will be
created.
logger[R]

Create a new instance of finder

It tries to find a file.

@param [String] file_name

The name of the file to be looked for

@param [String] working_directory

The directory where to start search

@return [RecursiveFileFinder]

The config instance. If the resulting data structure created by the
config_engine does not respond to `:[]` an empty config object will be
created.
raise_error[R]

Create a new instance of finder

It tries to find a file.

@param [String] file_name

The name of the file to be looked for

@param [String] working_directory

The directory where to start search

@return [RecursiveFileFinder]

The config instance. If the resulting data structure created by the
config_engine does not respond to `:[]` an empty config object will be
created.
working_directory[R]

Create a new instance of finder

It tries to find a file.

@param [String] file_name

The name of the file to be looked for

@param [String] working_directory

The directory where to start search

@return [RecursiveFileFinder]

The config instance. If the resulting data structure created by the
config_engine does not respond to `:[]` an empty config object will be
created.

Public Class Methods

new( file_name:, working_directory: Dir.getwd, logger: FeduxOrgStdlib::Logging::Logger.new, raise_error: true ) click to toggle source
# File lib/fedux_org_stdlib/recursive_file_finder.rb, line 27
def initialize(
  file_name:,
  working_directory: Dir.getwd,
  logger: FeduxOrgStdlib::Logging::Logger.new,
  raise_error: true
)
  @logger            = logger
  @working_directory = Pathname.new(working_directory).expand_path
  @file_name         = Pathname.new(file_name)
  @raise_error       = raise_error
end

Public Instance Methods

directory() click to toggle source

The directory where file was found

@raise [Errno::ENOENT]

If file cannot be found

@return [Pathname]

The path to directory
# File lib/fedux_org_stdlib/recursive_file_finder.rb, line 69
def directory
  return file.dirname if file

  fail Errno::ENOENT, file_name.to_s  if raise_error

  nil
end
file() click to toggle source

Return path to file

@raise [Errno::ENOENT]

If file cannot be found

@return [Pathname]

The path
# File lib/fedux_org_stdlib/recursive_file_finder.rb, line 46
def file
  return @found_path if @found_path

  @found_path = nil

  working_directory.ascend do |p|
    path = p + file_name
    @found_path = path if path.exist?
  end

  return @found_path if @found_path
  fail Errno::ENOENT, file_name.to_s  if raise_error

  nil
end