Skip to content

Commit

Permalink
more
Browse files Browse the repository at this point in the history
  • Loading branch information
ceritium committed Mar 20, 2024
1 parent 9c647b4 commit 84deac1
Show file tree
Hide file tree
Showing 5 changed files with 16 additions and 14 deletions.
2 changes: 1 addition & 1 deletion exe/flatito
Original file line number Diff line number Diff line change
Expand Up @@ -44,7 +44,7 @@ OptionParser.new do |opts|
end
end.parse!

Flatito::Config.parse_global_options(options)
Flatito::Config.prepare_with_options(options)

if stdin
Flatito.flat_content(stdin, options)
Expand Down
2 changes: 1 addition & 1 deletion lib/flatito/config.rb
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ module Config
class << self
attr_accessor :renderer, :stdout, :stder, :stdin

def parse_global_options(options)
def prepare_with_options(options)
self.renderer = Renderer.build(options)
end
end
Expand Down
20 changes: 10 additions & 10 deletions lib/flatito/flatten_yaml.rb
Original file line number Diff line number Diff line change
Expand Up @@ -36,8 +36,8 @@ def flatten_hash(hash, prefix = nil)
end
end
end
# rescue StandardError => e
# warn "Error parsing #{@pathname}, #{e.message}"
rescue StandardError => e
warn "Error parsing #{@pathname}, #{e.message}"
end

def with_line_numbers
Expand All @@ -46,14 +46,14 @@ def with_line_numbers

handler.parser.parse(content)
YAMLWithLineNumber::VisitorsToRuby.create.accept(handler.root)
# rescue Psych::SyntaxError
# warn "Invalid YAML #{@pathname}"
#
# []
# rescue StandardError => e
# warn "Error parsing #{@pathname}, #{e.message}"
#
# []
rescue Psych::SyntaxError
warn "Invalid YAML #{@pathname}"

[]
rescue StandardError => e
warn "Error parsing #{@pathname}, #{e.message}"

[]
end

def truncate(string, max = 50)
Expand Down
2 changes: 2 additions & 0 deletions lib/flatito/print_items.rb
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
# frozen_string_literal: true

module Flatito
class PrintItems
def self.call(search, items, pathname = nil)
Expand Down
4 changes: 2 additions & 2 deletions test/flatito/config_test.rb
Original file line number Diff line number Diff line change
Expand Up @@ -17,14 +17,14 @@ def tty?

test "when stdout is tty set renderer as tty" do
Flatito::Config.stdout = DummyTTY.new
Flatito::Config.parse_global_options({})
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.parse_global_options({})
Flatito::Config.prepare_with_options({})

assert_kind_of Flatito::Renderer::Plain, Flatito::Config.renderer
end
Expand Down

0 comments on commit 84deac1

Please sign in to comment.