cadre 0.1.0 → 0.2.0

Sign up to get free protection for your applications and to get access to all the features.
@@ -1,25 +1,25 @@
1
+ require 'cadre/notifier'
2
+
1
3
  module Cadre
2
4
  module Growl
3
- #XXXX This isn't going to work at all as is. Lifted from other code, as #ok
4
- #hints toward a working adapter
5
- class Notifier
6
- def close
7
- super
8
- summary = summary_line example_count, failure_count, pending_count
9
- if failure_count > 0
10
- growlnotify "--image ./autotest/fail.png -p Emergency -m '#{summary}' -t 'Spec failure detected'" #ok
11
- elsif pending_count > 0
12
- growlnotify "--image ./autotest/pending.png -p High -m '#{summary}' -t 'Pending spec(s) present'" #ok
13
- else
14
- growlnotify "--image ./autotest/pass.png -p 'Very Low' -m '#{summary}' -t 'All specs passed'" #ok
15
- end
5
+ class Notifier < ::Cadre::Notifier
6
+ register :growl
7
+
8
+ def self.available?
9
+ #XXXX This isn't going to work at all as is. Lifted from other code, as #ok
10
+ #hints toward a working adapter
11
+ availables["growlnotify"]
12
+ end
13
+
14
+ def go
15
+ # growlnotify "--image ./autotest/fail.png -p Emergency -m '#{summary}' -t '#{message}'" #ok
16
+ # growlnotify "--image ./autotest/pending.png -p High -m '#{summary}' -t '#{message}'" #ok
17
+ # growlnotify "--image ./autotest/pass.png -p 'Very Low' -m '#{summary}' -t '#{message}'" #ok
18
+ growlnotify "-m '#{summary}' -t '#{message}'" #ok
16
19
  end
17
20
 
18
21
  def growlnotify str
19
- system 'which growlnotify > /dev/null'
20
- if $?.exitstatus == 0
21
- system "growlnotify -n autotest #{str}"
22
- end
22
+ system "growlnotify -n cadre #{str}"
23
23
  end
24
24
 
25
25
  end
@@ -2,17 +2,22 @@ require 'cadre/valise'
2
2
 
3
3
  module Cadre
4
4
  module Libnotify
5
- class Notifier
6
- def initialize
7
- yield self if block_given?
8
- end
5
+ class Notifier < ::Cadre::Notifier
6
+ register :libnotify
9
7
 
10
- attr_accessor :summary, :message, :sound, :expire_time, :app_name, :transient
8
+ def self.available?
9
+ return availables["notify-send"]
10
+ end
11
11
 
12
12
  def go
13
13
  cmd = "notify-send #{options} \"#@summary\" \"#@message\""
14
14
  %x[#{cmd}]
15
- %x[paplay #{Valise.find(["sounds", sound]).full_path}] if String === sound
15
+
16
+ if available?("paplay")
17
+ %x[paplay #{Valise.find(["sounds", sound]).full_path}] if String === sound
18
+ elsif available?("aplay")
19
+ %x[aplay #{Valise.find(["sounds", sound]).full_path}] if String === sound
20
+ end
16
21
  end
17
22
 
18
23
  def options
@@ -0,0 +1,48 @@
1
+ module Cadre
2
+ class Notifier
3
+ class << self
4
+ def registry
5
+ @registry ||= {}
6
+ end
7
+
8
+ def register(name)
9
+ Notifier.registry[name] = self
10
+ end
11
+
12
+ def get
13
+ registry.each_pair do |name, notifier|
14
+ return notifier if notifier.available?
15
+ end
16
+
17
+ return DumbNotifier
18
+ end
19
+
20
+ def availables
21
+ @availables ||= Hash.new{|h,k| h[k] = system("which", k, :out => "/dev/null")}
22
+ end
23
+ end
24
+
25
+ def available?(program)
26
+ self.class.availables[program]
27
+ end
28
+
29
+ def initialize
30
+ yield self if block_given?
31
+ end
32
+
33
+ attr_accessor :summary, :message, :sound, :expire_time, :app_name, :transient
34
+
35
+ def go
36
+ end
37
+ end
38
+
39
+ class DumbNotifier < Notifier
40
+ def go
41
+ puts summary
42
+ puts message
43
+ end
44
+ end
45
+ end
46
+
47
+ require 'cadre/libnotify/notifier'
48
+ require 'cadre/growl/notifier'
@@ -1,4 +1,4 @@
1
- require 'cadre/libnotify/notifier'
1
+ require 'cadre/notifier'
2
2
  require 'rspec/core/formatters/base_formatter'
3
3
 
4
4
  rspec_pid = Process.pid
@@ -22,7 +22,8 @@ module Cadre
22
22
  end
23
23
 
24
24
  def dump_summary(duration, example_count, failure_count, pending_count)
25
- notifier = Libnotify::Notifier.new
25
+ notifier = Cadre::Notifier.get.new
26
+
26
27
  if duration < 20
27
28
  notifier.transient = true
28
29
  notifier.summary = "Finished spec run"
metadata CHANGED
@@ -2,14 +2,14 @@
2
2
  name: cadre
3
3
  version: !ruby/object:Gem::Version
4
4
  prerelease:
5
- version: 0.1.0
5
+ version: 0.2.0
6
6
  platform: ruby
7
7
  authors:
8
8
  - Judson Lester
9
9
  autorequire:
10
10
  bindir: bin
11
11
  cert_chain: []
12
- date: 2013-10-25 00:00:00.000000000 Z
12
+ date: 2013-11-06 00:00:00.000000000 Z
13
13
  dependencies:
14
14
  - !ruby/object:Gem::Dependency
15
15
  prerelease: false
@@ -19,20 +19,12 @@ dependencies:
19
19
  requirements:
20
20
  - - ~>
21
21
  - !ruby/object:Gem::Version
22
- segments:
23
- - 0
24
- - 18
25
- - 1
26
22
  version: 0.18.1
27
23
  none: false
28
24
  requirement: !ruby/object:Gem::Requirement
29
25
  requirements:
30
26
  - - ~>
31
27
  - !ruby/object:Gem::Version
32
- segments:
33
- - 0
34
- - 18
35
- - 1
36
28
  version: 0.18.1
37
29
  none: false
38
30
  - !ruby/object:Gem::Dependency
@@ -43,18 +35,12 @@ dependencies:
43
35
  requirements:
44
36
  - - ~>
45
37
  - !ruby/object:Gem::Version
46
- segments:
47
- - 1
48
- - 0
49
38
  version: '1.0'
50
39
  none: false
51
40
  requirement: !ruby/object:Gem::Requirement
52
41
  requirements:
53
42
  - - ~>
54
43
  - !ruby/object:Gem::Version
55
- segments:
56
- - 1
57
- - 0
58
44
  version: '1.0'
59
45
  none: false
60
46
  - !ruby/object:Gem::Dependency
@@ -65,18 +51,12 @@ dependencies:
65
51
  requirements:
66
52
  - - ~>
67
53
  - !ruby/object:Gem::Version
68
- segments:
69
- - 1
70
- - 0
71
54
  version: '1.0'
72
55
  none: false
73
56
  requirement: !ruby/object:Gem::Requirement
74
57
  requirements:
75
58
  - - ~>
76
59
  - !ruby/object:Gem::Version
77
- segments:
78
- - 1
79
- - 0
80
60
  version: '1.0'
81
61
  none: false
82
62
  description: ! " Three things:\n\n An rspec formatter that triggers libnotify on
@@ -106,6 +86,7 @@ files:
106
86
  - lib/cadre/config.rb
107
87
  - lib/cadre/command-line.rb
108
88
  - lib/cadre/valise.rb
89
+ - lib/cadre/notifier.rb
109
90
  - lib/cadre/simplecov/vim-formatter.rb
110
91
  - lib/cadre/simplecov.rb
111
92
  - bin/cadre
@@ -120,7 +101,7 @@ rdoc_options:
120
101
  - --main
121
102
  - doc/README
122
103
  - --title
123
- - cadre-0.1.0 Documentation
104
+ - cadre-0.2.0 Documentation
124
105
  require_paths:
125
106
  - lib/
126
107
  required_ruby_version: !ruby/object:Gem::Requirement
@@ -129,7 +110,7 @@ required_ruby_version: !ruby/object:Gem::Requirement
129
110
  - !ruby/object:Gem::Version
130
111
  segments:
131
112
  - 0
132
- hash: -11582157
113
+ hash: 711415251
133
114
  version: '0'
134
115
  none: false
135
116
  required_rubygems_version: !ruby/object:Gem::Requirement