Spec-Zone.ru › Homebrew

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

Inherits:
Object
  • Object
  • RuboCop::Cask::AST::StanzaBlock
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

  • #block_node ⇒ RuboCop::AST::BlockNode readonly private
  • #comments ⇒ Array<Parser::Source::Comment> readonly private

Instance Method Summary collapse

  • #initialize(block_node, comments) ⇒ void constructor private
  • #stanzas ⇒ Array<Stanza> private

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_node ⇒ RuboCop::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

#comments ⇒ Array<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

#stanzas ⇒ Array<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:

  • (Array<Stanza>)


25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
# 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 ||= T.let(
    block_body.each_node
              .select(&:stanza?)
              .select(&is_stanza)
              .map { |node| Stanza.new(node, comments) },
    T.nilable(T::Array[Stanza]),
  )
end

© 2009–present Homebrew contributors
Licensed under the BSD 2-Clause License.
https://docs.brew.sh/rubydoc/RuboCop/Cask/AST/StanzaBlock.html

Spec-Zone.ru

Настройки Оффлайн Что нового Помощь О нас
Spec-Zone .ru
спецификации, руководства, описания, API