Class: RuboCop::Cask::AST::CaskHeader
- Inherits:
-
Object
- Object
- RuboCop::Cask::AST::CaskHeader
- Defined in:
- 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
-
#method_node ⇒ Object
readonly
Returns the value of attribute method_node.
Instance Method Summary collapse
- #cask_token ⇒ Object
- #dsl_version? ⇒ Boolean
- #hash_node ⇒ Object
- #header_str ⇒ Object
-
#initialize(method_node) ⇒ CaskHeader
constructor
A new instance of CaskHeader.
- #pair_node ⇒ Object
- #preferred_header_str ⇒ Object
- #source_range ⇒ Object
Constructor Details
#initialize(method_node) ⇒ CaskHeader
Returns a new instance of CaskHeader.
10 11 12 |
# File 'Library/Homebrew/rubocops/cask/ast/cask_header.rb', line 10 def initialize(method_node) @method_node = method_node end |
Instance Attribute Details
#method_node ⇒ Object (readonly)
Returns the value of attribute method_node
14 15 16 |
# File 'Library/Homebrew/rubocops/cask/ast/cask_header.rb', line 14 def method_node @method_node end |
Instance Method Details
#cask_token ⇒ Object
32 33 34 35 36 37 38 39 40 |
# File 'Library/Homebrew/rubocops/cask/ast/cask_header.rb', line 32 def cask_token @cask_token ||= begin if dsl_version? pair_node.val_node.children.first else method_node.first_argument.str_content end end end |
#dsl_version? ⇒ Boolean
16 17 18 |
# File 'Library/Homebrew/rubocops/cask/ast/cask_header.rb', line 16 def dsl_version? hash_node end |
#hash_node ⇒ Object
42 43 44 |
# File 'Library/Homebrew/rubocops/cask/ast/cask_header.rb', line 42 def hash_node @hash_node ||= method_node.each_child_node(:hash).first end |
#header_str ⇒ Object
20 21 22 |
# File 'Library/Homebrew/rubocops/cask/ast/cask_header.rb', line 20 def header_str @header_str ||= source_range.source end |
#pair_node ⇒ Object
46 47 48 |
# File 'Library/Homebrew/rubocops/cask/ast/cask_header.rb', line 46 def pair_node @pair_node ||= hash_node.each_child_node(:pair).first end |
#preferred_header_str ⇒ Object
28 29 30 |
# File 'Library/Homebrew/rubocops/cask/ast/cask_header.rb', line 28 def preferred_header_str "cask '#{cask_token}'" end |
#source_range ⇒ Object
24 25 26 |
# File 'Library/Homebrew/rubocops/cask/ast/cask_header.rb', line 24 def source_range @source_range ||= method_node.loc.expression end |