Class: RuboCop::Cask::AST::Stanza
- Inherits:
-
Object
- Object
- RuboCop::Cask::AST::Stanza
- Extended by:
- Forwardable
- Defined in:
- lib/rubocop/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
-
#comments ⇒ Object
readonly
Returns the value of attribute comments.
-
#method_node ⇒ Object
(also: #stanza_node)
readonly
Returns the value of attribute method_node.
Instance Method Summary collapse
- #==(other) ⇒ Object (also: #eql?)
-
#initialize(method_node, comments) ⇒ Stanza
constructor
A new instance of Stanza.
- #same_group?(other) ⇒ Boolean
- #source_range ⇒ Object
- #source_range_with_comments ⇒ Object
- #stanza_group ⇒ Object
- #toplevel_stanza? ⇒ Boolean
Constructor Details
#initialize(method_node, comments) ⇒ Stanza
Returns a new instance of Stanza.
12 13 14 15 |
# File 'lib/rubocop/cask/ast/stanza.rb', line 12 def initialize(method_node, comments) @method_node = method_node @comments = comments end |
Instance Attribute Details
#comments ⇒ Object (readonly)
Returns the value of attribute comments.
17 18 19 |
# File 'lib/rubocop/cask/ast/stanza.rb', line 17 def comments @comments end |
#method_node ⇒ Object (readonly) Also known as: stanza_node
Returns the value of attribute method_node.
17 18 19 |
# File 'lib/rubocop/cask/ast/stanza.rb', line 17 def method_node @method_node end |
Instance Method Details
#==(other) ⇒ Object Also known as: eql?
50 51 52 |
# File 'lib/rubocop/cask/ast/stanza.rb', line 50 def ==(other) self.class == other.class && stanza_node == other.stanza_node end |
#same_group?(other) ⇒ Boolean
42 43 44 |
# File 'lib/rubocop/cask/ast/stanza.rb', line 42 def same_group?(other) stanza_group == other.stanza_group end |
#source_range ⇒ Object
24 25 26 |
# File 'lib/rubocop/cask/ast/stanza.rb', line 24 def source_range stanza_node.expression end |
#source_range_with_comments ⇒ Object
28 29 30 31 32 |
# File 'lib/rubocop/cask/ast/stanza.rb', line 28 def source_range_with_comments comments.reduce(source_range) do |range, comment| range.join(comment.loc.expression) end end |
#stanza_group ⇒ Object
38 39 40 |
# File 'lib/rubocop/cask/ast/stanza.rb', line 38 def stanza_group Constants::STANZA_GROUP_HASH[stanza_name] end |
#toplevel_stanza? ⇒ Boolean
46 47 48 |
# File 'lib/rubocop/cask/ast/stanza.rb', line 46 def toplevel_stanza? parent_node.cask_block? || parent_node.parent.cask_block? end |