Class: Qonfig::Commands::Definition::LoadFromENV Private

Inherits:
Base
  • Object
show all
Defined in:
lib/qonfig/commands/definition/load_from_env.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.2.0

Defined Under Namespace

Modules: ValueConverter

Instance Attribute Summary collapse

Instance Method Summary collapse

Methods inherited from Base

inheritable=, inheritable?, #inheritable?, inherited

Constructor Details

#initialize(convert_values: false, prefix: nil, trim_prefix: false) ⇒ LoadFromENV

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.

Returns a new instance of LoadFromENV.

Parameters:

  • convert_values (Hash) (defaults to: false)

    a customizable set of options

Options Hash (convert_values:):

  • (Boolean)

Raises:

Since:

  • 0.2.0



42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
# File 'lib/qonfig/commands/definition/load_from_env.rb', line 42

def initialize(convert_values: false, prefix: nil, trim_prefix: false)
  unless convert_values.is_a?(FalseClass) || convert_values.is_a?(TrueClass)
    raise Qonfig::ArgumentError, ':convert_values option should be a boolean'
  end

  unless prefix.is_a?(NilClass) || prefix.is_a?(String) || prefix.is_a?(Regexp)
    raise Qonfig::ArgumentError, ':prefix option should be a nil / string / regexp'
  end

  unless trim_prefix.is_a?(FalseClass) || trim_prefix.is_a?(TrueClass)
    raise Qonfig::ArgumentError, ':trim_refix options should be a boolean'
  end

  @convert_values = convert_values
  @prefix_pattern = prefix.is_a?(Regexp) ? prefix : /\A#{Regexp.escape(prefix.to_s)}.*\z/m
  @trim_prefix    = trim_prefix

  # TODO: mb trim_prefix ?
  @trim_pattern   = prefix.is_a?(Regexp) ? prefix : /\A(#{Regexp.escape(prefix.to_s)})/m
end

Instance Attribute Details

#convert_valuesBoolean (readonly)

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.

Returns:

  • (Boolean)

Since:

  • 0.2.0



15
16
17
# File 'lib/qonfig/commands/definition/load_from_env.rb', line 15

def convert_values
  @convert_values
end

#prefix_patternRegexp (readonly)

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.

Returns:

  • (Regexp)

Since:

  • 0.2.0



21
22
23
# File 'lib/qonfig/commands/definition/load_from_env.rb', line 21

def prefix_pattern
  @prefix_pattern
end

#trim_patternRegexp (readonly)

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.

Returns:

  • (Regexp)

Since:

  • 0.2.0



33
34
35
# File 'lib/qonfig/commands/definition/load_from_env.rb', line 33

def trim_pattern
  @trim_pattern
end

#trim_prefixBoolean (readonly)

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.

Returns:

  • (Boolean)

Since:

  • 0.2.0



27
28
29
# File 'lib/qonfig/commands/definition/load_from_env.rb', line 27

def trim_prefix
  @trim_prefix
end

Instance Method Details

#call(data_set, settings) ⇒ void

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.

This method returns an undefined value.

Parameters:

Since:

  • 0.2.0



69
70
71
72
73
# File 'lib/qonfig/commands/definition/load_from_env.rb', line 69

def call(data_set, settings)
  env_data = extract_env_data
  env_based_settings = build_data_set_klass(env_data).new.settings
  settings.__append_settings__(env_based_settings)
end