Class: SystemNavigation::AncestorMethodFinder

Inherits:
Object
  • Object
show all
Defined in:
lib/system_navigation/ancestor_method_finder.rb

Overview

Since:

  • 0.1.0

Class Method Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(behavior) ⇒ AncestorMethodFinder

Returns a new instance of AncestorMethodFinder.

Since:

  • 0.1.0



17
18
19
20
# File 'lib/system_navigation/ancestor_method_finder.rb', line 17

def initialize(behavior)
  @behavior = behavior
  @ancestor_list = behavior.ancestors - [behavior]
end

Class Method Details

.find_all_ancestors(of:) ⇒ Object

Since:

  • 0.1.0



5
6
7
8
9
10
11
12
13
14
15
# File 'lib/system_navigation/ancestor_method_finder.rb', line 5

def self.find_all_ancestors(of:)
  finder = self.new(of)
  singleton_finder = self.new(of.singleton_class)

  ancestor_list = []

  ancestor_list.concat(finder.find_all_methods)
  ancestor_list.concat(singleton_finder.find_all_methods)

  ancestor_list
end

Instance Method Details

#find_all_methodsObject

Since:

  • 0.1.0



22
23
24
25
26
27
28
29
30
31
32
# File 'lib/system_navigation/ancestor_method_finder.rb', line 22

def find_all_methods
  self.find_closest_ancestors(@ancestor_list).flat_map do |ancestor|
    selectors = MethodHash.create(based_on: ancestor, include_super: false)
    # No inheritance for singletons in Ruby
    [:public, :private, :protected].each { |t| selectors[t][:singleton] = [] }

    MethodQuery.execute(collection: selectors,
                        query: :convert_to_methods,
                        behavior: @behavior)
  end
end