orthoses 1.0.0 → 1.2.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 +4 -4
- data/Gemfile.lock +1 -1
- data/README.md +38 -22
- data/lib/orthoses/content/duplication_checker.rb +11 -6
- data/lib/orthoses/content/environment.rb +1 -1
- data/lib/orthoses/content.rb +6 -2
- data/lib/orthoses/create_file_by_name.rb +1 -22
- data/lib/orthoses/outputable/avoid_recursive_ancestor_error.rb +3 -0
- data/lib/orthoses/outputable/uniq_content_body.rb +26 -0
- data/lib/orthoses/outputable.rb +2 -0
- data/lib/orthoses/utils/underscore.rb +21 -0
- data/lib/orthoses/utils.rb +6 -4
- data/lib/orthoses/version.rb +1 -1
- data/lib/orthoses.rb +23 -25
- data/sig/orthoses/outputable/uniq_content_body.rbs +6 -0
- data/sig/orthoses/utils/underscore.rbs +4 -0
- data/sig/orthoses.rbs +1 -1
- metadata +7 -3
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 0520f0eccc23c9e57186592193f7c30175b59aa1364bcf5de49f1bcbff0a68d5
|
4
|
+
data.tar.gz: deaeb9dd3baed337b22a0b6990bbddd98df1c282c1dc6269edeb3a78060abae1
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 94037bb0ff51e74b055e8282048d818ca051a102fdcdb16f64dc00c1a83194bcd4a721d68c9dbf43e47a691b66ef7b992b319a69fff4b0afc9374cdf8001d0a2
|
7
|
+
data.tar.gz: 27611b811fead68b26ccd941d5111039ad7fddb0fdaad6d0509bf9b5d6bdfc29783daab517a959389a95890eba75ce57b5933a9c26158f17b3a2d8d0ab2948ff
|
data/Gemfile.lock
CHANGED
data/README.md
CHANGED
@@ -3,6 +3,10 @@
|
|
3
3
|
Orthoses is a framework for RBS generation.
|
4
4
|
The Rack architecture keeps your code organized and extensible.
|
5
5
|
|
6
|
+
- You can choose which middleware to use.
|
7
|
+
- You can write your own middleware to use.
|
8
|
+
- You can publish your middleware and share it with the world.
|
9
|
+
|
6
10
|
## PoC
|
7
11
|
|
8
12
|
https://gist.github.com/ksss/00592da24f28774bf8fc5db08331666e
|
@@ -19,27 +23,38 @@ If bundler is not being used to manage dependencies, install the gem by executin
|
|
19
23
|
|
20
24
|
## Usage
|
21
25
|
|
26
|
+
For example, You can write script in Rakefile.
|
27
|
+
|
22
28
|
```rb
|
23
|
-
|
24
|
-
|
25
|
-
|
26
|
-
|
27
|
-
|
28
|
-
|
29
|
-
|
30
|
-
|
29
|
+
require 'orthoses'
|
30
|
+
|
31
|
+
namespace :rbs do
|
32
|
+
desc "build RBS to sig/out"
|
33
|
+
task :build do
|
34
|
+
Orthoses::Builder.new do
|
35
|
+
use Orthoses::CreateFileByName,
|
36
|
+
base_dir: Rails.root.join("sig/out"),
|
37
|
+
header: "# !!! GENERATED CODE !!!"
|
38
|
+
use Orthoses::Filter do |name, _content|
|
39
|
+
path, _lineno = Object.const_source_location(name)
|
40
|
+
return false unless path
|
41
|
+
%r{app/models}.match?(path)
|
42
|
+
end
|
43
|
+
use YourCustom::Middleware
|
44
|
+
use Orthoses::Mixin
|
45
|
+
use Orthoses::Constant
|
46
|
+
use Orthoses::Walk,
|
47
|
+
root: "Foo"
|
48
|
+
run -> {
|
49
|
+
# load library or application
|
50
|
+
}
|
51
|
+
end.call
|
31
52
|
end
|
32
|
-
|
33
|
-
use Orthoses::Mixin
|
34
|
-
use Orthoses::Constant
|
35
|
-
use Orthoses::Walk,
|
36
|
-
root: "Foo"
|
37
|
-
run -> () {
|
38
|
-
# load library or application
|
39
|
-
}
|
40
|
-
end.call
|
53
|
+
end
|
41
54
|
```
|
42
55
|
|
56
|
+
Then, you can see the result files under `sig/out`.
|
57
|
+
|
43
58
|
## Utils
|
44
59
|
|
45
60
|
`Orthoses::Utils` is a collection of useful methods.
|
@@ -150,11 +165,6 @@ Run `rbs prototype rb` command process to `paths` option files.
|
|
150
165
|
|
151
166
|
Run `rbs prototype runtime` command process with `patterns` option string.
|
152
167
|
|
153
|
-
### Orthoses::AvoidRecursiveAncestorError
|
154
|
-
|
155
|
-
Mixin a module into an Object class raises `RBS::RecursiveAncestorError` when validation.
|
156
|
-
Please add this middleware then.
|
157
|
-
|
158
168
|
### Orthoses::Autoload
|
159
169
|
|
160
170
|
Force load const defined by `autoload`.
|
@@ -176,3 +186,9 @@ The gem is available as open source under the terms of the [MIT License](https:/
|
|
176
186
|
## Code of Conduct
|
177
187
|
|
178
188
|
Everyone interacting in the Orthoses project's codebases, issue trackers, chat rooms and mailing lists is expected to follow the [code of conduct](https://github.com/ksss/orthoses/blob/main/CODE_OF_CONDUCT.md).
|
189
|
+
|
190
|
+
# TODO
|
191
|
+
|
192
|
+
- Share middleware sets for commonly used use cases.
|
193
|
+
- For library.
|
194
|
+
- For application.
|
@@ -4,18 +4,23 @@ module Orthoses
|
|
4
4
|
class DuplicationChecker
|
5
5
|
def initialize(decl, env: nil)
|
6
6
|
@decl = decl
|
7
|
-
@env = env || Utils.rbs_environment
|
7
|
+
@env = env || Utils.rbs_environment
|
8
8
|
end
|
9
9
|
|
10
10
|
def update_decl
|
11
11
|
return unless @decl.respond_to?(:members)
|
12
12
|
uniq_map = {}
|
13
13
|
@decl.members.each do |member|
|
14
|
-
|
15
|
-
|
16
|
-
|
17
|
-
|
18
|
-
|
14
|
+
if member.instance_of?(RBS::AST::Members::MethodDefinition) && member.overload
|
15
|
+
# avoid to duplicate and keep order
|
16
|
+
uniq_map[Object.new] = member
|
17
|
+
else
|
18
|
+
key = member_key(member)
|
19
|
+
drop_member = uniq_map[key]
|
20
|
+
uniq_map[key] = member
|
21
|
+
if drop_member
|
22
|
+
Orthoses.logger.info("#{@decl.name} \"#{member.location.source}\" was droped since duplication")
|
23
|
+
end
|
19
24
|
end
|
20
25
|
end
|
21
26
|
drop_known_method_definition(uniq_map)
|
@@ -17,7 +17,7 @@ module Orthoses
|
|
17
17
|
|
18
18
|
def initialize(constant_filter: nil, mixin_filter: nil, attribute_filter: nil)
|
19
19
|
@load_env = RBS::Environment.new
|
20
|
-
@known_env = Utils.rbs_environment(
|
20
|
+
@known_env = Utils.rbs_environment(cache: false)
|
21
21
|
@constant_filter = constant_filter
|
22
22
|
@mixin_filter = mixin_filter
|
23
23
|
@attribute_filter = attribute_filter
|
data/lib/orthoses/content.rb
CHANGED
@@ -19,12 +19,14 @@ module Orthoses
|
|
19
19
|
attr_reader :name
|
20
20
|
attr_reader :body
|
21
21
|
attr_accessor :header
|
22
|
+
attr_accessor :comment
|
22
23
|
|
23
24
|
def initialize(name:)
|
24
25
|
Orthoses.logger.debug("Create Orthoses::Content for #{name}")
|
25
26
|
@name = name
|
26
27
|
@body = []
|
27
28
|
@header = nil
|
29
|
+
@comment = nil
|
28
30
|
end
|
29
31
|
|
30
32
|
def <<(line)
|
@@ -63,7 +65,9 @@ module Orthoses
|
|
63
65
|
end
|
64
66
|
|
65
67
|
def original_rbs
|
66
|
-
a = [
|
68
|
+
a = []
|
69
|
+
a << @comment if @comment
|
70
|
+
a << @header
|
67
71
|
a << " #{@body.join("\n ")}" if @body.length > 0
|
68
72
|
a << "end"
|
69
73
|
a.join("\n")
|
@@ -111,7 +115,7 @@ module Orthoses
|
|
111
115
|
end
|
112
116
|
|
113
117
|
def auto_header
|
114
|
-
env = Utils.rbs_environment
|
118
|
+
env = Utils.rbs_environment
|
115
119
|
if entry = env.class_decls[TypeName(name).absolute!]
|
116
120
|
@header = Content::HeaderBuilder.new(env: env).build(entry: entry)
|
117
121
|
return
|
@@ -13,33 +13,12 @@ module Orthoses
|
|
13
13
|
@if = binding.local_variable_get(:if)
|
14
14
|
end
|
15
15
|
|
16
|
-
using
|
17
|
-
refine String do
|
18
|
-
# avoid load active_support
|
19
|
-
def underscore
|
20
|
-
return self unless /[A-Z-]|::/.match?(self)
|
21
|
-
word = self.to_s.gsub("::", "/")
|
22
|
-
word.gsub!(/(?:(?<=([A-Za-z\d]))|\b)((?-mix:(?=a)b))(?=\b|[^a-z])/) { "#{$1 && '_' }#{$2.downcase}" }
|
23
|
-
word.gsub!(/([A-Z\d]+)([A-Z][a-z])/, '\1_\2')
|
24
|
-
word.gsub!(/([a-z\d])([A-Z])/, '\1_\2')
|
25
|
-
word.tr!("-", "_")
|
26
|
-
word.downcase!
|
27
|
-
word
|
28
|
-
end
|
29
|
-
end
|
30
|
-
})
|
16
|
+
using Utils::Underscore
|
31
17
|
|
32
18
|
def call
|
33
19
|
store = @loader.call
|
34
20
|
|
35
21
|
store.each do |name, content|
|
36
|
-
begin
|
37
|
-
content.uniq!
|
38
|
-
rescue NameError, LoadError => err
|
39
|
-
Orthoses.logger.error(err.inspect)
|
40
|
-
next
|
41
|
-
end
|
42
|
-
|
43
22
|
next unless @if.nil? || @if.call(name, content)
|
44
23
|
|
45
24
|
file_path = Pathname("#{@base_dir}/#{name.to_s.split('::').map(&:underscore).join('/')}.rbs")
|
@@ -0,0 +1,26 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
module Orthoses
|
4
|
+
module Outputable
|
5
|
+
# UniqContentBody is an internal middleware
|
6
|
+
# It's using on orthoses/outputable.rb
|
7
|
+
class UniqContentBody
|
8
|
+
def initialize(loader)
|
9
|
+
@loader = loader
|
10
|
+
end
|
11
|
+
|
12
|
+
def call
|
13
|
+
@loader.call.tap do |store|
|
14
|
+
store.each do |name, content|
|
15
|
+
begin
|
16
|
+
content.uniq!
|
17
|
+
rescue NameError, LoadError => err
|
18
|
+
Orthoses.logger.error(err.inspect)
|
19
|
+
next
|
20
|
+
end
|
21
|
+
end
|
22
|
+
end
|
23
|
+
end
|
24
|
+
end
|
25
|
+
end
|
26
|
+
end
|
data/lib/orthoses/outputable.rb
CHANGED
@@ -1,6 +1,7 @@
|
|
1
1
|
# frozen_string_literal: true
|
2
2
|
|
3
3
|
require 'orthoses/outputable/avoid_recursive_ancestor_error'
|
4
|
+
require 'orthoses/outputable/uniq_content_body'
|
4
5
|
|
5
6
|
module Orthoses
|
6
7
|
# Module for output middleware.
|
@@ -15,6 +16,7 @@ module Orthoses
|
|
15
16
|
module Outputable
|
16
17
|
def call
|
17
18
|
@loader = AvoidRecursiveAncestorError.new(@loader)
|
19
|
+
@loader = UniqContentBody.new(@loader)
|
18
20
|
super
|
19
21
|
end
|
20
22
|
end
|
@@ -0,0 +1,21 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
module Orthoses
|
4
|
+
module Utils
|
5
|
+
module Underscore
|
6
|
+
refine String do
|
7
|
+
# avoid load active_support
|
8
|
+
def underscore
|
9
|
+
return self unless /[A-Z-]|::/.match?(self)
|
10
|
+
word = self.to_s.gsub("::", "/")
|
11
|
+
word.gsub!(/(?:(?<=([A-Za-z\d]))|\b)((?-mix:(?=a)b))(?=\b|[^a-z])/) { "#{$1 && '_' }#{$2.downcase}" }
|
12
|
+
word.gsub!(/([A-Z\d]+)([A-Z][a-z])/, '\1_\2')
|
13
|
+
word.gsub!(/([a-z\d])([A-Z])/, '\1_\2')
|
14
|
+
word.tr!("-", "_")
|
15
|
+
word.downcase!
|
16
|
+
word
|
17
|
+
end
|
18
|
+
end
|
19
|
+
end
|
20
|
+
end
|
21
|
+
end
|
data/lib/orthoses/utils.rb
CHANGED
@@ -2,6 +2,8 @@
|
|
2
2
|
|
3
3
|
module Orthoses
|
4
4
|
module Utils
|
5
|
+
autoload :Underscore, "orthoses/utils/underscore"
|
6
|
+
|
5
7
|
def self.unautoload!
|
6
8
|
warn "`Orthoses::Utils.unautoload!` is deprecated. please use `Orthoses::Autoload` middleware instead."
|
7
9
|
ObjectSpace.each_object(Module) do |mod|
|
@@ -27,7 +29,7 @@ module Orthoses
|
|
27
29
|
end
|
28
30
|
end
|
29
31
|
|
30
|
-
def self.rbs_defined_const?(name, library: nil, collection:
|
32
|
+
def self.rbs_defined_const?(name, library: nil, collection: true)
|
31
33
|
return false if name.start_with?("#<")
|
32
34
|
env = rbs_environment(library: library, collection: collection)
|
33
35
|
name = name.sub(/Object::/, '')
|
@@ -35,7 +37,7 @@ module Orthoses
|
|
35
37
|
env.constant_decls.has_key?(target)
|
36
38
|
end
|
37
39
|
|
38
|
-
def self.rbs_defined_class?(name, library: nil, collection:
|
40
|
+
def self.rbs_defined_class?(name, library: nil, collection: true)
|
39
41
|
return false if name.start_with?("#<")
|
40
42
|
env = rbs_environment(library: library, collection: collection)
|
41
43
|
target = rbs_type_name(name)
|
@@ -69,7 +71,7 @@ module Orthoses
|
|
69
71
|
end
|
70
72
|
}.call
|
71
73
|
|
72
|
-
def self.rbs_environment(library: nil, collection:
|
74
|
+
def self.rbs_environment(library: nil, collection: true, cache: true)
|
73
75
|
@env_cache ||= {}
|
74
76
|
if cache && hit = @env_cache[[library, collection]]
|
75
77
|
return hit
|
@@ -188,7 +190,7 @@ module Orthoses
|
|
188
190
|
else
|
189
191
|
raise TypeError
|
190
192
|
end
|
191
|
-
rbs_environment
|
193
|
+
rbs_environment.class_decls[type_name]&.then do |entry|
|
192
194
|
entry.decls.first.decl.type_params
|
193
195
|
end
|
194
196
|
end
|
data/lib/orthoses/version.rb
CHANGED
data/lib/orthoses.rb
CHANGED
@@ -3,33 +3,31 @@
|
|
3
3
|
require 'rbs'
|
4
4
|
require 'pathname'
|
5
5
|
|
6
|
-
require_relative 'orthoses/attribute'
|
7
|
-
require_relative 'orthoses/builder'
|
8
|
-
require_relative 'orthoses/call_tracer'
|
9
|
-
require_relative 'orthoses/constant'
|
10
|
-
require_relative 'orthoses/content'
|
11
|
-
require_relative 'orthoses/create_file_by_name'
|
12
|
-
require_relative 'orthoses/delegate_class'
|
13
|
-
require_relative 'orthoses/filter'
|
14
|
-
require_relative 'orthoses/mixin'
|
15
|
-
require_relative 'orthoses/load_rbs'
|
16
|
-
require_relative 'orthoses/object_space_all'
|
17
|
-
require_relative 'orthoses/outputable'
|
18
|
-
require_relative 'orthoses/path_helper'
|
19
|
-
require_relative 'orthoses/pp'
|
20
|
-
require_relative 'orthoses/rbs_prototype_rb'
|
21
|
-
require_relative 'orthoses/rbs_prototype_runtime'
|
22
|
-
require_relative 'orthoses/store'
|
23
|
-
require_relative 'orthoses/tap'
|
24
|
-
require_relative 'orthoses/autoload'
|
25
|
-
require_relative 'orthoses/utils'
|
26
|
-
require_relative 'orthoses/version'
|
27
|
-
require_relative 'orthoses/walk'
|
28
|
-
require_relative 'orthoses/writer'
|
29
|
-
|
30
6
|
module Orthoses
|
31
|
-
|
7
|
+
autoload :Attribute, 'orthoses/attribute'
|
8
|
+
autoload :Builder, 'orthoses/builder'
|
9
|
+
autoload :CallTracer, 'orthoses/call_tracer'
|
10
|
+
autoload :Constant, 'orthoses/constant'
|
11
|
+
autoload :Content, 'orthoses/content'
|
12
|
+
autoload :CreateFileByName, 'orthoses/create_file_by_name'
|
13
|
+
autoload :DelegateClass, 'orthoses/delegate_class'
|
14
|
+
autoload :Filter, 'orthoses/filter'
|
15
|
+
autoload :Mixin, 'orthoses/mixin'
|
32
16
|
autoload :LazyTracePoint, 'orthoses/lazy_trace_point'
|
17
|
+
autoload :LoadRBS, 'orthoses/load_rbs'
|
18
|
+
autoload :ObjectSpaceAll, 'orthoses/object_space_all'
|
19
|
+
autoload :Outputable, 'orthoses/outputable'
|
20
|
+
autoload :PathHelper, 'orthoses/path_helper'
|
21
|
+
autoload :PP, 'orthoses/pp'
|
22
|
+
autoload :RBSPrototypeRB, 'orthoses/rbs_prototype_rb'
|
23
|
+
autoload :RBSPrototypeRuntime, 'orthoses/rbs_prototype_runtime'
|
24
|
+
autoload :Store, 'orthoses/store'
|
25
|
+
autoload :Tap, 'orthoses/tap'
|
26
|
+
autoload :Autoload, 'orthoses/autoload'
|
27
|
+
autoload :Utils, 'orthoses/utils'
|
28
|
+
autoload :VERSION, 'orthoses/version'
|
29
|
+
autoload :Walk, 'orthoses/walk'
|
30
|
+
autoload :Writer, 'orthoses/writer'
|
33
31
|
|
34
32
|
METHOD_METHOD = ::Kernel.instance_method(:method)
|
35
33
|
INSTANCE_METHOD_METHOD = ::Module.instance_method(:instance_method)
|
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: 1.
|
4
|
+
version: 1.2.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-
|
11
|
+
date: 2022-10-08 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: rbs
|
@@ -60,6 +60,7 @@ files:
|
|
60
60
|
- lib/orthoses/object_space_all.rb
|
61
61
|
- lib/orthoses/outputable.rb
|
62
62
|
- lib/orthoses/outputable/avoid_recursive_ancestor_error.rb
|
63
|
+
- lib/orthoses/outputable/uniq_content_body.rb
|
63
64
|
- lib/orthoses/path_helper.rb
|
64
65
|
- lib/orthoses/pp.rb
|
65
66
|
- lib/orthoses/rbs_prototype_rb.rb
|
@@ -67,6 +68,7 @@ files:
|
|
67
68
|
- lib/orthoses/store.rb
|
68
69
|
- lib/orthoses/tap.rb
|
69
70
|
- lib/orthoses/utils.rb
|
71
|
+
- lib/orthoses/utils/underscore.rb
|
70
72
|
- lib/orthoses/version.rb
|
71
73
|
- lib/orthoses/walk.rb
|
72
74
|
- lib/orthoses/writer.rb
|
@@ -103,6 +105,7 @@ files:
|
|
103
105
|
- sig/orthoses/object_space_all.rbs
|
104
106
|
- sig/orthoses/outputable.rbs
|
105
107
|
- sig/orthoses/outputable/avoid_recursive_ancestor_error.rbs
|
108
|
+
- sig/orthoses/outputable/uniq_content_body.rbs
|
106
109
|
- sig/orthoses/path_helper.rbs
|
107
110
|
- sig/orthoses/pp.rbs
|
108
111
|
- sig/orthoses/rbs_prototype_rb.rbs
|
@@ -110,6 +113,7 @@ files:
|
|
110
113
|
- sig/orthoses/store.rbs
|
111
114
|
- sig/orthoses/tap.rbs
|
112
115
|
- sig/orthoses/utils.rbs
|
116
|
+
- sig/orthoses/utils/underscore.rbs
|
113
117
|
- sig/orthoses/walk.rbs
|
114
118
|
- sig/orthoses/writer.rbs
|
115
119
|
homepage: https://github.com/ksss/orthoses
|
@@ -133,7 +137,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
|
|
133
137
|
- !ruby/object:Gem::Version
|
134
138
|
version: '0'
|
135
139
|
requirements: []
|
136
|
-
rubygems_version: 3.
|
140
|
+
rubygems_version: 3.3.16
|
137
141
|
signing_key:
|
138
142
|
specification_version: 4
|
139
143
|
summary: Framework for Generate RBS
|