Sha256: d4c231ce9e81ea52fc5e4ed294651587db56b6d8e7ddfb4a5e757908ecda444b

Contents?: true

Size: 1.3 KB

Versions: 1

Compression:

Stored size: 1.3 KB

Contents

require 'guard'
require 'guard/guard'

module Guard
  # Defines the guard, which is automatically seen by Guard
  class Cane < Guard
    DEFAULTS = {
      run_all_on_start: true
    }

    SUCCESS = ["Passed", { title: "Cane", image: :success }]
    FAILED = ["Failed", { title: "Cane", image: :failed }]

    attr_reader :last_result, :options

    def initialize(watchers = [], options = {})
      super

      @options = DEFAULTS.merge(options)
    end

    def start
      UI.info "Guard::Cane is running"

      run_all if options[:run_all_on_start]
    end

    def run_all
      cane
    end

    def run_on_modifications(paths)
      passed = cane paths
      run_all if options[:all_after_pass] && passed
    end

    def cane(paths = [])
      command = build_command(paths)

      UI.info "Running Cane: #{command}"

      result = system command

      if result
        Notifier.notify(*SUCCESS) if last_result == false
      else
        Notifier.notify(*FAILED)
      end

      @last_result = result

      result
    end

    def build_command(paths)
      command = []

      command << (options[:command] || "cane")

      if paths.any?
        joined_paths = paths.join(',')
        command << "--all '{#{joined_paths}}'"
      end

      command << options[:cli]

      command.compact.join(" ")
    end
  end
end

Version data entries

1 entries across 1 versions & 1 rubygems

Version Path
guard-cane-0.2.0 lib/guard/cane.rb