Module: RuboCop::Cop::Heredoc
Relationships & Source Files | |
Extension / Inclusion / Inheritance Descendants | |
Included In:
| |
Defined in: | lib/rubocop/cop/mixin/heredoc.rb |
Overview
Common functionality for working with heredoc strings.
Constant Summary
-
OPENING_DELIMITER =
# File 'lib/rubocop/cop/mixin/heredoc.rb', line 7/(<<[~-]?)['"`]?([^'"`]+)['"`]?/.freeze
Instance Method Summary
-
#on_dstr(node)
Alias for #on_str.
- #on_heredoc(_node)
- #on_str(node) (also: #on_dstr, #on_xstr)
-
#on_xstr(node)
Alias for #on_str.
- #delimiter_string(node) private
- #heredoc_type(node) private
- #indent_level(str) private
Instance Method Details
#delimiter_string(node) (private)
[ GitHub ]# File 'lib/rubocop/cop/mixin/heredoc.rb', line 28
def delimiter_string(node) return '' unless (match = node.source.match(OPENING_DELIMITER)) match.captures[1] end
#heredoc_type(node) (private)
[ GitHub ]# File 'lib/rubocop/cop/mixin/heredoc.rb', line 34
def heredoc_type(node) return '' unless (match = node.source.match(OPENING_DELIMITER)) match.captures[0] end
#indent_level(str) (private)
[ GitHub ]# File 'lib/rubocop/cop/mixin/heredoc.rb', line 23
def indent_level(str) indentations = str.lines.map { |line| line[/^\s*/] }.reject { |line| line.end_with?("\n") } indentations.empty? ? 0 : indentations.min_by(&:size).size end
#on_dstr(node)
Alias for #on_str.
# File 'lib/rubocop/cop/mixin/heredoc.rb', line 14
alias on_dstr on_str
#on_heredoc(_node)
# File 'lib/rubocop/cop/mixin/heredoc.rb', line 17
def on_heredoc(_node) raise NotImplementedError end
#on_str(node) Also known as: #on_dstr, #on_xstr
[ GitHub ]# File 'lib/rubocop/cop/mixin/heredoc.rb', line 9
def on_str(node) return unless node.heredoc? on_heredoc(node) end
#on_xstr(node)
Alias for #on_str.
# File 'lib/rubocop/cop/mixin/heredoc.rb', line 15
alias on_xstr on_str