Class: Aspicious::Watcher

Inherits:
Object
  • Object
show all
Defined in:
lib/aspicious/watcher.rb

Instance Attribute Summary collapse

Class Method Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(watchee) ⇒ Watcher



3
4
5
# File 'lib/aspicious/watcher.rb', line 3

def initialize(watchee)
  @watchee = watchee
end

Instance Attribute Details

#watcheeObject (readonly)

Returns the value of attribute watchee.



6
7
8
# File 'lib/aspicious/watcher.rb', line 6

def watchee
  @watchee
end

Class Method Details

.after(method_to_watch, callback, options = {}) ⇒ Object



33
34
35
# File 'lib/aspicious/watcher.rb', line 33

def after(method_to_watch, callback, options={})
  do_watch(method_to_watch, callback, options, :after)
end

.before(method_to_watch, callback, options = {}) ⇒ Object



29
30
31
# File 'lib/aspicious/watcher.rb', line 29

def before(method_to_watch, callback, options={})
  do_watch(method_to_watch, callback, options, :before)
end

.watch(*klasses) ⇒ Object



9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
# File 'lib/aspicious/watcher.rb', line 9

def watch(*klasses)
  @watching ||= []
  klasses.each do |klass|
    @watching << klass
    klass.class_eval "      unless self.instance_methods.include?('watchers')\n        attr_accessor :watchers\n        def watcher_for(klass)\n          self.watchers ||= []\n          unless watcher = self.watchers.detect{|w| w.is_a?(klass)}\n            watcher = klass.new(self)\n            self.watchers << watcher\n          end\n          return watcher\n        end\n      end\n    RUBY\n  end\nend\n", __FILE__, __LINE__