Class: RuboCop::Cask::AST::StanzaBlock Private
- 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
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.
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.
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.
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.
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 |