123456789_123456789_123456789_123456789_123456789_

Module: RuboCop::Cop::Heredoc

Overview

Common functionality for working with heredoc strings.

Constant Summary

Instance Method Summary

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.

[ GitHub ]

  
# File 'lib/rubocop/cop/mixin/heredoc.rb', line 14

alias on_dstr on_str

#on_heredoc(_node)

Raises:

  • (NotImplementedError)
[ GitHub ]

  
# 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.

[ GitHub ]

  
# File 'lib/rubocop/cop/mixin/heredoc.rb', line 15

alias on_xstr on_str