From 4ae201db85a6463a91beae08b0f6c68be30ea7e2 Mon Sep 17 00:00:00 2001 From: Sean Collins Date: Fri, 21 Jan 2022 07:49:53 -0400 Subject: [PATCH] Refactor to remove reference to newline --- lib/dry/files.rb | 16 ++++++---------- 1 file changed, 6 insertions(+), 10 deletions(-) diff --git a/lib/dry/files.rb b/lib/dry/files.rb index fe7ae65..ce9901b 100644 --- a/lib/dry/files.rb +++ b/lib/dry/files.rb @@ -737,11 +737,6 @@ def remove_block(path, target) private - # @since 0.1.0 - # @api private - NEW_LINE = $/ # rubocop:disable Style/SpecialGlobalVars - private_constant :NEW_LINE - # @since 0.1.0 # @api private CONTENT_OFFSET = 1 @@ -825,13 +820,14 @@ def _inject_line_after(path, target, contents, finder) # @api private def _offset_block_lines(contents, offset) contents.map do |line| - if line.match?(NEW_LINE) - line = line.split(NEW_LINE) - _offset_block_lines(line, offset) + case line.lines + in [line] + offset + line else - offset + line + NEW_LINE + lines = line.lines(chomp: true) + _offset_block_lines(lines, offset) end - end.join + end end # @since 0.1.0