Class: Ruborg::Config

Inherits:
Object
  • Object
show all
Defined in:
lib/ruborg/config.rb

Overview

Configuration management for ruborg Only supports multi-repository format

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(config_path, validate_types: true) ⇒ Config

Returns a new instance of Config.



12
13
14
15
16
17
18
# File 'lib/ruborg/config.rb', line 12

def initialize(config_path, validate_types: true)
  @config_path = config_path
  @validate_types = validate_types
  load_config
  validate_format
  validate_schema if @validate_types
end

Instance Attribute Details

#dataObject (readonly)

Returns the value of attribute data.



10
11
12
# File 'lib/ruborg/config.rb', line 10

def data
  @data
end

Instance Method Details

#get_repository(name) ⇒ Object



34
35
36
# File 'lib/ruborg/config.rb', line 34

def get_repository(name)
  repositories.find { |r| r["name"] == name }
end

#global_settingsObject



42
43
44
45
# File 'lib/ruborg/config.rb', line 42

def global_settings
  @data.slice("passbolt", "compression", "encryption", "auto_init", "borg_options", "log_file", "retention",
              "auto_prune", "hostname", "allow_remove_source", "borg_path", "skip_hash_check", "lock_wait")
end

#load_configObject



20
21
22
23
24
25
26
27
28
# File 'lib/ruborg/config.rb', line 20

def load_config
  raise ConfigError, "Configuration file not found: #{@config_path}" unless File.exist?(@config_path)

  @data = YAML.safe_load_file(@config_path, permitted_classes: [Symbol], aliases: true)
rescue Psych::SyntaxError => e
  raise ConfigError, "Invalid YAML syntax: #{e.message}"
rescue Psych::DisallowedClass => e
  raise ConfigError, "Invalid YAML content: #{e.message}"
end

#repositoriesObject



30
31
32
# File 'lib/ruborg/config.rb', line 30

def repositories
  @data["repositories"] || []
end

#repository_namesObject



38
39
40
# File 'lib/ruborg/config.rb', line 38

def repository_names
  repositories.map { |r| r["name"] }
end