class SugarUtils::File::WriteOptions

@api private

Public Class Methods

new(filename, options) click to toggle source

@parma filename [String] @param options [Hash]

# 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

Public Instance Methods

flush?() click to toggle source

@return [Boolean]

# File lib/sugar_utils/file/write_options.rb, line 21
def flush?
  @options[:flush] || false
end
group() click to toggle source

@return [String, Intekuuger]

# File lib/sugar_utils/file/write_options.rb, line 44
def group
  @options[:group] || @existing_group
end
owner() click to toggle source

@return [String, Integer]

# File lib/sugar_utils/file/write_options.rb, line 39
def owner
  @options[:owner] || @existing_owner
end
perm(default_value = 0o644) click to toggle source

@overload perm

The default permission is 0o644

@overload perm(default_value)

@param default_value [nil, Integer]
Override the default_value including allowing nil.

@return [Integer]

# 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) click to toggle source

@param keys [Array] @return [Hash]

# File lib/sugar_utils/file/write_options.rb, line 50
def slice(*args)
  keys = args.flatten.compact
  @options.select { |k| keys.include?(k) }
end