Class: Wralph::Config

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

Class Method Summary collapse

Class Method Details

.loadObject



11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
# File 'lib/wralph/config.rb', line 11

def load
  @config ||= begin
    config_file = Interfaces::Repo.config_file
    unless File.exist?(config_file)
      Interfaces::Print.warning "Config file #{config_file} not found, using default settings"
      return default_config
    end

    begin
      yaml_data = YAML.load_file(config_file)
      yaml_data = {} if yaml_data.nil? || yaml_data == false
      # Merge with defaults to ensure all keys exist
      merged_data = default_hash.merge(yaml_data) do |_key, default_val, yaml_val|
        if default_val.is_a?(Hash) && yaml_val.is_a?(Hash)
          default_val.merge(yaml_val)
        else
          yaml_val
        end
      end
      deep_struct(merged_data)
    rescue Psych::SyntaxError => e
      Interfaces::Print.warning "Failed to parse #{config_file}: #{e.message}"
      default_config
    end
  end

  @config
end

.method_missing(method_name, *args, &block) ⇒ Object



49
50
51
52
53
54
55
# File 'lib/wralph/config.rb', line 49

def method_missing(method_name, *args, &block)
  if load.respond_to?(method_name)
    load.public_send(method_name, *args, &block)
  else
    super
  end
end

.reloadObject



40
41
42
43
# File 'lib/wralph/config.rb', line 40

def reload
  @config = nil
  load
end

.resetObject



45
46
47
# File 'lib/wralph/config.rb', line 45

def reset
  @config = nil
end

.respond_to_missing?(method_name, include_private = false) ⇒ Boolean

Returns:

  • (Boolean)


57
58
59
# File 'lib/wralph/config.rb', line 57

def respond_to_missing?(method_name, include_private = false)
  load.respond_to?(method_name, include_private) || super
end