interloper 0.1.3 → 0.1.4
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/lib/interloper/version.rb +1 -1
- data/lib/interloper.rb +28 -16
- 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: 5cb36dfc9e08e0e172e7ac3f0de7bd0c34f46a93
|
4
|
+
data.tar.gz: f29ca06378acd3da798d29772e2db4c2b4ce5e84
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 936220a5ed55ef83bc124bf30a27bad78f6dbc9acd0e1fe4f1e3b56a5e52b0f170a6537823fb3a762257e3e084547d044cceada31d2612874c913ea3a66324c0
|
7
|
+
data.tar.gz: 1d8b52e6d03765526b8b36ea1af14176e21c1d7424b8484ecf98870f251324dba4fa2dd768e9fc9db6d7fcf338681f6d8cd78ebb5acb5640359ba55bc94db920
|
data/lib/interloper/version.rb
CHANGED
data/lib/interloper.rb
CHANGED
@@ -3,7 +3,7 @@ require "interloper/version"
|
|
3
3
|
module Interloper
|
4
4
|
|
5
5
|
def interloper_module
|
6
|
-
self.class.interloper_module
|
6
|
+
@interloper_module ||= self.class.interloper_module
|
7
7
|
end
|
8
8
|
|
9
9
|
def Interloper.included(base)
|
@@ -12,17 +12,25 @@ module Interloper
|
|
12
12
|
|
13
13
|
module ClassMethods
|
14
14
|
|
15
|
-
|
15
|
+
def interloper_const_name
|
16
|
+
if self.name
|
17
|
+
"#{self.name}Interloper"
|
18
|
+
else
|
19
|
+
"AnonymousInterloper#{self.object_id}"
|
20
|
+
end.to_sym
|
21
|
+
end
|
22
|
+
|
23
|
+
# Generates an Interloper module that is namespaced under the including
|
16
24
|
# class, if one does not already exist. Then prepends the Interloper
|
17
25
|
# module to the including class.
|
18
26
|
# @return Module the Interloper module that was prepended to the including
|
19
27
|
# class.
|
20
28
|
def interloper_module
|
21
|
-
|
22
|
-
|
23
|
-
|
24
|
-
|
25
|
-
const_get(
|
29
|
+
unless self.constants.include? interloper_const_name
|
30
|
+
const_set(interloper_const_name, generate_interloper_module)
|
31
|
+
prepend const_get(interloper_const_name)
|
32
|
+
end
|
33
|
+
const_get(interloper_const_name)
|
26
34
|
end
|
27
35
|
|
28
36
|
def generate_interloper_module
|
@@ -77,14 +85,18 @@ module Interloper
|
|
77
85
|
end
|
78
86
|
end
|
79
87
|
|
80
|
-
def define_interloper_methods(*method_names)
|
88
|
+
def define_interloper_methods(*method_names, interloper_module_name)
|
81
89
|
method_names.each do |method_name|
|
82
|
-
|
83
|
-
|
84
|
-
|
85
|
-
|
86
|
-
|
87
|
-
|
90
|
+
unless instance_methods.include? method_name
|
91
|
+
module_eval do
|
92
|
+
eval <<-CODE
|
93
|
+
def #{method_name}(*args, &block)
|
94
|
+
self.class.const_get(:#{interloper_module_name}).run_callbacks(:before, :#{method_name}, self, *args, &block)
|
95
|
+
super(*args, &block)
|
96
|
+
self.class.const_get(:#{interloper_module_name}).run_callbacks(:after, :#{method_name}, self, *args, &block)
|
97
|
+
end
|
98
|
+
CODE
|
99
|
+
end
|
88
100
|
end
|
89
101
|
end
|
90
102
|
end
|
@@ -93,12 +105,12 @@ module Interloper
|
|
93
105
|
end
|
94
106
|
|
95
107
|
def before(*method_names, &callback)
|
96
|
-
interloper_module.define_interloper_methods(*method_names)
|
108
|
+
interloper_module.define_interloper_methods(*method_names, interloper_const_name)
|
97
109
|
interloper_module.add_callbacks(:before, *method_names, &callback)
|
98
110
|
end
|
99
111
|
|
100
112
|
def after(*method_names, &callback)
|
101
|
-
interloper_module.define_interloper_methods(*method_names)
|
113
|
+
interloper_module.define_interloper_methods(*method_names, interloper_const_name)
|
102
114
|
interloper_module.add_callbacks(:after, *method_names, &callback)
|
103
115
|
end
|
104
116
|
end
|
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: interloper
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.1.
|
4
|
+
version: 0.1.4
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Andrew Myers
|
8
8
|
autorequire:
|
9
9
|
bindir: exe
|
10
10
|
cert_chain: []
|
11
|
-
date: 2017-10-
|
11
|
+
date: 2017-10-25 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: bundler
|