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
31 32 33 |
# File 'lib/icfs/users_fs.rb', line 31 def initialize(path) @path = path.dup end |
Instance Method Details
#flush(urg) ⇒ Boolean
Flush a user/role/group from a cache, if any
48 |
# File 'lib/icfs/users_fs.rb', line 48 def flush(urg); false; end |
#read(urg) ⇒ Hash
Read a user/role/group
54 55 56 57 58 59 60 61 62 63 64 |
# File 'lib/icfs/users_fs.rb', line 54 def read(urg) Items.validate(urg, 'User/Role/Group name'.freeze, Items::FieldUsergrp) json = File.read(_path(urg)) obj = Items.parse(json, 'User/Role/Group'.freeze, Users::ValUser) if obj['name'] != urg raise(Error::Values, 'UsersFs user %s name mismatch'.freeze % fn) end return obj rescue Errno::ENOENT return nil end |
#write(obj) ⇒ Object
Write a user/role/group
70 71 72 73 74 75 76 77 78 79 80 81 82 |
# File 'lib/icfs/users_fs.rb', line 70 def write(obj) Items.validate(obj, 'User/Role/Group'.freeze, Users::ValUser) json = JSON.pretty_generate(obj) # write to temp file tmp = Tempfile.new('_tmp'.freeze, @path, :encoding => 'ascii-8bit'.freeze) tmp.write(json) tmp.close # move FileUtils.mv(tmp.path, _path(obj['name'])) tmp.unlink end |