Class: Wralph::Config
- Inherits:
-
Object
- Object
- Wralph::Config
- Defined in:
- lib/wralph/config.rb
Class Method Summary collapse
- .load ⇒ Object
- .method_missing(method_name, *args, &block) ⇒ Object
- .reload ⇒ Object
- .reset ⇒ Object
- .respond_to_missing?(method_name, include_private = false) ⇒ Boolean
Class Method Details
.load ⇒ Object
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.}" 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 |
.reload ⇒ Object
40 41 42 43 |
# File 'lib/wralph/config.rb', line 40 def reload @config = nil load end |
.reset ⇒ Object
45 46 47 |
# File 'lib/wralph/config.rb', line 45 def reset @config = nil end |
.respond_to_missing?(method_name, include_private = false) ⇒ 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 |