Class: Wright::Util::FilePermissions Private
- Inherits:
-
Object
- Object
- Wright::Util::FilePermissions
- Defined in:
- lib/wright/util/file_permissions.rb
Overview
This class is part of a private API. You should avoid using this class if possible, as it may be removed or be changed in the future.
Helper class to manage file permissions.
Instance Attribute Summary collapse
-
#filename ⇒ String
private
The filename.
-
#gid ⇒ Integer
private
The file’s intended gid.
-
#mode ⇒ Integer
private
The file’s intended mode.
-
#uid ⇒ Integer
private
The file’s intended uid.
Class Method Summary collapse
-
.create_from_resource(resource, filetype) ⇒ Wright::Util::FilePermissions
private
Creates a FilePermissions object from a Resource::File or Resource::Directory.
Instance Method Summary collapse
-
#current_gid ⇒ Integer
private
The file’s current group’s gid.
-
#current_mode ⇒ Integer
private
The file’s current mode.
-
#current_uid ⇒ Integer
private
The file’s current owner’s uid.
-
#initialize(filename, filetype) ⇒ FilePermissions
constructor
private
Initializes a FilePermissions object.
-
#update ⇒ void
private
Updates the file’s uid, gid and mode.
-
#uptodate? ⇒ Bool
private
Checks if the file’s uid, gid and mode are up-to-date.
Constructor Details
#initialize(filename, filetype) ⇒ FilePermissions
This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.
Initializes a FilePermissions object.
46 47 48 49 50 51 52 |
# File 'lib/wright/util/file_permissions.rb', line 46 def initialize(filename, filetype) unless VALID_FILETYPES.include?(filetype) fail ArgumentError, "Invalid filetype '#{filetype}'" end @filename = filename @filetype = filetype end |
Instance Attribute Details
#filename ⇒ String
This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.
Returns the filename.
28 29 30 |
# File 'lib/wright/util/file_permissions.rb', line 28 def filename @filename end |
#gid ⇒ Integer
This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.
Returns the file’s intended gid.
34 35 36 |
# File 'lib/wright/util/file_permissions.rb', line 34 def gid @gid end |
#mode ⇒ Integer
This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.
Returns the file’s intended mode.
37 38 39 |
# File 'lib/wright/util/file_permissions.rb', line 37 def mode @mode end |
#uid ⇒ Integer
This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.
Returns the file’s intended uid.
31 32 33 |
# File 'lib/wright/util/file_permissions.rb', line 31 def uid @uid end |
Class Method Details
.create_from_resource(resource, filetype) ⇒ Wright::Util::FilePermissions
This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.
Creates a FilePermissions object from a Resource::File or Resource::Directory.
18 19 20 21 22 23 24 25 |
# File 'lib/wright/util/file_permissions.rb', line 18 def self.create_from_resource(resource, filetype) filepath = ::File.(resource.name) p = Wright::Util::FilePermissions.new(filepath, filetype) p.uid = Wright::Util::User.user_to_uid(resource.owner) p.gid = Wright::Util::User.group_to_gid(resource.group) p.mode = resource.mode p end |
Instance Method Details
#current_gid ⇒ Integer
This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.
Returns the file’s current group’s gid.
99 100 101 |
# File 'lib/wright/util/file_permissions.rb', line 99 def current_gid Wright::Util::File.file_group(filename) end |
#current_mode ⇒ Integer
This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.
Returns the file’s current mode.
89 90 91 |
# File 'lib/wright/util/file_permissions.rb', line 89 def current_mode Wright::Util::File.file_mode(filename) end |
#current_uid ⇒ Integer
This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.
Returns the file’s current owner’s uid.
94 95 96 |
# File 'lib/wright/util/file_permissions.rb', line 94 def current_uid Wright::Util::File.file_owner(filename) end |
#update ⇒ void
This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.
This method returns an undefined value.
Updates the file’s uid, gid and mode.
83 84 85 86 |
# File 'lib/wright/util/file_permissions.rb', line 83 def update ::File.chmod(mode, filename) if mode ::File.chown(uid, gid, filename) if uid || gid end |
#uptodate? ⇒ Bool
This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.
Checks if the file’s uid, gid and mode are up-to-date
72 73 74 75 76 77 78 |
# File 'lib/wright/util/file_permissions.rb', line 72 def uptodate? if ::File.exist?(filename) uid_uptodate? && gid_uptodate? && mode_uptodate? else false end end |