Class: RBS::Vendorer

Inherits:
Object
  • Object
show all
Defined in:
lib/rbs/vendorer.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(vendor_dir:) ⇒ Vendorer

Returns a new instance of Vendorer.



5
6
7
# File 'lib/rbs/vendorer.rb', line 5

def initialize(vendor_dir:)
  @vendor_dir = vendor_dir
end

Instance Attribute Details

#vendor_dirObject (readonly)

Returns the value of attribute vendor_dir.



3
4
5
# File 'lib/rbs/vendorer.rb', line 3

def vendor_dir
  @vendor_dir
end

Instance Method Details

#clean!Object



17
18
19
20
21
22
# File 'lib/rbs/vendorer.rb', line 17

def clean!
  ensure_dir do
    RBS.logger.info "Cleaning vendor root: #{vendor_dir}..."
    vendor_dir.rmtree
  end
end

#ensure_dirObject



9
10
11
12
13
14
15
# File 'lib/rbs/vendorer.rb', line 9

def ensure_dir
  unless vendor_dir.directory?
    vendor_dir.mkpath
  end

  yield
end

#gem!(name, version) ⇒ Object



31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
# File 'lib/rbs/vendorer.rb', line 31

def gem!(name, version)
  ensure_dir do
    sig_path = EnvironmentLoader.gem_sig_path(name, version)
    RBS.logger.debug "Checking gem signature path: name=#{name}, version=#{version}, path=#{sig_path}"

    if sig_path&.directory?
      gems_dir = vendor_dir + "gems"
      gems_dir.mkpath unless gems_dir.directory?

      gem_dir = gems_dir + name
      RBS.logger.info "Vendoring gem(#{name}:#{version}): #{sig_path} => #{gem_dir}..."
      FileUtils.copy_entry sig_path, gem_dir
    end
  end
end

#stdlib!Object



24
25
26
27
28
29
# File 'lib/rbs/vendorer.rb', line 24

def stdlib!()
  ensure_dir do
    RBS.logger.info "Vendoring stdlib: #{EnvironmentLoader::STDLIB_ROOT} => #{vendor_dir + "stdlib"}..."
    FileUtils.copy_entry EnvironmentLoader::STDLIB_ROOT, vendor_dir + "stdlib"
  end
end