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:

  • options (Hash)


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

def initialize(filename, options)
  @filename = filename
  @options  = options

  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)


21
22
23
# File 'lib/sugar_utils/file/write_options.rb', line 21

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)


44
45
46
# File 'lib/sugar_utils/file/write_options.rb', line 44

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)


39
40
41
# File 'lib/sugar_utils/file/write_options.rb', line 39

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)


32
33
34
35
36
# File 'lib/sugar_utils/file/write_options.rb', line 32

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:

  • keys (Array)

Returns:

  • (Hash)


50
51
52
53
# File 'lib/sugar_utils/file/write_options.rb', line 50

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