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

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



12
13
14
15
# File 'lib/rubocop/cask/ast/cask_block.rb', line 12

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.



17
18
19
# File 'lib/rubocop/cask/ast/cask_block.rb', line 17

def block_node
  @block_node
end

#commentsObject (readonly)

Returns the value of attribute comments.



17
18
19
# File 'lib/rubocop/cask/ast/cask_block.rb', line 17

def comments
  @comments
end

Instance Method Details

#headerObject



23
24
25
# File 'lib/rubocop/cask/ast/cask_block.rb', line 23

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

#sorted_toplevel_stanzasObject



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

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

#stanzasObject



27
28
29
30
31
32
# File 'lib/rubocop/cask/ast/cask_block.rb', line 27

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

#toplevel_stanzasObject



34
35
36
# File 'lib/rubocop/cask/ast/cask_block.rb', line 34

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