Module: Avm::Sources::Base::Configuration

Defined in:
lib/avm/sources/base/configuration.rb

Constant Summary collapse

PARENT_CONFIGURATION_SUFFIX =
%w[subs at].freeze
CONFIGURATION_FILENAMES =
%w[.avm.yml .avm.yaml].freeze

Instance Method Summary collapse

Instance Method Details

#configuration_entry(*entry_args) ⇒ EacConfig::NodeEntry

Returns:

  • (EacConfig::NodeEntry)


16
17
18
19
20
21
22
23
# File 'lib/avm/sources/base/configuration.rb', line 16

def configuration_entry(*entry_args)
  parent_configuration.if_present do |v|
    parent_entry = v.entry(*entry_args)
    return parent_entry if parent_entry.found?
  end

  configuration.entry(*entry_args)
end

#configuration_pathsArray<Pathname>

The possible absolute paths for configuration files.

Returns:

  • (Array<Pathname>)


28
29
30
# File 'lib/avm/sources/base/configuration.rb', line 28

def configuration_paths
  CONFIGURATION_FILENAMES.map { |filename| path.join(filename) }
end

#configuration_value_to_env_command(value) ⇒ EacRubyUtils::Envs::Command?

Returns:

  • (EacRubyUtils::Envs::Command, nil)


33
34
35
36
37
# File 'lib/avm/sources/base/configuration.rb', line 33

def configuration_value_to_env_command(value)
  return value if value.is_a?(::EacRubyUtils::Envs::Command)

  configuration_value_to_shell_words(value).if_present { |v| env.command(v).chdir(path) }
end

#configuration_value_to_shell_words(value) ⇒ Array<String>?

Returns:

  • (Array<String>, nil)


40
41
42
43
44
# File 'lib/avm/sources/base/configuration.rb', line 40

def configuration_value_to_shell_words(value)
  return nil if value.blank?

  value.is_a?(::Enumerable) ? value.map(&:to_s) : ::Shellwords.split(value.to_s)
end

#read_configuration_as_env_command(key) ⇒ EacRubyUtils::Envs::Command

Utility to read a configuration as a [EacRubyUtils::Envs::Command].

Returns:

  • (EacRubyUtils::Envs::Command)


53
54
55
# File 'lib/avm/sources/base/configuration.rb', line 53

def read_configuration_as_env_command(key)
  configuration_value_to_env_command(configuration_entry(key).value)
end

#read_configuration_as_shell_words(key) ⇒ Array<String>?

Returns:

  • (Array<String>, nil)


47
48
49
# File 'lib/avm/sources/base/configuration.rb', line 47

def read_configuration_as_shell_words(key)
  configuration_value_to_shell_words(configuration_entry(key).value)
end