Class: Swivel::Connection::Config

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

Overview

Encapsulates ~/.swivelrc configuration files. swivelrc files are just yaml text, so you’re encouraged to manually edit.

Load a ~/.swivelrc configuration, creating a default one if it doesn’t exist.

config = Swivel::Config.new

Load configuration from a different file

config.load 'different_configuration.yml'

Save configuration to file

config.save

Instance Attribute Summary collapse

Instance Method Summary collapse

Instance Attribute Details

#configObject

Returns the hash that stores the configuration settings.



660
661
662
# File 'lib/swivel.rb', line 660

def config
  @config
end

Instance Method Details

#load(filename = nil) ⇒ Object

Loads a configuration, which is then accessible through config.



665
666
667
668
669
670
671
672
673
674
675
676
677
# File 'lib/swivel.rb', line 665

def load filename = nil
  filename ||= CONFIG_DIR + '/' + CONFIG_FILE
  @filename = filename
  dir = File.dirname @filename
  FileUtils::mkdir_p dir unless File.exist? dir
  @config =
    unless File.exist? @filename
      DEFAULT_CONFIG.clone
    else
      YAML::load_file @filename
    end
  @config
end

#saveObject

Saves a configuration to the same file from which it was loaded.



680
681
682
683
684
# File 'lib/swivel.rb', line 680

def save
  open @filename, 'w+' do |f|
    YAML::dump @config, f
  end
end