Class: Arver::LocalConfig
- Inherits:
-
Object
- Object
- Arver::LocalConfig
- Includes:
- Singleton
- Defined in:
- lib/arver/local_config.rb
Instance Method Summary collapse
- #config ⇒ Object
- #config_dir ⇒ Object
- #config_dir=(directory) ⇒ Object
- #default ⇒ Object
- #load_file(filename) ⇒ Object
- #path ⇒ Object
- #save ⇒ Object
- #username ⇒ Object
- #username=(username) ⇒ Object
Instance Method Details
#config ⇒ Object
9 10 11 |
# File 'lib/arver/local_config.rb', line 9 def config @config ||= load_file( path ) end |
#config_dir ⇒ Object
34 35 36 |
# File 'lib/arver/local_config.rb', line 34 def config_dir File.(self.config['config_dir']) end |
#config_dir=(directory) ⇒ Object
38 39 40 |
# File 'lib/arver/local_config.rb', line 38 def config_dir=(directory) self.config['config_dir'] = directory end |
#default ⇒ Object
13 14 15 |
# File 'lib/arver/local_config.rb', line 13 def default { 'config_dir' => "~/.arverdata", 'username' => "" } end |
#load_file(filename) ⇒ Object
17 18 19 20 |
# File 'lib/arver/local_config.rb', line 17 def load_file(filename) content = YAML.load(File.read(filename)) if File.exists?(filename) self.default.merge(content||{}) end |
#path ⇒ Object
5 6 7 |
# File 'lib/arver/local_config.rb', line 5 def path File.("~/.arver") end |
#save ⇒ Object
22 23 24 |
# File 'lib/arver/local_config.rb', line 22 def save File.open( path, 'w' ) { |f| f.write(self.config.to_yaml) } end |
#username ⇒ Object
26 27 28 |
# File 'lib/arver/local_config.rb', line 26 def username self.config['username'] end |
#username=(username) ⇒ Object
30 31 32 |
# File 'lib/arver/local_config.rb', line 30 def username= username self.config['username'] = username end |