Class: Qonfig::Commands::Definition::ExposeSelf Private

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

Instance Attribute Summary collapse

Instance Method Summary collapse

Methods inherited from Base

inheritable=, inheritable?, #inheritable?, inherited

Constructor Details

#initialize(caller_location, env:, format:) ⇒ ExposeSelf

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 ExposeSelf.

Parameters:

  • caller_location (String)
  • env (Hash)

    a customizable set of options

  • format (Hash)

    a customizable set of options

Options Hash (env:):

  • (String, Symbol)

Options Hash (format:):

  • (String, Symbol)

Raises:

Since:

  • 0.14.0



33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
# File 'lib/qonfig/commands/definition/expose_self.rb', line 33

def initialize(caller_location, env:, format:)
  unless env.is_a?(Symbol) || env.is_a?(String)
    raise Qonfig::ArgumentError, ':env should be a string or a symbol'
  end

  raise Qonfig::ArgumentError, ':env should be provided' if env.to_s.empty?

  unless format.is_a?(String) || format.is_a?(Symbol)
    raise Qonfig::ArgumentError, 'Format should be a symbol or a string'
  end

  @caller_location = caller_location
  @env = env
  @format = format.tap { Qonfig::Loaders.resolve(format) }
end

Instance Attribute Details

#caller_locationString (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:

  • (String)

Since:

  • 0.14.0



19
20
21
# File 'lib/qonfig/commands/definition/expose_self.rb', line 19

def caller_location
  @caller_location
end

#envSymbol, String (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:

  • (Symbol, String)

Since:

  • 0.14.0



25
26
27
# File 'lib/qonfig/commands/definition/expose_self.rb', line 25

def env
  @env
end

#formatString, Symbol (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:

  • (String, Symbol)

Since:

  • 0.15.0



13
14
15
# File 'lib/qonfig/commands/definition/expose_self.rb', line 13

def format
  @format
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:

Raises:

Since:

  • 0.14.0



55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
# File 'lib/qonfig/commands/definition/expose_self.rb', line 55

def call(data_set, settings)
  self_placed_data = load_self_placed_end_data
  env_based_data_slice =
    self_placed_data[env] || self_placed_data[env.to_s] || self_placed_data[env.to_sym]

  raise(
    Qonfig::ExposeError,
    "#{file_path} file does not contain settings with <#{env}> environment key!"
  ) unless env_based_data_slice

  raise(
    Qonfig::IncompatibleEndDataStructureError,
    '__END__-data content must be a hash-like structure'
  ) unless env_based_data_slice.is_a?(Hash)

  self_placed_settings = build_data_set_klass(env_based_data_slice).new.settings
  settings.__append_settings__(self_placed_settings)
end