hooks 0.3.5 → 0.3.6
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/CHANGES.md +4 -0
- data/hooks.gemspec +1 -1
- data/lib/hooks.rb +1 -0
- data/lib/hooks/hook.rb +7 -5
- data/lib/hooks/version.rb +1 -1
- data/test/hook_test.rb +1 -1
- data/test/hooks_test.rb +6 -6
- data/test/instance_hooks_test.rb +2 -2
- data/test/test_helper.rb +6 -0
- 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: 3d492829007f205fe193790c8ffb3f1357dc0e3e
|
4
|
+
data.tar.gz: c91b0ddaba7851ba19f668987d8f2b3e3fc16592
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 2663911770685b2657e4e31e2a09781e060668bc8b2ba49294e02a35591b071d7a456b2e9ce42aaee954b0fa50e8dfd382618962d89344438842650066c0094e
|
7
|
+
data.tar.gz: 79f902652386af0c587b3c147010622190b3030b42c6733dafc97294610993c4afeee41c578c13ab2f28a554db96d2880b6edf89d3846a5152b73ad15c8f9ddc
|
data/CHANGES.md
CHANGED
data/hooks.gemspec
CHANGED
data/lib/hooks.rb
CHANGED
data/lib/hooks/hook.rb
CHANGED
@@ -1,3 +1,5 @@
|
|
1
|
+
require 'uber/options'
|
2
|
+
|
1
3
|
module Hooks
|
2
4
|
class Hook < Array
|
3
5
|
def initialize(options)
|
@@ -42,13 +44,13 @@ module Hooks
|
|
42
44
|
end
|
43
45
|
end
|
44
46
|
|
47
|
+
def <<(callback)
|
48
|
+
super Uber::Options::Value.new(callback, :dynamic => true) # allows string and symbol method names.
|
49
|
+
end
|
50
|
+
|
45
51
|
private
|
46
52
|
def execute_callback(scope, callback, *args)
|
47
|
-
|
48
|
-
scope.send(callback, *args)
|
49
|
-
else
|
50
|
-
scope.instance_exec(*args, &callback)
|
51
|
-
end
|
53
|
+
callback.evaluate(scope, *args) # from Uber::Options::Value.
|
52
54
|
end
|
53
55
|
|
54
56
|
def continue_execution?(result)
|
data/lib/hooks/version.rb
CHANGED
data/test/hook_test.rb
CHANGED
data/test/hooks_test.rb
CHANGED
@@ -22,7 +22,7 @@ class HooksTest < MiniTest::Spec
|
|
22
22
|
it "respond to Class.callbacks_for_hook" do
|
23
23
|
assert_equal [], klass.callbacks_for_hook(:after_eight)
|
24
24
|
klass.after_eight :dine
|
25
|
-
assert_equal [:dine], klass.callbacks_for_hook(:after_eight)
|
25
|
+
assert_equal [:dine], klass.callbacks_for_hook(:after_eight).map(&:to_sym)
|
26
26
|
end
|
27
27
|
|
28
28
|
it 'symbolizes strings when defining a hook' do
|
@@ -41,19 +41,19 @@ class HooksTest < MiniTest::Spec
|
|
41
41
|
describe "creates a public writer for the hook that" do
|
42
42
|
it "accepts method names" do
|
43
43
|
klass.after_eight :dine
|
44
|
-
assert_equal [:dine], klass._hooks[:after_eight]
|
44
|
+
assert_equal [:dine], klass._hooks[:after_eight].map(&:to_sym)
|
45
45
|
end
|
46
46
|
|
47
47
|
it "accepts blocks" do
|
48
48
|
klass.after_eight do true; end
|
49
|
-
assert klass._hooks[:after_eight].first.kind_of? Proc
|
49
|
+
assert klass._hooks[:after_eight].first.to_sym.kind_of? Proc
|
50
50
|
end
|
51
51
|
|
52
52
|
it "be inherited" do
|
53
53
|
klass.after_eight :dine
|
54
54
|
subklass = Class.new(klass)
|
55
55
|
|
56
|
-
assert_equal [:dine], subklass._hooks[:after_eight]
|
56
|
+
assert_equal [:dine], subklass._hooks[:after_eight].map(&:to_sym)
|
57
57
|
end
|
58
58
|
# TODO: check if options are not shared!
|
59
59
|
end
|
@@ -187,11 +187,11 @@ class HooksTest < MiniTest::Spec
|
|
187
187
|
let (:subclass) { Class.new(superclass) do after_eight :have_dinner end }
|
188
188
|
|
189
189
|
it "inherits callbacks from the hook" do
|
190
|
-
subclass.callbacks_for_hook(:after_eight).must_equal [:take_shower, :have_dinner]
|
190
|
+
subclass.callbacks_for_hook(:after_eight).map(&:to_sym).must_equal [:take_shower, :have_dinner]
|
191
191
|
end
|
192
192
|
|
193
193
|
it "doesn't mix up superclass hooks" do
|
194
|
-
subclass.superclass.callbacks_for_hook(:after_eight).must_equal [:take_shower]
|
194
|
+
subclass.superclass.callbacks_for_hook(:after_eight).map(&:to_sym).must_equal [:take_shower]
|
195
195
|
end
|
196
196
|
end
|
197
197
|
end
|
data/test/instance_hooks_test.rb
CHANGED
@@ -22,7 +22,7 @@ class InstanceHooksTest < HooksTest
|
|
22
22
|
klass.define_hook :after_eight
|
23
23
|
klass.after_eight :dine
|
24
24
|
|
25
|
-
assert_equal [:dine], subject.callbacks_for_hook(:after_eight)
|
25
|
+
assert_equal [:dine], subject.callbacks_for_hook(:after_eight).map(&:to_sym)
|
26
26
|
end
|
27
27
|
|
28
28
|
describe "#after_eight (adding callbacks)" do
|
@@ -32,7 +32,7 @@ class InstanceHooksTest < HooksTest
|
|
32
32
|
end
|
33
33
|
|
34
34
|
it "adds #after_eight hook" do
|
35
|
-
assert_equal [:dine], subject.callbacks_for_hook(:after_eight)
|
35
|
+
assert_equal [:dine], subject.callbacks_for_hook(:after_eight).map(&:to_sym)
|
36
36
|
end
|
37
37
|
|
38
38
|
it "responds to #run_hook" do
|
data/test/test_helper.rb
CHANGED
metadata
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: hooks
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.3.
|
4
|
+
version: 0.3.6
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Nick Sutterer
|
@@ -16,14 +16,14 @@ dependencies:
|
|
16
16
|
requirements:
|
17
17
|
- - ~>
|
18
18
|
- !ruby/object:Gem::Version
|
19
|
-
version: 0.0.
|
19
|
+
version: 0.0.4
|
20
20
|
type: :runtime
|
21
21
|
prerelease: false
|
22
22
|
version_requirements: !ruby/object:Gem::Requirement
|
23
23
|
requirements:
|
24
24
|
- - ~>
|
25
25
|
- !ruby/object:Gem::Version
|
26
|
-
version: 0.0.
|
26
|
+
version: 0.0.4
|
27
27
|
- !ruby/object:Gem::Dependency
|
28
28
|
name: minitest
|
29
29
|
requirement: !ruby/object:Gem::Requirement
|