Skip to content

Commit

Permalink
Refactor to remove reference to newline
Browse files Browse the repository at this point in the history
  • Loading branch information
cllns committed Jan 21, 2022
1 parent 77256ad commit 4ae201d
Showing 1 changed file with 6 additions and 10 deletions.
16 changes: 6 additions & 10 deletions lib/dry/files.rb
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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
Expand Down

0 comments on commit 4ae201d

Please sign in to comment.