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

Inherits:
Packager show all
Defined in:
lib/kamaze/project/tools/gemspec/packer.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



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

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:



74
75
76
77
78
79
80
81
82
83
84
# File 'lib/kamaze/project/tools/gemspec/packer.rb', line 74

def command_for(packable)
  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    = Pathname.new(specification.bin_dir)
      command.packable   = packable
    end
  end
end

#configHash

Get host config, retrieved from RbConfig::CONFIG

Returns:

  • (Hash)


41
42
43
# File 'lib/kamaze/project/tools/gemspec/packer.rb', line 41

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

#mutable_attributesObject



53
54
55
# File 'lib/kamaze/project/tools/gemspec/packer.rb', line 53

def mutable_attributes
  super + [:compiler]
end

#pack(packable) ⇒ Pathname

Pack given packable

Parameters:

  • packable (String)

Returns:

  • (Pathname)


49
50
51
# File 'lib/kamaze/project/tools/gemspec/packer.rb', line 49

def pack(packable)
  prepare.tap { command_for(packable).execute }
end

#packablesArray<Pathname>

Get buildable (relative path)

Returns:

  • (Array<Pathname>)


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

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

#setupObject (protected)



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

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