orthoses 0.8.0 → 0.9.0
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/Gemfile.lock +1 -1
- data/README.md +37 -1
- data/lib/orthoses/content/header_builder.rb +11 -6
- data/lib/orthoses/content.rb +5 -5
- data/lib/orthoses/utils.rb +7 -3
- data/lib/orthoses/version.rb +1 -1
- data/sig/orthoses/content/header_builder.rbs +1 -0
- data/sig/orthoses.rbs +1 -1
- metadata +3 -3
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 9a88a402248539e68e824aeb28c7a47a17b2b8c8920c454dbec4fe87305a5999
|
4
|
+
data.tar.gz: 1c9e0aa222e72261b5b5fd09649023c61eff09043823a4eb3e98d909aff93fc7
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: b825842ed1899b7e51ee40376845a4e869563c2fbe66e56a16ebe62672291acdb2a9e9e66a29bf4a7a8d0e3644fb6d2848b268cc2a09fbbe9adc3f85ef955872
|
7
|
+
data.tar.gz: 21bfe767137adea2246fcbb1f6883266f0b76aa1c367faafe773fcf902184374cda1ee175d4b62eee99435714dfc1bec7b1403d20db4dab5de3faabc4df98754
|
data/Gemfile.lock
CHANGED
data/README.md
CHANGED
@@ -41,6 +41,38 @@ Orthoses::Builder.new do
|
|
41
41
|
end.call
|
42
42
|
```
|
43
43
|
|
44
|
+
## Utils
|
45
|
+
|
46
|
+
`Orthoses::Utils` is a collection of useful methods.
|
47
|
+
|
48
|
+
### Orthoses::Utils.unautoload!
|
49
|
+
|
50
|
+
Load all const by recursive.
|
51
|
+
|
52
|
+
### Orthoses::Utils.each_const_recursive
|
53
|
+
|
54
|
+
Yield const by recursive.
|
55
|
+
|
56
|
+
### Orthoses::Utils.rbs_defined_const?
|
57
|
+
|
58
|
+
Checks if the const name is already defined.
|
59
|
+
|
60
|
+
### Orthoses::Utils.rbs_defined_class?
|
61
|
+
|
62
|
+
Checks if the class name is already defined.
|
63
|
+
|
64
|
+
### Orthoses::Utils.rbs_environment
|
65
|
+
|
66
|
+
Fetch cached `RBS::Environment`.
|
67
|
+
|
68
|
+
### Orthoses::Utils.object_to_rbs
|
69
|
+
|
70
|
+
Convert Ruby object to RBS string.
|
71
|
+
|
72
|
+
### Orthoses::Utils.module_name
|
73
|
+
|
74
|
+
Get true module name by `Module.instance_method(:name).bind(mod).call`.
|
75
|
+
|
44
76
|
## Middlewares
|
45
77
|
|
46
78
|
### Orthoses::Constant
|
@@ -48,10 +80,14 @@ end.call
|
|
48
80
|
Add constant signature to class/module.
|
49
81
|
Signatures are predicted from constant values.
|
50
82
|
|
83
|
+
### Orthoses::Attribute
|
84
|
+
|
85
|
+
Add `attr`, `attr_accessor`, `attr_reader` and `attr_writer` to output RBS.
|
86
|
+
All type set `untyped`.
|
87
|
+
|
51
88
|
### Orthoses::Mixin
|
52
89
|
|
53
90
|
Add module include/extend/prepend definition.
|
54
|
-
It use `Module#{includeed,extended,prepended}` for capture.
|
55
91
|
|
56
92
|
### Orthoses::ObjectSpaceAll
|
57
93
|
|
@@ -45,11 +45,7 @@ module Orthoses
|
|
45
45
|
def build_super_class(primary)
|
46
46
|
return nil if primary.decl.super_class.then { |s| s.nil? || s.name.relative!.to_s.then { |n| n == "Object" || n == "Random::Base" } }
|
47
47
|
|
48
|
-
context = primary
|
49
|
-
primary.outer[0, i + 1].map(&:name).inject(:+).to_namespace.absolute!
|
50
|
-
end
|
51
|
-
context.push(RBS::Namespace.root)
|
52
|
-
|
48
|
+
context = build_context(entry: primary)
|
53
49
|
super_class_name = @resolver.resolve(primary.decl.super_class.name, context: context) || primary.decl.super_class.name
|
54
50
|
if primary.decl.super_class.args.empty?
|
55
51
|
if super_class_entry = @env.class_decls[super_class_name]
|
@@ -65,7 +61,16 @@ module Orthoses
|
|
65
61
|
|
66
62
|
def build_interface(entry:, name_hint: nil)
|
67
63
|
full_name = name_hint || entry.decl.name.relative!
|
68
|
-
|
64
|
+
context = build_context(entry: entry)
|
65
|
+
resolved_name = @resolver.resolve(full_name, context: context) || full_name
|
66
|
+
"interface #{name_and_params(resolved_name.relative!, entry.decl.type_params)}"
|
67
|
+
end
|
68
|
+
|
69
|
+
def build_context(entry:)
|
70
|
+
context = entry.outer.length.times.map do |i|
|
71
|
+
entry.outer[0, i + 1].map(&:name).inject(:+).to_namespace.absolute!
|
72
|
+
end
|
73
|
+
context.push(RBS::Namespace.root)
|
69
74
|
end
|
70
75
|
|
71
76
|
def name_and_params(name, params)
|
data/lib/orthoses/content.rb
CHANGED
@@ -81,11 +81,6 @@ module Orthoses
|
|
81
81
|
end
|
82
82
|
|
83
83
|
def auto_header
|
84
|
-
if name.split('::').last.start_with?('_')
|
85
|
-
self.header = "interface #{name}"
|
86
|
-
return
|
87
|
-
end
|
88
|
-
|
89
84
|
env = Utils.rbs_environment(collection: true)
|
90
85
|
if entry = env.class_decls[TypeName(name).absolute!]
|
91
86
|
@header = Content::HeaderBuilder.new(env: env).build(entry: entry)
|
@@ -94,6 +89,11 @@ module Orthoses
|
|
94
89
|
|
95
90
|
return unless @header.nil?
|
96
91
|
|
92
|
+
if name.split('::').last.start_with?('_')
|
93
|
+
self.header = "interface #{name}"
|
94
|
+
return
|
95
|
+
end
|
96
|
+
|
97
97
|
val = Object.const_get(name)
|
98
98
|
|
99
99
|
case val
|
data/lib/orthoses/utils.rb
CHANGED
@@ -101,12 +101,16 @@ module Orthoses
|
|
101
101
|
def self.object_to_rbs(object, strict:)
|
102
102
|
case object
|
103
103
|
when Class, Module
|
104
|
-
|
104
|
+
if name = module_name(object)
|
105
|
+
"singleton(#{name})"
|
106
|
+
else
|
107
|
+
"untyped"
|
108
|
+
end
|
105
109
|
when Integer, Symbol, String
|
106
110
|
if strict
|
107
111
|
object.inspect
|
108
112
|
else
|
109
|
-
|
113
|
+
module_name(object.class) || 'untyped'
|
110
114
|
end
|
111
115
|
when true, false, nil
|
112
116
|
object.inspect
|
@@ -151,7 +155,7 @@ module Orthoses
|
|
151
155
|
# see also https://github.com/ruby/rbs/pull/975
|
152
156
|
'untyped'
|
153
157
|
else
|
154
|
-
|
158
|
+
module_name(object.class) || 'untyped'
|
155
159
|
end
|
156
160
|
end
|
157
161
|
|
data/lib/orthoses/version.rb
CHANGED
@@ -7,6 +7,7 @@ class Orthoses::Content::HeaderBuilder
|
|
7
7
|
private def build_class: (entry: untyped, ?name_hint: untyped?) -> ::String
|
8
8
|
private def build_super_class: (untyped primary) -> (nil | untyped)
|
9
9
|
private def build_interface: (entry: untyped, ?name_hint: untyped?) -> ::String
|
10
|
+
private def build_context: (entry: untyped) -> untyped
|
10
11
|
private def name_and_params: (untyped name, untyped params) -> ::String
|
11
12
|
private def name_and_args: (untyped name, untyped args) -> (::String | nil)
|
12
13
|
end
|
data/sig/orthoses.rbs
CHANGED
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: orthoses
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.
|
4
|
+
version: 0.9.0
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- ksss
|
8
8
|
autorequire:
|
9
9
|
bindir: exe
|
10
10
|
cert_chain: []
|
11
|
-
date: 2022-06-
|
11
|
+
date: 2022-06-14 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: rbs
|
@@ -117,7 +117,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
|
|
117
117
|
- !ruby/object:Gem::Version
|
118
118
|
version: '0'
|
119
119
|
requirements: []
|
120
|
-
rubygems_version: 3.3.
|
120
|
+
rubygems_version: 3.3.15
|
121
121
|
signing_key:
|
122
122
|
specification_version: 4
|
123
123
|
summary: Framework for Generate RBS
|