Class: RuboCopMethodOrder::PublicMethodNodeCollection

Inherits:
MethodNodeCollection show all
Defined in:
lib/rubocop_method_order/public_method_node_collection.rb

Overview

Hold collection of public instance methods that has custom sorted order.

Instance Attribute Summary

Attributes inherited from MethodNodeCollection

#nodes

Instance Method Summary collapse

Methods inherited from MethodNodeCollection

#offenses, #replacements

Constructor Details

#initializePublicMethodNodeCollection

Returns a new instance of PublicMethodNodeCollection.



6
7
8
9
# File 'lib/rubocop_method_order/public_method_node_collection.rb', line 6

def initialize
  @initialize_node = nil
  super
end

Instance Method Details

#push(method_node) ⇒ Object



11
12
13
14
# File 'lib/rubocop_method_order/public_method_node_collection.rb', line 11

def push(method_node)
  @initialize_node = method_node if method_node.method_name == :initialize
  super(method_node)
end

#sort(one, two) ⇒ Object



16
17
18
19
20
21
22
23
# File 'lib/rubocop_method_order/public_method_node_collection.rb', line 16

def sort(one, two)
  if @initialize_node
    return 0 if one == @initialize_node && two == @initialize_node
    return -1 if one == @initialize_node
    return 1 if two == @initialize_node
  end
  super
end