Class: SpecForge::Forge::Runner::ArrayIO

Inherits:
Object
  • Object
show all
Defined in:
lib/spec_forge/forge/runner/array_io.rb

Overview

IO-like object that stores writes in an array instead of a string buffer

Used with RSpec's JSON formatter to capture each JSON output as a separate entry rather than concatenating them into one long string.

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initializeArrayIO

Returns a new instance of ArrayIO.



23
24
25
# File 'lib/spec_forge/forge/runner/array_io.rb', line 23

def initialize
  @entries = []
end

Instance Attribute Details

#entriesArray<String> (readonly)

All entries written to this IO

Returns:



18
19
20
# File 'lib/spec_forge/forge/runner/array_io.rb', line 18

def entries
  @entries
end

Instance Method Details

#<<(string) ⇒ void

This method returns an undefined value.

Appends a string (alias for write)

Parameters:

  • string (String)

    The string to append



56
57
58
# File 'lib/spec_forge/forge/runner/array_io.rb', line 56

def <<(string)
  write(string)
end

#closevoid

This method returns an undefined value.

Marks the IO as closed



75
76
77
# File 'lib/spec_forge/forge/runner/array_io.rb', line 75

def close
  @closed = true
end

#closedBoolean

Returns Whether the IO has been closed.

Returns:

  • (Boolean)

    Whether the IO has been closed



21
# File 'lib/spec_forge/forge/runner/array_io.rb', line 21

attr_predicate :closed

#flushInteger

Clears all entries

Returns:

  • (Integer)

    Always returns 0



65
66
67
68
# File 'lib/spec_forge/forge/runner/array_io.rb', line 65

def flush
  @entries.clear
  0
end

#puts(*strings) ⇒ void

This method returns an undefined value.

Writes strings with newlines appended

Parameters:

  • strings (Array<String>)

    Strings to write



45
46
47
# File 'lib/spec_forge/forge/runner/array_io.rb', line 45

def puts(*strings)
  strings.each { |string| write(string + "\n") }
end

#write(string) ⇒ void

This method returns an undefined value.

Writes a string as a new entry

Parameters:

  • string (String)

    The string to write



34
35
36
# File 'lib/spec_forge/forge/runner/array_io.rb', line 34

def write(string)
  @entries << string
end