Class: Arver::Config

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

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initializeConfig

Returns a new instance of Config.



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

def initialize
  @tree = Arver::Tree.new
  @users = {}
end

Instance Attribute Details

#treeObject

Returns the value of attribute tree.



4
5
6
# File 'lib/arver/config.rb', line 4

def tree
  @tree
end

#usersObject

Returns the value of attribute users.



4
5
6
# File 'lib/arver/config.rb', line 4

def users
  @users
end

Instance Method Details

#==(other) ⇒ Object



49
50
51
52
# File 'lib/arver/config.rb', line 49

def == other
  return tree == other.tree && users == other.users if other.is_a?(Arver::Config)
  false
end

#exists?(user) ⇒ Boolean

Returns:

  • (Boolean)


37
38
39
# File 'lib/arver/config.rb', line 37

def exists?( user )
  ! users[user].nil?
end

#gpg_key(user) ⇒ Object



41
42
43
# File 'lib/arver/config.rb', line 41

def gpg_key user
  users[user]['gpg'] if exists?(user)
end

#loadObject



17
18
19
20
21
22
23
24
25
# File 'lib/arver/config.rb', line 17

def load
  if( ! File.exists?( path ) )
    Arver::Log.error( "config-dir "+path+" does not exist" )
    exit
  end
  @users= ( load_file( File.join(path,'users') ) )
  tree.clear
  tree.from_hash( load_file( File.join(path,'disks') ) )
end

#load_file(filename) ⇒ Object



27
28
29
# File 'lib/arver/config.rb', line 27

def load_file( filename )
  YAML.load( File.read(filename) ) if File.exists?( filename )
end

#pathObject



13
14
15
# File 'lib/arver/config.rb', line 13

def path
  File.expand_path( Arver::LocalConfig.instance.config_dir )
end

#saveObject



31
32
33
34
35
# File 'lib/arver/config.rb', line 31

def save
  FileUtils.mkdir_p( path ) unless File.exists?( path )
  File.open( File.join(path,'users'), 'w' ) { |f| f.write( users.to_yaml ) }
  File.open( File.join(path,'disks'), 'w' ) { |f| f.write( tree.to_yaml ) }
end

#slot(user) ⇒ Object



45
46
47
# File 'lib/arver/config.rb', line 45

def slot user
  users[user]['slot'] if exists?(user)
end