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

Inherits:
Object
  • Object
show all
Extended by:
Forwardable
Defined in:
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.



15
16
17
18
# File 'rubocops/cask/ast/cask_block.rb', line 15

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.



20
21
22
# File 'rubocops/cask/ast/cask_block.rb', line 20

def block_node
  @block_node
end

#commentsObject (readonly)

Returns the value of attribute comments.



20
21
22
# File 'rubocops/cask/ast/cask_block.rb', line 20

def comments
  @comments
end

Instance Method Details

#headerObject



26
27
28
# File 'rubocops/cask/ast/cask_block.rb', line 26

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

#sorted_toplevel_stanzasObject



42
43
44
# File 'rubocops/cask/ast/cask_block.rb', line 42

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

#stanzasObject



30
31
32
33
34
35
36
# File 'rubocops/cask/ast/cask_block.rb', line 30

def stanzas
  return [] unless cask_body

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

#toplevel_stanzasObject



38
39
40
# File 'rubocops/cask/ast/cask_block.rb', line 38

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