Class: Appydave::Tools::Configuration::Config
- Inherits:
-
Object
- Object
- Appydave::Tools::Configuration::Config
- Extended by:
- KLog::Logging
- Defined in:
- lib/appydave/tools/configuration/config.rb
Overview
Configuration class for handling multiple configurations
Class Attribute Summary collapse
-
.config_path ⇒ Object
Returns the value of attribute config_path.
-
.configurations ⇒ Object
readonly
Returns the value of attribute configurations.
-
.default_block ⇒ Object
readonly
Returns the value of attribute default_block.
Class Method Summary collapse
- .configure ⇒ Object
- .debug ⇒ Object
- .edit ⇒ Object
- .load ⇒ Object
- .method_missing(method_name, *_args) ⇒ Object
-
.print(*keys) ⇒ Object
def print log.kv ‘Configuration Path’, config_path configurations.each_value(&:print) end.
- .register(key, klass) ⇒ Object
- .respond_to_missing?(method_name, include_private = false) ⇒ Boolean
- .save ⇒ Object
- .set_default(&block) ⇒ Object
Class Attribute Details
.config_path ⇒ Object
Returns the value of attribute config_path.
11 12 13 |
# File 'lib/appydave/tools/configuration/config.rb', line 11 def config_path @config_path end |
.configurations ⇒ Object (readonly)
Returns the value of attribute configurations.
12 13 14 |
# File 'lib/appydave/tools/configuration/config.rb', line 12 def configurations @configurations end |
.default_block ⇒ Object (readonly)
Returns the value of attribute default_block.
13 14 15 |
# File 'lib/appydave/tools/configuration/config.rb', line 13 def default_block @default_block end |
Class Method Details
.configure ⇒ Object
15 16 17 18 19 20 21 22 23 24 |
# File 'lib/appydave/tools/configuration/config.rb', line 15 def configure if block_given? yield self elsif default_block default_block.call(self) else raise Appydave::Tools::Error, 'No configuration block provided' end ensure_config_directory end |
.debug ⇒ Object
61 62 63 64 |
# File 'lib/appydave/tools/configuration/config.rb', line 61 def debug log.kv 'Configuration Path', config_path configurations.each_value(&:debug) end |
.edit ⇒ Object
54 55 56 57 58 59 |
# File 'lib/appydave/tools/configuration/config.rb', line 54 def edit ensure_config_directory puts "Edit configuration: #{config_path}" open_vscode = "code --folder-uri '#{config_path}'" # --new-window Open3.capture3(open_vscode) end |
.load ⇒ Object
50 51 52 |
# File 'lib/appydave/tools/configuration/config.rb', line 50 def load configurations.each_value(&:load) end |
.method_missing(method_name, *_args) ⇒ Object
31 32 33 34 35 36 |
# File 'lib/appydave/tools/configuration/config.rb', line 31 def method_missing(method_name, *_args) raise Appydave::Tools::Error, 'Configuration has never been registered' if @configurations.nil? raise Appydave::Tools::Error, "Configuration not available: #{method_name}" unless @configurations.key?(method_name) @configurations[method_name] end |
.print(*keys) ⇒ Object
def print
log.kv 'Configuration Path', config_path
configurations.each_value(&:print)
end
71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 |
# File 'lib/appydave/tools/configuration/config.rb', line 71 def print(*keys) if keys.empty? keys = configurations.keys else keys.map!(&:to_sym) end keys.each do |key| if configurations[key] configurations[key].print else log.error "Configuration not available: #{key}" end end end |
.register(key, klass) ⇒ Object
26 27 28 29 |
# File 'lib/appydave/tools/configuration/config.rb', line 26 def register(key, klass) @configurations ||= {} @configurations[key] = klass.new end |
.respond_to_missing?(method_name, include_private = false) ⇒ Boolean
38 39 40 |
# File 'lib/appydave/tools/configuration/config.rb', line 38 def respond_to_missing?(method_name, include_private = false) @configurations.key?(method_name) || super end |
.save ⇒ Object
42 43 44 |
# File 'lib/appydave/tools/configuration/config.rb', line 42 def save configurations.each_value(&:save) end |
.set_default(&block) ⇒ Object
46 47 48 |
# File 'lib/appydave/tools/configuration/config.rb', line 46 def set_default(&block) @default_block = block end |