class Bashly::IndentationHelper
A helper class, used by the ‘Array#indent` extension. It will return the array of strings with all strings prefixed by `indentation` unless the line is within a heredoc block.
Attributes
Public Class Methods
Source
# File lib/bashly/concerns/indentation_helper.rb, line 8 def initialize(indentation) @indentation = indentation @marker = nil end
Public Instance Methods
Source
# File lib/bashly/concerns/indentation_helper.rb, line 13 def indent(line) if inside_heredoc? reset_marker if heredoc_closed?(line) line else set_heredoc_state(line) "#{indentation}#{line}" end end
Private Instance Methods
Source
# File lib/bashly/concerns/indentation_helper.rb, line 37 def extract_heredoc_marker(line) line =~ /<<-?\s*['"]?(\w+)['"]?/ ? $1 : nil end
Source
# File lib/bashly/concerns/indentation_helper.rb, line 41 def heredoc_closed?(line) inside_heredoc? && /^#{marker}\n?$/.match?(line) end
Source
# File lib/bashly/concerns/indentation_helper.rb, line 29 def inside_heredoc? !!marker end
Source
# File lib/bashly/concerns/indentation_helper.rb, line 25 def reset_marker @marker = nil end
Source
# File lib/bashly/concerns/indentation_helper.rb, line 33 def set_heredoc_state(line) @marker = extract_heredoc_marker(line) end