Class: Delfos::Patching::MethodCache

Inherits:
Object
  • Object
show all
Extended by:
Forwardable
Defined in:
lib/delfos/patching/method_cache.rb

Class Method Summary collapse

Instance Method Summary collapse

Constructor Details

#initializeMethodCache

Returns a new instance of MethodCache.



33
34
35
# File 'lib/delfos/patching/method_cache.rb', line 33

def initialize
  @added_methods = {}
end

Class Method Details

.each_methodObject



23
24
25
26
27
28
29
30
# File 'lib/delfos/patching/method_cache.rb', line 23

def each_method
  instance.send(:added_methods).each do |klass, methods|
    methods.each do |k, m|
      class_method = !!(k[/^ClassMethod_/])
      yield klass, m, class_method
    end
  end
end

.instanceObject



19
20
21
# File 'lib/delfos/patching/method_cache.rb', line 19

def instance
  @instance ||= new
end

.reset!Object



15
16
17
# File 'lib/delfos/patching/method_cache.rb', line 15

def reset!
  @instance = nil
end

Instance Method Details

#append(klass:, method:) ⇒ Object



47
48
49
50
51
52
53
# File 'lib/delfos/patching/method_cache.rb', line 47

def append(klass:, method:)
  class_method = method.respond_to?(:receiver) && method.receiver.is_a?(Class)
  key = key_for(class_method, method.name)
  m = fetch(klass)[key]

  fetch(klass)[key] = method if m.nil?
end

#files_for(klass) ⇒ Object



37
38
39
40
41
42
43
44
45
# File 'lib/delfos/patching/method_cache.rb', line 37

def files_for(klass)
  fetch(klass).
    values.
    map(&:source_location).
    compact.
    map(&:first).
    compact.
    uniq
end

#find(klass:, method_name:, class_method:) ⇒ Object



55
56
57
58
59
# File 'lib/delfos/patching/method_cache.rb', line 55

def find(klass:, method_name:, class_method:)
  key = key_for(class_method, method_name)

  fetch(klass)[key]
end