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

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

Overview

This class is part of a private API. This class may only be used in the Homebrew/brew repository. Third parties should avoid using this class if possible, as it may be removed or changed without warning.

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, all_comments) ⇒ Stanza

This method is part of a private API. This method may only be used in the Homebrew/brew repository. Third parties should avoid using this method if possible, as it may be removed or changed without warning.

Returns a new instance of Stanza.



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

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

Instance Attribute Details

#all_commentsObject (readonly)

This method is part of a private API. This method may only be used in the Homebrew/brew repository. Third parties should avoid using this method if possible, as it may be removed or changed without warning.



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

def all_comments
  @all_comments
end

#method_nodeObject (readonly) Also known as: stanza_node

This method is part of a private API. This method may only be used in the Homebrew/brew repository. Third parties should avoid using this method if possible, as it may be removed or changed without warning.



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

def method_node
  @method_node
end

Instance Method Details

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

This method is part of a private API. This method may only be used in the Homebrew/brew repository. Third parties should avoid using this method if possible, as it may be removed or changed without warning.



70
71
72
# File 'rubocops/cask/ast/stanza.rb', line 70

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

#commentsObject

This method is part of a private API. This method may only be used in the Homebrew/brew repository. Third parties should avoid using this method if possible, as it may be removed or changed without warning.



60
61
62
63
64
# File 'rubocops/cask/ast/stanza.rb', line 60

def comments
  @comments ||= stanza_node.each_node.reduce([]) do |comments, node|
    comments | comments_hash[node.loc]
  end
end

#comments_hashObject

This method is part of a private API. This method may only be used in the Homebrew/brew repository. Third parties should avoid using this method if possible, as it may be removed or changed without warning.



66
67
68
# File 'rubocops/cask/ast/stanza.rb', line 66

def comments_hash
  @comments_hash ||= Parser::Source::Comment.associate_locations(stanza_node.parent, all_comments)
end

#same_group?(other) ⇒ Boolean

This method is part of a private API. This method may only be used in the Homebrew/brew repository. Third parties should avoid using this method if possible, as it may be removed or changed without warning.

Returns:

  • (Boolean)


56
57
58
# File 'rubocops/cask/ast/stanza.rb', line 56

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

#source_rangeObject

This method is part of a private API. This method may only be used in the Homebrew/brew repository. Third parties should avoid using this method if possible, as it may be removed or changed without warning.



28
29
30
# File 'rubocops/cask/ast/stanza.rb', line 28

def source_range
  stanza_node.location_expression
end

#source_range_with_commentsObject

This method is part of a private API. This method may only be used in the Homebrew/brew repository. Third parties should avoid using this method if possible, as it may be removed or changed without warning.



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

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

#stanza_groupObject

This method is part of a private API. This method may only be used in the Homebrew/brew repository. Third parties should avoid using this method if possible, as it may be removed or changed without warning.



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

def stanza_group
  Constants::STANZA_GROUP_HASH[stanza_name]
end

#stanza_indexObject

This method is part of a private API. This method may only be used in the Homebrew/brew repository. Third parties should avoid using this method if possible, as it may be removed or changed without warning.



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

def stanza_index
  Constants::STANZA_ORDER.index(stanza_name)
end

#stanza_nameObject

This method is part of a private API. This method may only be used in the Homebrew/brew repository. Third parties should avoid using this method if possible, as it may be removed or changed without warning.



42
43
44
45
46
# File 'rubocops/cask/ast/stanza.rb', line 42

def stanza_name
  return :on_arch_conditional if arch_variable?

  stanza_node.method_name
end