Class: FlatKit::Output::IO

Inherits:
FlatKit::Output show all
Defined in:
lib/flat_kit/output/io.rb

Overview

Internal: Non-file Output impelementation - this is genrally to stdout or stderr

Constant Summary collapse

STDOUTS =
%w[stdout STDOUT - <stdout>].freeze
STDERRS =
%w[stderr STDERR <stderr>].freeze

Instance Attribute Summary collapse

Class Method Summary collapse

Instance Method Summary collapse

Methods inherited from FlatKit::Output

from, #tell

Methods included from DescendantTracker

#children, #find_child, #find_children, #inherited

Constructor Details

#initialize(obj) ⇒ IO

Returns a new instance of IO.



44
45
46
47
48
49
50
# File 'lib/flat_kit/output/io.rb', line 44

def initialize(obj)
  super()
  @count = 0
  @name = nil
  @io = nil
  init_name_and_io(obj)
end

Instance Attribute Details

#countObject (readonly)

Returns the value of attribute count.



8
9
10
# File 'lib/flat_kit/output/io.rb', line 8

def count
  @count
end

#ioObject (readonly)

internal api method for testing



11
12
13
# File 'lib/flat_kit/output/io.rb', line 11

def io
  @io
end

#nameObject (readonly)

Returns the value of attribute name.



8
9
10
# File 'lib/flat_kit/output/io.rb', line 8

def name
  @name
end

Class Method Details

.handles?(obj) ⇒ Boolean

Returns:

  • (Boolean)


16
17
18
19
20
21
22
# File 'lib/flat_kit/output/io.rb', line 16

def self.handles?(obj)
  return true if stderr?(obj)
  return true if stdout?(obj)
  return true if [::File, ::StringIO, ::IO].any? { |klass| obj.is_a?(klass) }

  false
end

.stderr?(obj) ⇒ Boolean

Returns:

  • (Boolean)


24
25
26
27
28
29
30
31
32
# File 'lib/flat_kit/output/io.rb', line 24

def self.stderr?(obj)
  case obj
  when String
    return true if STDERRS.include?(obj)
  when ::IO
    return true if obj == $stderr
  end
  false
end

.stdout?(obj) ⇒ Boolean

Returns:

  • (Boolean)


34
35
36
37
38
39
40
41
42
# File 'lib/flat_kit/output/io.rb', line 34

def self.stdout?(obj)
  case obj
  when String
    return true if STDOUTS.include?(obj)
  when ::IO
    return true if obj == $stdout
  end
  false
end

Instance Method Details

#closeObject

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



53
54
55
# File 'lib/flat_kit/output/io.rb', line 53

def close
  @io.close
end