Class: Prometheus::Config
- Inherits:
-
Settingslogic
- Object
- Settingslogic
- Prometheus::Config
- Defined in:
- lib/prometheus/extra/config/lib/config.rb
Class Attribute Summary collapse
-
.configurables ⇒ Object
Returns the value of attribute configurables.
Class Method Summary collapse
-
.ask(shell, key, opts = {}) ⇒ Object
Options for hash: :label => ‘Some Configurable’ :default => ‘default value’.
- .configure(shell = Thor::Shell::Basic.new) ⇒ Object
-
.missing_configurables ⇒ Object
Return an array of configurable keys that are not found in the user’s config.
- .save(shell = Thor::Shell::Basic.new) ⇒ Object
Class Attribute Details
.configurables ⇒ Object
Returns the value of attribute configurables.
5 6 7 |
# File 'lib/prometheus/extra/config/lib/config.rb', line 5 def configurables @configurables end |
Class Method Details
.ask(shell, key, opts = {}) ⇒ Object
Options for hash:
:label => 'Some Configurable'
:default => 'default value'
10 11 12 13 14 15 |
# File 'lib/prometheus/extra/config/lib/config.rb', line 10 def ask(shell, key, opts={}) default = Config[key] || opts[:default] opts[:label] ||= key answer = shell.ask(opts[:label] + " [#{default}]>") Config[key] = (answer.size > 0) ? answer : default end |
.configure(shell = Thor::Shell::Basic.new) ⇒ Object
29 30 31 32 33 34 35 36 37 38 39 40 41 42 |
# File 'lib/prometheus/extra/config/lib/config.rb', line 29 def configure(shell = Thor::Shell::Basic.new) if @configurables @configurables.each do |plugin, configurables| shell.say plugin, :blue configurables.each do |c| Config.ask(shell, c[:key], :label => " #{c[:label]}", :default => c[:default]) end end Config.save else shell.say 'No plugins require configuration' end end |
.missing_configurables ⇒ Object
Return an array of configurable keys that are not found in the user’s config
45 46 47 48 49 |
# File 'lib/prometheus/extra/config/lib/config.rb', line 45 def missing_configurables return [] unless @configurables configurable_keys = @configurables.map { |k, v| v.map { |i| i[:key].to_s } }.flatten configurable_keys.reject { |k| Config.keys.include? k } end |
.save(shell = Thor::Shell::Basic.new) ⇒ Object
17 18 19 20 21 22 23 24 25 26 27 |
# File 'lib/prometheus/extra/config/lib/config.rb', line 17 def save(shell = Thor::Shell::Basic.new) out = {}.update(self) begin File.open(CONFIG_PATH, 'w') { |f| f << out.to_yaml } puts shell.say 'Configuration saved!', :blue puts rescue Exception => e shell.say e, :red end end |