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
indentation[R]
marker[R]
Public Class Methods
new(indentation)
click to toggle source
# File lib/bashly/concerns/indentation_helper.rb, line 8 def initialize(indentation) @indentation = indentation @marker = nil end
Public Instance Methods
indent(line)
click to toggle 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
extract_heredoc_marker(line)
click to toggle source
# File lib/bashly/concerns/indentation_helper.rb, line 37 def extract_heredoc_marker(line) line =~ /<<-?\s*(\w+)/ ? $1 : nil end
heredoc_closed?(line)
click to toggle source
# File lib/bashly/concerns/indentation_helper.rb, line 41 def heredoc_closed?(line) inside_heredoc? && /^#{marker}\n?$/.match?(line) end
inside_heredoc?()
click to toggle source
# File lib/bashly/concerns/indentation_helper.rb, line 29 def inside_heredoc? !!marker end
reset_marker()
click to toggle source
# File lib/bashly/concerns/indentation_helper.rb, line 25 def reset_marker @marker = nil end
set_heredoc_state(line)
click to toggle source
# File lib/bashly/concerns/indentation_helper.rb, line 33 def set_heredoc_state(line) @marker = extract_heredoc_marker(line) end