Class: RuboCop::Cask::AST::CaskBlock
- Inherits:
-
Object
- Object
- RuboCop::Cask::AST::CaskBlock
- 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
-
#block_node ⇒ Object
(also: #cask_node)
readonly
Returns the value of attribute block_node.
-
#comments ⇒ Object
readonly
Returns the value of attribute comments.
Instance Method Summary collapse
- #header ⇒ Object
-
#initialize(block_node, comments) ⇒ CaskBlock
constructor
A new instance of CaskBlock.
- #sorted_toplevel_stanzas ⇒ Object
- #stanzas ⇒ Object
- #toplevel_stanzas ⇒ Object
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_node ⇒ Object (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 |
#comments ⇒ Object (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
#header ⇒ Object
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_stanzas ⇒ Object
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 |
#stanzas ⇒ Object
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_stanzas ⇒ Object
34 35 36 |
# File 'lib/rubocop/cask/ast/cask_block.rb', line 34 def toplevel_stanzas @toplevel_stanzas ||= stanzas.select(&:toplevel_stanza?) end |