abstriker 0.1.0 → 0.1.2
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/README.md +24 -0
- data/lib/abstriker.rb +29 -9
- data/lib/abstriker/version.rb +1 -1
- metadata +2 -2
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 9084bf87aeeb1ffa9f9ec57310d709c57f30ad039154c384720793eea694c632
|
4
|
+
data.tar.gz: 6ee676d5a9a1229d38ed3a4ae2b7a4e1fe07cd3f5b1100954e0f42cdd1cb9e66
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 01d1026f053c0fe15266eeeba49e0795f87537e6393a0c326e8ccb6e26756792e087705a0a121c442494d46253b4eb985a668e7408077620b19faa999af30673
|
7
|
+
data.tar.gz: a5f838cca75e71629eb62645a78ae851962c361290d448ec5d14bec066a6dfc2d45be57e4cbf917920ce800ae6e9f6cb77e9fa511ded96793ef86c263281fb8e
|
data/README.md
CHANGED
@@ -1,4 +1,5 @@
|
|
1
1
|
# Abstriker
|
2
|
+
[![Build Status](https://travis-ci.org/joker1007/abstriker.svg?branch=master)](https://travis-ci.org/joker1007/abstriker)
|
2
3
|
|
3
4
|
This gem adds `abstract` syntax. that is similar to Java's one.
|
4
5
|
`abstract` modified method requires subclass implementation.
|
@@ -48,6 +49,29 @@ end # => raise
|
|
48
49
|
If you want to disable Abstriker, write `Abstriker.disable = true` at first line.
|
49
50
|
If Abstriker is disabled, TracePoint never runs, and so there is no overhead of VM instruction.
|
50
51
|
|
52
|
+
### Caution
|
53
|
+
|
54
|
+
Must not call `include` or `extend` abstracted module outer class definition.
|
55
|
+
|
56
|
+
ex.
|
57
|
+
|
58
|
+
```ruby
|
59
|
+
module A1
|
60
|
+
extend Abstriker
|
61
|
+
|
62
|
+
abstract def foo
|
63
|
+
end
|
64
|
+
end
|
65
|
+
|
66
|
+
class A2;
|
67
|
+
end
|
68
|
+
|
69
|
+
A2.include(A1) # => Don't do this
|
70
|
+
```
|
71
|
+
|
72
|
+
This case leaves enabled TracePoint.
|
73
|
+
It is very high overhead.
|
74
|
+
|
51
75
|
### Examples
|
52
76
|
|
53
77
|
#### include module
|
data/lib/abstriker.rb
CHANGED
@@ -52,11 +52,23 @@ module Abstriker
|
|
52
52
|
private
|
53
53
|
|
54
54
|
def detect_event_type
|
55
|
-
|
56
|
-
if
|
57
|
-
[
|
58
|
-
|
59
|
-
|
55
|
+
callers = caller_locations(2, 3)
|
56
|
+
if callers[0].label == "inherited"
|
57
|
+
caller_info = callers[2]
|
58
|
+
if caller_info.label.match?(/initialize/) || caller_info.label.match?(/new/)
|
59
|
+
[:c_return, :b_call, :b_return, :raise]
|
60
|
+
else
|
61
|
+
[:end, :raise]
|
62
|
+
end
|
63
|
+
elsif callers[0].label == "included" || callers[0].label
|
64
|
+
caller_info = callers[2]
|
65
|
+
if caller_info.label.match?(/<class/) || caller_info.label.match?(/<module/)
|
66
|
+
[:end, :raise]
|
67
|
+
else
|
68
|
+
[:c_return, :b_call, :b_return, :raise]
|
69
|
+
end
|
70
|
+
else
|
71
|
+
raise "Not detect event_type"
|
60
72
|
end
|
61
73
|
end
|
62
74
|
|
@@ -77,11 +89,15 @@ module Abstriker
|
|
77
89
|
block_count += 1 if t.event == :b_call
|
78
90
|
block_count -= 1 if t.event == :b_return
|
79
91
|
|
80
|
-
|
92
|
+
t_self = t.self
|
93
|
+
target_end_event = t_self == klass && t.event == :end
|
94
|
+
target_b_return_event = t_self == klass && t.event == :b_return && block_count.zero?
|
95
|
+
target_c_return_event = t_self == Class && t.event == :c_return && t.method_id == :new
|
96
|
+
if target_end_event || target_b_return_event || target_c_return_event
|
81
97
|
klass.ancestors.drop(1).each do |mod|
|
82
98
|
Abstriker.abstract_methods[mod]&.each do |fmeth_name|
|
83
99
|
meth = klass.instance_method(fmeth_name)
|
84
|
-
|
100
|
+
if meth.owner == mod
|
85
101
|
tp.disable
|
86
102
|
klass.instance_variable_set("@__abstract_trace_point", nil)
|
87
103
|
raise Abstriker::NotImplementedError.new(klass, meth)
|
@@ -113,11 +129,15 @@ module Abstriker
|
|
113
129
|
block_count += 1 if t.event == :b_call
|
114
130
|
block_count -= 1 if t.event == :b_return
|
115
131
|
|
116
|
-
|
132
|
+
t_self = t.self
|
133
|
+
target_end_event = t_self == klass && t.event == :end
|
134
|
+
target_b_return_event = t_self == klass && t.event == :b_return && block_count.zero?
|
135
|
+
target_c_return_event = t_self == Class && t.event == :c_return && t.method_id == :new
|
136
|
+
if target_end_event || target_b_return_event || target_c_return_event
|
117
137
|
klass.singleton_class.ancestors.drop(1).each do |mod|
|
118
138
|
Abstriker.abstract_methods[mod]&.each do |fmeth_name|
|
119
139
|
meth = klass.singleton_class.instance_method(fmeth_name)
|
120
|
-
|
140
|
+
if meth.owner == mod
|
121
141
|
tp.disable
|
122
142
|
klass.instance_variable_set("@__abstract_singleton_trace_point", nil)
|
123
143
|
raise Abstriker::NotImplementedError.new(klass, meth)
|
data/lib/abstriker/version.rb
CHANGED
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: abstriker
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.1.
|
4
|
+
version: 0.1.2
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- joker1007
|
8
8
|
autorequire:
|
9
9
|
bindir: exe
|
10
10
|
cert_chain: []
|
11
|
-
date: 2018-01-
|
11
|
+
date: 2018-01-26 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: bundler
|