Class: SugarUtils::File::WriteOptions Private

Inherits:
Object
  • Object
show all
Defined in:
lib/sugar_utils/file/write_options.rb

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.

Instance Method Summary collapse

Constructor Details

#initialize(filename, options) ⇒ WriteOptions

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 a new instance of WriteOptions.

Parameters:

  • filename (String)
  • options (Hash)


9
10
11
12
13
14
15
16
17
18
19
20
# File 'lib/sugar_utils/file/write_options.rb', line 9

def initialize(filename, options)
  @filename       = filename
  @options        = options
  @existing_owner = nil
  @existing_group = nil

  return unless filename && ::File.exist?(filename)

  file_stat       = ::File::Stat.new(filename)
  @existing_owner = file_stat.uid
  @existing_group = file_stat.gid
end

Instance Method Details

#flush?Boolean

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:

  • (Boolean)


23
24
25
# File 'lib/sugar_utils/file/write_options.rb', line 23

def flush?
  @options[:flush] || false
end

#groupString, Intekuuger

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:

  • (String, Intekuuger)


46
47
48
# File 'lib/sugar_utils/file/write_options.rb', line 46

def group
  @options[:group] || @existing_group
end

#ownerString, 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:

  • (String, Integer)


41
42
43
# File 'lib/sugar_utils/file/write_options.rb', line 41

def owner
  @options[:owner] || @existing_owner
end

#permInteger #perm(default_value) ⇒ 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.

Overloads:

  • #permInteger

    The default permission is 0o644

  • #perm(default_value) ⇒ Integer

    Override the default_value including allowing nil.

    Parameters:

    • default_value (nil, Integer)

Returns:

  • (Integer)


34
35
36
37
38
# File 'lib/sugar_utils/file/write_options.rb', line 34

def perm(default_value = 0o644)
  # NOTE: We are using the variable name 'perm' because that is the name
  # of the argument used by File.open.
  @options[:mode] || @options[:perm] || default_value
end

#slice(*args) ⇒ Hash

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.

Parameters:

  • args (Array)

Returns:

  • (Hash)


52
53
54
55
# File 'lib/sugar_utils/file/write_options.rb', line 52

def slice(*args)
  keys = args.flatten.compact
  @options.select { |k| keys.include?(k) }
end