ruby_events 0.0.8 → 1.0.0

Sign up to get free protection for your applications and to get access to all the features.
Files changed (4) hide show
  1. data/README.markdown +4 -3
  2. data/Rakefile +2 -1
  3. data/lib/ruby_events.rb +9 -10
  4. metadata +4 -4
data/README.markdown CHANGED
@@ -42,8 +42,9 @@ You can do cooler and more advanced things, like add listeners to an Array:
42
42
  end
43
43
  end
44
44
 
45
- a.events.listen(:injected) do |event_data|
46
- puts event_data;
45
+ a.events.listen(:injected) do |a, item|
46
+ puts a
47
+ puts item
47
48
  end
48
49
 
49
50
  a.inject('This is a test')
@@ -54,7 +55,7 @@ a little bit of sugar:
54
55
  a = []
55
56
  a.events.fire_on_method('<<'.to_sym, :item_injected)
56
57
  a.events.listen(:injected) do |event_data|
57
- puts event_data;
58
+ puts event_data
58
59
  end
59
60
 
60
61
  a << 'this is a test'
data/Rakefile CHANGED
@@ -2,6 +2,7 @@
2
2
  # To change this template, choose Tools | Templates
3
3
  # and open the template in the editor.
4
4
 
5
+ require 'lib/ruby_events'
5
6
  require 'rubygems'
6
7
  require 'rake'
7
8
  require 'rake/clean'
@@ -11,7 +12,7 @@ require 'rake/testtask'
11
12
 
12
13
  spec = Gem::Specification.new do |s|
13
14
  s.name = 'ruby_events'
14
- s.version = '0.0.8'
15
+ s.version = RubyEvents::Events.version
15
16
  s.has_rdoc = true
16
17
  s.extra_rdoc_files = ['README.markdown']
17
18
  s.summary = 'A really simple event implementation that hooks into the Object class. Now all your objects can join in the fun of firing events!'
data/lib/ruby_events.rb CHANGED
@@ -9,7 +9,7 @@ module RubyEvents
9
9
  class Events
10
10
  # The current version of RubyEvents.
11
11
  def self.version
12
- '0.0.8'
12
+ '1.0.0'
13
13
  end
14
14
 
15
15
  # Initialize the events class by instantiating the class methods we'll be
@@ -43,19 +43,18 @@ module RubyEvents
43
43
  # Set an event to fire when passed method is called. This is useful for
44
44
  # adding callbacks or events to built-in methods.
45
45
  def fire_on_method(method, event_type, &block)
46
- parent = @parent
47
- method_s = method.to_s
48
- old_method = ('ruby_events_' + method_s + '_event_old').to_sym
49
- old_method_s = old_method.to_s
46
+ # We alias @parent to parent here, because class_eval can't see outside
47
+ # this scope otherwise.
48
+ parent, old_method = @parent, ('ruby_events_' + method.to_s + '_event_old').to_sym
50
49
  if parent && parent.respond_to?(method)
51
50
  parent.class.class_eval do
52
51
  # If the parent is already responding to the alias method, it means
53
52
  # the fire_on_method event was already triggered. Remove the other
54
53
  # event and continue if this happens.
55
54
  if parent.respond_to?(old_method, true)
56
- undef_method method
55
+ remove_method method
57
56
  alias_method method, old_method
58
- undef_method old_method
57
+ remove_method old_method
59
58
  end
60
59
 
61
60
  alias_method old_method, method
@@ -63,14 +62,14 @@ module RubyEvents
63
62
 
64
63
  # Make sure the self.send is at the end, or we won't return what we
65
64
  # are supposed to.
66
- define_method "#{method_s}" do |*args|
65
+ define_method method do |*args|
67
66
  events.fire(event_type, *args)
68
- block.call(*args) if(block) # Calling the block we've been passed
67
+ block.call(*args) if block # Calling the block we've been passed
69
68
  __send__(old_method, *args)
70
69
  end
71
70
  end
72
71
  else
73
- # TODO: Need to raise exception here.
72
+ raise RuntimeError.new('The given object does not respond to method you are trying to intercept calls to.')
74
73
  end
75
74
  end
76
75
 
metadata CHANGED
@@ -1,13 +1,13 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: ruby_events
3
3
  version: !ruby/object:Gem::Version
4
- hash: 15
4
+ hash: 23
5
5
  prerelease: false
6
6
  segments:
7
+ - 1
7
8
  - 0
8
9
  - 0
9
- - 8
10
- version: 0.0.8
10
+ version: 1.0.0
11
11
  platform: ruby
12
12
  authors:
13
13
  - Nathan Kleyn
@@ -15,7 +15,7 @@ autorequire:
15
15
  bindir: bin
16
16
  cert_chain: []
17
17
 
18
- date: 2010-05-18 00:00:00 +01:00
18
+ date: 2010-09-06 00:00:00 +01:00
19
19
  default_executable:
20
20
  dependencies: []
21
21