Class: Qonfig::Commands::LoadFromENV Private

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

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



39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
# File 'lib/qonfig/commands/load_from_env.rb', line 39

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
  @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



12
13
14
# File 'lib/qonfig/commands/load_from_env.rb', line 12

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



18
19
20
# File 'lib/qonfig/commands/load_from_env.rb', line 18

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



30
31
32
# File 'lib/qonfig/commands/load_from_env.rb', line 30

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



24
25
26
# File 'lib/qonfig/commands/load_from_env.rb', line 24

def trim_prefix
  @trim_prefix
end

Instance Method Details

#call(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



63
64
65
66
67
68
69
# File 'lib/qonfig/commands/load_from_env.rb', line 63

def call(settings)
  env_data = extract_env_data

  env_based_settings = build_data_set_class(env_data).new.settings

  settings.__append_settings__(env_based_settings)
end