Class: SpecForge::Forge::Runner::ArrayIO
- Inherits:
-
Object
- Object
- SpecForge::Forge::Runner::ArrayIO
- 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
-
#entries ⇒ Array<String>
readonly
All entries written to this IO.
Instance Method Summary collapse
-
#<<(string) ⇒ void
Appends a string (alias for write).
-
#close ⇒ void
Marks the IO as closed.
-
#closed ⇒ Boolean
Whether the IO has been closed.
-
#flush ⇒ Integer
Clears all entries.
-
#initialize ⇒ ArrayIO
constructor
A new instance of ArrayIO.
-
#puts(*strings) ⇒ void
Writes strings with newlines appended.
-
#write(string) ⇒ void
Writes a string as a new entry.
Constructor Details
#initialize ⇒ ArrayIO
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
#entries ⇒ Array<String> (readonly)
All entries written to this IO
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)
56 57 58 |
# File 'lib/spec_forge/forge/runner/array_io.rb', line 56 def <<(string) write(string) end |
#close ⇒ void
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 |
#closed ⇒ Boolean
Returns Whether the IO has been closed.
21 |
# File 'lib/spec_forge/forge/runner/array_io.rb', line 21 attr_predicate :closed |
#flush ⇒ Integer
Clears all entries
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
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
34 35 36 |
# File 'lib/spec_forge/forge/runner/array_io.rb', line 34 def write(string) @entries << string end |