Class: Putter::WatcherData

Inherits:
Object
  • Object
show all
Defined in:
lib/putter/watcher_data.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(options, klass) ⇒ WatcherData

Returns a new instance of WatcherData.



5
6
7
8
# File 'lib/putter/watcher_data.rb', line 5

def initialize(options, klass)
  @label = set_label(options[:label], klass)
  @proxy_methods = set_methods(options[:methods], klass.singleton_class)
end

Instance Attribute Details

#labelObject

Returns the value of attribute label.



3
4
5
# File 'lib/putter/watcher_data.rb', line 3

def label
  @label
end

#proxy_methodsObject

Returns the value of attribute proxy_methods.



3
4
5
# File 'lib/putter/watcher_data.rb', line 3

def proxy_methods
  @proxy_methods
end

Instance Method Details

#methods_to_proxy(singleton_klass) ⇒ Object



28
29
30
31
32
33
34
35
36
37
38
# File 'lib/putter/watcher_data.rb', line 28

def methods_to_proxy(singleton_klass)
  ignored_methods = Putter.configuration.methods_blacklist.map(&:to_sym)

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

  whitelist = Putter.configuration.methods_whitelist.map(&:to_sym) + [:new]

  singleton_klass.instance_methods - ignored_methods + whitelist
end

#set_label(label, klass) ⇒ Object



10
11
12
13
14
15
16
# File 'lib/putter/watcher_data.rb', line 10

def set_label(label, klass)
  if !label.nil? && label != ""
    label
  else
    klass.name
  end
end

#set_methods(methods, singleton_klass) ⇒ Object



18
19
20
21
22
23
24
25
26
# File 'lib/putter/watcher_data.rb', line 18

def set_methods(methods, singleton_klass)
  if methods.nil?
    methods_to_proxy(singleton_klass)
  elsif !methods.is_a?(Array)
    [methods]
  else
    methods
  end
end