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 CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: 2941ebbe45d7ab2dc9ad009628db52419a6a3b18a1fd1ad870164ab017bbb5e1
4
- data.tar.gz: 5a33b4b63f62b820f4642d56661cebd393c3381363a8f727655f123568b2784b
3
+ metadata.gz: 9a88a402248539e68e824aeb28c7a47a17b2b8c8920c454dbec4fe87305a5999
4
+ data.tar.gz: 1c9e0aa222e72261b5b5fd09649023c61eff09043823a4eb3e98d909aff93fc7
5
5
  SHA512:
6
- metadata.gz: bd9a27c8a8f6752fc73c2c65b8dbb0edcb9885425667a8a067a6d56cc2bb32473db565ea41089ad0f8b26c598275afa83e2fb3bbde6f668fc095c942bb75af01
7
- data.tar.gz: 4b6c157a129e1e3dfab42737ba1a4ba0f9c1c5ffe25defb693de3bce39f63fdcc746b155d030e273162e550ada315281553d921475bd4a333bf362a46e5a58bd
6
+ metadata.gz: b825842ed1899b7e51ee40376845a4e869563c2fbe66e56a16ebe62672291acdb2a9e9e66a29bf4a7a8d0e3644fb6d2848b268cc2a09fbbe9adc3f85ef955872
7
+ data.tar.gz: 21bfe767137adea2246fcbb1f6883266f0b76aa1c367faafe773fcf902184374cda1ee175d4b62eee99435714dfc1bec7b1403d20db4dab5de3faabc4df98754
data/Gemfile.lock CHANGED
@@ -1,7 +1,7 @@
1
1
  PATH
2
2
  remote: .
3
3
  specs:
4
- orthoses (0.8.0)
4
+ orthoses (0.9.0)
5
5
  rbs (~> 2.0)
6
6
 
7
7
  GEM
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.outer.length.times.map do |i|
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
- "interface #{name_and_params(full_name, entry.decl.type_params)}"
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)
@@ -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
@@ -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
- "singleton(#{object})"
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
- Utils.module_name(object.class) || 'untyped'
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
- Utils.module_name(object.class) || 'untyped'
158
+ module_name(object.class) || 'untyped'
155
159
  end
156
160
  end
157
161
 
@@ -1,5 +1,5 @@
1
1
  # frozen_string_literal: true
2
2
 
3
3
  module Orthoses
4
- VERSION = "0.8.0"
4
+ VERSION = "0.9.0"
5
5
  end
@@ -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
@@ -1,7 +1,7 @@
1
1
  # THIS IS GENERATED CODE from `$ rake generate_self_sig`
2
2
 
3
3
  module Orthoses
4
- VERSION: "0.8.0"
4
+ VERSION: "0.9.0"
5
5
 
6
6
  attr_accessor self.logger: ::Logger
7
7
 
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.8.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-10 00:00:00.000000000 Z
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.7
120
+ rubygems_version: 3.3.15
121
121
  signing_key:
122
122
  specification_version: 4
123
123
  summary: Framework for Generate RBS