class FlatKit::Output::File

Attributes

path[R]

Public Class Methods

handles?(obj) click to toggle source
# File lib/flat_kit/output/file.rb, line 8
def self.handles?(obj)
  return true if obj.instance_of?(Pathname)
  return false unless obj.instance_of?(String)

  # incase these get loaded in different orders
  return false if ::FlatKit::Output::IO.is_stdout?(obj)
  return false if ::FlatKit::Output::IO.is_stderr?(obj)

  return true
end
new(obj) click to toggle source
# File lib/flat_kit/output/file.rb, line 19
def initialize(obj)
  @path = Pathname.new(obj)
  path.dirname.mkpath
  @io = open_output(path)
end

Public Instance Methods

close() click to toggle source
# File lib/flat_kit/output/file.rb, line 29
def close
  @io.close
end
io() click to toggle source

internal api method for testing purposes

# File lib/flat_kit/output/file.rb, line 34
def io
  @io
end
name() click to toggle source
# File lib/flat_kit/output/file.rb, line 25
def name
  path.to_s
end

Private Instance Methods

open_output(path) click to toggle source

open the opropriate otuput type depending on the destination file name

TODO: add in bzip

# File lib/flat_kit/output/file.rb, line 43
def open_output(path)
  case path.extname
  when ".gz"
    Zlib::GzipWriter.open(path.to_s)
  # when ".gz"
  #   ::IO.popen("gzip -c > #{path}", "w")
  else
    path.open("wb")
  end
end