tapioca 0.1.3 → 0.1.4
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/README.md +3 -1
- data/lib/tapioca.rb +7 -2
- data/lib/tapioca/compilers/symbol_table/symbol_generator.rb +1 -0
- data/lib/tapioca/constant_locator.rb +35 -0
- data/lib/tapioca/gemfile.rb +19 -6
- data/lib/tapioca/version.rb +1 -1
- metadata +17 -3
- data/lib/t.rb +0 -50
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 75a87d3c876d0f813f47a8d40065ff30543661787819493d32b6116f387d1408
|
4
|
+
data.tar.gz: a546890d23895b079d35b37b326b604ae77d08b8219adda3b259f1a8042fa255
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: b8d394ddbf391ce726b55e252631362b10ad0e2ed868e673253b7ebd1b9817d0290784ddd4c6c47864c8453ceddbfa27933c4306d78f903080aa6222e43a4f8f
|
7
|
+
data.tar.gz: ad2cf1d229a5a77594e6b2d697b14ded970659c1fb65cc01e4671a2b799bd17d8afc814ca6cc91510a97e7dbdab3926cb60fdcc82a1afb78ecd7a9aa695628d9
|
data/README.md
CHANGED
@@ -9,7 +9,9 @@ Tapioca is a library used to generate RBI (Ruby interface) files for use with [S
|
|
9
9
|
Add this line to your application's `Gemfile`:
|
10
10
|
|
11
11
|
```ruby
|
12
|
-
|
12
|
+
group :development do
|
13
|
+
gem 'tapioca', '~> 0.1.2', require: false
|
14
|
+
end
|
13
15
|
```
|
14
16
|
|
15
17
|
and do not forget to execute `tapioca` using `bundler`:
|
data/lib/tapioca.rb
CHANGED
@@ -1,8 +1,7 @@
|
|
1
1
|
# typed: true
|
2
2
|
# frozen_string_literal: true
|
3
|
-
|
3
|
+
require "sorbet-runtime"
|
4
4
|
require "zeitwerk"
|
5
|
-
require_relative "./t"
|
6
5
|
|
7
6
|
loader = Zeitwerk::Loader.for_gem
|
8
7
|
loader.setup
|
@@ -19,4 +18,10 @@ module Tapioca
|
|
19
18
|
class Error < StandardError; end
|
20
19
|
end
|
21
20
|
|
21
|
+
T::Configuration.default_checked_level = :never
|
22
|
+
# Suppresses errors caused by T.cast, T.let, T.must, etc.
|
23
|
+
T::Configuration.inline_type_error_handler = ->(*) {}
|
24
|
+
# Suppresses errors caused by incorrect parameter ordering
|
25
|
+
T::Configuration.sig_validation_error_handler = ->(*) {}
|
26
|
+
|
22
27
|
loader.eager_load
|
@@ -459,6 +459,7 @@ module Tapioca
|
|
459
459
|
sig { params(constant: Module, strict: T::Boolean).returns(T::Boolean) }
|
460
460
|
def defined_in_gem?(constant, strict: true)
|
461
461
|
files = get_file_candidates(constant)
|
462
|
+
files = Tapioca::ConstantLocator.files_for(constant) if files.empty?
|
462
463
|
|
463
464
|
return !strict if files.empty?
|
464
465
|
|
@@ -0,0 +1,35 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
require 'set'
|
4
|
+
|
5
|
+
module Tapioca
|
6
|
+
# Registers a TracePoint immediately upon load to track points at which
|
7
|
+
# classes and modules are opened for definition. This is used to track
|
8
|
+
# correspondence between classes/modules and files, as this information isn't
|
9
|
+
# available in the ruby runtime without extra accounting.
|
10
|
+
module ConstantLocator
|
11
|
+
@class_files = {}
|
12
|
+
|
13
|
+
NAME = Module.instance_method(:name)
|
14
|
+
private_constant :NAME
|
15
|
+
|
16
|
+
# Immediately activated upon load. Observes class/module definition.
|
17
|
+
TracePoint.trace(:class) do |tp|
|
18
|
+
unless tp.self.singleton_class?
|
19
|
+
key = NAME.bind(tp.self).call
|
20
|
+
@class_files[key] ||= Set.new
|
21
|
+
@class_files[key] << tp.path
|
22
|
+
end
|
23
|
+
end
|
24
|
+
|
25
|
+
# Returns the files in which this class or module was opened. Doesn't know
|
26
|
+
# about situations where the class was opened prior to +require+ing,
|
27
|
+
# or where metaprogramming was used via +eval+, etc.
|
28
|
+
def files_for(klass)
|
29
|
+
name = String === klass ? klass : NAME.bind(klass).call
|
30
|
+
files = @class_files[name]
|
31
|
+
files || Set.new
|
32
|
+
end
|
33
|
+
module_function :files_for
|
34
|
+
end
|
35
|
+
end
|
data/lib/tapioca/gemfile.rb
CHANGED
@@ -62,7 +62,7 @@ module Tapioca
|
|
62
62
|
|
63
63
|
sig { params(spec: Spec).returns(T::Boolean) }
|
64
64
|
def ignore_gem_spec?(spec)
|
65
|
-
|
65
|
+
["sorbet", "sorbet-static"].include?(spec.name) ||
|
66
66
|
spec.full_gem_path.start_with?(gemfile_dir)
|
67
67
|
end
|
68
68
|
|
@@ -71,12 +71,25 @@ module Tapioca
|
|
71
71
|
File.expand_path(gemfile.path + "/..")
|
72
72
|
end
|
73
73
|
|
74
|
+
sig { returns(T::Array[T.untyped]) }
|
75
|
+
def rails_engines
|
76
|
+
engines = []
|
77
|
+
|
78
|
+
return engines unless Object.const_defined?("Rails::Engine")
|
79
|
+
|
80
|
+
base = Object.const_get("Rails::Engine")
|
81
|
+
ObjectSpace.each_object(base.singleton_class) do |k|
|
82
|
+
k = T.cast(k, Class)
|
83
|
+
next if k.singleton_class?
|
84
|
+
engines.unshift(k) unless k == base
|
85
|
+
end
|
86
|
+
|
87
|
+
engines.reject(&:abstract_railtie?)
|
88
|
+
end
|
89
|
+
|
74
90
|
sig { void }
|
75
91
|
def load_rails_engines
|
76
|
-
|
77
|
-
engines = Object.const_get("Rails::Engine").descendants.reject(&:abstract_railtie?)
|
78
|
-
|
79
|
-
engines.each do |engine|
|
92
|
+
rails_engines.each do |engine|
|
80
93
|
errored_files = []
|
81
94
|
|
82
95
|
engine.config.eager_load_paths.each do |load_path|
|
@@ -102,7 +115,7 @@ module Tapioca
|
|
102
115
|
|
103
116
|
sig { params(spec: Spec).void }
|
104
117
|
def initialize(spec)
|
105
|
-
@spec = T.let(spec, Spec)
|
118
|
+
@spec = T.let(spec, Tapioca::Gemfile::Spec)
|
106
119
|
end
|
107
120
|
|
108
121
|
sig { returns(String) }
|
data/lib/tapioca/version.rb
CHANGED
metadata
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: tapioca
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.1.
|
4
|
+
version: 0.1.4
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Ufuk Kayserilioglu
|
@@ -11,7 +11,7 @@ authors:
|
|
11
11
|
autorequire:
|
12
12
|
bindir: exe
|
13
13
|
cert_chain: []
|
14
|
-
date: 2019-07-
|
14
|
+
date: 2019-07-15 00:00:00.000000000 Z
|
15
15
|
dependencies:
|
16
16
|
- !ruby/object:Gem::Dependency
|
17
17
|
name: pry
|
@@ -41,6 +41,20 @@ dependencies:
|
|
41
41
|
- - "~>"
|
42
42
|
- !ruby/object:Gem::Version
|
43
43
|
version: 0.4.4371
|
44
|
+
- !ruby/object:Gem::Dependency
|
45
|
+
name: sorbet-runtime
|
46
|
+
requirement: !ruby/object:Gem::Requirement
|
47
|
+
requirements:
|
48
|
+
- - ">="
|
49
|
+
- !ruby/object:Gem::Version
|
50
|
+
version: '0'
|
51
|
+
type: :runtime
|
52
|
+
prerelease: false
|
53
|
+
version_requirements: !ruby/object:Gem::Requirement
|
54
|
+
requirements:
|
55
|
+
- - ">="
|
56
|
+
- !ruby/object:Gem::Version
|
57
|
+
version: '0'
|
44
58
|
- !ruby/object:Gem::Dependency
|
45
59
|
name: thor
|
46
60
|
requirement: !ruby/object:Gem::Requirement
|
@@ -165,12 +179,12 @@ files:
|
|
165
179
|
- README.md
|
166
180
|
- Rakefile
|
167
181
|
- exe/tapioca
|
168
|
-
- lib/t.rb
|
169
182
|
- lib/tapioca.rb
|
170
183
|
- lib/tapioca/cli.rb
|
171
184
|
- lib/tapioca/compilers/symbol_table/symbol_generator.rb
|
172
185
|
- lib/tapioca/compilers/symbol_table/symbol_loader.rb
|
173
186
|
- lib/tapioca/compilers/symbol_table_compiler.rb
|
187
|
+
- lib/tapioca/constant_locator.rb
|
174
188
|
- lib/tapioca/gemfile.rb
|
175
189
|
- lib/tapioca/generator.rb
|
176
190
|
- lib/tapioca/version.rb
|
data/lib/t.rb
DELETED
@@ -1,50 +0,0 @@
|
|
1
|
-
unless defined?(T)
|
2
|
-
module T
|
3
|
-
def self.any(type_a, type_b, *types); end
|
4
|
-
def self.nilable(type); end
|
5
|
-
def self.untyped; end
|
6
|
-
def self.noreturn; end
|
7
|
-
def self.all(type_a, type_b, *types); end
|
8
|
-
def self.enum(values); end
|
9
|
-
def self.proc; end
|
10
|
-
def self.self_type; end
|
11
|
-
def self.class_of(klass); end
|
12
|
-
def self.type_alias(type); end
|
13
|
-
def self.type_parameter(name); end
|
14
|
-
|
15
|
-
def self.cast(value, type, checked: true); value; end
|
16
|
-
def self.let(value, type, checked: true); value; end
|
17
|
-
def self.assert_type!(value, type, checked: true); value; end
|
18
|
-
def self.unsafe(value); value; end
|
19
|
-
def self.must(arg, msg=nil); arg; end
|
20
|
-
def self.reveal_type(value); value; end
|
21
|
-
end
|
22
|
-
|
23
|
-
module T::Sig
|
24
|
-
def sig(&blk); end
|
25
|
-
end
|
26
|
-
|
27
|
-
module T::Array
|
28
|
-
def self.[](type); end
|
29
|
-
end
|
30
|
-
|
31
|
-
module T::Hash
|
32
|
-
def self.[](keys, values); end
|
33
|
-
end
|
34
|
-
|
35
|
-
module T::Enumerable
|
36
|
-
def self.[](type); end
|
37
|
-
end
|
38
|
-
|
39
|
-
module T::Range
|
40
|
-
def self.[](type); end
|
41
|
-
end
|
42
|
-
|
43
|
-
module T::Set
|
44
|
-
def self.[](type); end
|
45
|
-
end
|
46
|
-
|
47
|
-
module T::Boolean
|
48
|
-
end
|
49
|
-
end
|
50
|
-
|