Class: Kamaze::Project::Tools::Gemspec::Packer

Inherits:
Packager show all
Defined in:
lib/kamaze/project/tools/gemspec/packer.rb,
lib/kamaze/project/tools/gemspec.rb

Overview

Provides a ready to use interface based on rubyc (aka ruby-packer)

Defined Under Namespace

Classes: Command

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

This class inherits a constructor from Kamaze::Project::Tools::Packager

Dynamic Method Handling

This class handles dynamic methods through the method_missing method in the class Kamaze::Project::Tools::Packager

Instance Attribute Details

#compilerObject

Binary (executable) used to pack the project



21
22
23
# File 'lib/kamaze/project/tools/gemspec/packer.rb', line 21

def compiler
  @compiler
end

#observer_peersHash|nil (readonly, protected) Originally defined in module Concern::Observable

Returns:

  • (Hash|nil)

Instance Method Details

#command_for(packable) ⇒ Command (protected)

Get command for (packing) a given packable

Parameters:

  • packable (String)

Returns:



76
77
78
79
80
81
82
83
84
85
86
87
88
# File 'lib/kamaze/project/tools/gemspec/packer.rb', line 76

def command_for(packable)
  bin_dir = ::Pathname.new(specification.bin_dir)

  Dir.chdir(pwd) do
    Command.new do |command|
      command.executable = compiler
      command.src_dir    = package_dirs.fetch(:src)
      command.tmp_dir    = package_dirs.fetch(:tmp)
      command.bin_dir    = bin_dir
      command.packable   = packable
    end
  end
end

#configHash

Get host config, retrieved from RbConfig::CONFIG

Returns:

  • (Hash)


38
39
40
# File 'lib/kamaze/project/tools/gemspec/packer.rb', line 38

def config
  (RbConfig::CONFIG.map { |k, v| [k.to_sym, v] }).to_h
end

#mutable_attributesObject



55
56
57
# File 'lib/kamaze/project/tools/gemspec/packer.rb', line 55

def mutable_attributes
  super + [:compiler]
end

#pack(packable) ⇒ Pathname

Pack given packable

Parameters:

  • packable (String)

Returns:

  • (Pathname)


46
47
48
49
50
51
52
53
# File 'lib/kamaze/project/tools/gemspec/packer.rb', line 46

def pack(packable)
  bin_dir = ::Pathname.new(specification.bin_dir)

  prepare
  command_for(packable).execute

  bin_dir.join(packable)
end

#packablesArray<Pathname>

Get buildable (relative path)

Returns:

  • (Array<Pathname>)


26
27
28
29
30
31
32
33
# File 'lib/kamaze/project/tools/gemspec/packer.rb', line 26

def packables
  specification.executables.map do |executable|
    package_dirs.fetch(:bin)
                .join(executable)
                .to_s.gsub(%r{^./}, '')
                .yield_self { |path| ::Pathname.new(path) }
  end
end

#setupObject (protected)



61
62
63
64
65
66
67
68
69
70
# File 'lib/kamaze/project/tools/gemspec/packer.rb', line 61

def setup
  super

  self.package_labels = [:src, :tmp, :bin]
  self.purgeables     = [:bin]
  self.package_name   = '%<os>s/%<arch>s' % {
    os: config.fetch(:host_os),
    arch: config.fetch(:host_cpu)
  }
end