Class: Guard::Titan
Constant Summary collapse
- VERSION =
'0.0.2'
Instance Attribute Summary collapse
-
#all_cmd ⇒ Object
Returns the value of attribute all_cmd.
-
#cmds ⇒ Object
Returns the value of attribute cmds.
-
#exclude_from_all ⇒ Object
Returns the value of attribute exclude_from_all.
-
#on_run_all ⇒ Object
Returns the value of attribute on_run_all.
-
#root ⇒ Object
Returns the value of attribute root.
-
#using ⇒ Object
Returns the value of attribute using.
Instance Method Summary collapse
- #all_cmd_keys(opts = {}) ⇒ Object
-
#initialize(watchers = [], opts = {}) ⇒ Titan
constructor
A new instance of Titan.
- #run(cmd, opts = {}) ⇒ Object
- #run_all ⇒ Object
- #run_on_changes(paths) ⇒ Object
-
#zeus_recent_cmd(opts = {}) ⇒ Object
TODO: run at guard command prompt.
- #zeus_test(file) ⇒ Object
- #zeus_test_all_default ⇒ Object
- #zeus_test_cmd ⇒ Object
- #zeus_test_root ⇒ Object
Constructor Details
#initialize(watchers = [], opts = {}) ⇒ Titan
Returns a new instance of Titan.
13 14 15 16 17 18 19 20 21 22 |
# File 'lib/guard/titan.rb', line 13 def initialize(watchers = [], opts = {}) super @using = opts[:using] || :minitest @exclude_from_all = opts[:exclude_from_all] || [] @on_run_all = opts[:on_run_all] || :recent # || :all || :all_keys @root = File.dirname(opts[:root]) @cmds = get_scripts @all_cmd = cmds.delete(:all) @all_cmd = zeus_test_all_default if (all_cmd.nil? || all_cmd.empty?) end |
Instance Attribute Details
#all_cmd ⇒ Object
Returns the value of attribute all_cmd.
10 11 12 |
# File 'lib/guard/titan.rb', line 10 def all_cmd @all_cmd end |
#cmds ⇒ Object
Returns the value of attribute cmds.
9 10 11 |
# File 'lib/guard/titan.rb', line 9 def cmds @cmds end |
#exclude_from_all ⇒ Object
Returns the value of attribute exclude_from_all.
11 12 13 |
# File 'lib/guard/titan.rb', line 11 def exclude_from_all @exclude_from_all end |
#on_run_all ⇒ Object
Returns the value of attribute on_run_all.
10 11 12 |
# File 'lib/guard/titan.rb', line 10 def on_run_all @on_run_all end |
#root ⇒ Object
Returns the value of attribute root.
9 10 11 |
# File 'lib/guard/titan.rb', line 9 def root @root end |
#using ⇒ Object
Returns the value of attribute using.
9 10 11 |
# File 'lib/guard/titan.rb', line 9 def using @using end |
Instance Method Details
#all_cmd_keys(opts = {}) ⇒ Object
77 78 79 |
# File 'lib/guard/titan.rb', line 77 def all_cmd_keys(opts = {}) cmds.keys - (['all'] + exclude_from_all.map(&:to_s)) end |
#run(cmd, opts = {}) ⇒ Object
70 71 72 73 74 75 |
# File 'lib/guard/titan.rb', line 70 def run(cmd, opts = {}) puts '='*40 puts "Running: #{cmd}" output = `#{cmd}` puts output end |
#run_all ⇒ Object
24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 |
# File 'lib/guard/titan.rb', line 24 def run_all case on_run_all when :all put_and_notify("All:", all_cmd) run(all_cmd) when :all_keys put_and_notify("All_Keys:", all_cmd_keys.join(',')) commands = all_cmd_keys.map {|k| cmds[k] } commands.each do |c| run(c) end when :recent put_and_notify("All Recent:", zeus_recent_cmd) run(zeus_recent_cmd) else put_and_notify("All Recent:", zeus_recent_cmd) run(zeus_recent_cmd) end end |
#run_on_changes(paths) ⇒ Object
87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 |
# File 'lib/guard/titan.rb', line 87 def run_on_changes(paths) put_and_notify("Changed:", paths.join(', ')) test_all = false dot_tee = [] normal_tests = paths.inject(Array.new) do |memo, p| if (p =~ /\.t\/(.*)$/) test_all = true if ($1=='all') dot_tee.push($1) else memo.push(p) end memo end if test_all run_all else run(zeus_test(normal_tests.join(' '))) if normal_tests.any? run(dot_tee.map { |k| cmds[k] }.join(' ; ')) if dot_tee.any? end end |
#zeus_recent_cmd(opts = {}) ⇒ Object
TODO: run at guard command prompt
82 83 84 85 |
# File 'lib/guard/titan.rb', line 82 def zeus_recent_cmd(opts = {}) # run tests that have changed since last commit "zeus test #{since_last_commit.join(' ')}" end |
#zeus_test(file) ⇒ Object
44 45 46 |
# File 'lib/guard/titan.rb', line 44 def zeus_test(file) "zeus #{zeus_test_cmd} #{root}/#{file}" end |
#zeus_test_all_default ⇒ Object
48 49 50 |
# File 'lib/guard/titan.rb', line 48 def zeus_test_all_default zeus_test("#{zeus_test_root}**/*_test.rb") end |
#zeus_test_cmd ⇒ Object
52 53 54 55 56 57 58 59 |
# File 'lib/guard/titan.rb', line 52 def zeus_test_cmd case using when :minitest then "test" when :rspec then "spec" when :testunit then "test" else "test/" end end |
#zeus_test_root ⇒ Object
61 62 63 64 65 66 67 68 |
# File 'lib/guard/titan.rb', line 61 def zeus_test_root case using when :minitest then "test/" when :rspec then "spec/" when :testunit then "test/" else "test/" end end |