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 target file’s name.
-
#group ⇒ Integer
private
The file’s target group id.
-
#mode ⇒ Integer
private
The file’s target mode.
-
#owner ⇒ Integer
private
The file’s target owner 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_group ⇒ Integer
private
The file’s current group’s gid.
-
#current_mode ⇒ Integer
private
The file’s current mode.
-
#current_owner ⇒ 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 owner, group and mode.
-
#uptodate? ⇒ Bool
private
Checks if the file’s owner, group 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.
45 46 47 48 49 50 51 |
# File 'lib/wright/util/file_permissions.rb', line 45 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 target file’s name.
27 28 29 |
# File 'lib/wright/util/file_permissions.rb', line 27 def filename @filename end |
#group ⇒ 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 target group id.
30 31 32 |
# File 'lib/wright/util/file_permissions.rb', line 30 def group @group 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 target mode.
33 34 35 |
# File 'lib/wright/util/file_permissions.rb', line 33 def mode @mode end |
#owner ⇒ 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 target owner uid.
36 37 38 |
# File 'lib/wright/util/file_permissions.rb', line 36 def owner @owner 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.
17 18 19 20 21 22 23 24 |
# File 'lib/wright/util/file_permissions.rb', line 17 def self.create_from_resource(resource, filetype) filepath = ::File.(resource.name) p = Wright::Util::FilePermissions.new(filepath, filetype) p.owner = resource.owner p.group = resource.group p.mode = resource.mode p end |
Instance Method Details
#current_group ⇒ 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.
108 109 110 |
# File 'lib/wright/util/file_permissions.rb', line 108 def current_group 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.
98 99 100 |
# File 'lib/wright/util/file_permissions.rb', line 98 def current_mode Wright::Util::File.file_mode(@filename) end |
#current_owner ⇒ 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.
103 104 105 |
# File 'lib/wright/util/file_permissions.rb', line 103 def current_owner 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 owner, group and mode.
92 93 94 95 |
# File 'lib/wright/util/file_permissions.rb', line 92 def update ::File.chmod(@mode, @filename) if @mode ::File.chown(@owner, @group, @filename) if @owner || @group 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 owner, group and mode are up-to-date
81 82 83 84 85 86 87 |
# File 'lib/wright/util/file_permissions.rb', line 81 def uptodate? if ::File.exist?(@filename) owner_uptodate? && group_uptodate? && mode_uptodate? else false end end |