Class: RuboCop::Cask::AST::StanzaBlock
- Extended by:
- T::Helpers
- Defined in:
- rubocops/cask/ast/cask_block.rb
Direct Known Subclasses
Instance Attribute Summary collapse
Instance Method Summary collapse
Constructor Details
#initialize(block_node, comments) ⇒ void
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)
13 14 15 |
# File 'rubocops/cask/ast/cask_block.rb', line 13 def block_node @block_node end |
#comments ⇒ Array<Parser::Source::Comment> (readonly)
16 17 18 |
# File 'rubocops/cask/ast/cask_block.rb', line 16 def comments @comments end |
Instance Method Details
#stanzas ⇒ Array<Stanza>
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 |