Sha256: c29cc8c6d54b29fe2fa9cf2640ce62ebf0ae3ed06ffb52c438149120e565124c

Contents?: true

Size: 1.28 KB

Versions: 4

Compression:

Stored size: 1.28 KB

Contents

require 'dply/helper'
require 'fileutils'
require 'yaml'

module Dply
  class Bundle

    include Helper

    def install
      init
      return if check
      cmd "bundle install -j5 --deployment"
    end

    def rake(task, **args)
      if gemfile_exists?
        cmd "bundle exec rake -Nf dply/Rakefile -R dply #{task}", env: env
      else
        cmd "rake -Nf dply/Rakefile -R dply #{task}", env: env
      end
    end

    def clean
      cmd "bundle clean"
    end

    private

    def init
      @init ||= begin
        h = {
          "BUNDLE_PATH" => "vendor/bundle",
          "BUNDLE_FROZEN" => "1",
          "BUNDLE_DISABLE_SHARED_GEMS" => "1"
        }
        FileUtils.mkdir_p ".bundle"
        File.open(".bundle/config", "w") { |f| f.write(YAML.dump h) }
      end
    end


    def check
      system "bundle check > /dev/null"
    end

    def env
      @env ||= begin
        env = {}
        env.merge! env_from_yml(".env.yml")
        env.merge! env_from_yml("config/env.yml")
        env
      end
    end

    def env_from_yml(path)
      if not File.readable? path
        logger.debug "skipped loading env from #{path}"
        return {}
      end
      require 'yaml'
      YAML.load_file(path)
    end

    def gemfile_exists?
      File.exists? "Gemfile"
    end

  end
end

Version data entries

4 entries across 4 versions & 1 rubygems

Version Path
dply-0.2.9 lib/dply/bundle.rb
dply-0.2.8 lib/dply/bundle.rb
dply-0.2.7 lib/dply/bundle.rb
dply-0.2.6 lib/dply/bundle.rb