Sha256: a3963737bc10766db0bf822c2c4bd6245f7de7049a5150869e714a514cd17ae9

Contents?: true

Size: 1.07 KB

Versions: 8

Compression:

Stored size: 1.07 KB

Contents

# frozen_string_literal: true

# @api private
# @since 0.12.0
class Qonfig::Commands::LoadFromTOML < Qonfig::Commands::Base
  # @return [String]
  #
  # @api private
  # @since 0.12.0
  attr_reader :file_path

  # @return [Boolean]
  #
  # @api private
  # @since 0.12.0
  attr_reader :strict

  # @param file_path [String]
  # @option strict [Boolean]
  #
  # @api private
  # @since 0.12.0
  def initialize(file_path, strict: true)
    @file_path = file_path
    @strict = strict
  end

  # @param data_set [Qonfig::DataSet]
  # @param settings [Qonfig::Settings]
  # @return [void]
  #
  # @api private
  # @since 0.12.0
  def call(data_set, settings)
    toml_data = Qonfig::Loaders::TOML.load_file(file_path, fail_on_unexist: strict)
    toml_based_settings = build_data_set_klass(toml_data).new.settings
    settings.__append_settings__(toml_based_settings)
  end

  private

  # @param toml_data [Hash]
  # @return [Class<Qonfig::DataSet>]
  #
  # @api private
  # @since 0.12.0
  def build_data_set_klass(toml_data)
    Qonfig::DataSet::ClassBuilder.build_from_hash(toml_data)
  end
end

Version data entries

8 entries across 8 versions & 1 rubygems

Version Path
qonfig-0.19.1 lib/qonfig/plugins/toml/commands/load_from_toml.rb
qonfig-0.19.0 lib/qonfig/plugins/toml/commands/load_from_toml.rb
qonfig-0.18.1 lib/qonfig/plugins/toml/commands/load_from_toml.rb
qonfig-0.18.0 lib/qonfig/plugins/toml/commands/load_from_toml.rb
qonfig-0.17.0 lib/qonfig/plugins/toml/commands/load_from_toml.rb
qonfig-0.16.0 lib/qonfig/plugins/toml/commands/load_from_toml.rb
qonfig-0.15.0 lib/qonfig/plugins/toml/commands/load_from_toml.rb
qonfig-0.14.0 lib/qonfig/plugins/toml/commands/load_from_toml.rb