Sha256: c56bdd718070e89b2500609d927dc237de6fa34bcc5014bcfe0b8d76368dae39

Contents?: true

Size: 1.1 KB

Versions: 3

Compression:

Stored size: 1.1 KB

Contents

# encoding: utf-8
require 'guard'
require 'guard/guard'
require 'bundler'

module Guard
  class Bundler < Guard
    autoload :Notifier, 'guard/bundler/notifier'

    def start
      refresh_bundle
    end

    def reload
      refresh_bundle
    end

    def run_all
      refresh_bundle
    end

    def run_on_additions(paths = [])
      refresh_bundle
    end

    def run_on_modifications(paths = [])
      refresh_bundle
    end

    def cli?
      !!options[:cli]
    end

    private

    def refresh_bundle
      if bundle_need_refresh?
        ::Guard::UI.info 'Refresh bundle', :reset => true
        start_at = Time.now
        ::Bundler.with_clean_env do
          @result = system("bundle install#{" #{options[:cli]}" if options[:cli]}")
        end
        Notifier.notify(@result, Time.now - start_at)
        @result
      else
        UI.info 'Bundle already up-to-date', :reset => true
        Notifier.notify('up-to-date', nil)
        true
      end
    end

    def bundle_need_refresh?
      ::Bundler.with_clean_env do
        `bundle check`
      end
      $? == 0 ? false : true
    end

  end
end

Version data entries

3 entries across 3 versions & 2 rubygems

Version Path
sidekiq-statsd-0.1.1 vendor/ruby/1.9.1/gems/guard-bundler-1.0.0/lib/guard/bundler.rb
sidekiq-statsd-0.1.0 vendor/ruby/1.9.1/gems/guard-bundler-1.0.0/lib/guard/bundler.rb
guard-bundler-1.0.0 lib/guard/bundler.rb