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
- #user_at(slot) ⇒ 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
61 62 63 64 |
# File 'lib/arver/config.rb', line 61 def == other return tree == other.tree && users == other.users if other.is_a?(Arver::Config) false end |
#exists?(user) ⇒ Boolean
42 43 44 |
# File 'lib/arver/config.rb', line 42 def exists?( user ) !users[user].nil? end |
#gpg_key(user) ⇒ Object
46 47 48 |
# File 'lib/arver/config.rb', line 46 def gpg_key user users[user]['gpg'] if exists?(user) end |
#load ⇒ Object
17 18 19 20 21 22 23 24 25 26 |
# File 'lib/arver/config.rb', line 17 def load if !File.directory?(path) Arver::Log.error("config "+path+" does not exist") exit 1 end @users = load_file(File.join(path,'users')) || {} tree.clear tree.from_hash(load_file(File.join(path,'disks'))) end |
#load_file(filename) ⇒ Object
28 29 30 31 32 33 34 |
# File 'lib/arver/config.rb', line 28 def load_file( filename ) if !File.exist?(filename) Arver::Log.error("missing config #{filename}") exit 1 end YAML.load(File.read(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
36 37 38 39 40 |
# File 'lib/arver/config.rb', line 36 def save FileUtils.mkdir_p( path ) unless File.exist?( 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
50 51 52 |
# File 'lib/arver/config.rb', line 50 def slot user users[user]['slot'] if exists?(user) end |
#user_at(slot) ⇒ Object
54 55 56 57 58 59 |
# File 'lib/arver/config.rb', line 54 def user_at(slot) users.each do |name, conf| return name if slot == conf['slot'] end 'unknown' end |