cpt_hook 0.1.0 → 0.2.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- checksums.yaml +4 -4
- data/lib/cpt_hook/hookable.rb +5 -4
- data/lib/cpt_hook/version.rb +1 -1
- metadata +2 -2
checksums.yaml
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
---
|
|
2
2
|
SHA1:
|
|
3
|
-
metadata.gz:
|
|
4
|
-
data.tar.gz:
|
|
3
|
+
metadata.gz: 97f08b3f7392783b1b9251d4775c486ce79c99e5
|
|
4
|
+
data.tar.gz: 5d685bcb264b6444e26be5d4881897b2d944a8d7
|
|
5
5
|
SHA512:
|
|
6
|
-
metadata.gz:
|
|
7
|
-
data.tar.gz:
|
|
6
|
+
metadata.gz: 778b3c11d8960046f7d80b0d19b3afd570611eb5578c04e5ab6320a576f784984d3bf0149d5e51fae950e26eaa46d8392e98b240a0a592a6727a9afb2f65380c
|
|
7
|
+
data.tar.gz: da271dbea04cb3afae2665e7f7472b3ef6633cc4b81d33f54aff580652d9ff49f061f80f94416b429330d58d845f48f7425be8fc9f3f0cc033e1b14ce8498c94
|
data/lib/cpt_hook/hookable.rb
CHANGED
|
@@ -10,7 +10,6 @@ module CptHook
|
|
|
10
10
|
super(obj)
|
|
11
11
|
|
|
12
12
|
additional_contexts = [additional_contexts] unless additional_contexts.is_a?(Array)
|
|
13
|
-
|
|
14
13
|
_add_hooks(:before, method_hooks, additional_contexts)
|
|
15
14
|
_add_hooks(:after, method_hooks, additional_contexts)
|
|
16
15
|
|
|
@@ -35,13 +34,15 @@ module CptHook
|
|
|
35
34
|
method_hooks.select {|hook| hook.key?(which)}.each do |hook|
|
|
36
35
|
hook[:contexts] = hook.fetch(:contexts, []).concat(additional_contexts)
|
|
37
36
|
define_singleton_method("#{which}_#{hook[which]}") do |*args, &block|
|
|
38
|
-
hook[:
|
|
37
|
+
hook[:call_chain].each do |call_chain|
|
|
38
|
+
call_args = call_chain.fetch(:with, [])
|
|
39
|
+
hook_fn = call_chain[:call]
|
|
39
40
|
if hook_fn.is_a?(Proc)
|
|
40
|
-
hook_fn.call
|
|
41
|
+
hook_fn.call(*call_args)
|
|
41
42
|
else
|
|
42
43
|
context = hook[:contexts].unshift(__getobj__).find {|c| c.respond_to?(hook_fn)}
|
|
43
44
|
raise "No context found for #{which} hook: #{hook_fn}" unless context
|
|
44
|
-
context.send(hook_fn)
|
|
45
|
+
context.send(hook_fn, *call_args)
|
|
45
46
|
end
|
|
46
47
|
end
|
|
47
48
|
end
|
data/lib/cpt_hook/version.rb
CHANGED
metadata
CHANGED
|
@@ -1,14 +1,14 @@
|
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
|
2
2
|
name: cpt_hook
|
|
3
3
|
version: !ruby/object:Gem::Version
|
|
4
|
-
version: 0.
|
|
4
|
+
version: 0.2.0
|
|
5
5
|
platform: ruby
|
|
6
6
|
authors:
|
|
7
7
|
- JDonavan
|
|
8
8
|
autorequire:
|
|
9
9
|
bindir: exe
|
|
10
10
|
cert_chain: []
|
|
11
|
-
date: 2017-11-
|
|
11
|
+
date: 2017-11-27 00:00:00.000000000 Z
|
|
12
12
|
dependencies:
|
|
13
13
|
- !ruby/object:Gem::Dependency
|
|
14
14
|
name: bundler
|