Class: RuboCop::Cask::AST::CaskBlock Private
- Inherits:
-
StanzaBlock
- Object
- StanzaBlock
- RuboCop::Cask::AST::CaskBlock
- Extended by:
- Forwardable
- Defined in:
- rubocops/cask/ast/cask_block.rb,
sorbet/rbi/dsl/rubo_cop/cask/ast/cask_block.rbi
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 block node that represents the entire cask definition. It includes various helper methods to aid cops in their analysis.
Instance Attribute Summary
Attributes inherited from StanzaBlock
Instance Method Summary collapse
- #cask_body(*args, &block) ⇒ T.untyped private
- #cask_node ⇒ Object private
- #header ⇒ Object private
- #stanzas ⇒ Object private
- #toplevel_stanzas ⇒ Object private
Methods inherited from StanzaBlock
Constructor Details
This class inherits a constructor from RuboCop::Cask::AST::StanzaBlock
Instance Method Details
#cask_body(*args, &block) ⇒ T.untyped
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.
10 |
# File 'sorbet/rbi/dsl/rubo_cop/cask/ast/cask_block.rbi', line 10 def cask_body(*args, &block); end |
#cask_node ⇒ Object
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.
49 50 51 |
# File 'rubocops/cask/ast/cask_block.rb', line 49 def cask_node block_node end |
#header ⇒ Object
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.
55 56 57 |
# File 'rubocops/cask/ast/cask_block.rb', line 55 def header @header ||= CaskHeader.new(block_node.method_node) end |
#stanzas ⇒ Object
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.
Use StanzaBlock#stanzas
for all cops, where possible.
60 61 62 63 64 65 66 |
# File 'rubocops/cask/ast/cask_block.rb', line 60 def stanzas return [] unless cask_body @stanzas ||= cask_body.each_node .select(&:stanza?) .map { |node| Stanza.new(node, comments) } end |
#toplevel_stanzas ⇒ Object
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.
68 69 70 71 72 73 74 75 76 77 78 |
# File 'rubocops/cask/ast/cask_block.rb', line 68 def toplevel_stanzas # If a `cask` block only contains one stanza, it is that stanza's direct parent, # otherwise stanzas are grouped in a block and `cask` is that block's parent. is_toplevel_stanza = if cask_body.begin_block? ->(stanza) { stanza.parent_node.parent.cask_block? } else ->(stanza) { stanza.parent_node.cask_block? } end @toplevel_stanzas ||= stanzas.select(&is_toplevel_stanza) end |