Class: Putter::Watcher

Inherits:
Object
  • Object
show all
Extended by:
MethodCreator
Defined in:
lib/putter/watcher.rb

Class Method Summary collapse

Methods included from MethodCreator

add_putter_method_to_proxy

Class Method Details

._set_label(label, class_name) ⇒ Object



45
46
47
48
49
50
51
# File 'lib/putter/watcher.rb', line 45

def self._set_label(label, class_name)
  if !label.nil? && label != ""
    @label = label
  else
    @label = class_name
  end
end

.class_proxy(klass) ⇒ Object



16
17
18
19
20
21
22
23
24
25
# File 'lib/putter/watcher.rb', line 16

def self.class_proxy(klass)
  proxy = MethodProxy.new

  methods_to_proxy(klass).each do |method|
    data = ProxyMethodData.new(method, label)
    add_putter_method_to_proxy(proxy, :module_exec, data)
  end

  proxy
end

.labelObject



37
38
39
# File 'lib/putter/watcher.rb', line 37

def self.label
  @label
end

.label=(label) ⇒ Object



41
42
43
# File 'lib/putter/watcher.rb', line 41

def self.label=(label)
  @label = label
end

.methods_to_proxy(klass) ⇒ Object



27
28
29
30
31
32
33
34
35
# File 'lib/putter/watcher.rb', line 27

def self.methods_to_proxy(klass)
  ignored_methods = []

  Putter.configuration.ignore_methods_from.each do |klass|
    ignored_methods += klass.methods
  end

  klass.instance_methods - ignored_methods + Putter.configuration.methods_whitelist.map(&:to_sym) + [:new]
end

.watch(obj, options = {}) ⇒ Object



7
8
9
10
11
12
13
14
# File 'lib/putter/watcher.rb', line 7

def self.watch(obj, options={})
  _set_label(options[:label], obj.name)

  class << obj
    prepend InstanceFollower
    prepend Putter::Watcher.class_proxy(self)
  end
end