rbs 0.14.0 → 0.18.1

Sign up to get free protection for your applications and to get access to all the features.
Files changed (144) hide show
  1. checksums.yaml +4 -4
  2. data/.github/workflows/ruby.yml +8 -4
  3. data/CHANGELOG.md +35 -0
  4. data/Gemfile +1 -0
  5. data/README.md +1 -1
  6. data/Rakefile +19 -1
  7. data/Steepfile +0 -1
  8. data/bin/test_runner.rb +15 -1
  9. data/{stdlib/builtin → core}/array.rbs +124 -120
  10. data/{stdlib/builtin → core}/basic_object.rbs +0 -0
  11. data/{stdlib/builtin → core}/binding.rbs +0 -0
  12. data/core/builtin.rbs +70 -0
  13. data/{stdlib/builtin → core}/class.rbs +0 -0
  14. data/{stdlib/builtin → core}/comparable.rbs +0 -0
  15. data/{stdlib/builtin → core}/complex.rbs +0 -0
  16. data/{stdlib/builtin → core}/constants.rbs +0 -0
  17. data/{stdlib/builtin → core}/data.rbs +0 -0
  18. data/{stdlib/builtin → core}/deprecated.rbs +0 -0
  19. data/{stdlib/builtin → core}/dir.rbs +1 -1
  20. data/{stdlib/builtin → core}/encoding.rbs +0 -0
  21. data/{stdlib/builtin → core}/enumerable.rbs +67 -60
  22. data/{stdlib/builtin → core}/enumerator.rbs +5 -5
  23. data/{stdlib/builtin → core}/errno.rbs +0 -0
  24. data/{stdlib/builtin → core}/errors.rbs +1 -1
  25. data/{stdlib/builtin → core}/exception.rbs +0 -0
  26. data/{stdlib/builtin → core}/false_class.rbs +0 -0
  27. data/{stdlib/builtin → core}/fiber.rbs +0 -0
  28. data/{stdlib/builtin → core}/fiber_error.rbs +0 -0
  29. data/{stdlib/builtin → core}/file.rbs +0 -0
  30. data/{stdlib/builtin → core}/file_test.rbs +0 -0
  31. data/{stdlib/builtin → core}/float.rbs +0 -0
  32. data/{stdlib/builtin → core}/gc.rbs +2 -2
  33. data/{stdlib/builtin → core}/hash.rbs +15 -15
  34. data/{stdlib/builtin → core}/integer.rbs +0 -0
  35. data/{stdlib/builtin → core}/io.rbs +6 -6
  36. data/{stdlib/builtin → core}/kernel.rbs +1 -85
  37. data/{stdlib/builtin → core}/marshal.rbs +0 -0
  38. data/{stdlib/builtin → core}/match_data.rbs +0 -0
  39. data/{stdlib/builtin → core}/math.rbs +0 -0
  40. data/{stdlib/builtin → core}/method.rbs +0 -0
  41. data/{stdlib/builtin → core}/module.rbs +13 -13
  42. data/{stdlib/builtin → core}/nil_class.rbs +0 -0
  43. data/{stdlib/builtin → core}/numeric.rbs +0 -0
  44. data/{stdlib/builtin → core}/object.rbs +1 -1
  45. data/core/object_space.rbs +98 -0
  46. data/{stdlib/builtin → core}/proc.rbs +0 -0
  47. data/{stdlib/builtin → core}/process.rbs +0 -0
  48. data/{stdlib/builtin → core}/random.rbs +1 -1
  49. data/{stdlib/builtin → core}/range.rbs +3 -3
  50. data/{stdlib/builtin → core}/rational.rbs +0 -0
  51. data/{stdlib/builtin → core}/rb_config.rbs +0 -0
  52. data/{stdlib/builtin → core}/regexp.rbs +0 -0
  53. data/{stdlib/builtin → core}/ruby_vm.rbs +0 -0
  54. data/{stdlib/builtin → core}/signal.rbs +0 -0
  55. data/{stdlib/builtin → core}/string.rbs +6 -6
  56. data/{stdlib/builtin → core}/string_io.rbs +7 -7
  57. data/{stdlib/builtin → core}/struct.rbs +2 -2
  58. data/{stdlib/builtin → core}/symbol.rbs +1 -1
  59. data/{stdlib/builtin → core}/thread.rbs +4 -4
  60. data/{stdlib/builtin → core}/thread_group.rbs +0 -0
  61. data/{stdlib/builtin → core}/time.rbs +0 -0
  62. data/{stdlib/builtin → core}/trace_point.rbs +0 -0
  63. data/{stdlib/builtin → core}/true_class.rbs +1 -1
  64. data/{stdlib/builtin → core}/unbound_method.rbs +0 -0
  65. data/{stdlib/builtin → core}/warning.rbs +0 -0
  66. data/docs/repo.md +125 -0
  67. data/docs/syntax.md +50 -6
  68. data/lib/rbs.rb +1 -0
  69. data/lib/rbs/cli.rb +105 -103
  70. data/lib/rbs/definition.rb +9 -4
  71. data/lib/rbs/definition_builder.rb +50 -17
  72. data/lib/rbs/environment_loader.rb +79 -105
  73. data/lib/rbs/environment_walker.rb +70 -35
  74. data/lib/rbs/parser.rb +404 -397
  75. data/lib/rbs/parser.y +18 -9
  76. data/lib/rbs/prototype/rb.rb +186 -25
  77. data/lib/rbs/prototype/runtime.rb +18 -7
  78. data/lib/rbs/repository.rb +121 -0
  79. data/lib/rbs/test/hook.rb +27 -15
  80. data/lib/rbs/test/setup.rb +5 -3
  81. data/lib/rbs/test/tester.rb +4 -1
  82. data/lib/rbs/test/type_check.rb +16 -5
  83. data/lib/rbs/type_name.rb +2 -1
  84. data/lib/rbs/vendorer.rb +38 -16
  85. data/lib/rbs/version.rb +1 -1
  86. data/sig/cli.rbs +58 -0
  87. data/sig/constant_table.rbs +1 -1
  88. data/sig/declarations.rbs +1 -1
  89. data/sig/definition.rbs +9 -4
  90. data/sig/definition_builder.rbs +4 -1
  91. data/sig/environment_loader.rbs +92 -46
  92. data/sig/members.rbs +2 -2
  93. data/sig/method_types.rbs +1 -1
  94. data/sig/namespace.rbs +1 -1
  95. data/sig/polyfill.rbs +42 -0
  96. data/sig/rbs.rbs +8 -0
  97. data/sig/repository.rbs +79 -0
  98. data/sig/vendorer.rbs +44 -0
  99. data/stdlib/abbrev/{abbrev.rbs → 0/abbrev.rbs} +0 -0
  100. data/stdlib/base64/{base64.rbs → 0/base64.rbs} +1 -1
  101. data/stdlib/benchmark/{benchmark.rbs → 0/benchmark.rbs} +0 -0
  102. data/stdlib/{bigdecimal/math → bigdecimal-math/0}/big_math.rbs +0 -0
  103. data/stdlib/bigdecimal/{big_decimal.rbs → 0/big_decimal.rbs} +0 -0
  104. data/stdlib/coverage/{coverage.rbs → 0/coverage.rbs} +2 -2
  105. data/stdlib/csv/{csv.rbs → 0/csv.rbs} +4 -4
  106. data/stdlib/date/{date.rbs → 0/date.rbs} +2 -2
  107. data/stdlib/date/{date_time.rbs → 0/date_time.rbs} +1 -1
  108. data/stdlib/dbm/0/dbm.rbs +277 -0
  109. data/stdlib/erb/{erb.rbs → 0/erb.rbs} +0 -0
  110. data/stdlib/fiber/{fiber.rbs → 0/fiber.rbs} +0 -0
  111. data/stdlib/find/{find.rbs → 0/find.rbs} +2 -2
  112. data/stdlib/forwardable/{forwardable.rbs → 0/forwardable.rbs} +0 -0
  113. data/stdlib/ipaddr/{ipaddr.rbs → 0/ipaddr.rbs} +0 -0
  114. data/stdlib/json/{json.rbs → 0/json.rbs} +0 -0
  115. data/stdlib/logger/{formatter.rbs → 0/formatter.rbs} +0 -0
  116. data/stdlib/logger/{log_device.rbs → 0/log_device.rbs} +1 -1
  117. data/stdlib/logger/{logger.rbs → 0/logger.rbs} +1 -1
  118. data/stdlib/logger/{period.rbs → 0/period.rbs} +0 -0
  119. data/stdlib/logger/{severity.rbs → 0/severity.rbs} +0 -0
  120. data/stdlib/mutex_m/{mutex_m.rbs → 0/mutex_m.rbs} +0 -0
  121. data/stdlib/pathname/{pathname.rbs → 0/pathname.rbs} +39 -39
  122. data/stdlib/prime/{integer-extension.rbs → 0/integer-extension.rbs} +0 -0
  123. data/stdlib/prime/{prime.rbs → 0/prime.rbs} +1 -1
  124. data/stdlib/pstore/0/pstore.rbs +287 -0
  125. data/stdlib/pty/{pty.rbs → 0/pty.rbs} +1 -1
  126. data/stdlib/securerandom/{securerandom.rbs → 0/securerandom.rbs} +0 -0
  127. data/stdlib/set/{set.rbs → 0/set.rbs} +10 -10
  128. data/stdlib/singleton/0/singleton.rbs +111 -0
  129. data/stdlib/tmpdir/{tmpdir.rbs → 0/tmpdir.rbs} +0 -0
  130. data/stdlib/tsort/0/cyclic.rbs +4 -0
  131. data/stdlib/tsort/0/interfaces.rbs +19 -0
  132. data/stdlib/tsort/0/tsort.rbs +363 -0
  133. data/stdlib/uri/{file.rbs → 0/file.rbs} +0 -0
  134. data/stdlib/uri/{generic.rbs → 0/generic.rbs} +1 -1
  135. data/stdlib/uri/{http.rbs → 0/http.rbs} +0 -0
  136. data/stdlib/uri/{https.rbs → 0/https.rbs} +0 -0
  137. data/stdlib/uri/{ldap.rbs → 0/ldap.rbs} +0 -0
  138. data/stdlib/uri/{ldaps.rbs → 0/ldaps.rbs} +0 -0
  139. data/stdlib/yaml/0/dbm.rbs +221 -0
  140. data/stdlib/yaml/0/store.rbs +53 -0
  141. data/stdlib/zlib/{zlib.rbs → 0/zlib.rbs} +0 -0
  142. data/steep/Gemfile.lock +9 -9
  143. metadata +108 -94
  144. data/stdlib/builtin/builtin.rbs +0 -42
@@ -19,7 +19,7 @@ module RBS
19
19
 
20
20
  def resolve_constant_reference_context: (Symbol, context: Array[Namespace]) -> Constant?
21
21
 
22
- def resolve_constant_reference_inherit: (Symbol, scopes: Array[Namespace], ?no_object: bool) -> Constant?
22
+ def resolve_constant_reference_inherit: (Symbol, scopes: Array[Namespace], ?no_object: boolish) -> Constant?
23
23
 
24
24
  def constant_scopes: (TypeName) -> Array[Namespace]
25
25
 
@@ -14,7 +14,7 @@ module RBS
14
14
  attr_reader variance: variance
15
15
  attr_reader skip_validation: bool
16
16
 
17
- def initialize: (name: Symbol, variance: variance, skip_validation: bool) -> void
17
+ def initialize: (name: Symbol, variance: variance, skip_validation: boolish) -> void
18
18
 
19
19
  include _ToJson
20
20
  end
@@ -18,16 +18,16 @@ module RBS
18
18
  class TypeDef
19
19
  attr_reader type: MethodType
20
20
  attr_reader member: method_member
21
- attr_reader defined_in: TypeName?
21
+ attr_reader defined_in: TypeName
22
22
  attr_reader implemented_in: TypeName?
23
23
 
24
- def initialize: (type: MethodType, member: method_member, defined_in: TypeName?, implemented_in: TypeName?) -> void
24
+ def initialize: (type: MethodType, member: method_member, defined_in: TypeName, implemented_in: TypeName?) -> void
25
25
 
26
26
  def comment: () -> AST::Comment?
27
27
 
28
28
  def annotations: () -> Array[AST::Annotation]
29
29
 
30
- def update: (?type: MethodType, ?member: method_member, ?defined_in: TypeName?, ?implemented_in: TypeName?) -> TypeDef
30
+ def update: (?type: MethodType, ?member: method_member, ?defined_in: TypeName, ?implemented_in: TypeName?) -> TypeDef
31
31
 
32
32
  def overload?: () -> bool
33
33
  end
@@ -42,8 +42,13 @@ module RBS
42
42
  attr_reader comments: Array[AST::Comment]
43
43
  attr_reader annotations: Array[AST::Annotation]
44
44
  attr_reader members: Array[method_member]
45
+ attr_reader alias_of: Method?
45
46
 
46
- def initialize: (super_method: Method?, defs: Array[TypeDef], accessibility: accessibility, ?annotations: Array[AST::Annotation]) -> void
47
+ def initialize: (super_method: Method?,
48
+ defs: Array[TypeDef],
49
+ accessibility: accessibility,
50
+ alias_of: Method?,
51
+ ?annotations: Array[AST::Annotation]) -> void
47
52
 
48
53
  def public?: () -> bool
49
54
 
@@ -61,6 +61,8 @@ module RBS
61
61
 
62
62
  def ensure_namespace!: (Namespace, location: Location?) -> void
63
63
 
64
+ def build_singleton: (TypeName) -> Definition
65
+
64
66
  def build_instance: (TypeName) -> Definition
65
67
 
66
68
  def build_interface: (TypeName) -> Definition
@@ -69,11 +71,12 @@ module RBS
69
71
 
70
72
  def build_one_singleton: (TypeName) -> Definition
71
73
 
74
+ type ancestors = Definition::InstanceAncestors | Definition::SingletonAncestors | nil
72
75
  def merge_definitions: (TypeName,
73
76
  Array[[Definition::Ancestor::t, Definition]],
74
77
  entry: Environment::ModuleEntry | Environment::ClassEntry,
75
78
  self_type: Definition::self_type,
76
- ancestors: Array[Definition::Ancestor::t]) -> Definition
79
+ ancestors: ancestors) -> Definition
77
80
 
78
81
  type method_kind = :instance | :singleton
79
82
  def merge_method: (TypeName, Hash[Symbol, Definition::Method], Symbol, Definition::Method, Substitution, kind: method_kind) -> void
@@ -1,58 +1,104 @@
1
1
  module RBS
2
+ # EnvironmentLoader is an object to load RBS files from filesystem.
3
+ #
4
+ # Set up your configuration through repository and `#add` method.
5
+ #
6
+ # # Set up the repository to load library RBSs from.
7
+ # repo = RBS::Repository.default
8
+ # repo.add(Pathname("vendor/rbs/gem-rbs"))
9
+ # repo.add(Pathname("vendor/rbs/internal-rbs"))
10
+ #
11
+ # loader = RBS::EnvironmentLoader.new(repository: repo)
12
+ #
13
+ # # Add libraries to load RBS files.
14
+ # loader.add(library: "minitest")
15
+ # loader.add(library: "rbs", version: "1.0.0")
16
+ #
17
+ # # Add dirs to load RBS files from.
18
+ # loader.add(path: Pathname("sig"))
19
+ #
20
+ # # Load RBSs into an environment.
21
+ # environment = RBS::Environment.new()
22
+ # loader.load(env: environment)
23
+ #
2
24
  class EnvironmentLoader
3
- class UnknownLibraryNameError < StandardError
4
- attr_reader name: String
5
-
6
- def initialize: (name: String) -> void
7
- end
8
-
9
- class LibraryPath
10
- attr_reader name: String
11
- attr_reader path: Pathname
25
+ class UnknownLibraryError < StandardError
26
+ attr_reader library: Library
12
27
 
13
- def initialize: (name: String, path: Pathname) -> void
28
+ def initialize: (lib: Library) -> void
14
29
  end
15
30
 
16
- class GemPath
31
+ class Library < Struct[String | String?]
17
32
  attr_reader name: String
18
33
  attr_reader version: String?
19
- attr_reader path: Pathname
20
34
 
21
- def initialize: (name: String, version: String?, path: Pathname) -> void
35
+ def initialize: (name: String, version: String?) -> void
22
36
  end
23
37
 
24
- STDLIB_ROOT: Pathname
25
-
26
- type path = Pathname | LibraryPath | GemPath
27
-
28
- attr_reader paths: Array[path]
29
- attr_reader stdlib_root: Pathname
30
- attr_reader gem_vendor_path: Pathname?
31
-
32
- def self.gem_sig_path: (String, String?) -> Pathname?
33
-
34
- def initialize: (?stdlib_root: Pathname, ?gem_vendor_path: Pathname?) -> void
35
-
36
- def add: (path: Pathname?) -> void
37
- | (library: String?) -> void
38
-
39
- def self.parse_library: (String) -> [String, String?]
40
-
41
- def stdlib?: (String) -> Pathname?
42
-
43
- def gem?: (String, String?) -> Pathname?
44
-
45
- def each_signature: (Pathname, ?immediate: bool) { (Pathname) -> void } -> void
46
- | (Pathname, ?immediate: bool) -> Enumerator[Pathname, void]
47
-
48
- def each_library_path: { (path, Pathname) -> void } -> void
49
-
50
- def no_builtin!: (?bool) -> self
51
-
52
- def no_builtin?: () -> bool
53
-
54
- def each_decl: () { (AST::Declarations::t, Buffer, Pathname, path | :stdlib) -> void } -> void
55
-
56
- def load: (env: Environment) -> Array[[AST::Declarations::t, Pathname, path | :stdlib]]
38
+ DEFAULT_CORE_ROOT: Pathname
39
+
40
+ attr_reader core_root: Pathname?
41
+ attr_reader repository: Repository
42
+
43
+ attr_reader libs: Array[Library]
44
+ attr_reader dirs: Array[Pathname]
45
+
46
+ # The source where the RBS comes from.
47
+ #
48
+ # `:core` means it is part of core library.
49
+ # `Library` means it is from library.
50
+ # `Pathname` means it is loaded from a directory.
51
+ #
52
+ type source = :core
53
+ | Library
54
+ | Pathname
55
+
56
+ # Accepts two optional keyword arguments.
57
+ #
58
+ # `core_root` is the path to the directory with RBSs for core classes.
59
+ # The default value is the core library included in RBS gem. (EnvironmentLoader::DEFAULT_CORE_ROOT)
60
+ # Passing `nil` means it skips loading core class definitions.
61
+ #
62
+ # `repository` is the repository for library classes.
63
+ # The default value is repository only with stdlib classes. (Repository.new)
64
+ #
65
+ def initialize: (?core_root: Pathname?, ?repository: Repository) -> void
66
+
67
+ # Add a path or library to load RBSs from.
68
+ #
69
+ # `path` can be a file or a directory.
70
+ # All `.rbs` files from the given directory will be loaded.
71
+ # Specifying a file will load the file regardless the extension of the file is.
72
+ #
73
+ # `library` can be a name of a gem.
74
+ # Specifying `nil` to `version` will load any version available.
75
+ # It first tries to load RBS files from gem with specified version.
76
+ # If RBS files cannot be found in the gem, it tries to load RBSs from repository.
77
+ #
78
+ def add: (path: Pathname) -> void
79
+ | (library: String, version: String?) -> void
80
+
81
+ # This is helper function to test if RBS for a library is available or not.
82
+ #
83
+ def has_library?: (library: String, version: String?) -> bool
84
+
85
+ # Add all declarations to environment.
86
+ #
87
+ # Raises `UnknownLibraryError` if RBS cannot be loaded from a library.
88
+ #
89
+ # Returns an array of tuples of the declaration, path to the file, and the source.
90
+ #
91
+ def load: (env: Environment) -> Array[[AST::Declarations::t, Pathname, source]]
92
+
93
+ # Returns a pair of spec and path for a gem with RBS.
94
+ # Returns nil if the gem is not installed, or the gem doesn't provide RBS.
95
+ #
96
+ def self.gem_sig_path: (String name, String? version) -> [Gem::Specification, Pathname]?
97
+
98
+ def each_decl: () { (AST::Declarations::t, Buffer, source, Pathname) -> void } -> void
99
+
100
+ def each_dir: { (source, Pathname) -> void } -> void
101
+
102
+ def each_file: (Pathname path, immediate: boolish, skip_hidden: boolish) { (Pathname) -> void } -> void
57
103
  end
58
104
  end
@@ -23,7 +23,7 @@ module RBS
23
23
  attr_reader comment: Comment?
24
24
  attr_reader overload: bool
25
25
 
26
- def initialize: (name: Symbol, kind: kind, types: Array[MethodType], annotations: Array[Annotation], location: Location?, comment: Comment?, overload: bool) -> void
26
+ def initialize: (name: Symbol, kind: kind, types: Array[MethodType], annotations: Array[Annotation], location: Location?, comment: Comment?, overload: boolish) -> void
27
27
 
28
28
  include _HashEqual
29
29
  include _ToJson
@@ -34,7 +34,7 @@ module RBS
34
34
 
35
35
  def overload?: () -> bool
36
36
 
37
- def update: (?name: Symbol, ?kind: kind, ?types: Array[MethodType], ?annotations: Array[Annotation], ?location: Location?, ?comment: Comment?, ?overload: bool) -> MethodDefinition
37
+ def update: (?name: Symbol, ?kind: kind, ?types: Array[MethodType], ?annotations: Array[Annotation], ?location: Location?, ?comment: Comment?, ?overload: boolish) -> MethodDefinition
38
38
  end
39
39
 
40
40
  module Var
@@ -4,7 +4,7 @@ module RBS
4
4
  attr_reader type: Types::Function
5
5
  attr_reader required: bool
6
6
 
7
- def initialize: (type: Types::Function, required: bool) -> void
7
+ def initialize: (type: Types::Function, required: boolish) -> void
8
8
 
9
9
  def ==: (untyped other) -> bool
10
10
 
@@ -28,7 +28,7 @@ module RBS
28
28
  class Namespace
29
29
  attr_reader path: Array[Symbol]
30
30
 
31
- def initialize: (path: Array[Symbol], absolute: bool) -> void
31
+ def initialize: (path: Array[Symbol], absolute: boolish) -> void
32
32
 
33
33
  # Returns new _empty_ namespace.
34
34
  def self.empty: () -> Namespace
@@ -1,3 +1,45 @@
1
1
  module Kernel
2
2
  def to_json: (*untyped) -> String
3
3
  end
4
+
5
+ module Gem
6
+ class Version
7
+ def self.correct?: (String) -> bool
8
+
9
+ def self.create: (String?) -> instance?
10
+
11
+ include Comparable
12
+
13
+ def prerelease?: () -> bool
14
+
15
+ def release: () -> self
16
+
17
+ def version: () -> String
18
+ end
19
+
20
+ class Specification
21
+ attr_reader version (): Version
22
+
23
+ attr_reader gem_dir (): String
24
+
25
+ def self.find_by_name: (String name, ?String? version) -> instance
26
+ end
27
+ end
28
+
29
+ class OptionParser
30
+ def initialize: () ?{ (instance) -> void } -> void
31
+
32
+ def on: (*String) { (String) -> void } -> void
33
+
34
+ attr_accessor version: String
35
+
36
+ attr_accessor banner: String
37
+
38
+ def order!: (Array[String]) -> void
39
+
40
+ def parse!: (Array[String]) -> void
41
+
42
+ def ver: () -> String
43
+
44
+ def help: () -> String
45
+ end
@@ -1,3 +1,11 @@
1
1
  module RBS
2
2
  def self.logger: () -> Logger
3
+
4
+ def self.logger_level: () -> untyped
5
+
6
+ def self.logger_level=: (untyped) -> untyped
7
+
8
+ def self.logger_output: () -> IO
9
+
10
+ def self.logger_output=: (IO) -> IO
3
11
  end
@@ -0,0 +1,79 @@
1
+ module RBS
2
+ # Set of RBS repositories.
3
+ #
4
+ # A repository object can handle multiple repository roots.
5
+ #
6
+ # repo = RBS::Repository.new()
7
+ # repo.add(Pathname("vendor/rbs/gem-rbs"))
8
+ # repo.add(Pathname("vendor/rbs/internal-rbs"))
9
+ # repo.add(Pathname("vendor/rbs/definitely-rbs"))
10
+ #
11
+ # repo.lookup("minitest", "2.1.3") => Pathname or nil
12
+ #
13
+ # If one gem version can resolve to several directories, the last added dir wins.
14
+ #
15
+ class Repository
16
+ class GemRBS
17
+ attr_reader name: String
18
+
19
+ # Array of gem dirs.
20
+ # Gem dir contains directories for each version.
21
+ attr_reader paths: Array[Pathname]
22
+
23
+ # Hash from a version to VersionPath object.
24
+ attr_reader versions(): Hash[Gem::Version, VersionPath]
25
+
26
+ @versions: Hash[Gem::Version, VersionPath]?
27
+
28
+ def initialize: (name: String) -> void
29
+
30
+ def load!: () -> void
31
+
32
+ def version_names: () -> Array[Gem::Version]
33
+
34
+ def oldest_version: () -> VersionPath
35
+
36
+ def latest_version: () -> VersionPath
37
+
38
+ def find_best_version: (Gem::Version?) -> VersionPath
39
+
40
+ # Returns true if versions is empty.
41
+ def empty?: () -> bool
42
+ end
43
+
44
+ class VersionPath
45
+ attr_reader gem: GemRBS
46
+ attr_reader version: Gem::Version
47
+ attr_reader path: Pathname
48
+
49
+ def initialize: (gem: GemRBS, version: Gem::Version, path: Pathname) -> void
50
+ end
51
+
52
+ DEFAULT_STDLIB_ROOT: Pathname
53
+
54
+ # Array of _root dir_s of repositories.
55
+ #
56
+ attr_reader dirs: Array[Pathname]
57
+
58
+ attr_reader gems: Hash[String, GemRBS]
59
+
60
+ # An optional keyword argument `no_stdlib` is to skip adding directory for stdlib classes.
61
+ # Passing truthy value will skip loading stdlib. (You can add the stdlib root by yourself.)
62
+ #
63
+ def initialize: (?no_stdlib: bool) -> void
64
+
65
+ # Add new _root dir_ to the repository set.
66
+ # If two repository dirs have exactly same gem-version definitions, the latter overwrites the prior.
67
+ #
68
+ def add: (Pathname dir) -> void
69
+
70
+ # Returns a directory for given `gem` name and `version`.
71
+ # `version` can be `nil` for _any version_.
72
+ #
73
+ # If the given gem cannot be found, it returns `nil`.
74
+ #
75
+ def lookup: (String gem, String? version) -> Pathname?
76
+
77
+ def lookup_path: (String gem, String? version) -> [GemRBS, VersionPath]?
78
+ end
79
+ end
@@ -0,0 +1,44 @@
1
+ module RBS
2
+ # Copies RBS files loaded through `loader` under `vendor_dir`.
3
+ #
4
+ # Core libraries and library RBS files will be copied.
5
+ #
6
+ # loader = RBS::EnvironmentLoader.new()
7
+ #
8
+ # loader.add(library: set) # Libraries will be copied.
9
+ # loader.add(library: "minitest", version: "1.2.3")
10
+ #
11
+ # loader.add(path: Pathname("sig")) # Dirs will be ignored.
12
+ #
13
+ # vendorer = RBS::Vendorer.new(vendor_dir: Pathname("vendor/rbs"), loader: loader)
14
+ # vendorer.clearn!
15
+ # vendorer.copy!
16
+ #
17
+ # The result will be:
18
+ # vendor/rbs/core => Will include core RBSs
19
+ # vendor/rbs/set-0 => Will include `set` library RBSs.
20
+ # vendor/rbs/minitest-1.2.3 => Will include `minitest` library RBSs.
21
+ #
22
+ # The vendorerd RBSs will be loaded through :dir source.
23
+ #
24
+ # loader = RBS::EnvironmentLoader.new(core_root: nil, repository: RBS::Repository.new(no_stdlib: true))
25
+ # loader.add(path: Pathname("vendor/rbs"))
26
+ # loader.add(path: Pathname("sig"))
27
+ #
28
+ class Vendorer
29
+ attr_reader vendor_dir: Pathname
30
+ attr_reader loader: EnvironmentLoader
31
+
32
+ def initialize: (vendor_dir: Pathname, loader: EnvironmentLoader) -> void
33
+
34
+ # Copy RBS files into `vendor_dir`.
35
+ # Ensures the `vendor_dir` exists.
36
+ def copy!: () -> void
37
+
38
+ # Deletes `vendor_dir` and its content if exists.
39
+ #
40
+ def clean!: () -> void
41
+
42
+ def ensure_dir: [A] () { () -> A } -> A
43
+ end
44
+ end