Class: RuboCop::Cask::AST::CaskBlock Private

Inherits:
StanzaBlock show all
Extended by:
Forwardable
Defined in:
rubocops/cask/ast/cask_block.rb

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

#block_node, #comments

Instance Method Summary collapse

Methods inherited from StanzaBlock

#initialize

Constructor Details

This class inherits a constructor from RuboCop::Cask::AST::StanzaBlock

Instance Method Details

#cask_nodeObject

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

#headerObject

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

#stanzasObject

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.



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_stanzasObject

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