Class: MrMurano::Config::ConfigFile

Inherits:
Struct
  • Object
show all
Defined in:
lib/MrMurano/Config.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

Instance Attribute Details

#cfgObject

Returns the value of attribute cfg

Returns:

  • (Object)

    the current value of cfg



33
34
35
# File 'lib/MrMurano/Config.rb', line 33

def cfg
  @cfg
end

#dataObject

Returns the value of attribute data

Returns:

  • (Object)

    the current value of data



33
34
35
# File 'lib/MrMurano/Config.rb', line 33

def data
  @data
end

#kindObject

Returns the value of attribute kind

Returns:

  • (Object)

    the current value of kind



33
34
35
# File 'lib/MrMurano/Config.rb', line 33

def kind
  @kind
end

#pathObject

Returns the value of attribute path

Returns:

  • (Object)

    the current value of path



33
34
35
# File 'lib/MrMurano/Config.rb', line 33

def path
  @path
end

Instance Method Details

#loadObject



34
35
36
37
38
39
40
41
42
43
# File 'lib/MrMurano/Config.rb', line 34

def load
  return if kind == :internal
  return if kind == :defaults
  # DEVs: Uncomment if you're trying to figure where settings are coming from.
  #   See also: murano config --locations
  #puts "Loading config at: #{path}"
  self[:path] = Pathname.new(path) unless path.is_a? Pathname
  self[:data] = IniFile.new(filename: path.to_s) if self[:data].nil?
  self[:data].restore
end

#writeObject



45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
# File 'lib/MrMurano/Config.rb', line 45

def write
  return if kind == :internal
  return if kind == :defaults
  if !self[:cfg].nil? && self[:cfg]['tool.dry']
    # $cfg.nil? when run from spec tests that don't load it with:
    #   include_context "CI_CMD"
    warning('--dry: Not writing config file')
    return
  end
  self[:path] = Pathname.new(path) unless path.is_a?(Pathname)
  # Ensure path to the file exists.
  unless path.dirname.exist?
    path.dirname.mkpath
    MrMurano::Config.fix_modes(path.dirname)
  end
  self[:data] = IniFile.new(filename: path.to_s) if self[:data].nil?
  self[:data].save
  path.chmod(0o600)
  nil
end