orthoses 1.19.0 → 1.20.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: 245f65c0f676602acf06354591c87ed0d5ed7cd39b997a4db2736004da99476f
4
- data.tar.gz: b8f5ec5da61b79d5cc1994f94cd71c6e9da1b36679dd8aef3f6d7c5fcd88bf46
3
+ metadata.gz: f3191a7b9ea732c52cbdcab6eb33dbee32226ddf1925fb4544bfb007f7a8d89a
4
+ data.tar.gz: 20194fdf983090f7aa1e1bb45931679d0297ac7c4b322022fdf3734c626012bb
5
5
  SHA512:
6
- metadata.gz: 9278d20b972e610772ca19fa849ea147564b49bacf5d0bd81854fe636be99eb2061482569b88370588424f4d3e6059ccb2530c896f8ce9bf921acfd675771153
7
- data.tar.gz: 4c271a0f6a3105fe3bb9813c392d47965cb709e2c86e38db6cc9cc3be54a009210a0cdef693a3c6b6ad441b2da5546e7c4a2284d2a0a2fb8c2aee47ffb6373a3
6
+ metadata.gz: e88b8032acd8a05caa7061b115c443d0128285919573ecd511cb180f2f3ae7099887095135597512106536f005a5a7e633b6a8fa66ce5b99f91e46820b7fe3b8
7
+ data.tar.gz: 5ea08ec94757c04b17658eee9aef976cd40f5dbc7174e3f30e399e053caa2c3f5f44db6ade7a079d13a86c3b7e9c9345a7d139ac627656ec27a9cd6b5bc17937
data/README.md CHANGED
@@ -189,11 +189,6 @@ If it is unknown whether it is a class or a module, it is defined as an empty mo
189
189
  You can specify that the specified RBS should not be intentionally generated.
190
190
  This is useful when you want to exclude handwritten RBS.
191
191
 
192
- ### Orthoses::ResolveTypeNames
193
-
194
- Call `RBS::Environment#resolve_type_names` and output.
195
- Using this middleware improves the efficiency of loading files after they are generated.
196
-
197
192
  ## Development
198
193
 
199
194
  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.
@@ -29,7 +29,7 @@ module Orthoses
29
29
 
30
30
  def build_module(entry:, name_hint: nil)
31
31
  primary = entry.primary
32
- full_name = name_hint || resolve_full_name(entry: primary).relative!
32
+ full_name = name_hint || resolve_full_name(entry: primary)
33
33
 
34
34
  self_types =
35
35
  if primary.decl.self_types.empty?
@@ -43,7 +43,7 @@ module Orthoses
43
43
 
44
44
  def build_class(entry:, name_hint: nil)
45
45
  primary = entry.primary
46
- full_name = name_hint || resolve_full_name(entry: primary).relative!
46
+ full_name = name_hint || resolve_full_name(entry: primary)
47
47
 
48
48
  "class #{name_and_params(full_name, primary.decl.type_params)}#{build_super_class(primary)}"
49
49
  end
@@ -66,7 +66,7 @@ module Orthoses
66
66
  end
67
67
 
68
68
  def build_interface(entry:, name_hint: nil)
69
- full_name = name_hint || resolve_full_name(entry: entry).relative!
69
+ full_name = name_hint || resolve_full_name(entry: entry)
70
70
  "interface #{name_and_params(full_name, entry.decl.type_params)}"
71
71
  end
72
72
 
@@ -55,6 +55,10 @@ module Orthoses
55
55
  file_path = Pathname("#{@to}/#{group_name.split('::').map(&:underscore).join('/')}.rbs")
56
56
  file_path.dirname.mkpath
57
57
  file_path.open('w+') do |out|
58
+ if @resolve_type_names
59
+ out.puts "# resolve-type-names: false"
60
+ out.puts
61
+ end
58
62
  if @header
59
63
  out.puts @header
60
64
  out.puts
@@ -0,0 +1,120 @@
1
+ # frozen_string_literal: true
2
+
3
+ module Orthoses
4
+ module Outputable
5
+ class ResolveTypeNames
6
+ def initialize(loader)
7
+ @loader = loader
8
+ end
9
+
10
+ def call
11
+ @loader.call.tap do |store|
12
+ env = Utils.rbs_environment(cache: false)
13
+
14
+ signatures = store.map do |name, content|
15
+ buffer = RBS::Buffer.new(content: content.to_rbs, name: "orthoses-resolve_type_names-#{name.downcase}.rbs")
16
+ decls = [content.to_decl]
17
+
18
+ # Add as known types
19
+ env.add_signature(buffer: buffer, directives: [], decls: decls)
20
+
21
+ # Will resolve names
22
+ [buffer, [[], decls]]
23
+ end.to_h
24
+
25
+ # Reduce resolving names
26
+ env.signatures.replace(signatures)
27
+ env = env.resolve_type_names
28
+
29
+ store.each do |name, content|
30
+ out = StringIO.new
31
+ writer = RBS::Writer.new(out: out)
32
+ type_name = RBS::TypeName.parse(content.name).absolute!
33
+ entry, members = entry_and_members(env, type_name)
34
+ content.header = content_header(entry)
35
+ members.each do |member|
36
+ writer.write_member(member)
37
+ end
38
+ content.body.replace(out.string.lines)
39
+ end
40
+ end
41
+ end
42
+
43
+ private
44
+
45
+ def entry_and_members(env, type_name)
46
+ if type_name.class?
47
+ env.class_decls[type_name]&.then do |entry|
48
+ [entry, entry.decls.flat_map { |decl| decl.decl.members }]
49
+ end
50
+ elsif type_name.interface?
51
+ env.interface_decls[type_name]&.then do |entry|
52
+ [entry, [entry.decl.members]]
53
+ end
54
+ end.then do |entry, members|
55
+ unless entry
56
+ Orthoses.logger.warn "No entry for #{type_name}"
57
+ return
58
+ end
59
+ [entry, members]
60
+ end
61
+ end
62
+
63
+ def content_header(entry)
64
+ case entry
65
+ when RBS::Environment::ClassEntry
66
+ class_header(entry.primary.decl)
67
+ when RBS::Environment::ModuleEntry
68
+ module_header(entry.primary.decl)
69
+ when RBS::Environment::InterfaceEntry
70
+ interface_header(entry.decl)
71
+ else
72
+ raise "unexpected entry: #{entry}"
73
+ end
74
+ end
75
+
76
+ def class_header(decl)
77
+ super_class = if super_class = decl.super_class
78
+ " < #{name_and_args(super_class.name, super_class.args)}"
79
+ end
80
+ "class #{name_and_params(decl.name, decl.type_params)}#{super_class}"
81
+ end
82
+
83
+ def module_header(decl)
84
+ self_type = unless decl.self_types.empty?
85
+ " : #{decl.self_types.join(", ")}"
86
+ end
87
+ "module #{name_and_params(decl.name, decl.type_params)}#{self_type}"
88
+ end
89
+
90
+ def interface_header(decl)
91
+ "interface #{name_and_params(decl.name, decl.type_params)}"
92
+ end
93
+
94
+ module WriterCopy
95
+ def name_and_args(name, args)
96
+ if name && args
97
+ if args.empty?
98
+ "#{name}"
99
+ else
100
+ "#{name}[#{args.join(", ")}]"
101
+ end
102
+ end
103
+ end
104
+
105
+ def name_and_params(name, params)
106
+ if params.empty?
107
+ "#{name}"
108
+ else
109
+ ps = params.each.map do |param|
110
+ param.to_s
111
+ end
112
+
113
+ "#{name}[#{ps.join(", ")}]"
114
+ end
115
+ end
116
+ end
117
+ include WriterCopy
118
+ end
119
+ end
120
+ end
@@ -15,10 +15,18 @@ module Orthoses
15
15
  # def call
16
16
  # ...
17
17
  module Outputable
18
+ autoload :ResolveTypeNames, 'orthoses/outputable/resolve_type_names'
19
+
20
+ def initialize(loader, resolve_type_names: false, **)
21
+ @resolve_type_names = resolve_type_names
22
+ super(loader, **)
23
+ end
24
+
18
25
  def call
19
26
  @loader = AvoidRecursiveAncestorError.new(@loader)
20
27
  @loader = ConstantizableFilter.new(@loader)
21
28
  @loader = UniqContentBody.new(@loader)
29
+ @loader = ResolveTypeNames.new(@loader) if @resolve_type_names
22
30
  super
23
31
  end
24
32
  end
@@ -1,5 +1,5 @@
1
1
  # frozen_string_literal: true
2
2
 
3
3
  module Orthoses
4
- VERSION = "1.19.0"
4
+ VERSION = "1.20.0"
5
5
  end
data/lib/orthoses.rb CHANGED
@@ -28,7 +28,6 @@ module Orthoses
28
28
  autoload :PP, 'orthoses/pp'
29
29
  autoload :RBSPrototypeRB, 'orthoses/rbs_prototype_rb'
30
30
  autoload :RBSPrototypeRuntime, 'orthoses/rbs_prototype_runtime'
31
- autoload :ResolveTypeNames, 'orthoses/resolve_type_names'
32
31
  autoload :Sort, 'orthoses/sort'
33
32
  autoload :Store, 'orthoses/store'
34
33
  autoload :Tap, 'orthoses/tap'
@@ -1,5 +1,5 @@
1
1
  # THIS IS GENERATED CODE from `$ rake sig`
2
2
 
3
- interface Orthoses::_Call
3
+ interface ::Orthoses::_Call
4
4
  def call: () -> Orthoses::store
5
5
  end
@@ -1,5 +1,5 @@
1
1
  # THIS IS GENERATED CODE from `$ rake sig`
2
2
 
3
- interface Orthoses::_MiddleWare
3
+ interface ::Orthoses::_MiddleWare
4
4
  include Orthoses::_Call
5
5
  end
@@ -1,8 +1,12 @@
1
1
  # THIS IS GENERATED CODE from `$ rake sig`
2
2
 
3
3
  module Orthoses::Outputable
4
+ @resolve_type_names: untyped
5
+
4
6
  @loader: untyped
5
7
 
8
+ def initialize: (untyped loader, ?resolve_type_names: bool, **untyped) -> void
9
+
6
10
  def call: () -> untyped
7
11
  end
8
12
 
@@ -23,6 +27,23 @@ class Orthoses::Outputable::ConstantizableFilter
23
27
  def call: () -> untyped
24
28
  end
25
29
 
30
+ class Orthoses::Outputable::ResolveTypeNames
31
+ @loader: untyped
32
+ def initialize: (untyped loader) -> void
33
+ def call: () -> untyped
34
+ private def entry_and_members: (untyped env, untyped type_name) -> untyped
35
+ private def content_header: (untyped entry) -> untyped
36
+ private def class_header: (untyped decl) -> ::String
37
+ private def module_header: (untyped decl) -> ::String
38
+ private def interface_header: (untyped decl) -> ::String
39
+ end
40
+
41
+ module Orthoses::Outputable::ResolveTypeNames::WriterCopy
42
+ def name_and_args: (untyped name, untyped args) -> (::String | nil)
43
+
44
+ def name_and_params: (untyped name, untyped params) -> ::String
45
+ end
46
+
26
47
  # UniqContentBody is an internal middleware
27
48
  # It's using on orthoses/outputable.rb
28
49
  class Orthoses::Outputable::UniqContentBody
@@ -5,16 +5,16 @@
5
5
  # patterns: ['Foo::*']
6
6
  class Orthoses::RBSPrototypeRuntime
7
7
  @loader: Orthoses::_Call
8
- @patterns: Array[_ToS & Object | _Call & Object]?
8
+ @patterns: Array[(_ToS & Object) | (_Call & Object)]?
9
9
  @method_definition_filter: Orthoses::Content::Environment::method_definition_filter?
10
10
  @alias_filter: Orthoses::Content::Environment::alias_filter?
11
11
  @constant_filter: Orthoses::Content::Environment::constant_filter?
12
12
  @mixin_filter: Orthoses::Content::Environment::mixin_filter?
13
13
  @attribute_filter: Orthoses::Content::Environment::attribute_filter?
14
- def initialize: (Orthoses::_Call loader, ?patterns: Array[_ToS & Object | _Call & Object]?, ?method_definition_filter: Orthoses::Content::Environment::method_definition_filter?, ?alias_filter: Orthoses::Content::Environment::alias_filter?, ?constant_filter: Orthoses::Content::Environment::constant_filter?, ?mixin_filter: Orthoses::Content::Environment::mixin_filter?, ?attribute_filter: Orthoses::Content::Environment::attribute_filter?) -> void
14
+ def initialize: (Orthoses::_Call loader, ?patterns: Array[(_ToS & Object) | (_Call & Object)]?, ?method_definition_filter: Orthoses::Content::Environment::method_definition_filter?, ?alias_filter: Orthoses::Content::Environment::alias_filter?, ?constant_filter: Orthoses::Content::Environment::constant_filter?, ?mixin_filter: Orthoses::Content::Environment::mixin_filter?, ?attribute_filter: Orthoses::Content::Environment::attribute_filter?) -> void
15
15
  def call: () -> Orthoses::store
16
16
  end
17
17
 
18
- interface Orthoses::RBSPrototypeRuntime::_Call
18
+ interface ::Orthoses::RBSPrototypeRuntime::_Call
19
19
  def call: () -> (Array[String] | String)
20
20
  end
metadata CHANGED
@@ -1,13 +1,13 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: orthoses
3
3
  version: !ruby/object:Gem::Version
4
- version: 1.19.0
4
+ version: 1.20.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - ksss
8
8
  bindir: exe
9
9
  cert_chain: []
10
- date: 2025-03-08 00:00:00.000000000 Z
10
+ date: 2025-04-01 00:00:00.000000000 Z
11
11
  dependencies:
12
12
  - !ruby/object:Gem::Dependency
13
13
  name: rbs
@@ -58,12 +58,12 @@ files:
58
58
  - lib/orthoses/outputable.rb
59
59
  - lib/orthoses/outputable/avoid_recursive_ancestor_error.rb
60
60
  - lib/orthoses/outputable/constantizable_filter.rb
61
+ - lib/orthoses/outputable/resolve_type_names.rb
61
62
  - lib/orthoses/outputable/uniq_content_body.rb
62
63
  - lib/orthoses/path_helper.rb
63
64
  - lib/orthoses/pp.rb
64
65
  - lib/orthoses/rbs_prototype_rb.rb
65
66
  - lib/orthoses/rbs_prototype_runtime.rb
66
- - lib/orthoses/resolve_type_names.rb
67
67
  - lib/orthoses/shims.rb
68
68
  - lib/orthoses/sort.rb
69
69
  - lib/orthoses/store.rb
@@ -104,7 +104,6 @@ files:
104
104
  - sig/orthoses/pp.rbs
105
105
  - sig/orthoses/rbs_prototype_rb.rbs
106
106
  - sig/orthoses/rbs_prototype_runtime.rbs
107
- - sig/orthoses/resolve_type_names.rbs
108
107
  - sig/orthoses/sort.rbs
109
108
  - sig/orthoses/store.rbs
110
109
  - sig/orthoses/tap.rbs
@@ -125,14 +124,14 @@ required_ruby_version: !ruby/object:Gem::Requirement
125
124
  requirements:
126
125
  - - ">="
127
126
  - !ruby/object:Gem::Version
128
- version: 3.1.0
127
+ version: 3.2.0
129
128
  required_rubygems_version: !ruby/object:Gem::Requirement
130
129
  requirements:
131
130
  - - ">="
132
131
  - !ruby/object:Gem::Version
133
132
  version: '0'
134
133
  requirements: []
135
- rubygems_version: 3.6.2
134
+ rubygems_version: 3.6.6
136
135
  specification_version: 4
137
136
  summary: Framework for Generate RBS
138
137
  test_files: []
@@ -1,97 +0,0 @@
1
- # frozen_string_literal: true
2
-
3
- module Orthoses
4
- # use Orthoses::ResolveTypeNames
5
- class ResolveTypeNames
6
- def initialize(loader)
7
- @loader = loader
8
- end
9
-
10
- def call
11
- @loader.call.tap do |store|
12
- env = Utils.rbs_environment(cache: false)
13
-
14
- signatures = store.map do |name, content|
15
- buffer = RBS::Buffer.new(content: content.to_rbs, name: "orthoses-resolve_type_names-#{name.downcase}.rbs")
16
- decls = [content.to_decl]
17
-
18
- # Add as known types
19
- env.add_signature(buffer: buffer, directives: [], decls: decls)
20
-
21
- # Will resolve names
22
- [buffer, [[], decls]]
23
- end.to_h
24
-
25
- # Reduce resolving names
26
- env.signatures.replace(signatures)
27
- env = env.resolve_type_names
28
-
29
- store.each do |name, content|
30
- out = StringIO.new
31
- writer = RBS::Writer.new(out: out)
32
- type_name = RBS::TypeName.parse(content.name).absolute!
33
- entry = env.class_decls[type_name] || raise
34
- content.header = content_header(entry)
35
- entry.decls.each do |decl|
36
- decl.decl.members.each do |member|
37
- writer.write_member(member)
38
- end
39
- end
40
- content.body.replace(out.string.lines)
41
- end
42
- end
43
- end
44
-
45
- private
46
-
47
- def content_header(entry)
48
- case primary_decl = entry.primary.decl
49
- when RBS::AST::Declarations::Class
50
- class_header(primary_decl)
51
- when RBS::AST::Declarations::Module
52
- module_header(primary_decl)
53
- else
54
- raise "unexpected decl: #{primary_decl.class}"
55
- end
56
- end
57
-
58
- def class_header(decl)
59
- super_class = if super_class = decl.super_class
60
- " < #{name_and_args(super_class.name, super_class.args)}"
61
- end
62
- "class #{name_and_params(decl.name, decl.type_params)}#{super_class}"
63
- end
64
-
65
- def module_header(decl)
66
- self_type = unless decl.self_types.empty?
67
- " : #{decl.self_types.join(", ")}"
68
- end
69
- "module #{name_and_params(decl.name, decl.type_params)}#{self_type}"
70
- end
71
-
72
- module WriterCopy
73
- def name_and_args(name, args)
74
- if name && args
75
- if args.empty?
76
- "#{name}"
77
- else
78
- "#{name}[#{args.join(", ")}]"
79
- end
80
- end
81
- end
82
-
83
- def name_and_params(name, params)
84
- if params.empty?
85
- "#{name}"
86
- else
87
- ps = params.each.map do |param|
88
- param.to_s
89
- end
90
-
91
- "#{name}[#{ps.join(", ")}]"
92
- end
93
- end
94
- end
95
- include WriterCopy
96
- end
97
- end
@@ -1,17 +0,0 @@
1
- # THIS IS GENERATED CODE from `$ rake sig`
2
-
3
- # use Orthoses::ResolveTypeNames
4
- class Orthoses::ResolveTypeNames
5
- @loader: untyped
6
- def initialize: (untyped loader) -> void
7
- 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
17
- end