rbs 2.8.4 → 3.0.0.dev.2
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/.github/workflows/ruby.yml +0 -3
- data/Gemfile +1 -1
- data/Gemfile.lock +17 -17
- data/README.md +1 -0
- data/Rakefile +66 -0
- data/core/array.rbs +1 -1
- data/core/builtin.rbs +1 -1
- data/core/hash.rbs +1 -1
- data/core/module.rbs +1 -1
- data/ext/rbs_extension/constants.c +18 -2
- data/ext/rbs_extension/constants.h +9 -1
- data/ext/rbs_extension/lexer.c +834 -777
- data/ext/rbs_extension/lexer.h +3 -1
- data/ext/rbs_extension/lexer.re +3 -1
- data/ext/rbs_extension/lexstate.c +4 -2
- data/ext/rbs_extension/parser.c +287 -57
- data/ext/rbs_extension/ruby_objs.c +71 -5
- data/ext/rbs_extension/ruby_objs.h +9 -2
- data/lib/rbs/annotate/rdoc_annotator.rb +1 -1
- data/lib/rbs/ast/declarations.rb +49 -2
- data/lib/rbs/ast/directives.rb +39 -0
- data/lib/rbs/ast/members.rb +49 -15
- data/lib/rbs/cli.rb +38 -19
- data/lib/rbs/collection/config/lockfile.rb +115 -0
- data/lib/rbs/collection/config/lockfile_generator.rb +99 -53
- data/lib/rbs/collection/config.rb +12 -40
- data/lib/rbs/collection/installer.rb +9 -13
- data/lib/rbs/collection/sources/base.rb +2 -2
- data/lib/rbs/collection/sources/git.rb +135 -62
- data/lib/rbs/collection/sources/rubygems.rb +10 -12
- data/lib/rbs/collection/sources/stdlib.rb +10 -13
- data/lib/rbs/collection/sources.rb +7 -1
- data/lib/rbs/collection.rb +1 -0
- data/lib/rbs/definition.rb +1 -1
- data/lib/rbs/definition_builder/ancestor_builder.rb +24 -8
- data/lib/rbs/definition_builder/method_builder.rb +3 -3
- data/lib/rbs/definition_builder.rb +456 -579
- data/lib/rbs/environment/use_map.rb +77 -0
- data/lib/rbs/environment.rb +356 -85
- data/lib/rbs/environment_loader.rb +20 -17
- data/lib/rbs/environment_walker.rb +1 -1
- data/lib/rbs/errors.rb +34 -37
- data/lib/rbs/locator.rb +3 -3
- data/lib/rbs/parser_aux.rb +8 -6
- data/lib/rbs/prototype/helpers.rb +29 -13
- data/lib/rbs/prototype/node_usage.rb +99 -0
- data/lib/rbs/prototype/rb.rb +3 -2
- data/lib/rbs/prototype/rbi.rb +6 -4
- data/lib/rbs/prototype/runtime.rb +25 -12
- data/lib/rbs/resolver/constant_resolver.rb +23 -7
- data/lib/rbs/resolver/type_name_resolver.rb +2 -1
- data/lib/rbs/sorter.rb +3 -3
- data/lib/rbs/substitution.rb +19 -0
- data/lib/rbs/test/setup.rb +1 -1
- data/lib/rbs/type_alias_dependency.rb +1 -1
- data/lib/rbs/type_alias_regularity.rb +3 -3
- data/lib/rbs/types.rb +1 -5
- data/lib/rbs/validator.rb +25 -3
- data/lib/rbs/variance_calculator.rb +2 -2
- data/lib/rbs/version.rb +1 -1
- data/lib/rbs/writer.rb +54 -19
- data/lib/rbs.rb +3 -2
- data/lib/rdoc_plugin/parser.rb +3 -3
- data/schema/members.json +15 -10
- data/sig/ancestor_graph.rbs +22 -2
- data/sig/collection/config/lockfile.rbs +80 -0
- data/sig/collection/config/lockfile_generator.rbs +53 -0
- data/sig/collection/config.rbs +5 -48
- data/sig/collection/installer.rbs +1 -1
- data/sig/collection/sources.rbs +76 -33
- data/sig/constant.rbs +1 -1
- data/sig/declarations.rbs +36 -3
- data/sig/definition.rbs +1 -1
- data/sig/definition_builder.rbs +94 -82
- data/sig/directives.rbs +61 -0
- data/sig/environment.rbs +150 -28
- data/sig/environment_loader.rbs +2 -2
- data/sig/errors.rbs +42 -0
- data/sig/members.rbs +31 -7
- data/sig/parser.rbs +8 -15
- data/sig/prototype/node_usage.rbs +20 -0
- data/sig/resolver/constant_resolver.rbs +1 -2
- data/sig/shims/bundler.rbs +31 -0
- data/sig/shims/rubygems.rbs +15 -0
- data/sig/shims.rbs +0 -22
- data/sig/substitution.rbs +6 -0
- data/sig/use_map.rbs +35 -0
- data/sig/validator.rbs +12 -5
- data/sig/writer.rbs +6 -2
- metadata +16 -9
- data/lib/rbs/constant_table.rb +0 -167
- data/lib/rbs/type_name_resolver.rb +0 -67
- data/sig/constant_table.rbs +0 -30
- data/sig/type_name_resolver.rbs +0 -26
@@ -7,7 +7,7 @@ VALUE rbs_alias(VALUE typename, VALUE args, VALUE location);
|
|
7
7
|
VALUE rbs_ast_annotation(VALUE string, VALUE location);
|
8
8
|
VALUE rbs_ast_comment(VALUE string, VALUE location);
|
9
9
|
VALUE rbs_ast_type_param(VALUE name, VALUE variance, bool unchecked, VALUE upper_bound, VALUE location);
|
10
|
-
VALUE
|
10
|
+
VALUE rbs_ast_decl_type_alias(VALUE name, VALUE type_params, VALUE type, VALUE annotations, VALUE location, VALUE comment);
|
11
11
|
VALUE rbs_ast_decl_class_super(VALUE name, VALUE args, VALUE location);
|
12
12
|
VALUE rbs_ast_decl_class(VALUE name, VALUE type_params, VALUE super_class, VALUE members, VALUE annotations, VALUE location, VALUE comment);
|
13
13
|
VALUE rbs_ast_decl_constant(VALUE name, VALUE type, VALUE location, VALUE comment);
|
@@ -15,9 +15,12 @@ VALUE rbs_ast_decl_global(VALUE name, VALUE type, VALUE location, VALUE comment)
|
|
15
15
|
VALUE rbs_ast_decl_interface(VALUE name, VALUE type_params, VALUE members, VALUE annotations, VALUE location, VALUE comment);
|
16
16
|
VALUE rbs_ast_decl_module_self(VALUE name, VALUE args, VALUE location);
|
17
17
|
VALUE rbs_ast_decl_module(VALUE name, VALUE type_params, VALUE self_types, VALUE members, VALUE annotations, VALUE location, VALUE comment);
|
18
|
+
VALUE rbs_ast_decl_module_alias(VALUE new_name, VALUE old_name, VALUE location, VALUE comment);
|
19
|
+
VALUE rbs_ast_decl_class_alias(VALUE new_name, VALUE old_name, VALUE location, VALUE comment);
|
18
20
|
VALUE rbs_ast_members_alias(VALUE new_name, VALUE old_name, VALUE kind, VALUE annotations, VALUE location, VALUE comment);
|
19
21
|
VALUE rbs_ast_members_attribute(VALUE klass, VALUE name, VALUE type, VALUE ivar_name, VALUE kind, VALUE annotations, VALUE location, VALUE comment, VALUE visibility);
|
20
|
-
VALUE rbs_ast_members_method_definition(VALUE name, VALUE kind, VALUE
|
22
|
+
VALUE rbs_ast_members_method_definition(VALUE name, VALUE kind, VALUE overloads, VALUE annotations, VALUE location, VALUE comment, VALUE overloading, VALUE visibility);
|
23
|
+
VALUE rbs_ast_members_method_definition_overload(VALUE annotations, VALUE method_type);
|
21
24
|
VALUE rbs_ast_members_mixin(VALUE klass, VALUE name, VALUE args, VALUE annotations, VALUE location, VALUE comment);
|
22
25
|
VALUE rbs_ast_members_variable(VALUE klass, VALUE name, VALUE type, VALUE location, VALUE comment);
|
23
26
|
VALUE rbs_ast_members_visibility(VALUE klass, VALUE location);
|
@@ -40,4 +43,8 @@ VALUE rbs_type_name(VALUE namespace, VALUE name);
|
|
40
43
|
VALUE rbs_union(VALUE types, VALUE location);
|
41
44
|
VALUE rbs_variable(VALUE name, VALUE location);
|
42
45
|
|
46
|
+
VALUE rbs_ast_directives_use(VALUE clauses, VALUE location);
|
47
|
+
VALUE rbs_ast_directives_use_single_clause(VALUE type_name, VALUE new_name, VALUE location);
|
48
|
+
VALUE rbs_ast_directives_use_wildcard_clause(VALUE namespace, VALUE location);
|
49
|
+
|
43
50
|
#endif
|
data/lib/rbs/ast/declarations.rb
CHANGED
@@ -265,7 +265,7 @@ module RBS
|
|
265
265
|
end
|
266
266
|
end
|
267
267
|
|
268
|
-
class
|
268
|
+
class TypeAlias < Base
|
269
269
|
attr_reader :name
|
270
270
|
attr_reader :type_params
|
271
271
|
attr_reader :type
|
@@ -283,7 +283,7 @@ module RBS
|
|
283
283
|
end
|
284
284
|
|
285
285
|
def ==(other)
|
286
|
-
other.is_a?(
|
286
|
+
other.is_a?(TypeAlias) &&
|
287
287
|
other.name == name &&
|
288
288
|
other.type_params == type_params &&
|
289
289
|
other.type == type
|
@@ -379,6 +379,53 @@ module RBS
|
|
379
379
|
}.to_json(state)
|
380
380
|
end
|
381
381
|
end
|
382
|
+
|
383
|
+
class AliasDecl < Base
|
384
|
+
attr_reader :new_name, :old_name, :location, :comment
|
385
|
+
|
386
|
+
def initialize(new_name:, old_name:, location:, comment:)
|
387
|
+
@new_name = new_name
|
388
|
+
@old_name = old_name
|
389
|
+
@location = location
|
390
|
+
@comment = comment
|
391
|
+
end
|
392
|
+
|
393
|
+
def ==(other)
|
394
|
+
other.is_a?(self.class) &&
|
395
|
+
other.new_name == new_name &&
|
396
|
+
other.old_name == old_name
|
397
|
+
end
|
398
|
+
|
399
|
+
alias eql? ==
|
400
|
+
|
401
|
+
def hash
|
402
|
+
self.class.hash ^ new_name.hash ^ old_name.hash
|
403
|
+
end
|
404
|
+
end
|
405
|
+
|
406
|
+
class ClassAlias < AliasDecl
|
407
|
+
def to_json(state = _ = nil)
|
408
|
+
{
|
409
|
+
declaration: :class_alias,
|
410
|
+
new_name: new_name,
|
411
|
+
old_name: old_name,
|
412
|
+
location: location,
|
413
|
+
comment: comment
|
414
|
+
}.to_json(state)
|
415
|
+
end
|
416
|
+
end
|
417
|
+
|
418
|
+
class ModuleAlias < AliasDecl
|
419
|
+
def to_json(state = _ = nil)
|
420
|
+
{
|
421
|
+
declaration: :module_alias,
|
422
|
+
new_name: new_name,
|
423
|
+
old_name: old_name,
|
424
|
+
location: location,
|
425
|
+
comment: comment
|
426
|
+
}.to_json(state)
|
427
|
+
end
|
428
|
+
end
|
382
429
|
end
|
383
430
|
end
|
384
431
|
end
|
@@ -0,0 +1,39 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
module RBS
|
4
|
+
module AST
|
5
|
+
module Directives
|
6
|
+
class Base
|
7
|
+
end
|
8
|
+
|
9
|
+
class Use < Base
|
10
|
+
class SingleClause
|
11
|
+
attr_reader :type_name, :new_name, :location
|
12
|
+
|
13
|
+
def initialize(type_name:, new_name:, location:)
|
14
|
+
@type_name = type_name
|
15
|
+
@new_name = new_name
|
16
|
+
@location = location
|
17
|
+
end
|
18
|
+
end
|
19
|
+
|
20
|
+
class WildcardClause
|
21
|
+
attr_reader :namespace, :location
|
22
|
+
|
23
|
+
def initialize(namespace:, location:)
|
24
|
+
@location = location
|
25
|
+
@namespace = namespace
|
26
|
+
end
|
27
|
+
end
|
28
|
+
|
29
|
+
attr_reader :clauses, :location
|
30
|
+
|
31
|
+
def initialize(clauses:, location:)
|
32
|
+
@clauses = clauses
|
33
|
+
@location = location
|
34
|
+
end
|
35
|
+
end
|
36
|
+
|
37
|
+
end
|
38
|
+
end
|
39
|
+
end
|
data/lib/rbs/ast/members.rb
CHANGED
@@ -7,23 +7,57 @@ module RBS
|
|
7
7
|
end
|
8
8
|
|
9
9
|
class MethodDefinition < Base
|
10
|
+
class Overload
|
11
|
+
attr_reader :method_type, :annotations
|
12
|
+
|
13
|
+
def initialize(method_type:, annotations:)
|
14
|
+
@method_type = method_type
|
15
|
+
@annotations = annotations
|
16
|
+
end
|
17
|
+
|
18
|
+
def ==(other)
|
19
|
+
other.is_a?(Overload) && other.method_type == method_type && other.annotations == annotations
|
20
|
+
end
|
21
|
+
|
22
|
+
def hash
|
23
|
+
method_type.hash ^ annotations.hash
|
24
|
+
end
|
25
|
+
|
26
|
+
alias eql? ==
|
27
|
+
|
28
|
+
def update(annotations: self.annotations, method_type: self.method_type)
|
29
|
+
Overload.new(annotations: annotations, method_type: method_type)
|
30
|
+
end
|
31
|
+
|
32
|
+
def sub(subst)
|
33
|
+
update(method_type: self.method_type.sub(subst))
|
34
|
+
end
|
35
|
+
|
36
|
+
def to_json(state = _ = nil)
|
37
|
+
{
|
38
|
+
annotations: annotations,
|
39
|
+
method_type: method_type
|
40
|
+
}.to_json(state)
|
41
|
+
end
|
42
|
+
end
|
43
|
+
|
10
44
|
attr_reader :name
|
11
45
|
attr_reader :kind
|
12
|
-
attr_reader :
|
46
|
+
attr_reader :overloads
|
13
47
|
attr_reader :annotations
|
14
48
|
attr_reader :location
|
15
49
|
attr_reader :comment
|
16
|
-
attr_reader :
|
50
|
+
attr_reader :overloading
|
17
51
|
attr_reader :visibility
|
18
52
|
|
19
|
-
def initialize(name:, kind:,
|
53
|
+
def initialize(name:, kind:, overloads:, annotations:, location:, comment:, overloading:, visibility:)
|
20
54
|
@name = name
|
21
55
|
@kind = kind
|
22
|
-
@
|
56
|
+
@overloads = overloads
|
23
57
|
@annotations = annotations
|
24
58
|
@location = location
|
25
59
|
@comment = comment
|
26
|
-
@
|
60
|
+
@overloading = overloading
|
27
61
|
@visibility = visibility
|
28
62
|
end
|
29
63
|
|
@@ -31,15 +65,15 @@ module RBS
|
|
31
65
|
other.is_a?(MethodDefinition) &&
|
32
66
|
other.name == name &&
|
33
67
|
other.kind == kind &&
|
34
|
-
other.
|
35
|
-
other.
|
68
|
+
other.overloads == overloads &&
|
69
|
+
other.overloading? == overloading? &&
|
36
70
|
other.visibility == visibility
|
37
71
|
end
|
38
72
|
|
39
73
|
alias eql? ==
|
40
74
|
|
41
75
|
def hash
|
42
|
-
name.hash ^ kind.hash ^
|
76
|
+
name.hash ^ kind.hash ^ overloads.hash ^ overloading?.hash ^ visibility.hash
|
43
77
|
end
|
44
78
|
|
45
79
|
def instance?
|
@@ -50,19 +84,19 @@ module RBS
|
|
50
84
|
kind == :singleton || kind == :singleton_instance
|
51
85
|
end
|
52
86
|
|
53
|
-
def
|
54
|
-
|
87
|
+
def overloading?
|
88
|
+
overloading
|
55
89
|
end
|
56
90
|
|
57
|
-
def update(name: self.name, kind: self.kind,
|
91
|
+
def update(name: self.name, kind: self.kind, overloads: self.overloads, annotations: self.annotations, location: self.location, comment: self.comment, overloading: self.overloading?, visibility: self.visibility)
|
58
92
|
self.class.new(
|
59
93
|
name: name,
|
60
94
|
kind: kind,
|
61
|
-
|
95
|
+
overloads: overloads,
|
62
96
|
annotations: annotations,
|
63
97
|
location: location,
|
64
98
|
comment: comment,
|
65
|
-
|
99
|
+
overloading: overloading,
|
66
100
|
visibility: visibility
|
67
101
|
)
|
68
102
|
end
|
@@ -72,11 +106,11 @@ module RBS
|
|
72
106
|
member: :method_definition,
|
73
107
|
name: name,
|
74
108
|
kind: kind,
|
75
|
-
|
109
|
+
overloads: overloads,
|
76
110
|
annotations: annotations,
|
77
111
|
location: location,
|
78
112
|
comment: comment,
|
79
|
-
|
113
|
+
overloading: overloading?,
|
80
114
|
visibility: visibility
|
81
115
|
}.to_json(state)
|
82
116
|
end
|
data/lib/rbs/cli.rb
CHANGED
@@ -29,7 +29,12 @@ module RBS
|
|
29
29
|
end
|
30
30
|
|
31
31
|
loader = EnvironmentLoader.new(core_root: core_root, repository: repository)
|
32
|
-
|
32
|
+
if config_path
|
33
|
+
lock_path = Collection::Config.to_lockfile_path(config_path)
|
34
|
+
if lock_path.file?
|
35
|
+
lock = Collection::Config::Lockfile.from_lockfile(lockfile_path: lock_path, data: YAML.load_file(lock_path.to_s))
|
36
|
+
end
|
37
|
+
end
|
33
38
|
loader.add_collection(lock) if lock
|
34
39
|
|
35
40
|
dirs.each do |dir|
|
@@ -433,15 +438,15 @@ EOU
|
|
433
438
|
env = Environment.from_loader(loader).resolve_type_names
|
434
439
|
|
435
440
|
builder = DefinitionBuilder.new(env: env)
|
436
|
-
validator = Validator.new(env: env, resolver: TypeNameResolver.
|
441
|
+
validator = Validator.new(env: env, resolver: Resolver::TypeNameResolver.new(env))
|
437
442
|
|
438
443
|
env.class_decls.each do |name, decl|
|
439
444
|
stdout.puts "Validating class/module definition: `#{name}`..."
|
440
445
|
builder.build_instance(name).each_type do |type|
|
441
|
-
validator.validate_type type, context:
|
446
|
+
validator.validate_type type, context: nil
|
442
447
|
end
|
443
448
|
builder.build_singleton(name).each_type do |type|
|
444
|
-
validator.validate_type type, context:
|
449
|
+
validator.validate_type type, context: nil
|
445
450
|
end
|
446
451
|
|
447
452
|
d = decl.primary.decl
|
@@ -462,10 +467,15 @@ EOU
|
|
462
467
|
end
|
463
468
|
end
|
464
469
|
|
470
|
+
env.class_alias_decls.each do |name, entry|
|
471
|
+
stdout.puts "Validating class/module alias definition: `#{name}`..."
|
472
|
+
validator.validate_class_alias(entry: entry)
|
473
|
+
end
|
474
|
+
|
465
475
|
env.interface_decls.each do |name, decl|
|
466
476
|
stdout.puts "Validating interface: `#{name}`..."
|
467
477
|
builder.build_interface(name).each_type do |type|
|
468
|
-
validator.validate_type type, context:
|
478
|
+
validator.validate_type type, context: nil
|
469
479
|
end
|
470
480
|
|
471
481
|
validator.validate_type_params(
|
@@ -490,13 +500,13 @@ EOU
|
|
490
500
|
|
491
501
|
env.global_decls.each do |name, global|
|
492
502
|
stdout.puts "Validating global: `#{name}`..."
|
493
|
-
validator.validate_type global.decl.type, context:
|
503
|
+
validator.validate_type global.decl.type, context: nil
|
494
504
|
end
|
495
505
|
|
496
|
-
env.
|
506
|
+
env.type_alias_decls.each do |name, decl|
|
497
507
|
stdout.puts "Validating alias: `#{name}`..."
|
498
508
|
builder.expand_alias1(name).tap do |type|
|
499
|
-
validator.validate_type type, context:
|
509
|
+
validator.validate_type type, context: nil
|
500
510
|
end
|
501
511
|
validator.validate_type_alias(entry: decl)
|
502
512
|
end
|
@@ -532,14 +542,26 @@ EOU
|
|
532
542
|
env = Environment.from_loader(loader).resolve_type_names
|
533
543
|
|
534
544
|
builder = DefinitionBuilder.new(env: env)
|
535
|
-
|
545
|
+
resolver = Resolver::ConstantResolver.new(builder: builder)
|
546
|
+
|
547
|
+
resolver_context = context ? [nil, TypeName(context).absolute!] : nil #: Resolver::context
|
548
|
+
stdout.puts "Context: #{context}"
|
549
|
+
const_name = TypeName(args[0])
|
550
|
+
stdout.puts "Constant name: #{const_name}"
|
536
551
|
|
537
|
-
|
538
|
-
|
539
|
-
|
540
|
-
|
552
|
+
if const_name.absolute?
|
553
|
+
constant = resolver.table.constant(const_name)
|
554
|
+
else
|
555
|
+
head, *components = const_name.to_namespace.path
|
556
|
+
head or raise
|
541
557
|
|
542
|
-
|
558
|
+
constant = resolver.resolve(head, context: resolver_context)
|
559
|
+
constant = components.inject(constant) do |const, component|
|
560
|
+
if const
|
561
|
+
resolver.resolve_child(const.name, component)
|
562
|
+
end
|
563
|
+
end
|
564
|
+
end
|
543
565
|
|
544
566
|
if constant
|
545
567
|
stdout.puts " => #{constant.name}: #{constant.type}"
|
@@ -1038,15 +1060,12 @@ EOB
|
|
1038
1060
|
case args[0]
|
1039
1061
|
when 'install'
|
1040
1062
|
unless params[:frozen]
|
1041
|
-
|
1042
|
-
Collection::Config.generate_lockfile(config_path: config_path, gemfile_lock_path: gemfile_lock_path)
|
1063
|
+
Collection::Config.generate_lockfile(config_path: config_path, definition: Bundler.definition)
|
1043
1064
|
end
|
1044
1065
|
Collection::Installer.new(lockfile_path: lock_path, stdout: stdout).install_from_lockfile
|
1045
1066
|
when 'update'
|
1046
|
-
gemfile_lock_path = Bundler.default_lockfile
|
1047
|
-
|
1048
1067
|
# TODO: Be aware of argv to update only specified gem
|
1049
|
-
Collection::Config.generate_lockfile(config_path: config_path,
|
1068
|
+
Collection::Config.generate_lockfile(config_path: config_path, definition: Bundler.definition, with_lockfile: false)
|
1050
1069
|
Collection::Installer.new(lockfile_path: lock_path, stdout: stdout).install_from_lockfile
|
1051
1070
|
when 'init'
|
1052
1071
|
if config_path.exist?
|
@@ -0,0 +1,115 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
module RBS
|
4
|
+
module Collection
|
5
|
+
class Config
|
6
|
+
class Lockfile
|
7
|
+
attr_reader :lockfile_path, :lockfile_dir, :path, :gemfile_lock_path, :sources, :gems
|
8
|
+
|
9
|
+
def initialize(lockfile_path:, path:, gemfile_lock_path:)
|
10
|
+
@lockfile_path = lockfile_path
|
11
|
+
@lockfile_dir = lockfile_path.parent
|
12
|
+
@path = path
|
13
|
+
@gemfile_lock_path = gemfile_lock_path
|
14
|
+
|
15
|
+
@sources = {}
|
16
|
+
@gems = {}
|
17
|
+
end
|
18
|
+
|
19
|
+
def fullpath
|
20
|
+
lockfile_dir + path
|
21
|
+
end
|
22
|
+
|
23
|
+
def gemfile_lock_fullpath
|
24
|
+
if gemfile_lock_path
|
25
|
+
lockfile_dir + gemfile_lock_path
|
26
|
+
end
|
27
|
+
end
|
28
|
+
|
29
|
+
def each_source(&block)
|
30
|
+
if block
|
31
|
+
sources.each_value(&block)
|
32
|
+
yield Sources::Rubygems.instance
|
33
|
+
yield Sources::Stdlib.instance
|
34
|
+
else
|
35
|
+
enum_for :each_source
|
36
|
+
end
|
37
|
+
end
|
38
|
+
|
39
|
+
def to_lockfile
|
40
|
+
# @type var data: lockfile_data
|
41
|
+
|
42
|
+
data = {
|
43
|
+
"sources" => sources.each_value.sort_by {|s| s.name }.map {|source| source.to_lockfile },
|
44
|
+
"path" => path.to_s,
|
45
|
+
"gems" => gems.each_value.sort_by {|g| g[:name] }.map {|hash| library_data(hash) },
|
46
|
+
"gemfile_lock_path" => gemfile_lock_path.to_s
|
47
|
+
}
|
48
|
+
|
49
|
+
data.delete("sources") if sources.empty?
|
50
|
+
data.delete("gems") if gems.empty?
|
51
|
+
|
52
|
+
data
|
53
|
+
end
|
54
|
+
|
55
|
+
def self.from_lockfile(lockfile_path:, data:)
|
56
|
+
path = Pathname(data["path"])
|
57
|
+
if p = data["gemfile_lock_path"]
|
58
|
+
gemfile_lock_path = Pathname(p)
|
59
|
+
end
|
60
|
+
|
61
|
+
lockfile = Lockfile.new(lockfile_path: lockfile_path, path: path, gemfile_lock_path: gemfile_lock_path)
|
62
|
+
|
63
|
+
if sources = data["sources"]
|
64
|
+
sources.each do |src|
|
65
|
+
git = Sources::Git.new(
|
66
|
+
name: src["name"],
|
67
|
+
revision: src["revision"],
|
68
|
+
remote: src["remote"],
|
69
|
+
repo_dir: src["repo_dir"]
|
70
|
+
)
|
71
|
+
lockfile.sources[git.name] = git
|
72
|
+
end
|
73
|
+
end
|
74
|
+
|
75
|
+
if gems = data["gems"]
|
76
|
+
gems.each do |gem|
|
77
|
+
src = gem["source"]
|
78
|
+
source = Sources.from_config_entry(src)
|
79
|
+
lockfile.gems[gem["name"]] = {
|
80
|
+
name: gem["name"],
|
81
|
+
version: gem["version"],
|
82
|
+
source: source
|
83
|
+
}
|
84
|
+
end
|
85
|
+
end
|
86
|
+
|
87
|
+
lockfile
|
88
|
+
end
|
89
|
+
|
90
|
+
def library_data(lib)
|
91
|
+
{
|
92
|
+
"name" => lib[:name],
|
93
|
+
"version" => lib[:version],
|
94
|
+
"source" => lib[:source].to_lockfile
|
95
|
+
}
|
96
|
+
end
|
97
|
+
|
98
|
+
def check_rbs_availability!
|
99
|
+
raise CollectionNotAvailable unless fullpath.exist?
|
100
|
+
|
101
|
+
gems.each_value do |gem|
|
102
|
+
source = gem[:source]
|
103
|
+
|
104
|
+
case source
|
105
|
+
when Sources::Git
|
106
|
+
meta_path = fullpath.join(gem[:name], gem[:version], Sources::Git::METADATA_FILENAME)
|
107
|
+
raise CollectionNotAvailable unless meta_path.exist?
|
108
|
+
raise CollectionNotAvailable unless library_data(gem) == YAML.load(meta_path.read)
|
109
|
+
end
|
110
|
+
end
|
111
|
+
end
|
112
|
+
end
|
113
|
+
end
|
114
|
+
end
|
115
|
+
end
|