Skip to content

Commit 098bcac

Browse files
committed
Introduce :trace_point_filter option for filtering purpose and re-run rake sig
1 parent 46857e0 commit 098bcac

File tree

11 files changed

+41
-28
lines changed

11 files changed

+41
-28
lines changed

known_sig/orthoses/trace.rbs

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,10 @@
11
module Orthoses
22
class Trace
3-
interface _CallablePatterns
4-
def call: (String, TracePoint) -> boolish
3+
interface _Callable
4+
def call: (String) -> boolish
55
end
66

7-
def initialize: (Orthoses::_Call loader, patterns: Array[String] | _CallablePatterns, ?sort_union_types: bool?) -> void
7+
def initialize: (Orthoses::_Call loader, patterns: Array[String], trace_point_filter: _Callable?, ?sort_union_types: bool?) -> void
88
def call: () -> Orthoses::store
99
end
1010
end

known_sig/orthoses/trace/attribute.rbs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@ module Orthoses
33
class Attribute
44
include Orthoses::Trace::Targetable
55

6-
def initialize: (Orthoses::_Call loader, patterns: Array[String] | Orthoses::Trace::_CallablePatterns, ?sort_union_types: bool?) -> void
6+
def initialize: (Orthoses::_Call loader, patterns: Array[String], trace_point_filter: _Callable?, ?sort_union_types: bool?) -> void
77
def call: () -> Orthoses::store
88
end
99
end

known_sig/orthoses/trace/method.rbs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@ module Orthoses
33
class Method
44
include Orthoses::Trace::Targetable
55

6-
def initialize: (Orthoses::_Call loader, patterns: Array[String] | Orthoses::Trace::_CallablePatterns, ?sort_union_types: bool?) -> void
6+
def initialize: (Orthoses::_Call loader, patterns: Array[String], trace_point_filter: _Callable?, ?sort_union_types: bool?) -> void
77
def call: () -> Orthoses::store
88
end
99
end

lib/orthoses/trace/attribute.rb

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -23,9 +23,10 @@ def attr_writer(*names)
2323

2424
include Targetable
2525

26-
def initialize(loader, patterns:, sort_union_types: true)
26+
def initialize(loader, patterns:, trace_point_filter: nil, sort_union_types: true)
2727
@loader = loader
2828
@patterns = patterns
29+
@trace_point_filter = trace_point_filter
2930
@sort_union_types = sort_union_types
3031

3132
@captured_dict = Hash.new { |h, k| h[k] = Hash.new { |hh, kk| hh[kk] = [] } }

lib/orthoses/trace/attribute_test.rb

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -120,16 +120,16 @@ class TraceAttributeTest::Foo::Baz
120120
end
121121
end
122122

123-
def test_pattern_proc(t)
124-
patterns = ->(name) { name == "TraceAttributeTest::Foo" }
123+
def test_trace_point_filter(t)
124+
trace_point_filter = ->(name) { name == "TraceAttributeTest::Foo" }
125125
store = Orthoses::Trace::Attribute.new(->{
126126
LOADER_ATTRIBUTE.call
127127
foo = Foo.new
128128
foo.attr_read_publ
129129
Foo::Bar.new.attr_acce_publ = /reg/
130130

131131
Orthoses::Utils.new_store
132-
}, patterns: patterns).call
132+
}, patterns: %w[*], trace_point_filter: trace_point_filter).call
133133

134134
actual = store.map { |n, c| c.to_rbs }.join("\n")
135135
expect = <<~RBS

lib/orthoses/trace/method.rb

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,9 +7,10 @@ class Method
77
Info = Struct.new(:key, :op_name_types, :raised, keyword_init: true)
88
include Targetable
99

10-
def initialize(loader, patterns:, sort_union_types: true)
10+
def initialize(loader, patterns:, trace_point_filter: nil, sort_union_types: true)
1111
@loader = loader
1212
@patterns = patterns
13+
@trace_point_filter = trace_point_filter
1314
@sort_union_types = sort_union_types
1415

1516
@stack = []

lib/orthoses/trace/method_test.rb

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -140,9 +140,9 @@ def self.a: () -> Integer
140140
end
141141
end
142142

143-
def test_pattern_proc(t)
143+
def test_trace_point_filter(t)
144144
# only non-private methods
145-
patterns = ->(name) { name == "TraceMethodTest::M" }
145+
trace_point_filter = ->(name) { name == "TraceMethodTest::M" }
146146
store = Orthoses::Trace::Method.new(-> {
147147
LOADER_METHOD.call
148148

@@ -151,7 +151,7 @@ def test_pattern_proc(t)
151151
m.call_priv(true)
152152

153153
Orthoses::Utils.new_store
154-
}, patterns: patterns).call
154+
}, patterns: %w[*], trace_point_filter: trace_point_filter).call
155155

156156
actual = store.map { |n, c| c.to_rbs }.join("\n")
157157
expect = <<~RBS

lib/orthoses/trace/targetable.rb

Lines changed: 7 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -4,15 +4,13 @@ module Orthoses
44
class Trace
55
module Targetable
66
def target?(name)
7-
if @trace_point_filter
8-
@trace_point_filter.call(name)
9-
else
10-
@patterns.any? do |pattern|
11-
if pattern.end_with?("*")
12-
(name || "").start_with?(pattern.chop)
13-
else
14-
name == pattern
15-
end
7+
return false if @trace_point_filter && !@trace_point_filter.call(name)
8+
9+
@patterns.any? do |pattern|
10+
if pattern.end_with?("*")
11+
(name || "").start_with?(pattern.chop)
12+
else
13+
name == pattern
1614
end
1715
end
1816
end

sig/orthoses/content.rbs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -86,6 +86,7 @@ class Orthoses::Content::HeaderBuilder
8686
@resolver: untyped
8787
def initialize: (env: untyped) -> void
8888
def build: (entry: untyped, ?name_hint: untyped?) -> untyped
89+
private def resolve_full_name: (entry: untyped) -> untyped
8990
private def build_module: (entry: untyped, ?name_hint: untyped?) -> ::String
9091
private def build_class: (entry: untyped, ?name_hint: untyped?) -> ::String
9192
private def build_super_class: (untyped primary) -> (nil | untyped)

sig/orthoses/resolve_type_names.rbs

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5,4 +5,13 @@ class Orthoses::ResolveTypeNames
55
@loader: untyped
66
def initialize: (untyped loader) -> void
77
def call: () -> untyped
8+
private def content_header: (untyped entry) -> untyped
9+
private def class_header: (untyped decl) -> ::String
10+
private def module_header: (untyped decl) -> ::String
11+
end
12+
13+
module Orthoses::ResolveTypeNames::WriterCopy
14+
def name_and_args: (untyped name, untyped args) -> (::String | nil)
15+
16+
def name_and_params: (untyped name, untyped params) -> ::String
817
end

0 commit comments

Comments
 (0)