class FlatKit::Output::IO

Constants

STDERRS
STDOUTS

Attributes

count[R]

Public Class Methods

handles?(obj) click to toggle source
# File lib/flat_kit/output/io.rb, line 9
def self.handles?(obj)
  return true if is_stderr?(obj)
  return true if is_stdout?(obj)
  return true if [ ::File, ::StringIO, ::IO ].any? { |klass| obj.kind_of?(klass) }
  return false
end
is_stderr?(obj) click to toggle source
# File lib/flat_kit/output/io.rb, line 16
def self.is_stderr?(obj)
  case obj
  when String
    return true if STDERRS.include?(obj)
  when ::IO
    return true if obj == ::STDERR
  end
  return false
end
is_stdout?(obj) click to toggle source
# File lib/flat_kit/output/io.rb, line 26
def self.is_stdout?(obj)
  case obj
  when String
    return true if STDOUTS.include?(obj)
  when ::IO
    return true if obj == ::STDOUT
  end
  return false
end
new(obj) click to toggle source
# File lib/flat_kit/output/io.rb, line 36
def initialize(obj)
  @count = 0
  if self.class.is_stdout?(obj) then
    @name = "<STDOUT>"
    @io = $stdout
  elsif self.class.is_stderr?(obj) then
    @name = "<STDERR>"
    @io = $stderr
  elsif obj.kind_of?(::File) then
    @name = obj.path
    @io = obj
  elsif obj.kind_of?(::StringIO) then
    @name = obj.inspect
    @io = obj
  elsif obj.kind_of?(::IO) then
    @name = obj.inspect
    @io = obj
  else
    raise ::FlatKit::Error, "Unable to create #{self.class} from #{obj.class} : #{obj.inspect}"
  end
end

Public Instance Methods

close() click to toggle source

this goes to an io stream and we are not in charge of opening it

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

internal api method for testing

# File lib/flat_kit/output/io.rb, line 68
def io
  @io
end
name() click to toggle source
# File lib/flat_kit/output/io.rb, line 58
def name
  @name
end