Class: Carioca::Services::Config::ConfigFile

Inherits:
Object
  • Object
show all
Includes:
Constants
Defined in:
lib/carioca/services/config.rb

Overview

config file manager

Constant Summary

Constants included from Constants

Constants::BUILTINS, Constants::DEFAULT_COLORS_STATUS, Constants::DEFAULT_CONFIG_FILE, Constants::DEFAULT_CONFIG_ROOT, Constants::DEFAULT_DEBUGGER_TRACER, Constants::DEFAULT_EMOJI_STATUS, Constants::DEFAULT_ENVIRONMENT, Constants::DEFAULT_ENVIRONMENTS_LIST, Constants::DEFAULT_LOCALE, Constants::DEFAULT_LOG_LEVEL, Constants::DEFAULT_MASTER_KEY_FILE, Constants::DEFAULT_OUTPUT_MODE, Constants::DEFAULT_OUTPUT_TARGET, Constants::DEFAULT_REGISTRY_FILE, Constants::DEFAULT_SECURE_STORE_FILE, Constants::DEFAULT_USER_CONFIG_PATH, Constants::SERVICES_FULL_LIST_SPECS, Constants::SERVICES_MANDATORY_SPECS, Constants::SERVICES_SPECS_DETAIL

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(filename:) ⇒ ConfigFile

Returns a new instance of ConfigFile.



34
35
36
37
38
39
# File 'lib/carioca/services/config.rb', line 34

def initialize(filename:)
  @filename = filename
  @data = {}
  @error = ''
  open
end

Instance Attribute Details

#dataObject

Returns the value of attribute data.



31
32
33
# File 'lib/carioca/services/config.rb', line 31

def data
  @data
end

#errorObject (readonly)

Returns the value of attribute error.



32
33
34
# File 'lib/carioca/services/config.rb', line 32

def error
  @error
end

#filenameObject

Returns the value of attribute filename.



31
32
33
# File 'lib/carioca/services/config.rb', line 31

def filename
  @filename
end

Instance Method Details

#create!(force: false) ⇒ Object



45
46
47
48
49
# File 'lib/carioca/services/config.rb', line 45

def create!(force: false)
  write_ok = true
  write_ok = force if File.exist? @filename
  File.write(@filename, @data.to_yaml) if write_ok
end

#error?Boolean

Returns:

  • (Boolean)


41
42
43
# File 'lib/carioca/services/config.rb', line 41

def error?
  !@error.empty?
end

#openObject



51
52
53
54
55
56
57
58
59
60
61
# File 'lib/carioca/services/config.rb', line 51

def open
  if File.exist?(@filename)
    begin
      @data = YAML.load_file(@filename)
    rescue StandardError => e
      @error = e.message
      @data = {}
    end
  end
  prepare!
end