Class: FlatKit::Output::File

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

Instance Attribute Summary collapse

Class Method Summary collapse

Instance Method Summary collapse

Methods inherited from FlatKit::Output

from

Methods included from DescendantTracker

#children, #find_child, #inherited

Constructor Details

#initialize(obj) ⇒ File

Returns a new instance of File.



19
20
21
22
23
# File 'lib/flat_kit/output/file.rb', line 19

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

Instance Attribute Details

#pathObject (readonly)

Returns the value of attribute path.



6
7
8
# File 'lib/flat_kit/output/file.rb', line 6

def path
  @path
end

Class Method Details

.handles?(obj) ⇒ Boolean

Returns:

  • (Boolean)


8
9
10
11
12
13
14
15
16
17
# 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

Instance Method Details

#closeObject



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

def close
  @io.close
end

#ioObject

internal api method for testing purposes



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

def io
  @io
end

#nameObject



25
26
27
# File 'lib/flat_kit/output/file.rb', line 25

def name
  path.to_s
end