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

Inherits:
Object
  • Object
show all
Extended by:
T::Sig
Defined in:
rubocops/cask/ast/cask_header.rb

Overview

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) ⇒ CaskHeader

Returns a new instance of CaskHeader.



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

def initialize(method_node)
  @method_node = method_node
end

Instance Attribute Details

#method_nodeObject (readonly)

Returns the value of attribute method_node.



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

def method_node
  @method_node
end

Instance Method Details

#cask_tokenObject



35
36
37
38
39
40
41
# File 'rubocops/cask/ast/cask_header.rb', line 35

def cask_token
  @cask_token ||= if dsl_version?
    pair_node.val_node.children.first
  else
    method_node.first_argument.str_content
  end
end

#dsl_version?Boolean

Returns:

  • (Boolean)


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

def dsl_version?
  hash_node
end

#hash_nodeObject



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

def hash_node
  @hash_node ||= method_node.each_child_node(:hash).first
end

#header_strObject



22
23
24
# File 'rubocops/cask/ast/cask_header.rb', line 22

def header_str
  @header_str ||= source_range.source
end

#pair_nodeObject



47
48
49
# File 'rubocops/cask/ast/cask_header.rb', line 47

def pair_node
  @pair_node ||= hash_node.each_child_node(:pair).first
end

#preferred_header_strString

Returns:



31
32
33
# File 'rubocops/cask/ast/cask_header.rb', line 31

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

#source_rangeObject



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

def source_range
  @source_range ||= method_node.loc.expression
end