orthoses 1.13.0 → 1.15.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: 23443bbc790318672ea55f35fa859be2850d01abacd34f4274944c3bdc0bffab
4
- data.tar.gz: a92d9b0d889bb0fdbebfb643adf7471b62ff4b2f0f5faab7d4899f6f957df610
3
+ metadata.gz: '0555497d665f5573dfa6a86e454c165195f0e33ae82842fa83c2cff54b7d360d'
4
+ data.tar.gz: c760feb2cecc92c04f0eecedf9790d7ac9be2dd5a7aed5850d009d51e49594dd
5
5
  SHA512:
6
- metadata.gz: 2efacfd0945ca2070f50373c2b8cae1f4a0cba220a2cf2a815636fe76ed4d17ddd39124a40a9227e842f0215f05f764aebf49cf8d2b4ba8254412baf82789062
7
- data.tar.gz: 7a79c8c1515ac995d4a261776d68c01a684820aa9b00b635a93929e6561f8b5c431909f4ff158451e2f0daeddbf9948e6ef178c5123fc4b5bfdcbc30d294300f
6
+ metadata.gz: f3febe9350d66db369d8d8b24bd3ef6e3a1885b0207a5bef263a048e4eab732604f48d0fe27900ae1318f29ea87cc1f018a06f9b62a544aae8a402d0312674d1
7
+ data.tar.gz: e90e69dcd746b3a83984e3234e51666f9cc9102670a71f09676ce97c664c79ff9f68b84ed3da4d7d43a4aa5213b091f05e6455ca6c4709ee54a13dfeab91de23
data/README.md CHANGED
@@ -175,15 +175,20 @@ Force load const defined by `autoload`.
175
175
 
176
176
  Sort signatures by class/module.
177
177
 
178
- ## Orthoses::Trace
178
+ ### Orthoses::Trace
179
179
 
180
180
  Trace the argument and return value objects when the method is actually called and determine the type.
181
181
 
182
- ## Orthoses::MissingName
182
+ ### Orthoses::MissingName
183
183
 
184
184
  Completes undefined class/module names.
185
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
186
 
187
+ ### Orthoses::ExcludeRBS
188
+
189
+ You can specify that the specified RBS should not be intentionally generated.
190
+ This is useful when you want to exclude handwritten RBS.
191
+
187
192
  ## Development
188
193
 
189
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.
@@ -18,7 +18,9 @@ module Orthoses
18
18
  drop_known_method_definition
19
19
  drop_known_const_definition
20
20
 
21
- @decl.members.replace(@uniq_map.values)
21
+ # HACK
22
+ new_members = @uniq_map.values
23
+ @decl.instance_eval { @members = new_members }
22
24
 
23
25
  @uniq_map.clear
24
26
  end
@@ -3,6 +3,11 @@
3
3
  require 'orthoses/outputable'
4
4
 
5
5
  module Orthoses
6
+ # @param to [String, nil]
7
+ # @param header [String, nil]
8
+ # @param if [Proc, nil]
9
+ # @param depth [Integer, Hash{String => Integer}, nil]
10
+ # @param rmtree [Boolean]
6
11
  class CreateFileByName
7
12
  prepend Outputable
8
13
 
@@ -43,8 +48,7 @@ module Orthoses
43
48
  @if.nil? || @if.call(name, content)
44
49
  end
45
50
  grouped = store.group_by do |name, _|
46
- splitted = name.to_s.split('::')
47
- (@depth ? splitted[0, @depth] : splitted).join('::')
51
+ extract(name)
48
52
  end
49
53
 
50
54
  grouped.each do |group_name, group|
@@ -64,5 +68,24 @@ module Orthoses
64
68
  end
65
69
  end
66
70
  end
71
+
72
+ def extract(name)
73
+ case @depth
74
+ when nil
75
+ name.to_s
76
+ when Integer
77
+ name.split('::')[0, @depth].join('::')
78
+ when Hash
79
+ found_key, found_index = @depth.find do |n, _|
80
+ name.start_with?(n)
81
+ end
82
+ case found_index
83
+ when nil
84
+ name.to_s
85
+ else
86
+ name.split('::')[0, found_index].join('::')
87
+ end
88
+ end
89
+ end
67
90
  end
68
91
  end
@@ -0,0 +1,36 @@
1
+ # frozen_string_literal: true
2
+
3
+ module Orthoses
4
+ # Exclude RBS from output.
5
+ # @example
6
+ # use Orthoses::ExcludeRBS, paths: Dir['sig/hand-written/**/*.rbs']
7
+ class ExcludeRBS
8
+ def initialize(loader, paths: nil, rbs: nil)
9
+ raise ArgumentError, ':paths or :rbs keyword is required' if paths.nil? && rbs.nil?
10
+
11
+ @loader = loader
12
+ @paths = paths
13
+ @rbs = rbs
14
+ end
15
+
16
+ def call
17
+ case
18
+ when @paths
19
+ @paths.each do |path|
20
+ add_signature_to_known_env(File.read(path.to_s))
21
+ end
22
+ when @rbs
23
+ add_signature_to_known_env(@rbs)
24
+ else
25
+ raise "bug"
26
+ end
27
+
28
+ @loader.call
29
+ end
30
+
31
+ def add_signature_to_known_env(rbs)
32
+ buffer, directives, decls = ::RBS::Parser.parse_signature(rbs)
33
+ Utils.rbs_environment.add_signature(buffer: buffer, directives: directives, decls: decls)
34
+ end
35
+ end
36
+ end
@@ -23,9 +23,10 @@ module Orthoses
23
23
 
24
24
  include Targetable
25
25
 
26
- def initialize(loader, patterns:)
26
+ def initialize(loader, patterns:, sort_union_types: true)
27
27
  @loader = loader
28
28
  @patterns = patterns
29
+ @sort_union_types = sort_union_types
29
30
 
30
31
  @captured_dict = Hash.new { |h, k| h[k] = Hash.new { |hh, kk| hh[kk] = [] } }
31
32
  end
@@ -45,6 +46,7 @@ module Orthoses
45
46
 
46
47
  @captured_dict.each do |mod_name, captures|
47
48
  captures.each do |(kind, prefix, name), types|
49
+ types.sort! if @sort_union_types
48
50
  injected = Utils::TypeList.new(types).inject
49
51
  store[mod_name] << "#{kind} #{prefix}#{name}: #{injected}"
50
52
  end
@@ -7,9 +7,10 @@ module Orthoses
7
7
  Info = Struct.new(:key, :op_name_types, :raised, keyword_init: true)
8
8
  include Targetable
9
9
 
10
- def initialize(loader, patterns:)
10
+ def initialize(loader, patterns:, sort_union_types: true)
11
11
  @loader = loader
12
12
  @patterns = patterns
13
+ @sort_union_types = sort_union_types
13
14
 
14
15
  @stack = []
15
16
  @args_return_map = Hash.new { |h, k| h[k] = [] }
@@ -36,9 +37,7 @@ module Orthoses
36
37
  case tp.event
37
38
  when :call
38
39
  if tp.defined_class.singleton_class?
39
- # e.g. `Minitest::Spec::DSL#to_s`` may return `nil` with `#to_s`
40
- m = tp.defined_class.to_s&.match(/#<Class:([\w:]+)>/) or next
41
- mod_name = m[1] or next
40
+ mod_name = Utils.attached_module_name(tp.defined_class) or next
42
41
  kind = :singleton
43
42
  else
44
43
  mod_name = Utils.module_name(tp.defined_class) or next
@@ -81,6 +80,7 @@ module Orthoses
81
80
 
82
81
  @args_return_map.map do |(mod_name, kind, visibility, method_id), type_samples|
83
82
  type_samples.uniq!
83
+ type_samples.sort! if @sort_union_types
84
84
  method_types = type_samples.map do |(op_name_types, return_type)|
85
85
  required_positionals = []
86
86
  optional_positionals = []
@@ -171,6 +171,17 @@ module Orthoses
171
171
  end
172
172
  end
173
173
 
174
+ def self.attached_module_name(mod)
175
+ if mod.respond_to?(:attached_object)
176
+ attached_object = mod.attached_object
177
+ (attached_object&.is_a?(Module) && attached_object.name) || nil
178
+ else
179
+ # e.g. `Minitest::Spec::DSL#to_s` may return `nil` with `#to_s`
180
+ m = mod.to_s&.match(/#<Class:([\w:]+)>/)
181
+ m && m[1]
182
+ end
183
+ end
184
+
174
185
  def self.known_type_params(name)
175
186
  type_name =
176
187
  case name
@@ -1,5 +1,5 @@
1
1
  # frozen_string_literal: true
2
2
 
3
3
  module Orthoses
4
- VERSION = "1.13.0"
4
+ VERSION = "1.15.0"
5
5
  end
data/lib/orthoses.rb CHANGED
@@ -14,6 +14,7 @@ module Orthoses
14
14
  autoload :CreateFileByName, 'orthoses/create_file_by_name'
15
15
  autoload :DelegateClass, 'orthoses/delegate_class'
16
16
  autoload :Descendants, 'orthoses/descendants'
17
+ autoload :ExcludeRBS, 'orthoses/exclude_rbs'
17
18
  autoload :Filter, 'orthoses/filter'
18
19
  autoload :Mixin, 'orthoses/mixin'
19
20
  autoload :LazyTracePoint, 'orthoses/lazy_trace_point'
@@ -17,7 +17,7 @@ module Orthoses::CallTracer::Capturable
17
17
  end
18
18
 
19
19
  module Orthoses::CallTracer::Capturable::ExtractRestParameters
20
- def __extract_rest_parameters__: (*untyped rest, **untyped kw_rest) { () -> untyped } -> { :* => untyped, :** => untyped, :& => untyped, :"..." => ::Array[untyped] }
20
+ def __extract_rest_parameters__: (*untyped rest, **untyped kw_rest) { (*untyped, **untyped) -> untyped } -> untyped
21
21
  end
22
22
 
23
23
  class Orthoses::CallTracer::Capture < ::Struct[untyped]
@@ -3,7 +3,7 @@
3
3
  class Orthoses::Constant
4
4
  @loader: Orthoses::_Call
5
5
  @strict: bool
6
- @if: ^(Module mod, Symbol const, untyped val, String rbs) -> boolish?
6
+ @if: (^(Module mod, Symbol const, untyped val, String rbs) -> boolish)?
7
7
  @on_error: ^(Orthoses::ConstLoadError) -> void | nil
8
8
  def initialize: (Orthoses::_Call loader, ?strict: bool, ?if: ^(Module, Symbol, untyped) -> boolish | nil, ?on_error: ^(Orthoses::ConstLoadError) -> void | nil) -> void
9
9
  def call: () -> Orthoses::store
@@ -1,5 +1,10 @@
1
1
  # THIS IS GENERATED CODE from `$ rake sig`
2
2
 
3
+ # @param to [String, nil]
4
+ # @param header [String, nil]
5
+ # @param if [Proc, nil]
6
+ # @param depth [Integer, Hash{String => Integer}, nil]
7
+ # @param rmtree [Boolean]
3
8
  class Orthoses::CreateFileByName
4
9
  @loader: Orthoses::_Call
5
10
  @to: untyped
@@ -7,6 +12,7 @@ class Orthoses::CreateFileByName
7
12
  @depth: untyped
8
13
  @rmtree: untyped
9
14
  @if: untyped
10
- def initialize: (Orthoses::_Call loader, to: String, ?header: String?, ?depth: Integer?, ?rmtree: boolish) -> void
15
+ def initialize: (Orthoses::_Call loader, to: String, ?header: String?, ?depth: Integer | Hash[String, Integer] | nil, ?rmtree: boolish) -> void
11
16
  def call: () -> Orthoses::store
17
+ def extract: (untyped name) -> untyped
12
18
  end
@@ -0,0 +1,13 @@
1
+ # THIS IS GENERATED CODE from `$ rake sig`
2
+
3
+ # Exclude RBS from output.
4
+ # @example
5
+ # use Orthoses::ExcludeRBS, paths: Dir['sig/hand-written/**/*.rbs']
6
+ class Orthoses::ExcludeRBS
7
+ @loader: untyped
8
+ @paths: untyped
9
+ @rbs: untyped
10
+ def initialize: (untyped loader, ?paths: untyped?, ?rbs: untyped?) -> void
11
+ def call: () -> untyped
12
+ def add_signature_to_known_env: (untyped rbs) -> untyped
13
+ end
@@ -10,9 +10,10 @@ end
10
10
  class Orthoses::Trace::Attribute
11
11
  @loader: untyped
12
12
  @patterns: untyped
13
+ @sort_union_types: untyped
13
14
  @captured_dict: untyped
14
- def initialize: (untyped loader, patterns: untyped) -> void
15
- def call: () -> untyped
15
+ def initialize: (Orthoses::_Call loader, patterns: Array[String], ?sort_union_types: bool?) -> void
16
+ def call: () -> Orthoses::store
16
17
  private def build_trace_hook: () -> untyped
17
18
  include Orthoses::Trace::Targetable
18
19
  end
@@ -30,11 +31,12 @@ end
30
31
  class Orthoses::Trace::Method
31
32
  @loader: untyped
32
33
  @patterns: untyped
34
+ @sort_union_types: untyped
33
35
  @stack: untyped
34
36
  @args_return_map: untyped
35
37
  @alias_map: untyped
36
- def initialize: (untyped loader, patterns: untyped) -> void
37
- def call: () -> untyped
38
+ def initialize: (Orthoses::_Call loader, patterns: Array[String], ?sort_union_types: bool?) -> void
39
+ def call: () -> Orthoses::store
38
40
  private def build_trace_point: () -> untyped
39
41
  private def build_members: () -> untyped
40
42
  private def build_method_definitions: () -> untyped
@@ -21,6 +21,8 @@ module Orthoses::Utils
21
21
 
22
22
  def self.module_to_type_name: (Module) -> RBS::TypeName?
23
23
 
24
+ def self.attached_module_name: (Module) -> String?
25
+
24
26
  def self.known_type_params: (Module | String) -> Array[RBS::AST::TypeParam]?
25
27
 
26
28
  def self.new_store: () -> Orthoses::store
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: 1.13.0
4
+ version: 1.15.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - ksss
8
8
  autorequire:
9
9
  bindir: exe
10
10
  cert_chain: []
11
- date: 2023-11-05 00:00:00.000000000 Z
11
+ date: 2024-10-25 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: rbs
@@ -49,6 +49,7 @@ files:
49
49
  - lib/orthoses/create_file_by_name.rb
50
50
  - lib/orthoses/delegate_class.rb
51
51
  - lib/orthoses/descendants.rb
52
+ - lib/orthoses/exclude_rbs.rb
52
53
  - lib/orthoses/filter.rb
53
54
  - lib/orthoses/lazy_trace_point.rb
54
55
  - lib/orthoses/load_rbs.rb
@@ -89,6 +90,7 @@ files:
89
90
  - sig/orthoses/create_file_by_name.rbs
90
91
  - sig/orthoses/delegate_class.rbs
91
92
  - sig/orthoses/descendants.rbs
93
+ - sig/orthoses/exclude_rbs.rbs
92
94
  - sig/orthoses/filter.rbs
93
95
  - sig/orthoses/lazy_trace_point.rbs
94
96
  - sig/orthoses/load_rbs.rbs
@@ -122,14 +124,14 @@ required_ruby_version: !ruby/object:Gem::Requirement
122
124
  requirements:
123
125
  - - ">="
124
126
  - !ruby/object:Gem::Version
125
- version: 3.0.0
127
+ version: 3.1.0
126
128
  required_rubygems_version: !ruby/object:Gem::Requirement
127
129
  requirements:
128
130
  - - ">="
129
131
  - !ruby/object:Gem::Version
130
132
  version: '0'
131
133
  requirements: []
132
- rubygems_version: 3.4.10
134
+ rubygems_version: 3.5.16
133
135
  signing_key:
134
136
  specification_version: 4
135
137
  summary: Framework for Generate RBS