Class: RBS::Vendorer
- Inherits:
-
Object
- Object
- RBS::Vendorer
- Defined in:
- sig/vendorer.rbs,
lib/rbs/vendorer.rb
Overview
Copies RBS files loaded through loader under vendor_dir.
Core libraries and library RBS files will be copied.
loader = RBS::EnvironmentLoader.new()
loader.add(library: set) # Libraries will be copied.
loader.add(library: "minitest", version: "1.2.3")
loader.add(path: Pathname("sig")) # Dirs will be ignored.
vendorer = RBS::Vendorer.new(vendor_dir: Pathname("vendor/rbs"), loader: loader)
vendorer.clean!
vendorer.copy!
The result will be:
vendor/rbs/core => Will include core RBSs
vendor/rbs/set-0 => Will include `set` library RBSs.
vendor/rbs/minitest-1.2.3 => Will include `minitest` library RBSs.
The vendored RBSs will be loaded through :dir source.
loader = RBS::EnvironmentLoader.new(core_root: nil, repository: RBS::Repository.new(no_stdlib: true))
loader.add(path: Pathname("vendor/rbs"))
loader.add(path: Pathname("sig"))
Instance Attribute Summary collapse
-
#loader ⇒ EnvironmentLoader
readonly
Returns the value of attribute loader.
-
#vendor_dir ⇒ Pathname
readonly
Returns the value of attribute vendor_dir.
Instance Method Summary collapse
-
#clean! ⇒ void
Deletes
vendor_dirand its content if exists. -
#copy! ⇒ void
Copy RBS files into
vendor_dir. - #ensure_dir ⇒ void
-
#initialize(vendor_dir:, loader:) ⇒ Vendorer
constructor
A new instance of Vendorer.
Constructor Details
#initialize(vendor_dir:, loader:) ⇒ Vendorer
Returns a new instance of Vendorer.
8 9 10 11 |
# File 'lib/rbs/vendorer.rb', line 8 def initialize(vendor_dir:, loader:) @vendor_dir = vendor_dir @loader = loader end |
Instance Attribute Details
#loader ⇒ EnvironmentLoader (readonly)
Returns the value of attribute loader.
6 7 8 |
# File 'lib/rbs/vendorer.rb', line 6 def loader @loader end |
#vendor_dir ⇒ Pathname (readonly)
Returns the value of attribute vendor_dir.
5 6 7 |
# File 'lib/rbs/vendorer.rb', line 5 def vendor_dir @vendor_dir end |
Instance Method Details
#clean! ⇒ void
This method returns an undefined value.
Deletes vendor_dir and its content if exists.
47 48 49 50 51 52 |
# File 'sig/vendorer.rbs', line 47 def clean! ensure_dir do RBS.logger.info "Cleaning vendor root: #{vendor_dir}..." vendor_dir.rmtree end end |
#copy! ⇒ void
This method returns an undefined value.
Copy RBS files into vendor_dir.
Ensures the vendor_dir exists.
43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 |
# File 'sig/vendorer.rbs', line 43 def copy! # @type var paths: Set[[Pathname, Pathname]] paths = Set[] if core_root = loader.core_root RBS.logger.info "Vendoring core RBSs in #{vendor_dir + "core"}..." FileFinder.each_file(core_root, skip_hidden: true) do |file_path| paths << [file_path, Pathname("core") + file_path.relative_path_from(core_root)] end end loader.libs.each do |lib| case when (spec, path = EnvironmentLoader.gem_sig_path(lib.name, lib.version)) dest_dir = Pathname("#{lib.name}-#{spec.version}") RBS.logger.info "Vendoring #{lib.name}(#{spec.version}) RBSs in #{vendor_dir + dest_dir}..." FileFinder.each_file(path, skip_hidden: true) do |file_path| paths << [file_path, dest_dir + file_path.relative_path_from(path)] end when (rbs, path = loader.repository.lookup_path(lib.name, lib.version)) dest_dir = Pathname("#{rbs.name}-#{path.version}") RBS.logger.info "Vendoring #{lib.name}(#{path.version}) RBSs in #{vendor_dir + dest_dir}..." FileFinder.each_file(path.path, skip_hidden: true) do |file_path| paths << [file_path, dest_dir + file_path.relative_path_from(path.path)] end else RBS.logger.error "Couldn't find RBSs for #{lib.name} (#{lib.version}); skipping..." end end paths.each do |from, to| dest = vendor_dir + to dest.parent.mkpath unless dest.parent.directory? FileUtils.copy_file(from.to_s, dest.to_s) end end |
#ensure_dir ⇒ void
This method returns an undefined value.
13 14 15 16 17 18 19 |
# File 'lib/rbs/vendorer.rb', line 13 def ensure_dir unless vendor_dir.directory? vendor_dir.mkpath end yield end |