Class: IronWorkerNG::Feature::Ruby::MergeGem::Feature

Inherits:
Base
  • Object
show all
Defined in:
lib/iron_worker_ng/feature/ruby/merge_gem.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

Methods inherited from Base

#build_command, #container_add, #rebase

Constructor Details

#initialize(code, spec) ⇒ Feature

Returns a new instance of Feature.



16
17
18
19
20
21
22
23
24
# File 'lib/iron_worker_ng/feature/ruby/merge_gem.rb', line 16

def initialize(code, spec)
  super(code)

  @spec = spec

  if @spec.name == 'nokogiri' && @spec.version.to_s.start_with?('1.6.') && (not code.use_build_cache)
    IronCore::Logger.warn 'IronWorkerNG', "WARNING: Building nokogiri version #{@spec.version} will take a lot of time. Switching to version '~> 1.5.9' should fix this"
  end
end

Instance Attribute Details

#specObject (readonly)

Returns the value of attribute spec.



14
15
16
# File 'lib/iron_worker_ng/feature/ruby/merge_gem.rb', line 14

def spec
  @spec
end

Instance Method Details

#bundle(container) ⇒ Object



39
40
41
42
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
# File 'lib/iron_worker_ng/feature/ruby/merge_gem.rb', line 39

def bundle(container)
  if not @code.full_remote_build
    if @spec.extensions.length == 0 || IronWorkerNG::Feature::Ruby::MergeGem.merge_binary?
      IronCore::Logger.debug 'IronWorkerNG', "Bundling ruby gem with name='#{@spec.name}' and version='#{@spec.version}'"

      loaded_from = @spec.loaded_from

      # yet another bundler fix

      if loaded_from.end_with?("/gems/bundler-#{@spec.version}/lib/bundler")
        loaded_from = loaded_from.gsub("/gems/bundler-#{@spec.version}/lib/bundler", "/specifications/bundler-#{@spec.version}.gemspec")
      end

      # and yet another one

      if loaded_from.end_with?("/gems/bundler-#{@spec.version}/lib/bundler/source")
        loaded_from = loaded_from.gsub("/gems/bundler-#{@spec.version}/lib/bundler/source", "/specifications/bundler-#{@spec.version}.gemspec")
      end

      if File.exists?(gem_path)
        container_add(container, '__gems__/gems/' + @spec.full_name, gem_path)
      else
        from_dir = File.dirname(loaded_from)

        @spec.files.each do |fname|
          container_add(container, '__gems__/gems/' + @spec.full_name + '/' + fname, from_dir + '/' + fname) if File.file?(from_dir + '/' + fname)
        end
      end

      container_add(container, "__gems__/specifications/#{@spec.full_name}.gemspec", loaded_from)
    else
      IronCore::Logger.warn 'IronWorkerNG', "Skipping ruby gem with name='#{@spec.name}' and version='#{@spec.version}' as it contains native extensions, switching to full remote build should fix this (add 'remote' to your .worker)"
    end
  end
end

#gem_pathObject



26
27
28
29
30
31
32
33
34
35
36
37
# File 'lib/iron_worker_ng/feature/ruby/merge_gem.rb', line 26

def gem_path
  path = @spec.full_gem_path

  # bundler fixes

  ['/gems/' + @spec.full_name, '/gems'].each do |bad_part|
    path.gsub!(bad_part + '/lib' + bad_part, bad_part)
    path.gsub!(bad_part + bad_part, bad_part)
  end

  path
end