orthoses 1.6.0 → 1.8.0

Sign up to get free protection for your applications and to get access to all the features.
Files changed (80) hide show
  1. checksums.yaml +4 -4
  2. data/README.md +10 -3
  3. data/lib/orthoses/builder.rb +7 -3
  4. data/lib/orthoses/content/duplication_checker.rb +54 -17
  5. data/lib/orthoses/content/environment.rb +14 -1
  6. data/lib/orthoses/content.rb +46 -44
  7. data/lib/orthoses/create_file_by_name.rb +38 -7
  8. data/lib/orthoses/filter.rb +2 -2
  9. data/lib/orthoses/missing_name.rb +81 -0
  10. data/lib/orthoses/mixin.rb +9 -4
  11. data/lib/orthoses/rbs_prototype_rb.rb +16 -2
  12. data/lib/orthoses/rbs_prototype_runtime.rb +21 -2
  13. data/lib/orthoses/utils.rb +1 -1
  14. data/lib/orthoses/version.rb +1 -1
  15. data/lib/orthoses.rb +1 -0
  16. data/sig/orthoses/_call.rbs +1 -1
  17. data/sig/orthoses/_middle_ware.rbs +1 -1
  18. data/sig/orthoses/attribute/hook.rbs +1 -1
  19. data/sig/orthoses/attribute.rbs +1 -1
  20. data/sig/orthoses/autoload/hook.rbs +1 -1
  21. data/sig/orthoses/autoload.rbs +1 -1
  22. data/sig/orthoses/builder/call_logable.rbs +1 -1
  23. data/sig/orthoses/builder.rbs +14 -4
  24. data/sig/orthoses/call_tracer/capturable.rbs +1 -1
  25. data/sig/orthoses/call_tracer/capture.rbs +1 -1
  26. data/sig/orthoses/call_tracer/lazy.rbs +14 -2
  27. data/sig/orthoses/call_tracer.rbs +1 -1
  28. data/sig/orthoses/const_load_error.rbs +1 -1
  29. data/sig/orthoses/constant.rbs +1 -1
  30. data/sig/orthoses/content/array_io.rbs +1 -1
  31. data/sig/orthoses/content/duplication_checker.rbs +7 -2
  32. data/sig/orthoses/content/environment.rbs +8 -3
  33. data/sig/orthoses/content/header_builder.rbs +1 -1
  34. data/sig/orthoses/content.rbs +3 -2
  35. data/sig/orthoses/create_file_by_name.rbs +2 -2
  36. data/sig/orthoses/delegate_class/hook.rbs +1 -1
  37. data/sig/orthoses/delegate_class.rbs +1 -1
  38. data/sig/orthoses/filter.rbs +6 -1
  39. data/sig/orthoses/lazy_trace_point.rbs +9 -1
  40. data/sig/orthoses/load_rbs.rbs +1 -1
  41. data/sig/orthoses/missing_name/missing_class.rbs +7 -0
  42. data/sig/orthoses/missing_name/missing_module.rbs +7 -0
  43. data/sig/orthoses/missing_name.rbs +6 -0
  44. data/sig/orthoses/mixin/hook.rbs +2 -2
  45. data/sig/orthoses/mixin.rbs +2 -2
  46. data/sig/orthoses/name_space_error.rbs +1 -1
  47. data/sig/orthoses/object_space_all.rbs +1 -1
  48. data/sig/orthoses/outputable/avoid_recursive_ancestor_error.rbs +3 -1
  49. data/sig/orthoses/outputable/constantizable_filter.rbs +3 -1
  50. data/sig/orthoses/outputable/uniq_content_body.rbs +3 -1
  51. data/sig/orthoses/outputable.rbs +1 -1
  52. data/sig/orthoses/path_helper.rbs +1 -1
  53. data/sig/orthoses/pp.rbs +3 -1
  54. data/sig/orthoses/rbs_prototype_rb.rbs +10 -3
  55. data/sig/orthoses/rbs_prototype_runtime.rbs +13 -3
  56. data/sig/orthoses/sort.rbs +2 -1
  57. data/sig/orthoses/store.rbs +3 -1
  58. data/sig/orthoses/tap.rbs +4 -1
  59. data/sig/orthoses/trace/attribute.rbs +1 -1
  60. data/sig/orthoses/trace/method/info.rbs +1 -1
  61. data/sig/orthoses/trace/method.rbs +1 -1
  62. data/sig/orthoses/trace/targetable.rbs +1 -1
  63. data/sig/orthoses/trace.rbs +1 -1
  64. data/sig/orthoses/utils/type_list.rbs +2 -1
  65. data/sig/orthoses/utils/underscore.rbs +1 -1
  66. data/sig/orthoses/utils.rbs +2 -2
  67. data/sig/orthoses/walk.rbs +1 -1
  68. data/sig/orthoses/writer.rbs +1 -1
  69. data/sig/orthoses.rbs +2 -2
  70. metadata +7 -13
  71. data/Gemfile +0 -15
  72. data/Gemfile.lock +0 -76
  73. data/examples/minitest/Rakefile +0 -56
  74. data/examples/rack-test/Gemfile +0 -8
  75. data/examples/rack-test/Gemfile.lock +0 -30
  76. data/examples/rack-test/Rakefile +0 -7
  77. data/examples/rack-test/generate.rb +0 -31
  78. data/examples/simple_middleware.rb +0 -11
  79. data/examples/simple_middleware.rbs +0 -7
  80. data/orthoses.gemspec +0 -36
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: 0bde1745c71d6d30b7b45ce7f956a1c02f0d44353932c3743211aa1c05f58d39
4
- data.tar.gz: bbe5b95a7665d39faab82b5f53e18cffd22962df1913f1c52698ea51c6045e2c
3
+ metadata.gz: 0bbf41507135a45b3b2a45ffff90500a68a39f4497bf1fcbd72d94579fd27ae8
4
+ data.tar.gz: 8a6daa8a64d8bfbda565e24ec53622ca5530f5624e80f0c6fdfed5ca13b10786
5
5
  SHA512:
6
- metadata.gz: 496d255f99751ac854e5b05ecac69b1e0dc7dbb5fca53bf99d6d622e2dbb154af643de7bf8de8190dca15ff1933fac35c17735da9285532a8a3246d7002836cd
7
- data.tar.gz: 56c77cf9074eeb75547c1be3868e9843b0d5337400d2248592879f76fd6cc14f99660d8dbbf593c1d66bac1152e1dafbaa4820ea45a49f5f47945027ce45d53a
6
+ metadata.gz: c9d4a29dfc22972be165a703c4e86272a6e045ab34a91f76b560eeb329dca0795dab6eef59f419b50b7da4c390fcfa71d74d217baad3aa65b43f0000a2f7a126
7
+ data.tar.gz: 5579c33080fb673b50445fc8193f2876f8065e9ccc7ad2042020539a688f1242bfbe9dab265a780057040051f555f20b04ff62734ef844d25fea099a835d1c2a
data/README.md CHANGED
@@ -29,11 +29,13 @@ For example, You can write script in Rakefile.
29
29
  require 'orthoses'
30
30
 
31
31
  namespace :rbs do
32
- desc "build RBS to sig/out"
32
+ desc "build RBS to sig/orthoses"
33
33
  task :build do
34
34
  Orthoses::Builder.new do
35
35
  use Orthoses::CreateFileByName,
36
- base_dir: Rails.root.join("sig/out"),
36
+ depth: 1,
37
+ to: "sig/orthoses",
38
+ rmtree: true,
37
39
  header: "# !!! GENERATED CODE !!!"
38
40
  use Orthoses::Filter do |name, _content|
39
41
  path, _lineno = Object.const_source_location(name)
@@ -53,7 +55,7 @@ namespace :rbs do
53
55
  end
54
56
  ```
55
57
 
56
- Then, you can see the result files under `sig/out`.
58
+ Then, you can see the result files under `sig/orthoses`.
57
59
 
58
60
  ## Utils
59
61
 
@@ -177,6 +179,11 @@ Sort signatures by class/module.
177
179
 
178
180
  Trace the argument and return value objects when the method is actually called and determine the type.
179
181
 
182
+ ## Orthoses::MissingName
183
+
184
+ Completes undefined class/module names.
185
+ If it is unknown whether it is a class or a module, it is defined as an empty module, and if it is a superclass, it is defined as an empty class.
186
+
180
187
  ## Development
181
188
 
182
189
  After checking out the repo, run `bin/setup` to install dependencies. You can also run `bin/console` for an interactive prompt that will allow you to experiment.
@@ -13,7 +13,7 @@ module Orthoses
13
13
  class Builder
14
14
  def initialize(&block)
15
15
  @use = []
16
- @run = nil
16
+ @runner = nil
17
17
  instance_eval(&block) if block
18
18
  end
19
19
 
@@ -37,7 +37,11 @@ module Orthoses
37
37
 
38
38
  def run(loader)
39
39
  use Store
40
- @run = proc do
40
+ reset_runner(loader)
41
+ end
42
+
43
+ def reset_runner(loader)
44
+ @runner = proc do
41
45
  Orthoses.logger.info("[loader].call start")
42
46
  loader.call.tap do
43
47
  Orthoses.logger.info("[loader].call end")
@@ -46,7 +50,7 @@ module Orthoses
46
50
  end
47
51
 
48
52
  def to_loader
49
- @use.reverse.inject(@run) { |current, next_proc| next_proc[current] }
53
+ @use.reverse.inject(@runner) { |current, next_proc| next_proc[current] }
50
54
  end
51
55
 
52
56
  def call
@@ -4,48 +4,86 @@ module Orthoses
4
4
  class DuplicationChecker
5
5
  def initialize(decl, env: nil)
6
6
  @decl = decl
7
- @env = env || Utils.rbs_environment
7
+ @known_env = env || Utils.rbs_environment
8
+ @builder = RBS::DefinitionBuilder.new(env: @known_env)
9
+ @uniq_map = {}
8
10
  end
9
11
 
10
12
  def update_decl
11
13
  return unless @decl.respond_to?(:members)
12
- uniq_map = {}
14
+
15
+ uniq_members
16
+ drop_set_method_definition
17
+ drop_known_method_definition
18
+ drop_known_const_definition
19
+
20
+ @decl.members.replace(@uniq_map.values)
21
+
22
+ @uniq_map.clear
23
+ end
24
+
25
+ private
26
+
27
+ def uniq_members
13
28
  @decl.members.each do |member|
14
29
  if member.instance_of?(RBS::AST::Members::MethodDefinition) && member.overloading?
15
30
  # avoid to duplicate and keep order
16
- uniq_map[Object.new] = member
31
+ @uniq_map[Object.new] = member
17
32
  else
18
33
  key = member_key(member)
19
- drop_member = uniq_map[key]
20
- uniq_map[key] = member
34
+ drop_member = @uniq_map[key]
35
+ @uniq_map[key] = member
21
36
  if drop_member
22
37
  Orthoses.logger.info("#{@decl.name} \"#{member.location.source}\" was droped since duplication")
23
38
  end
24
39
  end
25
40
  end
26
- drop_known_method_definition(uniq_map)
27
- @decl.members.replace(uniq_map.values)
28
41
  end
29
42
 
30
- private
43
+ def drop_set_method_definition
44
+ attr_accessors = @uniq_map.values.grep(RBS::AST::Members::AttrAccessor)
45
+ attr_accessors.each do |member|
46
+ @uniq_map.delete([RBS::AST::Members::MethodDefinition, :"#{member.name}=", member.kind])
47
+ end
48
+ end
31
49
 
32
- def drop_known_method_definition(uniq_map)
50
+ def drop_known_method_definition
33
51
  decl_name = @decl.name.absolute!
34
- if m_entry = @env.class_decls[decl_name]
52
+ if m_entry = @known_env.class_decls[decl_name]
35
53
  m_entry.decls.each do |d|
36
- d.decl.members.grep_v(RBS::AST::Members::LocationOnly).each do |member|
37
- uniq_map.delete(member_key(member))
54
+ drop_known_method_definition_recur(d)
55
+ end
56
+ end
57
+ end
58
+
59
+ def drop_known_method_definition_recur(d)
60
+ d.decl.members.each do |member|
61
+ case member
62
+ when RBS::AST::Members::LocationOnly
63
+ # ignore
64
+ when RBS::AST::Members::AttrAccessor
65
+ @uniq_map.delete([RBS::AST::Members::MethodDefinition, member.name, member.kind])
66
+ @uniq_map.delete([RBS::AST::Members::MethodDefinition, :"#{member.name}=", member.kind])
67
+ else
68
+ if member.kind_of?(RBS::AST::Members::Include) && member.name.interface?
69
+ # If interface is included, it is shared in the same namespace.
70
+ drop_known_method_definition_recur(@known_env.interface_decls[member.name])
71
+ else
72
+ @uniq_map.delete(member_key(member))
38
73
  end
39
74
  end
40
75
  end
76
+ end
41
77
 
42
- constants_in_uniq_map = uniq_map.select do |key, value|
78
+ def drop_known_const_definition
79
+ decl_name = @decl.name.absolute!
80
+ constants_in_uniq_map = @uniq_map.select do |key, value|
43
81
  value.kind_of?(RBS::AST::Declarations::Constant)
44
82
  end
45
83
  constants_in_uniq_map.each do |key, value|
46
84
  type_name = decl_name + value.name
47
- if @env.constant_decls[type_name]
48
- uniq_map.delete(key)
85
+ if @known_env.constant_decls[type_name]
86
+ @uniq_map.delete(key)
49
87
  end
50
88
  end
51
89
  end
@@ -60,12 +98,11 @@ module Orthoses
60
98
  when RBS::AST::Members::Alias
61
99
  [RBS::AST::Members::MethodDefinition, member.new_name, member.kind]
62
100
  when RBS::AST::Members::AttrAccessor
63
- # FIXME: how to check "#{member.name}=" ?
64
101
  [RBS::AST::Members::MethodDefinition, member.name, member.kind]
65
102
  when RBS::AST::Members::AttrReader
66
103
  [RBS::AST::Members::MethodDefinition, member.name, member.kind]
67
104
  when RBS::AST::Members::AttrWriter
68
- [RBS::AST::Members::MethodDefinition, "#{member.name}=", member.kind]
105
+ [RBS::AST::Members::MethodDefinition, :"#{member.name}=", member.kind]
69
106
  else
70
107
  [member.class, member.name]
71
108
  end
@@ -16,9 +16,17 @@ module Orthoses
16
16
  end
17
17
  end
18
18
 
19
- def initialize(constant_filter: nil, mixin_filter: nil, attribute_filter: nil)
19
+ def initialize(
20
+ method_definition_filter: nil,
21
+ alias_filter: nil,
22
+ constant_filter: nil,
23
+ mixin_filter: nil,
24
+ attribute_filter: nil
25
+ )
20
26
  @load_env = RBS::Environment.new
21
27
  @known_env = Utils.rbs_environment(cache: false)
28
+ @method_definition_filter = method_definition_filter
29
+ @alias_filter = alias_filter
22
30
  @constant_filter = constant_filter
23
31
  @mixin_filter = mixin_filter
24
32
  @attribute_filter = attribute_filter
@@ -35,6 +43,7 @@ module Orthoses
35
43
  each do |add_content|
36
44
  content = store[add_content.name]
37
45
  content.header = add_content.header
46
+ content.comment ||= add_content.comment
38
47
  content.concat(add_content.body)
39
48
  end
40
49
  end
@@ -47,6 +56,7 @@ module Orthoses
47
56
  @load_env.class_decls.each do |type_name, m_entry|
48
57
  name = type_name.relative!.to_s
49
58
  content = Content.new(name: name)
59
+ content.comment = m_entry.primary.decl.comment&.string&.gsub(/^/, "# ")
50
60
  content.header = header_builder.build(entry: m_entry, name_hint: name)
51
61
  decls_to_lines(m_entry.decls.map(&:decl)).each do |line|
52
62
  content << line
@@ -94,9 +104,12 @@ module Orthoses
94
104
  when RBS::AST::Declarations::Constant
95
105
  next unless @constant_filter.nil? || @constant_filter.call(member)
96
106
  when RBS::AST::Members::MethodDefinition
107
+ next unless @method_definition_filter.nil? || @method_definition_filter.call(member)
97
108
  if last_visibility == :private && member.kind != :singleton_instance
98
109
  member.instance_variable_set(:@visibility, :private)
99
110
  end
111
+ when RBS::AST::Members::Alias
112
+ next unless @alias_filter.nil? || @alias_filter.call(member)
100
113
  when RBS::AST::Members::Mixin
101
114
  next unless @mixin_filter.nil? || @mixin_filter.call(member)
102
115
  when RBS::AST::Members::Attribute
@@ -74,12 +74,52 @@ module Orthoses
74
74
  end
75
75
 
76
76
  def original_rbs
77
- a = []
78
- a << @comment if @comment
79
- a << @header
80
- a << " #{@body.join("\n ")}" if @body.length > 0
81
- a << "end"
82
- a.join("\n")
77
+ io = StringIO.new
78
+ io.puts @comment if @comment
79
+ io.puts @header
80
+ @body.each do |line|
81
+ io.puts " #{line}"
82
+ end
83
+ io.puts "end"
84
+ io.string
85
+ end
86
+
87
+ def auto_header
88
+ env = Utils.rbs_environment
89
+ if entry = env.class_decls[TypeName(name).absolute!]
90
+ @header = Content::HeaderBuilder.new(env: env).build(entry: entry)
91
+ return
92
+ end
93
+
94
+ return unless @header.nil?
95
+
96
+ if interface?
97
+ self.header = "interface #{name}"
98
+ return
99
+ end
100
+
101
+ val = Object.const_get(name)
102
+
103
+ case val
104
+ when Class
105
+ superclass =
106
+ if val.superclass && val.superclass != Object
107
+ super_module_name = Utils.module_name(val.superclass)
108
+
109
+ if super_module_name && super_module_name != "Random::Base" # https://github.com/ruby/rbs/pull/977
110
+ " < ::#{super_module_name}#{temporary_type_params(super_module_name)}"
111
+ else
112
+ nil
113
+ end
114
+ else
115
+ nil
116
+ end
117
+ self.header = "class #{Utils.module_name(val)}#{type_params(name)}#{superclass}"
118
+ when Module
119
+ self.header = "module #{Utils.module_name(val)}#{type_params(name)}"
120
+ else
121
+ raise "#{val.inspect} is not class/module"
122
+ end
83
123
  end
84
124
 
85
125
  private
@@ -132,44 +172,6 @@ module Orthoses
132
172
  raise
133
173
  end
134
174
 
135
- def auto_header
136
- env = Utils.rbs_environment
137
- if entry = env.class_decls[TypeName(name).absolute!]
138
- @header = Content::HeaderBuilder.new(env: env).build(entry: entry)
139
- return
140
- end
141
-
142
- return unless @header.nil?
143
-
144
- if interface?
145
- self.header = "interface #{name}"
146
- return
147
- end
148
-
149
- val = Object.const_get(name)
150
-
151
- case val
152
- when Class
153
- superclass =
154
- if val.superclass && val.superclass != Object
155
- super_module_name = Utils.module_name(val.superclass)
156
-
157
- if super_module_name && super_module_name != "Random::Base" # https://github.com/ruby/rbs/pull/977
158
- " < ::#{super_module_name}#{temporary_type_params(super_module_name)}"
159
- else
160
- nil
161
- end
162
- else
163
- nil
164
- end
165
- self.header = "class #{Utils.module_name(val)}#{type_params(name)}#{superclass}"
166
- when Module
167
- self.header = "module #{Utils.module_name(val)}#{type_params(name)}"
168
- else
169
- raise "#{val.inspect} is not class/module"
170
- end
171
- end
172
-
173
175
  def temporary_type_params(name)
174
176
  Utils.known_type_params(name)&.then do |params|
175
177
  if params.empty?
@@ -6,31 +6,62 @@ module Orthoses
6
6
  class CreateFileByName
7
7
  prepend Outputable
8
8
 
9
- def initialize(loader, base_dir:, header: nil, if: nil)
9
+ def initialize(loader, base_dir: nil, to: nil, header: nil, if: nil, depth: nil, rmtree: false)
10
+ unless base_dir.nil?
11
+ warn "[Orthoses::CreateFileByName] base_dir: option is deprecated. Please use to: option instead."
12
+ end
13
+
14
+ to = to || base_dir
15
+ unless to
16
+ raise ArgumentError, "should set to: option"
17
+ end
18
+
19
+ relative_path_from_pwd = Pathname(to).expand_path.relative_path_from(Pathname.pwd).to_s
20
+ unless relative_path_from_pwd == "." || !relative_path_from_pwd.match?(%r{\A[/\.]})
21
+ raise ArgumentError, "to=\"#{to}\" should be under current dir=\"#{Pathname.pwd}\"."
22
+ end
23
+
10
24
  @loader = loader
11
- @base_dir = base_dir
25
+ @to = to
12
26
  @header = header
27
+ @depth = depth
28
+ @rmtree = rmtree
13
29
  @if = binding.local_variable_get(:if)
14
30
  end
15
31
 
16
32
  using Utils::Underscore
17
33
 
18
34
  def call
35
+ if @rmtree
36
+ Orthoses.logger.debug("Remove dir #{@to} since `rmtree: true`")
37
+ Pathname(@to).rmtree rescue nil
38
+ end
39
+
19
40
  store = @loader.call
20
41
 
21
- store.each do |name, content|
22
- next unless @if.nil? || @if.call(name, content)
42
+ store.select! do |name, content|
43
+ @if.nil? || @if.call(name, content)
44
+ end
45
+ grouped = store.group_by do |name, _|
46
+ splitted = name.to_s.split('::')
47
+ (@depth ? splitted[0, @depth] : splitted).join('::')
48
+ end
23
49
 
24
- file_path = Pathname("#{@base_dir}/#{name.to_s.split('::').map(&:underscore).join('/')}.rbs")
50
+ grouped.each do |group_name, group|
51
+ file_path = Pathname("#{@to}/#{group_name.split('::').map(&:underscore).join('/')}.rbs")
25
52
  file_path.dirname.mkpath
26
53
  file_path.open('w+') do |out|
27
54
  if @header
28
55
  out.puts @header
29
56
  out.puts
30
57
  end
31
- out.puts content.to_rbs
58
+ group.sort!
59
+ contents = group.map do |(name, content)|
60
+ content.to_rbs
61
+ end.join("\n")
62
+ out.puts contents
63
+ Orthoses.logger.info("Generate file to #{file_path.to_s}")
32
64
  end
33
- Orthoses.logger.info("Generate file to #{file_path.to_s}")
34
65
  end
35
66
  end
36
67
  end
@@ -16,8 +16,8 @@ module Orthoses
16
16
  def call
17
17
  @loader.call.tap do |store|
18
18
  store.filter! do |name, content|
19
- @block.call(name, content).tap do
20
- Orthoses.logger.debug("Filter pass [#{name}]")
19
+ @block.call(name, content).tap do |bool|
20
+ Orthoses.logger.debug("[Filter] #{bool ? "Pass" : "Reject"} [#{name}]")
21
21
  end
22
22
  end
23
23
  end
@@ -0,0 +1,81 @@
1
+ # frozen_string_literal: true
2
+
3
+ module Orthoses
4
+ class MissingName
5
+ def initialize(loader)
6
+ @loader = loader
7
+ end
8
+
9
+ def call
10
+ @loader.call.tap do |store|
11
+ MissingClass.new(store).call
12
+ MissingModule.new(store).call
13
+ end
14
+ end
15
+
16
+ private
17
+
18
+ class MissingClass
19
+ def initialize(store)
20
+ @store = store
21
+ end
22
+
23
+ def call
24
+ @store.values.each do |content|
25
+ recur(content)
26
+ end
27
+ end
28
+
29
+ private
30
+
31
+ def recur(content)
32
+ content.auto_header
33
+ if content.header && content.header.include?("<")
34
+ _, superclass = content.header.split(/\s*<\s*/, 2)
35
+ superclass.sub!(/\[.*/, "")
36
+ new_name = TypeName(superclass).relative!.to_s
37
+ recur(@store[new_name])
38
+ end
39
+ end
40
+ end
41
+
42
+ class MissingModule
43
+ def initialize(store)
44
+ @store = store
45
+ end
46
+
47
+ def call
48
+ missings = []
49
+ @store.keys.each do |key_name|
50
+ missings.concat split_name(key_name)
51
+ end
52
+ missings.uniq!
53
+ missings.each do |missing|
54
+ @store[missing].header = "module #{missing}"
55
+ end
56
+ end
57
+
58
+ private
59
+
60
+ def split_name(key_name)
61
+ ret = []
62
+
63
+ type_name = TypeName(key_name).relative!
64
+ if !Utils.rbs_defined_class?(type_name.to_s) && !@store.has_key?(type_name.to_s)
65
+ ret << type_name.to_s
66
+ end
67
+
68
+ path = type_name.namespace.path
69
+ path.each_with_index do |sym, index|
70
+ name = path[0, index + 1].join("::")
71
+ next if name.empty?
72
+ if !Utils.rbs_defined_class?(name) && !@store.has_key?(name)
73
+ ret << name
74
+ end
75
+ end
76
+
77
+ ret
78
+ end
79
+ end
80
+ end
81
+ end
@@ -50,6 +50,7 @@ module Orthoses
50
50
 
51
51
  base_mod_name = Utils.module_name(base_mod)
52
52
  next unless base_mod_name
53
+ next if base_mod_name.include?("#")
53
54
 
54
55
  content = store[base_mod_name]
55
56
  capture.argument[:modules].each do |mod|
@@ -58,13 +59,17 @@ module Orthoses
58
59
 
59
60
  next if mod_name.start_with?("Orthoses")
60
61
 
61
- known_type_params = Utils.known_type_params(mod)
62
- next unless known_type_params.nil? || known_type_params.empty?
62
+ type_params_sig = ""
63
+ if type_params = Utils.known_type_params(mod)
64
+ if !type_params.empty?
65
+ type_params_sig = "[#{type_params.map{"untyped"}.join(", ")}]"
66
+ end
67
+ end
63
68
 
64
69
  next unless @if.nil? || @if.call(base_mod, how, mod)
65
70
 
66
- store[mod_name]
67
- content << "#{how} #{mod_name}"
71
+ store[mod_name].header = "module #{mod_name}"
72
+ content << "#{how} #{mod_name}#{type_params_sig}"
68
73
  end
69
74
  end
70
75
  end
@@ -1,11 +1,23 @@
1
1
  module Orthoses
2
2
  # Call `rbs prototype rb` and add to store
3
3
  # use Orthoses::RBSPrototypeRB,
4
- # paths: Dir.glob("lib/**/*.rb")
4
+ # paths: Dir.glob("lib/**/*.rb"),
5
+ # method_definition_filter: ->(member) { false },
6
+ # alias_filter: ->(member) { false }
5
7
  class RBSPrototypeRB
6
- def initialize(loader, paths:, constant_filter: nil, mixin_filter: nil, attribute_filter: nil)
8
+ def initialize(
9
+ loader,
10
+ paths:,
11
+ method_definition_filter: nil,
12
+ alias_filter: nil,
13
+ constant_filter: nil,
14
+ mixin_filter: nil,
15
+ attribute_filter: nil
16
+ )
7
17
  @loader = loader
8
18
  @paths = paths
19
+ @method_definition_filter = method_definition_filter
20
+ @alias_filter = alias_filter
9
21
  @constant_filter = constant_filter
10
22
  @mixin_filter = mixin_filter
11
23
  @attribute_filter = attribute_filter
@@ -23,6 +35,8 @@ module Orthoses
23
35
  end
24
36
  end
25
37
  env = Orthoses::Content::Environment.new(
38
+ method_definition_filter: @method_definition_filter,
39
+ alias_filter: @alias_filter,
26
40
  constant_filter: @constant_filter,
27
41
  mixin_filter: @mixin_filter,
28
42
  attribute_filter: @attribute_filter,
@@ -3,14 +3,33 @@ module Orthoses
3
3
  # use Orthoses::RBSPrototypeRuntime,
4
4
  # patterns: ['Foo::*']
5
5
  class RBSPrototypeRuntime
6
- def initialize(loader, patterns:)
6
+ def initialize(
7
+ loader,
8
+ patterns:,
9
+ method_definition_filter: nil,
10
+ alias_filter: nil,
11
+ constant_filter: nil,
12
+ mixin_filter: nil,
13
+ attribute_filter: nil
14
+ )
7
15
  @loader = loader
8
16
  @patterns = patterns
17
+ @method_definition_filter = method_definition_filter
18
+ @alias_filter = alias_filter
19
+ @constant_filter = constant_filter
20
+ @mixin_filter = mixin_filter
21
+ @attribute_filter = attribute_filter
9
22
  end
10
23
 
11
24
  def call
12
25
  @loader.call.tap do |store|
13
- content_env = Orthoses::Content::Environment.new
26
+ content_env = Orthoses::Content::Environment.new(
27
+ method_definition_filter: @method_definition_filter,
28
+ alias_filter: @alias_filter,
29
+ constant_filter: @constant_filter,
30
+ mixin_filter: @mixin_filter,
31
+ attribute_filter: @attribute_filter,
32
+ )
14
33
 
15
34
  patterns = @patterns
16
35
  env = RBS::Environment.new
@@ -177,7 +177,7 @@ module Orthoses
177
177
  when String
178
178
  TypeName(name).absolute!
179
179
  when Module
180
- module_to_type_name(name)
180
+ module_to_type_name(name).absolute!
181
181
  else
182
182
  raise TypeError
183
183
  end
@@ -1,5 +1,5 @@
1
1
  # frozen_string_literal: true
2
2
 
3
3
  module Orthoses
4
- VERSION = "1.6.0"
4
+ VERSION = "1.8.0"
5
5
  end
data/lib/orthoses.rb CHANGED
@@ -17,6 +17,7 @@ module Orthoses
17
17
  autoload :Mixin, 'orthoses/mixin'
18
18
  autoload :LazyTracePoint, 'orthoses/lazy_trace_point'
19
19
  autoload :LoadRBS, 'orthoses/load_rbs'
20
+ autoload :MissingName, 'orthoses/missing_name'
20
21
  autoload :ObjectSpaceAll, 'orthoses/object_space_all'
21
22
  autoload :Outputable, 'orthoses/outputable'
22
23
  autoload :PathHelper, 'orthoses/path_helper'
@@ -1,4 +1,4 @@
1
- # THIS IS GENERATED CODE from `$ rake generate_self_sig`
1
+ # THIS IS GENERATED CODE from `$ rake sig`
2
2
 
3
3
  interface Orthoses::_Call
4
4
  def call: () -> Orthoses::store
@@ -1,4 +1,4 @@
1
- # THIS IS GENERATED CODE from `$ rake generate_self_sig`
1
+ # THIS IS GENERATED CODE from `$ rake sig`
2
2
 
3
3
  interface Orthoses::_MiddleWare
4
4
  include Orthoses::_Call
@@ -1,4 +1,4 @@
1
- # THIS IS GENERATED CODE from `$ rake generate_self_sig`
1
+ # THIS IS GENERATED CODE from `$ rake sig`
2
2
 
3
3
  module Orthoses::Attribute::Hook
4
4
  def attr: (*untyped names) -> untyped
@@ -1,4 +1,4 @@
1
- # THIS IS GENERATED CODE from `$ rake generate_self_sig`
1
+ # THIS IS GENERATED CODE from `$ rake sig`
2
2
 
3
3
  class Orthoses::Attribute
4
4
  def initialize: (Orthoses::_Call loader) -> void
@@ -1,4 +1,4 @@
1
- # THIS IS GENERATED CODE from `$ rake generate_self_sig`
1
+ # THIS IS GENERATED CODE from `$ rake sig`
2
2
 
3
3
  module Orthoses::Autoload::Hook
4
4
  def autoload: (untyped name, untyped path) -> untyped