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

Inherits:
Object
  • Object
show all
Extended by:
Forwardable
Defined in:
Library/Homebrew/rubocops/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.


15
16
17
18
# File 'Library/Homebrew/rubocops/cask/ast/stanza.rb', line 15

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

Instance Attribute Details

#commentsObject (readonly)

Returns the value of attribute comments


20
21
22
# File 'Library/Homebrew/rubocops/cask/ast/stanza.rb', line 20

def comments
  @comments
end

#method_nodeObject (readonly) Also known as: stanza_node

Returns the value of attribute method_node


20
21
22
# File 'Library/Homebrew/rubocops/cask/ast/stanza.rb', line 20

def method_node
  @method_node
end

Instance Method Details

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


53
54
55
# File 'Library/Homebrew/rubocops/cask/ast/stanza.rb', line 53

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

#same_group?(other) ⇒ Boolean

Returns:

  • (Boolean)

45
46
47
# File 'Library/Homebrew/rubocops/cask/ast/stanza.rb', line 45

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

#source_rangeObject


27
28
29
# File 'Library/Homebrew/rubocops/cask/ast/stanza.rb', line 27

def source_range
  stanza_node.expression
end

#source_range_with_commentsObject


31
32
33
34
35
# File 'Library/Homebrew/rubocops/cask/ast/stanza.rb', line 31

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

#stanza_groupObject


41
42
43
# File 'Library/Homebrew/rubocops/cask/ast/stanza.rb', line 41

def stanza_group
  Constants::STANZA_GROUP_HASH[stanza_name]
end

#toplevel_stanza?Boolean

Returns:

  • (Boolean)

49
50
51
# File 'Library/Homebrew/rubocops/cask/ast/stanza.rb', line 49

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