Class: Wright::Util::FilePermissions Private

Inherits:
Object
  • Object
show all
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

Class Method Summary collapse

Instance Method Summary collapse

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.

Parameters:

  • filename (String)

    the file’s name

  • filetype (Symbol)

    the file’s type (:file or :directory)



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

#filenameString

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.

Returns:

  • (String)

    the target file’s name



27
28
29
# File 'lib/wright/util/file_permissions.rb', line 27

def filename
  @filename
end

#groupInteger

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.

Returns:

  • (Integer)

    the file’s target group id



30
31
32
# File 'lib/wright/util/file_permissions.rb', line 30

def group
  @group
end

#modeInteger

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.

Returns:

  • (Integer)

    the file’s target mode



33
34
35
# File 'lib/wright/util/file_permissions.rb', line 33

def mode
  @mode
end

#ownerInteger

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.

Returns:

  • (Integer)

    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.

Parameters:

Returns:



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.expand_path(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_groupInteger

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.

Returns:

  • (Integer)

    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_modeInteger

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.

Returns:

  • (Integer)

    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_ownerInteger

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.

Returns:

  • (Integer)

    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

#updatevoid

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

Returns:

  • (Bool)

    true if the file is up to date, false otherwise



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