django_signal 1.0.2 → 1.1.0

Sign up to get free protection for your applications and to get access to all the features.
Files changed (2) hide show
  1. data/lib/django_signal.rb +15 -10
  2. metadata +1 -1
@@ -13,6 +13,7 @@ require 'weakref'
13
13
  # * No providing_args, since they had no functional relevance.
14
14
  #
15
15
  class DjangoSignal
16
+ class InvalidReceiver < StandardError; end
16
17
  #
17
18
  # Create a new signal.
18
19
  #
@@ -24,7 +25,8 @@ class DjangoSignal
24
25
  #
25
26
  # Connect receiver to sender for signal.
26
27
  #
27
- # +receiver+:: A callable which is to receive signals.
28
+ # +receiver+:: A callable which is to receive signals. The receiver must
29
+ # be able to handler 2+ arguments (+signal, sender, *send_args+).
28
30
  # If dispatch_uid is given, the receiver will not be added if
29
31
  # another receiver already exists with that dispatch_uid.
30
32
  # +sender+:: The sender to which the receiver should respond or nil to
@@ -36,6 +38,16 @@ class DjangoSignal
36
38
  def connect(receiver, sender=nil, dispatch_uid=nil)
37
39
  lookup_key = make_key(receiver, sender, dispatch_uid)
38
40
 
41
+ begin
42
+ receiver.method(:call) rescue nil or raise NoMethodError
43
+ if -1 < receiver.arity && receiver.arity < 2
44
+ raise InvalidReceiver, 'Receiver must be able to handle 2+ arguments.'
45
+ end
46
+ rescue NoMethodError
47
+ raise InvalidReceiver, 'Receiver must be a callable (and respond to arity method).'
48
+ end
49
+
50
+
39
51
  @lock.synchronize {
40
52
  @receivers[lookup_key] ||= receiver
41
53
  }
@@ -100,15 +112,8 @@ class DjangoSignal
100
112
  end
101
113
 
102
114
  def simple_call(receiver, sender, *args)
103
- opts = {}
104
- if args.last.is_a?(Hash)
105
- opts = args.pop
106
- end
107
- opts.merge!(
108
- :signal => self,
109
- :sender => sender
110
- )
111
- args.push(opts)
115
+ args.unshift(sender)
116
+ args.unshift(self)
112
117
 
113
118
  receiver.call(*args)
114
119
  end
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: django_signal
3
3
  version: !ruby/object:Gem::Version
4
- version: 1.0.2
4
+ version: 1.1.0
5
5
  prerelease:
6
6
  platform: ruby
7
7
  authors: