Sha256: 1f6389289b99d39db127573c9e79c1ab6c15430844f083748a952d9dfe740323

Contents?: true

Size: 756 Bytes

Versions: 5

Compression:

Stored size: 756 Bytes

Contents

# A module that provides a method to load configuration settings from a YAML file.
module YamlConfigurable
  # Loads configuration settings from a YAML file.
  #
  # @param file_path [String] The path to the YAML file.
  def load_from_yaml(file_path)
    return unless File.exist?(file_path)

    config_hash = YAML.load_file(file_path)

    set_if_present(config, :before_path, config_hash.dig('directories', 'before'))
    set_if_present(config, :after_path, config_hash.dig('directories', 'after'))
    set_if_present(config, :extensions, config_hash['extensions'])
    set_if_present(config, :silent, config_hash['silent'])
  end

  private

  def set_if_present(config, key, value)
    config.public_send("#{key}=", value) if value.present?
  end
end

Version data entries

5 entries across 5 versions & 1 rubygems

Version Path
pg_objects-1.4.0 lib/pg_objects/yaml_configurable.rb
pg_objects-1.3.3 lib/pg_objects/yaml_configurable.rb
pg_objects-1.3.2 lib/pg_objects/yaml_configurable.rb
pg_objects-1.3.1 lib/pg_objects/yaml_configurable.rb
pg_objects-1.3.0 lib/pg_objects/yaml_configurable.rb