Module: Befog::Commands::Mixins::Configurable
- Defined in:
- lib/befog/commands/mixins/configurable.rb
Class Method Summary collapse
Instance Method Summary collapse
- #_configuration ⇒ Object
- #configuration ⇒ Object
- #configuration_name ⇒ Object
- #configuration_path ⇒ Object
- #save ⇒ Object
Class Method Details
.included(target) ⇒ Object
6 7 8 9 10 11 12 13 14 15 16 17 18 19 |
# File 'lib/befog/commands/mixins/configurable.rb', line 6 def self.included(target) target.module_eval do option :path, :short => :p, :default => "~/.befog", :description => "Path to the configuration file" option :name, :short => :n, :default => "default", :description => "The name of this configuration" end end |
Instance Method Details
#_configuration ⇒ Object
25 26 27 |
# File 'lib/befog/commands/mixins/configurable.rb', line 25 def _configuration @configuration ||= (YAML.load_file(configuration_path) rescue {}) end |
#configuration ⇒ Object
29 30 31 |
# File 'lib/befog/commands/mixins/configurable.rb', line 29 def configuration _configuration[configuration_name] ||= {} end |
#configuration_name ⇒ Object
33 34 35 |
# File 'lib/befog/commands/mixins/configurable.rb', line 33 def configuration_name [:name] end |
#configuration_path ⇒ Object
21 22 23 |
# File 'lib/befog/commands/mixins/configurable.rb', line 21 def configuration_path @configuration_path = File.([:path]) end |
#save ⇒ Object
37 38 39 40 41 42 |
# File 'lib/befog/commands/mixins/configurable.rb', line 37 def save # Make sure we load the configuration before opening the file for writing configuration_for_writing = _configuration File.open(configuration_path,"w") { |f| YAML.dump(configuration_for_writing,f) } $stdout.puts "Configuration written to: #{configuration_path}" end |