Class: Wright::Util::FileOwner Private

Inherits:
Object
  • Object
show all
Defined in:
lib/wright/util/file_owner.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 support user:group notation in file owner strings.

Instance Attribute Summary collapse

Instance Method Summary collapse

Instance Attribute Details

#groupString, 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 group's name or gid.

Returns:

  • (String, Integer)

    the group's name or gid


10
11
12
# File 'lib/wright/util/file_owner.rb', line 10

def group
  @group
end

#userString, 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 user's name or uid.

Returns:

  • (String, Integer)

    the user's name or uid


7
8
9
# File 'lib/wright/util/file_owner.rb', line 7

def user
  @user
end

Instance Method Details

#split_user_and_group(user_and_group) ⇒ Object (private)

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.


47
48
49
50
51
52
53
54
55
56
57
58
# File 'lib/wright/util/file_owner.rb', line 47

def split_user_and_group(user_and_group)
  user = user_and_group
  group = nil
  return [user, group] unless user_and_group.is_a?(String)

  if user_and_group.count(':') > 1
    fail ArgumentError, "Invalid owner: '#{user_and_group}'"
  end

  user, group = user_and_group.split(':')
  [user, group]
end

#user_and_group=(user_and_group) ⇒ 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.

Sets user and group simultaneously.

Examples:

owner = FileOwner.new

owner.user_and_group = 'user:group'
owner.user# => "user"

owner.group# => "group"


owner.user_and_group = 'newuser'
owner.user# => "newuser"

owner.group# => "group"


owner.user_and_group = 42
owner.user# => 42

Parameters:

  • user_and_group (String, Integer)

    a user in user:group notation or a uid

Raises:

  • (ArgumentError)

    if the owner string contains more than one colon


39
40
41
42
43
# File 'lib/wright/util/file_owner.rb', line 39

def user_and_group=(user_and_group)
  user, group = split_user_and_group(user_and_group)
  @user = user
  @group = group if group
end