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

Inherits:
Object
  • Object
show all
Extended by:
Forwardable
Defined in:
brew/Library/Homebrew/rubocops/cask/ast/cask_block.rb

Overview

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 collapse

Instance Method Summary collapse

Constructor Details

#initialize(block_node, comments) ⇒ CaskBlock

Returns a new instance of CaskBlock



14
15
16
17
# File 'brew/Library/Homebrew/rubocops/cask/ast/cask_block.rb', line 14

def initialize(block_node, comments)
  @block_node = block_node
  @comments = comments
end

Instance Attribute Details

#block_nodeObject (readonly) Also known as: cask_node

Returns the value of attribute block_node



19
20
21
# File 'brew/Library/Homebrew/rubocops/cask/ast/cask_block.rb', line 19

def block_node
  @block_node
end

#commentsObject (readonly)

Returns the value of attribute comments



19
20
21
# File 'brew/Library/Homebrew/rubocops/cask/ast/cask_block.rb', line 19

def comments
  @comments
end

Instance Method Details

#headerObject



25
26
27
# File 'brew/Library/Homebrew/rubocops/cask/ast/cask_block.rb', line 25

def header
  @header ||= CaskHeader.new(cask_node.method_node)
end

#sorted_toplevel_stanzasObject



41
42
43
# File 'brew/Library/Homebrew/rubocops/cask/ast/cask_block.rb', line 41

def sorted_toplevel_stanzas
  @sorted_toplevel_stanzas ||= sort_stanzas(toplevel_stanzas)
end

#stanzasObject



29
30
31
32
33
34
35
# File 'brew/Library/Homebrew/rubocops/cask/ast/cask_block.rb', line 29

def stanzas
  return [] unless cask_body

  @stanzas ||= cask_body.each_node
                        .select(&:stanza?)
                        .map { |node| Stanza.new(node, stanza_comments(node)) }
end

#toplevel_stanzasObject



37
38
39
# File 'brew/Library/Homebrew/rubocops/cask/ast/cask_block.rb', line 37

def toplevel_stanzas
  @toplevel_stanzas ||= stanzas.select(&:toplevel_stanza?)
end