Class: RuboCop::Cask::AST::StanzaBlock Private

Inherits:
Object
  • Object
show all
Extended by:
T::Helpers
Defined in:
rubocops/cask/ast/cask_block.rb

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.

Direct Known Subclasses

CaskBlock

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(block_node, comments) ⇒ void

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.

Parameters:

  • block_node (RuboCop::AST::BlockNode)
  • comments (Array<Parser::Source::Comment>)


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

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

Instance Attribute Details

#block_nodeRuboCop::AST::BlockNode (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.

Returns:

  • (RuboCop::AST::BlockNode)


13
14
15
# File 'rubocops/cask/ast/cask_block.rb', line 13

def block_node
  @block_node
end

#commentsArray<Parser::Source::Comment> (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.

Returns:

  • (Array<Parser::Source::Comment>)


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

def comments
  @comments
end

Instance Method Details

#stanzasArray<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:



25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
# File 'rubocops/cask/ast/cask_block.rb', line 25

def stanzas
  return [] unless (block_body = block_node.block_body)

  # If a block only contains one stanza, it is that stanza's direct parent, otherwise
  # stanzas are grouped in a nested block and the block is that nested block's parent.
  is_stanza = if block_body.begin_block?
    ->(node) { node.parent.parent == block_node }
  else
    ->(node) { node.parent == block_node }
  end

  @stanzas ||= block_body.each_node
                         .select(&:stanza?)
                         .select(&is_stanza)
                         .map { |node| Stanza.new(node, comments) }
end