Class: RuboCop::Cask::AST::Stanza
- Extended by:
- Forwardable
- Defined in:
- rubocops/cask/ast/stanza.rb
Overview
This class wraps the AST send/block node that encapsulates the method call that comprises the stanza. It includes various helper methods to aid cops in their analysis.
Instance Attribute Summary collapse
-
#all_comments ⇒ Object
readonly
Returns the value of attribute all_comments.
-
#method_node ⇒ Object
(also: #stanza_node)
readonly
Returns the value of attribute method_node.
Instance Method Summary collapse
-
#==(other) ⇒ Object
(also: #eql?)
-
#comments ⇒ Object
-
#comments_hash ⇒ Object
-
#initialize(method_node, all_comments) ⇒ Stanza
constructor
A new instance of Stanza.
-
#same_group?(other) ⇒ Boolean
-
#source_range ⇒ Object
-
#source_range_with_comments ⇒ Object
-
#stanza_group ⇒ Object
-
#stanza_index ⇒ Object
-
#stanza_name ⇒ Object
Constructor Details
#initialize(method_node, all_comments) ⇒ Stanza
Returns a new instance of Stanza.
15 16 17 18 |
# File 'rubocops/cask/ast/stanza.rb', line 15 def initialize(method_node, all_comments) @method_node = method_node @all_comments = all_comments end |
Instance Attribute Details
#all_comments ⇒ Object (readonly)
Returns the value of attribute all_comments.
20 21 22 |
# File 'rubocops/cask/ast/stanza.rb', line 20 def all_comments @all_comments end |
#method_node ⇒ Object (readonly) Also known as: stanza_node
Returns the value of attribute method_node.
20 21 22 |
# File 'rubocops/cask/ast/stanza.rb', line 20 def method_node @method_node end |
Instance Method Details
#==(other) ⇒ Object Also known as: eql?
70 71 72 |
# File 'rubocops/cask/ast/stanza.rb', line 70 def ==(other) self.class == other.class && stanza_node == other.stanza_node end |
#comments ⇒ Object
60 61 62 63 64 |
# File 'rubocops/cask/ast/stanza.rb', line 60 def comments @comments ||= stanza_node.each_node.reduce([]) do |comments, node| comments | comments_hash[node.loc] end end |
#comments_hash ⇒ Object
66 67 68 |
# File 'rubocops/cask/ast/stanza.rb', line 66 def comments_hash @comments_hash ||= Parser::Source::Comment.associate_locations(stanza_node.parent, all_comments) end |
#same_group?(other) ⇒ Boolean
56 57 58 |
# File 'rubocops/cask/ast/stanza.rb', line 56 def same_group?(other) stanza_group == other.stanza_group end |
#source_range ⇒ Object
28 29 30 |
# File 'rubocops/cask/ast/stanza.rb', line 28 def source_range stanza_node.location_expression end |
#source_range_with_comments ⇒ Object
32 33 34 35 36 |
# File 'rubocops/cask/ast/stanza.rb', line 32 def source_range_with_comments comments.reduce(source_range) do |range, comment| range.join(comment.loc.expression) end end |
#stanza_group ⇒ Object
48 49 50 |
# File 'rubocops/cask/ast/stanza.rb', line 48 def stanza_group Constants::STANZA_GROUP_HASH[stanza_name] end |
#stanza_index ⇒ Object
52 53 54 |
# File 'rubocops/cask/ast/stanza.rb', line 52 def stanza_index Constants::STANZA_ORDER.index(stanza_name) end |
#stanza_name ⇒ Object
42 43 44 45 46 |
# File 'rubocops/cask/ast/stanza.rb', line 42 def stanza_name return :on_arch_conditional if arch_variable? stanza_node.method_name end |