Sha256: 92a11509c5ade2e02854edccd7929ab06f86c4b978fd4c8c289644c3624b524d

Contents?: true

Size: 1.6 KB

Versions: 1

Compression:

Stored size: 1.6 KB

Contents

require 'fileutils'
require 'tempfile'

require 'vendorificator/vendor'

module Vendorificator
  class Vendor::Tool < Vendor
    arg_reader :specs, :command

    def before_conjure!
      upstream_version # to cache the version in instance attribute,
                       # it will be needed when we don't have the
                       # specs
    end

    def conjure!
      specs.each do |spec|
        src = File.join(environment.git.git_work_tree, spec)
        if File.exist?(src)
          FileUtils.install File.join(environment.git.git_work_tree, spec),
                            File.join(git.git_work_tree, spec),
                            verbose: true
        end
      end
      Dir.chdir(git.git_work_tree) do
        system self.command or raise RuntimeError, "Command failed"
      end
      super
    end

    def git_add_extra_paths
      specs.inject(super) do |rv, path|
        rv << path
      end
    end

    def upstream_version
      @upstream_version ||= git.capturing.
        log({:n => 1, :pretty => 'format:%ad-%h', :date => 'short'}, *specs).
        strip
    end
  end

  class Config
    register_module :tool, Vendor::Tool

    def rubygems_bundler(&block)
      tool 'rubygems',
           :path => 'cache', # Hardcoded, meh
           :specs => [ 'Gemfile', 'Gemfile.lock' ],
           :command => 'bundle package --all',
           &block
    end

    def chef_berkshelf(&block)
      tool 'cookbooks',
           :path => 'cookbooks',
           :specs => [ 'Berksfile', 'Berksfile.lock' ],
           :command => 'berks install --path vendor/cookbooks',
           &block
    end
  end
end

Version data entries

1 entries across 1 versions & 1 rubygems

Version Path
vendorificator-0.5.git.v0.4.0.63.g8e9d54d lib/vendorificator/vendor/tool.rb