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

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



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

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

Instance Attribute Details

#commentsObject (readonly)

Returns the value of attribute comments



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

def comments
  @comments
end

#method_nodeObject (readonly) Also known as: stanza_node

Returns the value of attribute method_node



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

def method_node
  @method_node
end

Instance Method Details

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



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

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

#same_group?(other) ⇒ Boolean

Returns:

  • (Boolean)


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

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

#source_rangeObject



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

def source_range
  stanza_node.expression
end

#source_range_with_commentsObject



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

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

#stanza_groupObject



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

def stanza_group
  Constants::STANZA_GROUP_HASH[stanza_name]
end

#toplevel_stanza?Boolean

Returns:

  • (Boolean)


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

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