Class: RuboCop::Cask::AST::CaskHeader Private

Inherits:
Object
  • Object
show all
Defined in:
rubocops/cask/ast/cask_header.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 method node that represents the cask header. It includes various helper methods to aid cops in their analysis.

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(method_node) ⇒ void

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.

Parameters:



11
12
13
# File 'rubocops/cask/ast/cask_header.rb', line 11

def initialize(method_node)
  @method_node = method_node
end

Instance Attribute Details

#method_nodeT.all(RuboCop::AST::Node, RuboCop::AST::ParameterizedNode::RestArguments) (readonly)

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.

Returns:



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

def method_node
  @method_node
end

Instance Method Details

#cask_tokenString

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.

Returns:



34
35
36
# File 'rubocops/cask/ast/cask_header.rb', line 34

def cask_token
  @cask_token ||= T.let(method_node.first_argument.str_content, T.nilable(String))
end

#hash_nodeT.all(RuboCop::AST::Node, RuboCop::AST::ParameterizedNode::RestArguments)

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.

Returns:



39
40
41
# File 'rubocops/cask/ast/cask_header.rb', line 39

def hash_node
  @hash_node ||= T.let(method_node.each_child_node(:hash).first, T.nilable(RuboCop::AST::Node))
end

#header_strString

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.

Returns:



19
20
21
# File 'rubocops/cask/ast/cask_header.rb', line 19

def header_str
  @header_str ||= T.let(source_range.source, T.nilable(String))
end

#pair_nodeT.all(RuboCop::AST::Node, RuboCop::AST::ParameterizedNode::RestArguments)

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.

Returns:



44
45
46
# File 'rubocops/cask/ast/cask_header.rb', line 44

def pair_node
  @pair_node ||= T.let(hash_node.each_child_node(:pair).first, T.nilable(RuboCop::AST::Node))
end

#preferred_header_strString

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.

Returns:



29
30
31
# File 'rubocops/cask/ast/cask_header.rb', line 29

def preferred_header_str
  "cask '#{cask_token}'"
end

#source_rangeParser::Source::Range

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.



24
25
26
# File 'rubocops/cask/ast/cask_header.rb', line 24

def source_range
  @source_range ||= T.let(method_node.loc.expression, T.nilable(Parser::Source::Range))
end