-
Notifications
You must be signed in to change notification settings - Fork 5
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #53 from lxxxvi/allow-writing-to-STDOUT
Allow writing to stdout
- Loading branch information
Showing
6 changed files
with
116 additions
and
15 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,27 @@ | ||
# frozen_string_literal: true | ||
|
||
module Ruboclean | ||
# Orders the items within the groups alphabetically | ||
class StreamWriter | ||
def initialize(target_file_pathname, content) | ||
@target_file_pathname = target_file_pathname | ||
@content = content | ||
end | ||
|
||
def write! | ||
if stdout? | ||
puts content | ||
else | ||
target_file_pathname.write(content) | ||
end | ||
end | ||
|
||
private | ||
|
||
attr_reader :target_file_pathname, :content | ||
|
||
def stdout? | ||
target_file_pathname.basename.to_s == "STDOUT" | ||
end | ||
end | ||
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,24 @@ | ||
# frozen_string_literal: true | ||
|
||
require "test_helper" | ||
|
||
module Ruboclean | ||
class StreamWriterTest < BaseTest | ||
def test_writes_to_path | ||
Tempfile.create do |tmpfile| | ||
target_file_pathname = Pathname.new(tmpfile) | ||
Ruboclean::StreamWriter.new(target_file_pathname, "magnificent file output").write! | ||
|
||
assert_equal "magnificent file output", target_file_pathname.read | ||
end | ||
end | ||
|
||
def test_writes_to_stdout | ||
target_file_pathname = Pathname.new("STDOUT") | ||
|
||
assert_output("magnificent STDOUT output\n") do | ||
Ruboclean::StreamWriter.new(target_file_pathname, "magnificent STDOUT output").write! | ||
end | ||
end | ||
end | ||
end |