-
Notifications
You must be signed in to change notification settings - Fork 3
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
For example: ``` cat test/fixtures/merge.yml | flatito ```
- Loading branch information
Showing
12 changed files
with
175 additions
and
74 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,17 @@ | ||
# frozen_string_literal: true | ||
|
||
module Flatito | ||
module Config | ||
@stdout = $stdout | ||
@stderr = $stderr | ||
@stdin = $stdin | ||
|
||
class << self | ||
attr_accessor :renderer, :stdout, :stder, :stdin | ||
|
||
def prepare_with_options(options) | ||
self.renderer = Renderer.build(options) | ||
end | ||
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
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,30 @@ | ||
# frozen_string_literal: true | ||
|
||
module Flatito | ||
class PrintItems | ||
include RegexFromSearch | ||
attr_reader :search | ||
|
||
def initialize(search) | ||
@search = search | ||
end | ||
|
||
def print(items, pathname = nil) | ||
items = filter_by_search(items) if search | ||
return unless items.any? | ||
|
||
renderer.print_pathname(pathname) if pathname | ||
renderer.print_items(items) | ||
end | ||
|
||
def filter_by_search(items) | ||
items.select do |item| | ||
regex.match?(item.key) | ||
end | ||
end | ||
|
||
def renderer | ||
Config.renderer | ||
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,9 @@ | ||
# frozen_string_literal: true | ||
|
||
module Flatito | ||
module Utils | ||
def truncate(string, max = 50) | ||
string.length > max ? "#{string[0...max]}..." : string | ||
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
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,31 @@ | ||
# frozen_string_literal: true | ||
|
||
require "test_helper" | ||
|
||
class Flatito::ConfigTest < Minitest::Test | ||
class DummyTTY < StringIO | ||
def tty? | ||
true | ||
end | ||
end | ||
|
||
class DummyNotTTY < StringIO | ||
def tty? | ||
false | ||
end | ||
end | ||
|
||
test "when stdout is tty set renderer as tty" do | ||
Flatito::Config.stdout = DummyTTY.new | ||
Flatito::Config.prepare_with_options({}) | ||
|
||
assert_kind_of Flatito::Renderer::TTY, Flatito::Config.renderer | ||
end | ||
|
||
test "when stdout is not tty set renderer as plain" do | ||
Flatito::Config.stdout = DummyNotTTY.new | ||
Flatito::Config.prepare_with_options({}) | ||
|
||
assert_kind_of Flatito::Renderer::Plain, Flatito::Config.renderer | ||
end | ||
end |
Oops, something went wrong.