Class: StackedConfig::Layers::ExecutableGemLayer

Inherits:
GenericLayer
  • Object
show all
Defined in:
lib/stacked_config/layers/executable_gem_layer.rb

Constant Summary

Constants included from SourceHelper

SourceHelper::DEFAULT_OS_FLAVOUR, SourceHelper::EXTENSIONS, SourceHelper::OS_FLAVOURS

Class Method Summary collapse

Instance Method Summary collapse

Methods inherited from GenericLayer

#initialize, #possible_config_files, #rescan

Methods included from SourceHelper

included, os_flavour, #os_flavour, supported_oses, #supported_oses

Constructor Details

This class inherits a constructor from StackedConfig::Layers::GenericLayer

Class Method Details

.executable_gem_config_rootObject



7
8
9
10
11
12
13
14
15
# File 'lib/stacked_config/layers/executable_gem_layer.rb', line 7

def self.executable_gem_config_root
  return nil unless $PROGRAM_NAME

  Gem.loaded_specs.each_pair do |name, spec|
    executable_basename = File.basename($PROGRAM_NAME)
    return spec.full_gem_path if spec.executables.include? executable_basename
  end
  nil
end

Instance Method Details

#executable_gem_config_rootObject



17
18
19
# File 'lib/stacked_config/layers/executable_gem_layer.rb', line 17

def executable_gem_config_root
  self.class.executable_gem_config_root
end

#perform_substitutions(path_part) ⇒ Object



32
33
34
35
36
37
38
39
# File 'lib/stacked_config/layers/executable_gem_layer.rb', line 32

def perform_substitutions path_part
  return nil unless executable_gem_config_root
  res = path_part.dup
  res.gsub! '##EXECUTABLE_GEM_CONFIG_ROOT##', executable_gem_config_root
  exec_name = manager.nil? ? StackedConfig::Orchestrator.default_config_file_base_name : manager.config_file_base_name
  res.gsub! '##PROGRAM_NAME##', exec_name
  res
end

#possible_sourcesObject



21
22
23
24
25
26
27
28
29
30
# File 'lib/stacked_config/layers/executable_gem_layer.rb', line 21

def possible_sources
  [
      %w(##EXECUTABLE_GEM_CONFIG_ROOT## etc ##PROGRAM_NAME##.##EXTENSION##),
      %w(##EXECUTABLE_GEM_CONFIG_ROOT## etc ##PROGRAM_NAME## config.##EXTENSION##),
      %w(##EXECUTABLE_GEM_CONFIG_ROOT## etc ##PROGRAM_NAME## ##PROGRAM_NAME##.##EXTENSION##),
      %w(##EXECUTABLE_GEM_CONFIG_ROOT## config ##PROGRAM_NAME##.##EXTENSION##),
      %w(##EXECUTABLE_GEM_CONFIG_ROOT## config ##PROGRAM_NAME## config.##EXTENSION##),
      %w(##EXECUTABLE_GEM_CONFIG_ROOT## config ##PROGRAM_NAME## ##PROGRAM_NAME##.##EXTENSION##)
  ]
end