Class: Bashly::IndentationHelper

Inherits:
Object
  • Object
show all
Defined in:
lib/bashly/concerns/indentation_helper.rb

Overview

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.

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(indentation) ⇒ IndentationHelper

Returns a new instance of IndentationHelper.



8
9
10
11
# File 'lib/bashly/concerns/indentation_helper.rb', line 8

def initialize(indentation)
  @indentation = indentation
  @marker = nil
end

Instance Attribute Details

#indentationObject (readonly)

Returns the value of attribute indentation.



6
7
8
# File 'lib/bashly/concerns/indentation_helper.rb', line 6

def indentation
  @indentation
end

#markerObject (readonly)

Returns the value of attribute marker.



6
7
8
# File 'lib/bashly/concerns/indentation_helper.rb', line 6

def marker
  @marker
end

Instance Method Details

#indent(line) ⇒ Object



13
14
15
16
17
18
19
20
21
# 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