Sha256: 79638d56697d52b11e815adf04c3374a41eb89c2167089857ac030854fd5300b

Contents?: true

Size: 915 Bytes

Versions: 1

Compression:

Stored size: 915 Bytes

Contents

require 'guard'
require 'guard/plugin'

module Guard
  class Depend < Plugin
    require 'guard/depend/detect'
    require 'guard/depend/runner'

    DEFAULTS = {
      run_on_start: false,
      output_paths: [],
      cmd: nil
    }

    attr_reader :options, :runner, :detect

    def initialize(options = {})
      super
      @options = DEFAULTS.merge(options)
      @runner = Runner.new
      @detect = Detect.new(@options[:output_paths])
    end

    def start
      UI.info "#{self.class} is running"
      run_all if @options[:run_on_start]
    end

    def stop
    end

    def reload
    end

    def run_all
      @runner.run(@options[:cmd])
    end

    def run_on_changes(paths = [])
      run_if_outdated(paths)
    end

    private
    def run_if_outdated(paths = [])
      @runner.run(@options[:cmd]) if detect.out_of_date?(paths)
    end
  end
end

Version data entries

1 entries across 1 versions & 1 rubygems

Version Path
guard-depend-0.1.0 lib/guard/depend.rb