Module: ConfigSL::FromFile::ClassMethods

Defined in:
lib/configsl/from_file.rb

Overview

Required class methods for loading config files.

Instance Method Summary collapse

Instance Method Details

#from_file(path = nil, format: nil) ⇒ self

Loads configuration from a file.

If no path is specified, uses the file file that matches the default path, name, and file formats. If multiple files are found, they will be sorted based on the order the file formats are defined, adn the first file will be load.

Parameters:

  • path (String) (defaults to: nil)

    Optional path to the file to load.

  • format (Symbol) (defaults to: nil)

    Optional format to use for the file. Uses the file extension if not specified.

Returns:

  • (self)


48
49
50
51
52
53
# File 'lib/configsl/from_file.rb', line 48

def from_file(path = nil, format: nil)
  path ||= find_file.first
  format ||= find_file_format(File.extname(path))
  file = @config_file_formats[format][:class].new(path)
  new(file.read)
end