Class: Guard::Haskell
- Inherits:
-
Plugin
- Object
- Plugin
- Guard::Haskell
- Defined in:
- lib/guard/haskell.rb
Defined Under Namespace
Classes: Repl
Instance Attribute Summary collapse
-
#all_on_pass ⇒ Object
readonly
Returns the value of attribute all_on_pass.
-
#all_on_start ⇒ Object
readonly
Returns the value of attribute all_on_start.
-
#ghci_options ⇒ Object
readonly
Returns the value of attribute ghci_options.
-
#last_run ⇒ Object
readonly
Returns the value of attribute last_run.
-
#repl ⇒ Object
readonly
Returns the value of attribute repl.
-
#targets ⇒ Object
readonly
Returns the value of attribute targets.
-
#top_spec ⇒ Object
readonly
Returns the value of attribute top_spec.
Instance Method Summary collapse
-
#initialize(options = {}) ⇒ Haskell
constructor
A new instance of Haskell.
- #reload ⇒ Object
- #run(pattern) ⇒ Object
- #run_all ⇒ Object
- #run_on_additions(paths) ⇒ Object
- #run_on_modifications(paths) ⇒ Object
- #start ⇒ Object
- #stop ⇒ Object
- #success? ⇒ Boolean
Constructor Details
#initialize(options = {}) ⇒ Haskell
28 29 30 31 32 33 34 35 36 |
# File 'lib/guard/haskell.rb', line 28 def initialize = {} super @last_run = :success # try to prove it wasn't :-) @top_spec = [:top_spec] || "test/Spec.hs" = [:ghci_options] || [] @all_on_start = [:all_on_start] || false @all_on_pass = [:all_on_pass] || false @repl = Repl.new end |
Instance Attribute Details
#all_on_pass ⇒ Object (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_start ⇒ Object (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_options ⇒ Object (readonly)
Returns the value of attribute ghci_options.
25 26 27 |
# File 'lib/guard/haskell.rb', line 25 def end |
#last_run ⇒ Object (readonly)
Returns the value of attribute last_run.
25 26 27 |
# File 'lib/guard/haskell.rb', line 25 def last_run @last_run end |
#repl ⇒ Object (readonly)
Returns the value of attribute repl.
25 26 27 |
# File 'lib/guard/haskell.rb', line 25 def repl @repl end |
#targets ⇒ Object (readonly)
Returns the value of attribute targets.
25 26 27 |
# File 'lib/guard/haskell.rb', line 25 def targets @targets end |
#top_spec ⇒ Object (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
#reload ⇒ Object
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_all ⇒ Object
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 |
#start ⇒ Object
38 39 40 41 42 43 44 45 46 47 |
# File 'lib/guard/haskell.rb', line 38 def start repl.start() repl.init(top_spec) @targets = ::Set.new(::Dir.glob("**/*.{hs,lhs}")) if all_on_start run_all end end |
#stop ⇒ Object
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 |