Class: FlatKit::Output::File

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

Overview

Internal: File output implementation

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) ⇒ File

Returns a new instance of File.



27
28
29
30
31
32
# File 'lib/flat_kit/output/file.rb', line 27

def initialize(obj)
  super()
  @path = Pathname.new(obj)
  path.dirname.mkpath
  @io = open_output(path)
end

Instance Attribute Details

#ioObject (readonly)

internal api method for testing purposes



14
15
16
# File 'lib/flat_kit/output/file.rb', line 14

def io
  @io
end

#pathObject (readonly)

Returns the value of attribute path.



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

def path
  @path
end

Class Method Details

.handles?(obj) ⇒ Boolean

Returns:

  • (Boolean)


16
17
18
19
20
21
22
23
24
25
# File 'lib/flat_kit/output/file.rb', line 16

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.stdout?(obj)
  return false if ::FlatKit::Output::IO.stderr?(obj)

  true
end

Instance Method Details

#closeObject



38
39
40
# File 'lib/flat_kit/output/file.rb', line 38

def close
  @io.close
end

#nameObject



34
35
36
# File 'lib/flat_kit/output/file.rb', line 34

def name
  path.to_s
end