Class: RuboCop::Cask::AST::Stanza

Inherits:
Object
  • Object
show all
Extended by:
Forwardable
Defined in:
lib/rubocop/cask/ast/stanza.rb

Overview

This class wraps the AST send/block node that encapsulates the method call that comprises the stanza. It includes various helper methods to aid cops in their analysis.

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(method_node, comments) ⇒ Stanza

Returns a new instance of Stanza.



12
13
14
15
# File 'lib/rubocop/cask/ast/stanza.rb', line 12

def initialize(method_node, comments)
  @method_node = method_node
  @comments = comments
end

Instance Attribute Details

#commentsObject (readonly)

Returns the value of attribute comments.



17
18
19
# File 'lib/rubocop/cask/ast/stanza.rb', line 17

def comments
  @comments
end

#method_nodeObject (readonly) Also known as: stanza_node

Returns the value of attribute method_node.



17
18
19
# File 'lib/rubocop/cask/ast/stanza.rb', line 17

def method_node
  @method_node
end

Instance Method Details

#==(other) ⇒ Object Also known as: eql?



50
51
52
# File 'lib/rubocop/cask/ast/stanza.rb', line 50

def ==(other)
  self.class == other.class && stanza_node == other.stanza_node
end

#same_group?(other) ⇒ Boolean

Returns:

  • (Boolean)


42
43
44
# File 'lib/rubocop/cask/ast/stanza.rb', line 42

def same_group?(other)
  stanza_group == other.stanza_group
end

#source_rangeObject



24
25
26
# File 'lib/rubocop/cask/ast/stanza.rb', line 24

def source_range
  stanza_node.expression
end

#source_range_with_commentsObject



28
29
30
31
32
# File 'lib/rubocop/cask/ast/stanza.rb', line 28

def source_range_with_comments
  comments.reduce(source_range) do |range, comment|
    range.join(comment.loc.expression)
  end
end

#stanza_groupObject



38
39
40
# File 'lib/rubocop/cask/ast/stanza.rb', line 38

def stanza_group
  Constants::STANZA_GROUP_HASH[stanza_name]
end

#toplevel_stanza?Boolean

Returns:

  • (Boolean)


46
47
48
# File 'lib/rubocop/cask/ast/stanza.rb', line 46

def toplevel_stanza?
  parent_node.cask_block? || parent_node.parent.cask_block?
end