Sha256: b156f78490fe8302c41b328ffbca10f34bcc3ca79fa4ce2fa0ea644e7f892d79

Contents?: true

Size: 1.53 KB

Versions: 5

Compression:

Stored size: 1.53 KB

Contents

require 'dply/shell'
module Dply
  class Bundle

    include Shell

    def initialize(deployment: true)
      @deployment = deployment
    end

    def install
      return if not gemfile_exists?
      if @deployment
        install_deployment
      else
        install_global
      end
    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 install_global
      exitstatus = system "bundle check > /dev/null"
      return if exitstatus
      cmd "bundle install -j5"
    end

    def install_deployment
      if deployment_config_present?
        exitstatus = system "bundle check > /dev/null"
        return if exitstatus
      end
      cmd "bundle install -j5 --deployment"
    end

    def deployment_config_present?
      file = ".bundle/config"
      if not File.readable? file
        return false
      end
      config = YAML.load_file file
      config["BUNDLE_FROZEN"] == "1" && config["BUNDLE_PATH"] == "vendor/bundle"
    rescue
      return false
    end

    def env
      @env ||= env_from_yml
    end

    def env_from_yml
      path = "config/env.yml"
      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

5 entries across 5 versions & 1 rubygems

Version Path
dply-0.2.3 lib/dply/bundle.rb
dply-0.2.2 lib/dply/bundle.rb
dply-0.2.0 lib/dply/bundle.rb
dply-0.1.19 lib/dply/bundle.rb
dply-0.1.18 lib/dply/bundle.rb