call_me_ruby 1.0.2 → 1.1.0
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/README.md +2 -4
- data/lib/call_me_ruby.rb +12 -9
- metadata +3 -3
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 4e6e02413c6182d502789c0490bc3def4abeaca0
|
4
|
+
data.tar.gz: 60369859b5d6f97370ae84ad395d3d16d340701f
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: b75fa99c0513f9d650caa07eba047e43097519164c4c054191407be3bab45475f9cdac806cfea53583ff47ff28f0a2e4295a90f971913e8f83ebef140e5ccd58
|
7
|
+
data.tar.gz: b23dcc096039d15454e8035a824f9d16b37b5cb6f7dfbb977dc543855f66783a2892b3d1eacaf6b8c5f9975b8245e5ff0184ad26c737d6027b120673860e62cb
|
data/README.md
CHANGED
@@ -32,12 +32,10 @@ class MyAmazingClass
|
|
32
32
|
|
33
33
|
def will_succeed
|
34
34
|
puts 'foo'
|
35
|
-
# If a callback returns a "truthy" value, than it's considered to have succeeded. However...
|
36
|
-
true
|
37
35
|
end
|
38
36
|
|
39
|
-
def
|
40
|
-
# If a callback returns
|
37
|
+
def will_fail
|
38
|
+
# If a callback returns false, then no more callbacks will be called and publish will return false. If
|
41
39
|
# all callbacks succeed, then publish will return true. Use this to make things fail fast as you need.
|
42
40
|
false
|
43
41
|
end
|
data/lib/call_me_ruby.rb
CHANGED
@@ -20,10 +20,9 @@ module CallMeRuby
|
|
20
20
|
@class_callbacks ||= Hash.new { |h, k| h[k] = [] }
|
21
21
|
end
|
22
22
|
|
23
|
-
def subscribe(*
|
24
|
-
|
25
|
-
|
26
|
-
end
|
23
|
+
def subscribe(name, *methods, &block)
|
24
|
+
methods.each { |method| class_callbacks[name] << method }
|
25
|
+
class_callbacks[name] << block if block_given?
|
27
26
|
end
|
28
27
|
end
|
29
28
|
|
@@ -31,17 +30,21 @@ module CallMeRuby
|
|
31
30
|
@callbacks ||= Hash.new { |h, k| h[k] = [] }
|
32
31
|
end
|
33
32
|
|
34
|
-
def subscribe(*
|
35
|
-
|
36
|
-
|
37
|
-
end
|
33
|
+
def subscribe(name, *methods, &block)
|
34
|
+
methods.each { |method| callbacks[name] << method }
|
35
|
+
callbacks[name] << block if block_given?
|
38
36
|
end
|
39
37
|
|
40
38
|
def publish(name, *args)
|
41
39
|
class_callback_methods = self.class.class_callbacks[name]
|
42
40
|
callback_methods = callbacks[name]
|
43
41
|
|
44
|
-
(class_callback_methods + callback_methods).each
|
42
|
+
(class_callback_methods + callback_methods).each do |callback|
|
43
|
+
result = (callback.respond_to?(:call) ? callback.call(*args) : send(callback, *args))
|
44
|
+
# Exit early if the block explicitly returns `false`.
|
45
|
+
return false if result == false
|
46
|
+
end
|
47
|
+
|
45
48
|
true
|
46
49
|
end
|
47
50
|
end
|
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: call_me_ruby
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 1.0
|
4
|
+
version: 1.1.0
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Nathan Kleyn
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date: 2015-
|
11
|
+
date: 2015-09-19 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: coveralls
|
@@ -123,7 +123,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
|
|
123
123
|
version: '0'
|
124
124
|
requirements: []
|
125
125
|
rubyforge_project:
|
126
|
-
rubygems_version: 2.4.5
|
126
|
+
rubygems_version: 2.4.5.1
|
127
127
|
signing_key:
|
128
128
|
specification_version: 4
|
129
129
|
summary: Simple, declarative, ActiveModel style callbacks (aka hooks or events) in
|