Class: SystemNavigation::MethodQuery

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

Overview

Since:

  • 0.1.0

Class Method Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(collection, behavior) ⇒ MethodQuery

Returns a new instance of MethodQuery.

Since:

  • 0.1.0



9
10
11
12
# File 'lib/system_navigation/method_query.rb', line 9

def initialize(collection, behavior)
  @collection = collection
  @behavior = behavior
end

Class Method Details

.execute(collection:, query:, behavior: nil, **rest) ⇒ Object

Since:

  • 0.1.0



3
4
5
6
7
# File 'lib/system_navigation/method_query.rb', line 3

def self.execute(collection:, query:, behavior: nil, **rest)
  args = [query]
  args << rest unless rest.empty?
  self.new(collection, behavior).__send__(*args)
end

Instance Method Details

#all_in_the_same_file?Boolean

Returns:

  • (Boolean)

Since:

  • 0.1.0



41
42
43
44
45
# File 'lib/system_navigation/method_query.rb', line 41

def all_in_the_same_file?
  self.instance_and_singleton_do(
    for_all: proc { |_scope, _selectors, method| method.source_location[0] }
  ).as_array.uniq.count == 1
end

#convert_to_methodsObject

Since:

  • 0.1.0



14
15
16
17
18
19
20
21
22
23
24
# File 'lib/system_navigation/method_query.rb', line 14

def convert_to_methods
  self.instance_and_singleton_do(
    for_instance: proc { |_scope, _selectors, selector|
      @behavior.instance_method(selector)
    },

    for_singleton: proc { |_scope, _selectors, selector|
      @behavior.singleton_class.instance_method(selector)
    }
  )
end

#find_accessing_methods(var:, only_set:, only_get:) ⇒ Object

Since:

  • 0.1.0



47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
# File 'lib/system_navigation/method_query.rb', line 47

def find_accessing_methods(var:, only_set:, only_get:)
  self.instance_and_singleton_do(
    for_all: proc { |_scope, _selectors, method|
      compiled_method = CompiledMethod.compile(method)
      if only_set
        compiled_method.unwrap if compiled_method.writes_field?(var)
      elsif only_get
        compiled_method.unwrap if compiled_method.reads_field?(var)
      else
        if compiled_method.reads_field?(var) ||
           compiled_method.writes_field?(var)
          compiled_method.unwrap
        end
      end
    }
  )
end

#find_literal(literal:) ⇒ Object

Since:

  • 0.1.0



32
33
34
35
36
37
38
39
# File 'lib/system_navigation/method_query.rb', line 32

def find_literal(literal:)
  self.instance_and_singleton_do(
    for_all: proc { |_scope, _selectors, method|
      compiled_method = CompiledMethod.compile(method)
      compiled_method.unwrap if compiled_method.has_literal?(literal)
    }
  )
end

#select_sent_messagesObject

Since:

  • 0.1.0



65
66
67
68
69
70
71
72
# File 'lib/system_navigation/method_query.rb', line 65

def select_sent_messages
  self.instance_and_singleton_do(
    for_all: proc { |_scope, _selectors, method|
      compiled_method = CompiledMethod.compile(method)
      compiled_method.sent_messages.uniq.map(&:to_sym)
    }
  )
end

#tupleizeObject

Since:

  • 0.1.0



26
27
28
29
30
# File 'lib/system_navigation/method_query.rb', line 26

def tupleize
  self.instance_and_singleton_do(
    for_all: proc { |_scope, _selectors, method| [method.name, method] }
  )
end