Class: Jets::Builders::GemReplacer

Inherits:
Object
  • Object
show all
Extended by:
Memoist
Defined in:
lib/jets/builders/gem_replacer.rb

Instance Method Summary collapse

Constructor Details

#initialize(ruby_version, options) ⇒ GemReplacer

Returns a new instance of GemReplacer.



4
5
6
7
# File 'lib/jets/builders/gem_replacer.rb', line 4

def initialize(ruby_version, options)
  @ruby_version = ruby_version
  @options = options
end

Instance Method Details

#report_missing_gemsObject



23
24
25
# File 'lib/jets/builders/gem_replacer.rb', line 23

def report_missing_gems

end

#runObject



9
10
11
12
13
14
15
16
17
18
19
20
21
# File 'lib/jets/builders/gem_replacer.rb', line 9

def run
  check = Jets::Gems::Check.new
  found_gems = check.run! # exits early if missing gems found

  # Reaching here means its safe to download and extract the gems
  found_gems.each do |gem_name, source|
    options = @options.merge(source_url: source)
    gem_extractor = Jets::Gems::Extract::Gem.new(gem_name, options)
    gem_extractor.run
  end

  tidy
end

#tidyObject

remove unnecessary files to reduce package size



28
29
30
31
# File 'lib/jets/builders/gem_replacer.rb', line 28

def tidy
  tidy_gems("#{@options[:project_root]}/bundled/gems/ruby/*/gems/*")
  tidy_gems("#{@options[:project_root]}/bundled/gems/ruby/*/bundler/gems/*")
end

#tidy_gem(path) ⇒ Object

Clean up some unneeded files to try to keep the package size down In a generated jets app this made a decent 9% difference:

175M test2
191M test3


43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
# File 'lib/jets/builders/gem_replacer.rb', line 43

def tidy_gem(path)
  # remove top level tests and cache folders
  Dir.glob("#{path}/*").each do |path|
    next unless File.directory?(path)
    folder = File.basename(path)
    if %w[test tests spec features benchmark cache doc].include?(folder)
      FileUtils.rm_rf(path)
    end
  end

  Dir.glob("#{path}/**/*").each do |path|
    next unless File.file?(path)
    ext = File.extname(path)
    if %w[.rdoc .md .markdown].include?(ext) or
       path =~ /LICENSE|CHANGELOG|README/
      FileUtils.rm_f(path)
    end
  end
end

#tidy_gems(gems_path) ⇒ Object



33
34
35
36
37
# File 'lib/jets/builders/gem_replacer.rb', line 33

def tidy_gems(gems_path)
  Dir.glob(gems_path).each do |gem_path|
    tidy_gem(gem_path)
  end
end