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.
Files changed (4) hide show
  1. checksums.yaml +4 -4
  2. data/README.md +2 -4
  3. data/lib/call_me_ruby.rb +12 -9
  4. metadata +3 -3
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: 07e566f61c0d73b151e6682991fd421c59ff53c8
4
- data.tar.gz: 9d481c38e3d49d5a25298f632c82d227aa507292
3
+ metadata.gz: 4e6e02413c6182d502789c0490bc3def4abeaca0
4
+ data.tar.gz: 60369859b5d6f97370ae84ad395d3d16d340701f
5
5
  SHA512:
6
- metadata.gz: 9f35fdd93b9dda001c3904767e01d9fd80fb1b2b66601cb4ce8a654f5e706c44574a25f641fa6e2afc528084cfd58aa7bbdabf1eca8bc5aa64244f23d160d9ca
7
- data.tar.gz: 69ab0b289154d59d56ec4ee607288eb605553aa683f1eedddd289a565956723c9aeb0fa5add5fa07b9e911006f85f60f421b1a37273033ccdba73ac11780e372
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 bar
40
- # If a callback returns a "falsy" value, then no more callbacks will be called and publish will return false. If
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(*names, sym)
24
- names.each do |name|
25
- class_callbacks[name] << sym
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(*names, sym)
35
- names.each do |name|
36
- callbacks[name] << sym
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 { |method| return false unless send(method, *args) }
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.2
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-02-02 00:00:00.000000000 Z
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