class Guard::Haskell

Constants

DEFAULT_OPTIONS
Options

Attributes

last_run[R]
opts[RW]
repl[RW]
targets[R]

Public Class Methods

new(user_options = {}) click to toggle source
Calls superclass method
# File lib/guard/haskell.rb, line 35
def initialize(user_options = {})
  super
  self.opts = Options.new(*DEFAULT_OPTIONS.merge(user_options).values)
end

Public Instance Methods

reload() click to toggle source
# File lib/guard/haskell.rb, line 57
def reload
  stop
  start
end
run(pattern) click to toggle source
# File lib/guard/haskell.rb, line 67
def run(pattern)
  if opts.focus_on_fail and last_run == :runtime_failure
    repl.reload_and_rerun
  else
    repl.reload_and_run_matching(pattern)
  end
  success?
end
run_all() click to toggle source
# File lib/guard/haskell.rb, line 62
def run_all
  repl.reload_and_run_matching
  success?
end
run_on_additions(paths) click to toggle source
# File lib/guard/haskell.rb, line 101
def run_on_additions(paths)
  unless paths.all? { |path| targets.include?(path) }
    @targets += paths
    reload
  end
end
run_on_modifications(paths) click to toggle source
# File lib/guard/haskell.rb, line 108
def run_on_modifications(paths)
  case paths.first
  when /(.+)Spec\.l?hs$/, /(.+)\.l?hs$/ then run($1.to_module_name)
  when /\.cabal$/ then reload
  end
end
start() click to toggle source
# File lib/guard/haskell.rb, line 40
def start
  @last_run = :success # try to prove it wasn't :-)
  self.repl = Repl.new(opts.cabal_target, opts.repl_options)
  throw :cabal_repl_initialization_has_failed if self.repl.status == :loading_failure
  success?

  @targets = ::Set.new(::Dir.glob("**/*.{hs,lhs}"))

  if opts.all_on_start
    run_all
  end
end
stop() click to toggle source
# File lib/guard/haskell.rb, line 53
def stop
  repl.exit
end
success?() click to toggle source
# File lib/guard/haskell.rb, line 76
def success?
  case [last_run, repl.status]
  when [:runtime_failure, :success],
      [:compile_failure, :success]
    @last_run = :success
    Notifier.notify('Success')
    if opts.all_on_pass
      run_all
    end
  when [:success, :success]
    Notifier.notify('Success')
  when [:runtime_failure, :compile_failure],
    [:runtime_failure, :runtime_failure],
    [:compile_failure, :compile_failure]
    Notifier.notify('Failure', image: :failed)
  when [:compile_failure, :runtime_failure],
    [:success, :runtime_failure]
    @last_run = :runtime_failure
    Notifier.notify('Failure', image: :failed)
  when [:success, :compile_failure]
    @last_run = :compile_failure
    Notifier.notify('Failure', image: :failed)
  end
end