Class: Guard::Haskell

Inherits:
Plugin
  • Object
show all
Defined in:
lib/guard/haskell.rb

Defined Under Namespace

Classes: Repl

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(options = {}) ⇒ Haskell



28
29
30
31
32
33
34
35
36
# File 'lib/guard/haskell.rb', line 28

def initialize options = {}
  super
  @last_run     = :success # try to prove it wasn't :-)
  @top_spec     = options[:top_spec] || "test/Spec.hs"
  @ghci_options = options[:ghci_options] || []
  @all_on_start = options[:all_on_start] || false
  @all_on_pass  = options[:all_on_pass] || false
  @repl         = Repl.new
end

Instance Attribute Details

#all_on_passObject (readonly)

Returns the value of attribute all_on_pass.



26
27
28
# File 'lib/guard/haskell.rb', line 26

def all_on_pass
  @all_on_pass
end

#all_on_startObject (readonly)

Returns the value of attribute all_on_start.



26
27
28
# File 'lib/guard/haskell.rb', line 26

def all_on_start
  @all_on_start
end

#ghci_optionsObject (readonly)

Returns the value of attribute ghci_options.



25
26
27
# File 'lib/guard/haskell.rb', line 25

def ghci_options
  @ghci_options
end

#last_runObject (readonly)

Returns the value of attribute last_run.



25
26
27
# File 'lib/guard/haskell.rb', line 25

def last_run
  @last_run
end

#replObject (readonly)

Returns the value of attribute repl.



25
26
27
# File 'lib/guard/haskell.rb', line 25

def repl
  @repl
end

#targetsObject (readonly)

Returns the value of attribute targets.



25
26
27
# File 'lib/guard/haskell.rb', line 25

def targets
  @targets
end

#top_specObject (readonly)

Returns the value of attribute top_spec.



25
26
27
# File 'lib/guard/haskell.rb', line 25

def top_spec
  @top_spec
end

Instance Method Details

#reloadObject



53
54
55
56
# File 'lib/guard/haskell.rb', line 53

def reload
  stop
  start
end

#run(pattern) ⇒ Object



63
64
65
66
67
68
69
70
# File 'lib/guard/haskell.rb', line 63

def run pattern
  if last_run == :runtime_failure
    repl.rerun
  else
    repl.run(pattern)
  end
  success?
end

#run_allObject



58
59
60
61
# File 'lib/guard/haskell.rb', line 58

def run_all
  repl.run
  success?
end

#run_on_additions(paths) ⇒ Object



97
98
99
100
101
102
# File 'lib/guard/haskell.rb', line 97

def run_on_additions paths
  unless paths.all? { |path| targets.include? path }
    @targets += paths
    repl.init(top_spec)
  end
end

#run_on_modifications(paths) ⇒ Object



104
105
106
107
108
109
# File 'lib/guard/haskell.rb', line 104

def run_on_modifications paths
  case paths.first
  when /(.+)Spec\.l?hs$/, /(.+)\.l?hs$/
    run($1.strip_lowercase_directories.path_to_module_name)
  end
end

#startObject



38
39
40
41
42
43
44
45
46
47
# File 'lib/guard/haskell.rb', line 38

def start
  repl.start(ghci_options)
  repl.init(top_spec)

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

  if all_on_start
    run_all
  end
end

#stopObject



49
50
51
# File 'lib/guard/haskell.rb', line 49

def stop
  repl.exit
end

#success?Boolean



72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
# File 'lib/guard/haskell.rb', line 72

def success?
  case [last_run, repl.result]
  when [:runtime_failure, :success],
      [:compile_failure, :success]
    @last_run = :success
    Notifier.notify('Success')
    if 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