orthoses 1.13.0 → 1.14.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: 23443bbc790318672ea55f35fa859be2850d01abacd34f4274944c3bdc0bffab
4
- data.tar.gz: a92d9b0d889bb0fdbebfb643adf7471b62ff4b2f0f5faab7d4899f6f957df610
3
+ metadata.gz: ccd997f8aa90c6f1d49fdebe0a58c2de59d0df1e7146efa5c69d7d3614927c1b
4
+ data.tar.gz: 2f02a44951ad7b654e48d21c3b4100955997f102d616c494461bbbfeefdc7cc1
5
5
  SHA512:
6
- metadata.gz: 2efacfd0945ca2070f50373c2b8cae1f4a0cba220a2cf2a815636fe76ed4d17ddd39124a40a9227e842f0215f05f764aebf49cf8d2b4ba8254412baf82789062
7
- data.tar.gz: 7a79c8c1515ac995d4a261776d68c01a684820aa9b00b635a93929e6561f8b5c431909f4ff158451e2f0daeddbf9948e6ef178c5123fc4b5bfdcbc30d294300f
6
+ metadata.gz: 2023496aaf266db6a0d5945a288891967fb3b61bf0b2851e270e56fc6e87398abd7bc761db2dd35dde313bd8f0c66cbfc9ede859d0b008356d4275bd9efa36fb
7
+ data.tar.gz: 622b6a3bd44b197620c5221998316d334bf47f5332a9e561df87226a8480fb4ebee1ab0ab50f7f7f5bed97fb24cc137ee5f427000004b469caadccc9987f40bb
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.
@@ -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
@@ -1,5 +1,5 @@
1
1
  # frozen_string_literal: true
2
2
 
3
3
  module Orthoses
4
- VERSION = "1.13.0"
4
+ VERSION = "1.14.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
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.14.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-07-03 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
@@ -129,7 +131,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
129
131
  - !ruby/object:Gem::Version
130
132
  version: '0'
131
133
  requirements: []
132
- rubygems_version: 3.4.10
134
+ rubygems_version: 3.5.11
133
135
  signing_key:
134
136
  specification_version: 4
135
137
  summary: Framework for Generate RBS