Class: Rdm::Settings

Inherits:
Object
  • Object
show all
Defined in:
lib/rdm/settings.rb

Constant Summary collapse

SETTING_KEYS =
[
  :role, :package_subdir_name, :configs_dir, :config_path, :role_config_path,
  :silence_missing_package_file, :silence_missing_package, :compile_path,
  :compile_ignore_files, :compile_add_files, :env_files_dir, :env_file_name
].freeze
SETTING_VARIABLES =
[:role, :configs_dir, :config_path, :role_config_path].freeze

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initializeSettings

Default settings



13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
# File 'lib/rdm/settings.rb', line 13

def initialize
  silence_missing_package(false)
  silence_missing_package_file(false)
  package_subdir_name('package')
  configs_dir('configs')
  env_files_dir('env_files')
  compile_ignore_files([
    '.gitignore',
    '.byebug_history',
    '.irbrc',
    '.rspec',
    '*_spec.rb',
    '*.log'
  ])
  compile_add_files([
    'Gemfile',
    'Gemfile.lock'
  ])
  compile_path('/tmp/rdm/:package_name')
end

Instance Attribute Details

#settingsObject (readonly)

Returns the value of attribute settings.



2
3
4
# File 'lib/rdm/settings.rb', line 2

def settings
  @settings
end

Instance Method Details

#fetch_setting(key, value = nil, &block) ⇒ Object



40
41
42
43
44
45
46
47
# File 'lib/rdm/settings.rb', line 40

def fetch_setting(key, value = nil, &block)
  if value.nil? && !block_given?
    read_setting(key)
  else
    write_value = value.nil? ? block : value
    write_setting(key, write_value)
  end
end

#read_setting(key, vars: {}) ⇒ Object



49
50
51
52
53
54
55
56
57
58
# File 'lib/rdm/settings.rb', line 49

def read_setting(key, vars: {})
  value = @settings[key.to_s]
  if value.is_a?(Proc)
    value.call
  elsif value.is_a?(String)
    replace_variables(value, except: key, additional_vars: vars)
  else
    value
  end
end