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

Inherits:
Object
  • Object
show all
Defined in:
brew/Library/Homebrew/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



9
10
11
# File 'brew/Library/Homebrew/rubocops/cask/ast/cask_header.rb', line 9

def initialize(method_node)
  @method_node = method_node
end

Instance Attribute Details

#method_nodeObject (readonly)

Returns the value of attribute method_node



13
14
15
# File 'brew/Library/Homebrew/rubocops/cask/ast/cask_header.rb', line 13

def method_node
  @method_node
end

Instance Method Details

#cask_tokenObject



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

def cask_token
  @cask_token ||= pair_node.val_node.children.first
end

#dsl_version?Boolean

Returns:

  • (Boolean)


15
16
17
# File 'brew/Library/Homebrew/rubocops/cask/ast/cask_header.rb', line 15

def dsl_version?
  hash_node
end

#hash_nodeObject



35
36
37
# File 'brew/Library/Homebrew/rubocops/cask/ast/cask_header.rb', line 35

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

#header_strObject



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

def header_str
  @header_str ||= source_range.source
end

#pair_nodeObject



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

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

#preferred_header_strObject



27
28
29
# File 'brew/Library/Homebrew/rubocops/cask/ast/cask_header.rb', line 27

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

#source_rangeObject



23
24
25
# File 'brew/Library/Homebrew/rubocops/cask/ast/cask_header.rb', line 23

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