Class: Arver::LocalConfig

Inherits:
Object
  • Object
show all
Includes:
Singleton
Defined in:
lib/arver/local_config.rb

Instance Method Summary collapse

Instance Method Details

#configObject



9
10
11
# File 'lib/arver/local_config.rb', line 9

def config
  @config ||= load_file( path )
end

#config_dirObject



34
35
36
# File 'lib/arver/local_config.rb', line 34

def config_dir
  File.expand_path(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

#defaultObject



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

#pathObject



5
6
7
# File 'lib/arver/local_config.rb', line 5

def path
  File.expand_path("~/.arver")
end

#saveObject



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

#usernameObject



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