Sha256: f9767717ea663b8c3182ddf0c852bc8bd270b45b80f536d114b8752f8fce79c5
Contents?: true
Size: 1.67 KB
Versions: 1
Compression:
Stored size: 1.67 KB
Contents
module Wright module Util # Helper class to support +user:group+ notation in file owner # strings. class FileOwner # @return [String, Integer] the user's name or uid attr_accessor :user # @return [String, Integer] the group's name or gid attr_accessor :group def initialize(user_and_group = nil, group = nil) self.user_and_group = user_and_group self.group = group if group end # Sets user and group simultaneously. # # @param user_and_group [String, Integer] a user in +user:group+ # notation or a uid # # @example # 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 # # @return [void] # @raise [ArgumentError] if the owner string contains more than # one colon def user_and_group=(user_and_group) user, group = split_user_and_group(user_and_group) self.user = user self.group = group if group end private 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 end end end
Version data entries
1 entries across 1 versions & 1 rubygems
Version | Path |
---|---|
wright-0.5.0 | lib/wright/util/file_owner.rb |