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 CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: 58fc310fb1c93359f11f08ece41ac5447b228166230656b8a481a21efb13ff42
4
- data.tar.gz: c941dc1843f1bdb93cb567fa3e2a0c7fa9379b765832a9a01ccfe19ba9dd32f7
3
+ metadata.gz: 9084bf87aeeb1ffa9f9ec57310d709c57f30ad039154c384720793eea694c632
4
+ data.tar.gz: 6ee676d5a9a1229d38ed3a4ae2b7a4e1fe07cd3f5b1100954e0f42cdd1cb9e66
5
5
  SHA512:
6
- metadata.gz: aa481fe912ed555b398e61ab3f64b9f3a51e3cada25148143ad8e7587bceacf3fb3afb5208b0b47327c174915168d9577bcb62b87ca629719f5001f5c94cd934
7
- data.tar.gz: cd96e6d7772f00590e3a260a42602d52d7e14916e32c699c82f6b22930b7b1a962e1a901bf5bcab509c59ef12d79d7111784058248f0393a60ea1833f512973e
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
@@ -52,11 +52,23 @@ module Abstriker
52
52
  private
53
53
 
54
54
  def detect_event_type
55
- caller_info = caller_locations(3, 1)[0]
56
- if caller_info.label.match?(/block/)
57
- [:end, :raise]
58
- elsif caller_info.label.match?(/initialize/) || caller_info.label.match?(/new/)
59
- [:b_call, :b_return, :raise]
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
- if t.self == klass && (t.event == :end || t.event == :b_return && block_count.zero?)
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
- unless meth&.owner == klass
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
- if t.self == klass && (t.event == :end || t.event == :b_return && block_count.zero?)
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
- unless meth&.owner == klass.singleton_class
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)
@@ -1,3 +1,3 @@
1
1
  module Abstriker
2
- VERSION = "0.1.0"
2
+ VERSION = "0.1.2"
3
3
  end
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.0
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-25 00:00:00.000000000 Z
11
+ date: 2018-01-26 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: bundler