Class: Arver::Config
Instance Attribute Summary collapse
-
#tree ⇒ Object
Returns the value of attribute tree.
-
#users ⇒ Object
Returns the value of attribute users.
Instance Method Summary collapse
- #==(other) ⇒ Object
- #exists?(user) ⇒ Boolean
- #gpg_key(user) ⇒ Object
-
#initialize ⇒ Config
constructor
A new instance of Config.
- #load ⇒ Object
- #load_file(filename) ⇒ Object
- #path ⇒ Object
- #save ⇒ Object
- #slot(user) ⇒ Object
Constructor Details
Instance Attribute Details
#tree ⇒ Object
Returns the value of attribute tree.
4 5 6 |
# File 'lib/arver/config.rb', line 4 def tree @tree end |
#users ⇒ Object
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
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 |
#load ⇒ Object
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 |
#path ⇒ Object
13 14 15 |
# File 'lib/arver/config.rb', line 13 def path File.( Arver::LocalConfig.instance.config_dir ) end |
#save ⇒ Object
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 |