Class: Qonfig::Uploaders::YAML Private

Inherits:
File
  • Object
show all
Defined in:
lib/qonfig/uploaders/yaml.rb

Overview

This class is part of a private API. You should avoid using this class if possible, as it may be removed or be changed in the future.

Since:

  • 0.11.0

Defined Under Namespace

Classes: YAMLRepresenter

Constant Summary collapse

DEFAULT_OPTIONS =

This constant is part of a private API. You should avoid using this constant if possible, as it may be removed or be changed in the future.

Returns:

  • (Hash<Symbol,Any>)

Since:

  • 0.11.0

{
  indentation: 2,
  line_width: -1,
  canonical: false,
  header: false,
  symbolize_keys: false
}.freeze
KEY_SYMBOLIZER =

This constant is part of a private API. You should avoid using this constant if possible, as it may be removed or be changed in the future.

Returns:

  • (Proc)

Since:

  • 0.11.0

-> (value) { value.to_sym }.freeze

Constants inherited from File

File::EMPTY_SETTINGS_REPRESENTATION, File::FILE_OPENING_MODE

Class Method Summary collapse

Methods inherited from File

upload

Methods inherited from Base

upload

Class Method Details

.hash_representation_options(options, &value_processor) ⇒ Hash

This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.

Parameters:

  • options (Hash<Symbol|String,Any>)
  • value_processor (Block)

Returns:

  • (Hash)

Since:

  • 0.11.0



60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
# File 'lib/qonfig/uploaders/yaml.rb', line 60

def hash_representation_options(options, &value_processor)
  {}.tap do |representation_opts|
    # NOTE: this case/when with the same logic is only used for better code readbility
    # rubocop:disable Lint/DuplicateBranch
    case
    # NOTE: options has :symbolize_keys key
    when options.key?(:symbolize_keys) && !!options[:symbolize_keys]
      representation_opts[:transform_key] = KEY_SYMBOLIZER
    # NOTE: options does not have :symbolize_keys key
    when !options.key?(:symbolize_keys) && DEFAULT_OPTIONS[:symbolize_keys]
      # :nocov:
      representation_opts[:transform_key] = KEY_SYMBOLIZER
      # :nocov:
    end
    # rubocop:enable Lint/DuplicateBranch

    # NOTE: provide value transformer
    if block_given?
      representation_opts[:transform_value] = value_processor
    end
  end
end

.represent_settings(settings, options, &value_processor) ⇒ String

This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.

Parameters:

  • settings (Qonfig::Settings)
  • options (Hash<Symbol,Any>)
  • value_processor (Block)

Returns:

  • (String)

Since:

  • 0.11.0



48
49
50
51
52
# File 'lib/qonfig/uploaders/yaml.rb', line 48

def represent_settings(settings, options, &value_processor)
  settings_hash_opts = hash_representation_options(options, &value_processor)
  settings_hash = settings.__to_hash__(**settings_hash_opts)
  to_yaml_string(settings_hash, options)
end

.to_yaml_string(settings_hash, yaml_options) ⇒ String

This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.

Parameters:

  • settings_hash (Hash<String|Symbol,Any>)
  • yaml_options (Hash<Symbol,Any>)

Returns:

  • (String)

Since:

  • 0.11.0



89
90
91
92
93
# File 'lib/qonfig/uploaders/yaml.rb', line 89

def to_yaml_string(settings_hash, yaml_options)
  representer = YAMLRepresenter.create(yaml_options)
  representer << settings_hash
  representer.tree.yaml(nil, yaml_options)
end