Sha256: 34d6795e361fe4d7208ca64b20e7097c1aa3afa25f771c18ad76fa740f898301

Contents?: true

Size: 1.79 KB

Versions: 17

Compression:

Stored size: 1.79 KB

Contents

require 'fileutils'
require 'forwardable'

Dir[File.join(Dir.pwd, 'tasks', '**', '*.rb')].each { |f| require f }

module Distribution
  class Package
    extend Forwardable
    include PackageHelpers

    attr_reader :config, :dir, :tarball, :package, :arch, :root

    def_delegators :@config, :version, :rb_version, :package_name,
                   :packaging_dir, :native_extensions

    def initialize(arch)
      abort 'Ruby 2.1.x required' if RUBY_VERSION !~ /^2\.1\./

      @arch = arch
      @config = ::Distribution.configuration
      @dir = "#{package_name}-#{version}-#{arch}"
      @package = self
      @root = File.expand_path '.'
    end

    def self.create(args)
      new(*args).build
    end

    def build
      initialize_install_dir
      copy_datapimp
      install_ruby_and_gems
      create_executable
      post_cleanup
      @tarball = create_tarball
      clean_dir
    end

    private

    def clean_dir
      FileUtils.cd root do
        FileUtils.remove_dir(dir, true) if Dir.exist? dir
      end
    end

    def post_cleanup
      print_to_console 'Cleaning up...'

      files = ["#{packaging_dir}/traveling-ruby-#{rb_version}-#{arch}.tar.gz"]

      files.each { |file| FileUtils.rm file if File.exist? file }
    end

    def create_tarball
      Tarball.new self
    end

    def create_executable
      Executable.create self
    end

    def install_ruby_and_gems
      TravellingRuby.install self
    end

    def initialize_install_dir
      clean_dir

      FileUtils.cd root do
        FileUtils.mkdir_p "#{dir}/lib/app"
      end
    end

    def copy_datapimp
      print_to_console 'Copying datapimp...'

      %w(datapimp.gemspec Gemfile Gemfile.lock lib bin)
        .each do |folder|
        FileUtils.cp_r File.join(root, folder), "#{dir}/lib/app"
      end
    end
  end
end

Version data entries

17 entries across 17 versions & 1 rubygems

Version Path
datapimp-1.0.21 tasks/distribution/package.rb
datapimp-1.0.20 tasks/distribution/package.rb
datapimp-1.0.15 tasks/distribution/package.rb
datapimp-1.0.14 tasks/distribution/package.rb
datapimp-1.0.13 tasks/distribution/package.rb
datapimp-1.0.12 tasks/distribution/package.rb
datapimp-1.0.11 tasks/distribution/package.rb
datapimp-1.0.10 tasks/distribution/package.rb
datapimp-1.0.9 tasks/distribution/package.rb
datapimp-1.0.8 tasks/distribution/package.rb
datapimp-1.0.6 tasks/distribution/package.rb
datapimp-1.0.5 tasks/distribution/package.rb
datapimp-1.0.4 tasks/distribution/package.rb
datapimp-1.0.3 tasks/distribution/package.rb
datapimp-1.0.2 tasks/distribution/package.rb
datapimp-1.0.1 tasks/distribution/package.rb
datapimp-1.0.0 tasks/distribution/package.rb