Class: ICFS::UsersFs
Overview
Implements Users from a file system
Constant Summary
Constants inherited from Users
Instance Method Summary collapse
-
#flush(urg) ⇒ Boolean
Flush a user/role/group from a cache, if any.
-
#initialize(path) ⇒ UsersFs
constructor
New instance.
-
#read(urg) ⇒ Hash
Read a user/role/group.
-
#write(obj) ⇒ Object
Write a user/role/group.
Constructor Details
#initialize(path) ⇒ UsersFs
New instance
33 34 35 |
# File 'lib/icfs/users_fs.rb', line 33 def initialize(path) @path = path.dup end |
Instance Method Details
#flush(urg) ⇒ Boolean
Flush a user/role/group from a cache, if any
50 |
# File 'lib/icfs/users_fs.rb', line 50 def flush(urg); false; end |
#read(urg) ⇒ Hash
Read a user/role/group
56 57 58 59 60 61 62 63 64 65 66 |
# File 'lib/icfs/users_fs.rb', line 56 def read(urg) Items.validate(urg, 'User/Role/Group name', Items::FieldUsergrp) json = File.read(_path(urg)) obj = Items.parse(json, 'User/Role/Group', Users::ValUser) if obj['name'] != urg raise(Error::Values, 'UsersFs user %s name mismatch' % fn) end return obj rescue Errno::ENOENT return nil end |
#write(obj) ⇒ Object
Write a user/role/group
72 73 74 75 76 77 78 79 80 81 82 83 84 |
# File 'lib/icfs/users_fs.rb', line 72 def write(obj) Items.validate(obj, 'User/Role/Group', Users::ValUser) json = JSON.pretty_generate(obj) # write to temp file tmp = Tempfile.new('_tmp', @path, :encoding => 'ascii-8bit') tmp.write(json) tmp.close # move FileUtils.mv(tmp.path, _path(obj['name'])) tmp.unlink end |