tapioca 0.9.4 → 0.10.0
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/LICENSE.txt +21 -0
- data/README.md +48 -22
- data/lib/tapioca/cli.rb +17 -23
- data/lib/tapioca/commands/annotations.rb +2 -2
- data/lib/tapioca/commands/dsl.rb +43 -65
- data/lib/tapioca/commands/gem.rb +18 -50
- data/lib/tapioca/commands/todo.rb +1 -2
- data/lib/tapioca/dsl/compiler.rb +34 -37
- data/lib/tapioca/dsl/compilers/aasm.rb +7 -3
- data/lib/tapioca/dsl/compilers/action_controller_helpers.rb +7 -3
- data/lib/tapioca/dsl/compilers/action_mailer.rb +7 -3
- data/lib/tapioca/dsl/compilers/active_job.rb +7 -3
- data/lib/tapioca/dsl/compilers/active_model_attributes.rb +9 -5
- data/lib/tapioca/dsl/compilers/active_model_secure_password.rb +11 -7
- data/lib/tapioca/dsl/compilers/active_record_associations.rb +7 -3
- data/lib/tapioca/dsl/compilers/active_record_columns.rb +7 -3
- data/lib/tapioca/dsl/compilers/active_record_enum.rb +7 -3
- data/lib/tapioca/dsl/compilers/active_record_fixtures.rb +8 -4
- data/lib/tapioca/dsl/compilers/active_record_relations.rb +7 -3
- data/lib/tapioca/dsl/compilers/active_record_scope.rb +5 -3
- data/lib/tapioca/dsl/compilers/active_record_typed_store.rb +8 -4
- data/lib/tapioca/dsl/compilers/active_resource.rb +7 -3
- data/lib/tapioca/dsl/compilers/active_storage.rb +9 -5
- data/lib/tapioca/dsl/compilers/active_support_concern.rb +21 -18
- data/lib/tapioca/dsl/compilers/active_support_current_attributes.rb +7 -3
- data/lib/tapioca/dsl/compilers/config.rb +12 -8
- data/lib/tapioca/dsl/compilers/frozen_record.rb +7 -3
- data/lib/tapioca/dsl/compilers/graphql_input_object.rb +71 -0
- data/lib/tapioca/dsl/compilers/graphql_mutation.rb +81 -0
- data/lib/tapioca/dsl/compilers/identity_cache.rb +8 -4
- data/lib/tapioca/dsl/compilers/mixed_in_class_attributes.rb +9 -5
- data/lib/tapioca/dsl/compilers/protobuf.rb +69 -25
- data/lib/tapioca/dsl/compilers/rails_generators.rb +12 -8
- data/lib/tapioca/dsl/compilers/sidekiq_worker.rb +7 -3
- data/lib/tapioca/dsl/compilers/smart_properties.rb +10 -6
- data/lib/tapioca/dsl/compilers/state_machines.rb +7 -3
- data/lib/tapioca/dsl/compilers/url_helpers.rb +29 -26
- data/lib/tapioca/dsl/compilers.rb +0 -5
- data/lib/tapioca/dsl/helpers/active_record_column_type_helper.rb +1 -9
- data/lib/tapioca/dsl/helpers/graphql_type_helper.rb +62 -0
- data/lib/tapioca/dsl/pipeline.rb +19 -11
- data/lib/tapioca/gem/listeners/source_location.rb +16 -9
- data/lib/tapioca/gemfile.rb +30 -0
- data/lib/tapioca/helpers/config_helper.rb +2 -2
- data/lib/tapioca/helpers/rbi_helper.rb +43 -30
- data/lib/tapioca/helpers/source_uri.rb +77 -0
- data/lib/tapioca/helpers/test/dsl_compiler.rb +1 -1
- data/lib/tapioca/helpers/test/isolation.rb +7 -3
- data/lib/tapioca/internal.rb +5 -1
- data/lib/tapioca/loaders/dsl.rb +84 -0
- data/lib/tapioca/loaders/gem.rb +85 -0
- data/lib/tapioca/{runtime → loaders}/loader.rb +39 -31
- data/lib/tapioca/repo_index.rb +12 -8
- data/lib/tapioca/runtime/dynamic_mixin_compiler.rb +2 -2
- data/lib/tapioca/runtime/trackers/constant_definition.rb +15 -13
- data/lib/tapioca/runtime/trackers/mixin.rb +35 -31
- data/lib/tapioca/runtime/trackers/required_ancestor.rb +21 -19
- data/lib/tapioca/static/requires_compiler.rb +2 -3
- data/lib/tapioca/static/symbol_table_parser.rb +19 -17
- data/lib/tapioca/version.rb +1 -1
- data/lib/tapioca.rb +24 -20
- metadata +10 -5
- data/Gemfile +0 -53
- data/Rakefile +0 -18
@@ -19,42 +19,46 @@ module Tapioca
|
|
19
19
|
end
|
20
20
|
end
|
21
21
|
|
22
|
-
|
23
|
-
|
24
|
-
.params(block: T.proc.returns(T.type_parameter(:Result)))
|
25
|
-
.returns(T.type_parameter(:Result))
|
26
|
-
end
|
27
|
-
def self.with_disabled_registration(&block)
|
28
|
-
@enabled = false
|
22
|
+
class << self
|
23
|
+
extend T::Sig
|
29
24
|
|
30
|
-
|
31
|
-
|
32
|
-
|
33
|
-
|
25
|
+
sig do
|
26
|
+
type_parameters(:Result)
|
27
|
+
.params(block: T.proc.returns(T.type_parameter(:Result)))
|
28
|
+
.returns(T.type_parameter(:Result))
|
29
|
+
end
|
30
|
+
def with_disabled_registration(&block)
|
31
|
+
@enabled = false
|
34
32
|
|
35
|
-
|
36
|
-
|
37
|
-
|
38
|
-
|
39
|
-
mixin_type: Type,
|
40
|
-
).void
|
41
|
-
end
|
42
|
-
def self.register(constant, mixin, mixin_type)
|
43
|
-
return unless @enabled
|
33
|
+
block.call
|
34
|
+
ensure
|
35
|
+
@enabled = true
|
36
|
+
end
|
44
37
|
|
45
|
-
|
38
|
+
sig do
|
39
|
+
params(
|
40
|
+
constant: Module,
|
41
|
+
mixin: Module,
|
42
|
+
mixin_type: Type,
|
43
|
+
).void
|
44
|
+
end
|
45
|
+
def register(constant, mixin, mixin_type)
|
46
|
+
return unless @enabled
|
46
47
|
|
47
|
-
|
48
|
-
constants.fetch(mixin_type).store(constant, location)
|
49
|
-
end
|
48
|
+
location = Reflection.resolve_loc(caller_locations)
|
50
49
|
|
51
|
-
|
52
|
-
|
53
|
-
|
54
|
-
|
55
|
-
|
56
|
-
|
57
|
-
|
50
|
+
constants = constants_with_mixin(mixin)
|
51
|
+
constants.fetch(mixin_type).store(constant, location)
|
52
|
+
end
|
53
|
+
|
54
|
+
sig { params(mixin: Module).returns(T::Hash[Type, T::Hash[Module, String]]) }
|
55
|
+
def constants_with_mixin(mixin)
|
56
|
+
@mixins_to_constants[mixin] ||= {
|
57
|
+
Type::Prepend => {}.compare_by_identity,
|
58
|
+
Type::Include => {}.compare_by_identity,
|
59
|
+
Type::Extend => {}.compare_by_identity,
|
60
|
+
}
|
61
|
+
end
|
58
62
|
end
|
59
63
|
end
|
60
64
|
end
|
@@ -5,29 +5,31 @@ module Tapioca
|
|
5
5
|
module Runtime
|
6
6
|
module Trackers
|
7
7
|
module RequiredAncestor
|
8
|
-
extend T::Sig
|
9
|
-
|
10
8
|
@required_ancestors_map = {}.compare_by_identity
|
11
9
|
|
12
|
-
|
13
|
-
|
14
|
-
ancestors = @required_ancestors_map[requiring] ||= []
|
15
|
-
ancestors << block
|
16
|
-
end
|
10
|
+
class << self
|
11
|
+
extend T::Sig
|
17
12
|
|
18
|
-
|
19
|
-
|
20
|
-
|
21
|
-
|
13
|
+
sig { params(requiring: T::Helpers, block: T.proc.returns(Module)).void }
|
14
|
+
def register(requiring, block)
|
15
|
+
ancestors = @required_ancestors_map[requiring] ||= []
|
16
|
+
ancestors << block
|
17
|
+
end
|
18
|
+
|
19
|
+
sig { params(mod: Module).returns(T::Array[T.proc.returns(Module)]) }
|
20
|
+
def required_ancestors_blocks_by(mod)
|
21
|
+
@required_ancestors_map[mod] || []
|
22
|
+
end
|
22
23
|
|
23
|
-
|
24
|
-
|
25
|
-
|
26
|
-
|
27
|
-
|
28
|
-
|
29
|
-
|
30
|
-
|
24
|
+
sig { params(mod: Module).returns(T::Array[T.nilable(Module)]) }
|
25
|
+
def required_ancestors_by(mod)
|
26
|
+
blocks = required_ancestors_blocks_by(mod)
|
27
|
+
blocks.map do |block|
|
28
|
+
block.call
|
29
|
+
rescue NameError
|
30
|
+
# The ancestor required doesn't exist, let's return nil and let the compiler decide what to do.
|
31
|
+
nil
|
32
|
+
end
|
31
33
|
end
|
32
34
|
end
|
33
35
|
end
|
@@ -42,10 +42,9 @@ module Tapioca
|
|
42
42
|
|
43
43
|
sig { params(file_path: String).returns(T::Enumerable[String]) }
|
44
44
|
def collect_requires(file_path)
|
45
|
-
File.binread(file_path).lines.
|
45
|
+
File.binread(file_path).lines.filter_map do |line|
|
46
46
|
/^\s*require\s*(\(\s*)?['"](?<name>[^'"]+)['"](\s*\))?/.match(line) { |m| m["name"] }
|
47
|
-
end.
|
48
|
-
.reject { |require| require.include?('#{') } # ignore interpolation
|
47
|
+
end.reject { |require| require.include?('#{') } # ignore interpolation
|
49
48
|
end
|
50
49
|
|
51
50
|
sig { params(config: Spoom::Sorbet::Config, file_path: Pathname).returns(T::Boolean) }
|
@@ -6,15 +6,21 @@ module Tapioca
|
|
6
6
|
class SymbolTableParser
|
7
7
|
extend T::Sig
|
8
8
|
|
9
|
-
|
10
|
-
|
11
|
-
|
12
|
-
|
13
|
-
|
14
|
-
|
15
|
-
|
16
|
-
|
17
|
-
|
9
|
+
SKIP_PARSE_KINDS = T.let(["CLASS_OR_MODULE", "STATIC_FIELD"].freeze, T::Array[String])
|
10
|
+
|
11
|
+
class << self
|
12
|
+
extend T::Sig
|
13
|
+
|
14
|
+
sig { params(json_string: String).returns(T::Set[String]) }
|
15
|
+
def parse_json(json_string)
|
16
|
+
obj = JSON.parse(json_string)
|
17
|
+
|
18
|
+
parser = SymbolTableParser.new
|
19
|
+
parser.parse_object(obj)
|
20
|
+
parser.symbols
|
21
|
+
rescue JSON::ParserError
|
22
|
+
Set.new
|
23
|
+
end
|
18
24
|
end
|
19
25
|
|
20
26
|
sig { returns(T::Set[String]) }
|
@@ -35,14 +41,10 @@ module Tapioca
|
|
35
41
|
name = child.fetch("name")
|
36
42
|
name = name.fetch("name") if name.is_a?(Hash)
|
37
43
|
|
38
|
-
next if
|
39
|
-
|
40
|
-
|
41
|
-
|
42
|
-
# once the minimum version is moved past that.
|
43
|
-
next unless ["CLASS", "CLASS_OR_MODULE", "STATIC_FIELD"].include?(kind)
|
44
|
-
next if name =~ /[<>()$]/
|
45
|
-
next if name =~ /^[0-9]+$/
|
44
|
+
next if name.nil?
|
45
|
+
next unless SKIP_PARSE_KINDS.include?(kind)
|
46
|
+
next if name.match?(/[<>()$]/)
|
47
|
+
next if name.match?(/^[0-9]+$/)
|
46
48
|
next if name == "T::Helpers"
|
47
49
|
|
48
50
|
@symbols.add(fully_qualified_name(name))
|
data/lib/tapioca/version.rb
CHANGED
data/lib/tapioca.rb
CHANGED
@@ -8,29 +8,33 @@ module Tapioca
|
|
8
8
|
|
9
9
|
@traces = T.let([], T::Array[TracePoint])
|
10
10
|
|
11
|
-
|
12
|
-
|
13
|
-
@traces << TracePoint.trace(trace_name, &block)
|
14
|
-
end
|
11
|
+
class << self
|
12
|
+
extend T::Sig
|
15
13
|
|
16
|
-
|
17
|
-
|
18
|
-
|
19
|
-
|
14
|
+
sig { params(trace_name: Symbol, block: T.proc.params(arg0: TracePoint).void).void }
|
15
|
+
def register_trace(trace_name, &block)
|
16
|
+
@traces << TracePoint.trace(trace_name, &block)
|
17
|
+
end
|
20
18
|
|
21
|
-
|
22
|
-
|
23
|
-
.
|
24
|
-
|
25
|
-
|
26
|
-
|
27
|
-
|
28
|
-
|
29
|
-
|
30
|
-
|
19
|
+
sig { void }
|
20
|
+
def disable_traces
|
21
|
+
@traces.each(&:disable)
|
22
|
+
end
|
23
|
+
|
24
|
+
sig do
|
25
|
+
type_parameters(:Result)
|
26
|
+
.params(blk: T.proc.returns(T.type_parameter(:Result)))
|
27
|
+
.returns(T.type_parameter(:Result))
|
28
|
+
end
|
29
|
+
def silence_warnings(&blk)
|
30
|
+
original_verbosity = $VERBOSE
|
31
|
+
$VERBOSE = nil
|
32
|
+
::Gem::DefaultUserInteraction.use_ui(::Gem::SilentUI.new) do
|
33
|
+
blk.call
|
34
|
+
end
|
35
|
+
ensure
|
36
|
+
$VERBOSE = original_verbosity
|
31
37
|
end
|
32
|
-
ensure
|
33
|
-
$VERBOSE = original_verbosity
|
34
38
|
end
|
35
39
|
|
36
40
|
class Error < StandardError; end
|
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.
|
4
|
+
version: 0.10.0
|
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: 2022-08-
|
14
|
+
date: 2022-08-31 00:00:00.000000000 Z
|
15
15
|
dependencies:
|
16
16
|
- !ruby/object:Gem::Dependency
|
17
17
|
name: bundler
|
@@ -159,9 +159,8 @@ executables:
|
|
159
159
|
extensions: []
|
160
160
|
extra_rdoc_files: []
|
161
161
|
files:
|
162
|
-
-
|
162
|
+
- LICENSE.txt
|
163
163
|
- README.md
|
164
|
-
- Rakefile
|
165
164
|
- exe/tapioca
|
166
165
|
- lib/tapioca.rb
|
167
166
|
- lib/tapioca/cli.rb
|
@@ -196,6 +195,8 @@ files:
|
|
196
195
|
- lib/tapioca/dsl/compilers/active_support_current_attributes.rb
|
197
196
|
- lib/tapioca/dsl/compilers/config.rb
|
198
197
|
- lib/tapioca/dsl/compilers/frozen_record.rb
|
198
|
+
- lib/tapioca/dsl/compilers/graphql_input_object.rb
|
199
|
+
- lib/tapioca/dsl/compilers/graphql_mutation.rb
|
199
200
|
- lib/tapioca/dsl/compilers/identity_cache.rb
|
200
201
|
- lib/tapioca/dsl/compilers/mixed_in_class_attributes.rb
|
201
202
|
- lib/tapioca/dsl/compilers/protobuf.rb
|
@@ -207,6 +208,7 @@ files:
|
|
207
208
|
- lib/tapioca/dsl/extensions/frozen_record.rb
|
208
209
|
- lib/tapioca/dsl/helpers/active_record_column_type_helper.rb
|
209
210
|
- lib/tapioca/dsl/helpers/active_record_constants_helper.rb
|
211
|
+
- lib/tapioca/dsl/helpers/graphql_type_helper.rb
|
210
212
|
- lib/tapioca/dsl/pipeline.rb
|
211
213
|
- lib/tapioca/executor.rb
|
212
214
|
- lib/tapioca/gem.rb
|
@@ -236,17 +238,20 @@ files:
|
|
236
238
|
- lib/tapioca/helpers/rbi_files_helper.rb
|
237
239
|
- lib/tapioca/helpers/rbi_helper.rb
|
238
240
|
- lib/tapioca/helpers/sorbet_helper.rb
|
241
|
+
- lib/tapioca/helpers/source_uri.rb
|
239
242
|
- lib/tapioca/helpers/test/content.rb
|
240
243
|
- lib/tapioca/helpers/test/dsl_compiler.rb
|
241
244
|
- lib/tapioca/helpers/test/isolation.rb
|
242
245
|
- lib/tapioca/helpers/test/template.rb
|
243
246
|
- lib/tapioca/internal.rb
|
247
|
+
- lib/tapioca/loaders/dsl.rb
|
248
|
+
- lib/tapioca/loaders/gem.rb
|
249
|
+
- lib/tapioca/loaders/loader.rb
|
244
250
|
- lib/tapioca/rbi_ext/model.rb
|
245
251
|
- lib/tapioca/rbi_formatter.rb
|
246
252
|
- lib/tapioca/repo_index.rb
|
247
253
|
- lib/tapioca/runtime/dynamic_mixin_compiler.rb
|
248
254
|
- lib/tapioca/runtime/generic_type_registry.rb
|
249
|
-
- lib/tapioca/runtime/loader.rb
|
250
255
|
- lib/tapioca/runtime/reflection.rb
|
251
256
|
- lib/tapioca/runtime/trackers.rb
|
252
257
|
- lib/tapioca/runtime/trackers/autoload.rb
|
data/Gemfile
DELETED
@@ -1,53 +0,0 @@
|
|
1
|
-
# frozen_string_literal: true
|
2
|
-
|
3
|
-
source("https://rubygems.org")
|
4
|
-
|
5
|
-
gemspec
|
6
|
-
|
7
|
-
gem("minitest")
|
8
|
-
gem("minitest-hooks")
|
9
|
-
gem("minitest-reporters")
|
10
|
-
gem("pry-byebug")
|
11
|
-
gem("rubocop-shopify", require: false)
|
12
|
-
gem("rubocop-sorbet", ">= 0.4.1")
|
13
|
-
gem("rubocop-rspec", require: false)
|
14
|
-
gem("ruby-lsp", require: false)
|
15
|
-
|
16
|
-
group(:deployment, :development) do
|
17
|
-
gem("rake")
|
18
|
-
end
|
19
|
-
|
20
|
-
group(:development, :test) do
|
21
|
-
gem("smart_properties", require: false)
|
22
|
-
gem("frozen_record", require: false)
|
23
|
-
gem("sprockets", require: false)
|
24
|
-
gem("rails", require: false)
|
25
|
-
gem("state_machines", require: false)
|
26
|
-
gem("activerecord-typedstore", require: false)
|
27
|
-
gem("sqlite3")
|
28
|
-
gem("identity_cache", require: false)
|
29
|
-
gem(
|
30
|
-
"cityhash",
|
31
|
-
git: "https://github.com/csfrancis/cityhash.git",
|
32
|
-
ref: "3cfc7d01f333c01811d5e834f1495eaa29f87c36",
|
33
|
-
require: false
|
34
|
-
)
|
35
|
-
gem("activeresource", require: false)
|
36
|
-
gem("google-protobuf", require: false)
|
37
|
-
gem("shopify-money", require: false)
|
38
|
-
gem("sidekiq", require: false)
|
39
|
-
gem("nokogiri", require: false)
|
40
|
-
gem("config", github: "rubyconfig/config", branch: "master", require: false)
|
41
|
-
gem("aasm", require: false)
|
42
|
-
gem("bcrypt", require: false)
|
43
|
-
gem("xpath", require: false)
|
44
|
-
|
45
|
-
# net-smtp was removed from default gems in Ruby 3.1, but is used by the `mail` gem.
|
46
|
-
# So we need to add it as a dependency until `mail` is fixed:
|
47
|
-
# https://github.com/rails/rails/blob/0919aa97260ab8240150278d3b07a1547489e3fd/Gemfile#L178-L191
|
48
|
-
gem("net-smtp", "0.3.1", require: false)
|
49
|
-
end
|
50
|
-
|
51
|
-
group :test do
|
52
|
-
gem("webmock")
|
53
|
-
end
|
data/Rakefile
DELETED
@@ -1,18 +0,0 @@
|
|
1
|
-
# frozen_string_literal: true
|
2
|
-
|
3
|
-
require "bundler/gem_tasks"
|
4
|
-
Dir["tasks/**/*.rake"].each { |t| load t }
|
5
|
-
|
6
|
-
require "rubocop/rake_task"
|
7
|
-
RuboCop::RakeTask.new
|
8
|
-
|
9
|
-
desc "Run tests"
|
10
|
-
task :test do
|
11
|
-
require "shellwords"
|
12
|
-
test = Array(ENV.fetch("TEST", []))
|
13
|
-
test_opts = Shellwords.split(ENV.fetch("TESTOPTS", ""))
|
14
|
-
success = system("bin/test", *test, *test_opts)
|
15
|
-
success || exit(false)
|
16
|
-
end
|
17
|
-
|
18
|
-
task(default: :test)
|