Skip to content

Commit

Permalink
Drop workarounds for Ruby < 2.4
Browse files Browse the repository at this point in the history
  • Loading branch information
ehelms authored and ekohl committed Jun 1, 2021
1 parent a45b1eb commit 35a7034
Show file tree
Hide file tree
Showing 4 changed files with 9 additions and 21 deletions.
9 changes: 1 addition & 8 deletions Gemfile
Original file line number Diff line number Diff line change
Expand Up @@ -5,20 +5,13 @@ gemspec

gem 'json_pure'

if RUBY_VERSION < '2.1'
# Technically not needed, but avoids issues with bundler versions
gem 'rdoc', '< 5.0.0'
elsif RUBY_VERSION < '2.2'
gem 'rdoc', '< 6.0.0'
end

if ENV['PUPPET_VERSION']
gem 'puppet', "~> #{ENV['PUPPET_VERSION']}"
else
gem 'puppet', '>= 4.5.0', '< 8.0.0'
end

gem 'puppet-strings', RUBY_VERSION >= '2.1' ? '>= 1.2.1' : '~> 1.2.1'
gem 'puppet-strings', '>= 1.2.1'

group :puppet_module do
gem 'metadata-json-lint'
Expand Down
7 changes: 3 additions & 4 deletions lib/kafo/fact_writer.rb
Original file line number Diff line number Diff line change
Expand Up @@ -14,10 +14,9 @@ def self.write_facts(facts, directory)
end

def self.wrapper
# Ruby 2.0 doesn't have <<~ heredocs
<<-WRAPPER
require 'yaml'
Facter.add(:kafo) { setcode { YAML.load_file(File.join(__dir__, '#{DATA_FILENAME}')) } }
<<~WRAPPER
require 'yaml'
Facter.add(:kafo) { setcode { YAML.load_file(File.join(__dir__, '#{DATA_FILENAME}')) } }
WRAPPER
end
end
Expand Down
12 changes: 4 additions & 8 deletions lib/kafo/kafo_configure.rb
Original file line number Diff line number Diff line change
Expand Up @@ -525,8 +525,8 @@ def run_installation
@progress_bar.update(line) if @progress_bar
end
rescue Errno::EIO # we reach end of input
exit_status = PTY.check(pid, true) if PTY.respond_to?(:check) # ruby >= 1.9.2
if exit_status.nil? # process is still running or we have old ruby so we don't know
exit_status = PTY.check(pid, true)
if exit_status.nil? # process is still running
begin
Process.wait(pid)
rescue Errno::ECHILD # process could exit meanwhile so we rescue
Expand All @@ -535,7 +535,7 @@ def run_installation
end
end
end
rescue PTY::ChildExited => e # could be raised by Process.wait on older ruby or by PTY.check
rescue PTY::ChildExited => e # could be raised by PTY.check
self.class.exit_handler.exit_code = e.status.exitstatus
end

Expand Down Expand Up @@ -564,11 +564,7 @@ def config_file
end

def normalize_encoding(line)
if line.respond_to?(:encode) && line.respond_to?(:valid_encoding?)
line.valid_encoding? ? line : line.encode('UTF-16be', :invalid => :replace, :replace => '?').encode('UTF-8')
else # Ruby 1.8.7, doesn't worry about invalid encodings
line
end
line.valid_encoding? ? line : line.encode('UTF-16be', :invalid => :replace, :replace => '?').encode('UTF-8')
end
end
end
2 changes: 1 addition & 1 deletion test/kafo/fact_writer_test.rb
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ module Kafo
end

describe '#wrapper' do
specify { _(subject.wrapper).must_equal(" require 'yaml'\n Facter.add(:kafo) { setcode { YAML.load_file(File.join(__dir__, 'kafo.yaml')) } }\n") }
specify { _(subject.wrapper).must_equal("require 'yaml'\nFacter.add(:kafo) { setcode { YAML.load_file(File.join(__dir__, 'kafo.yaml')) } }\n") }
end
end
end

0 comments on commit 35a7034

Please sign in to comment.