guard-pusher 0.0.1 → 0.0.2
Sign up to get free protection for your applications and to get access to all the features.
- data/lib/guard/pusher/version.rb +1 -1
- data/lib/guard/pusher.rb +17 -14
- data/spec/guard/pusher_spec.rb +80 -47
- metadata +14 -14
data/lib/guard/pusher/version.rb
CHANGED
data/lib/guard/pusher.rb
CHANGED
@@ -1,22 +1,36 @@
|
|
1
1
|
require 'guard'
|
2
2
|
require 'guard/guard'
|
3
3
|
require 'pusher'
|
4
|
+
require 'erb'
|
4
5
|
|
5
6
|
module Guard
|
6
7
|
class Pusher < Guard
|
7
8
|
|
9
|
+
def self.configure(options)
|
10
|
+
%w{app_id key secret}.inject(Hash.new) { |hash, key|
|
11
|
+
hash[key] = options[key] || options[key.to_sym]
|
12
|
+
hash
|
13
|
+
}.each { |config, value|
|
14
|
+
::Pusher.send("#{config}=", value)
|
15
|
+
}
|
16
|
+
|
17
|
+
::Pusher['guard-pusher']
|
18
|
+
|
19
|
+
rescue ::Pusher::ConfigurationError
|
20
|
+
end
|
21
|
+
|
8
22
|
def initialize(watchers = [], options = {})
|
9
23
|
super
|
10
24
|
|
11
25
|
@options = options
|
12
26
|
|
13
27
|
config = if File.file?('config/pusher.yml')
|
14
|
-
YAML.
|
28
|
+
YAML.load(ERB.new(File.read('config/pusher.yml')).result)['development']
|
15
29
|
else
|
16
30
|
options
|
17
31
|
end
|
18
32
|
|
19
|
-
if
|
33
|
+
if self.class.configure(config)
|
20
34
|
UI.info('Pusher is ready.', :reset => true)
|
21
35
|
else
|
22
36
|
UI.info("D'oh! Pusher not properly configured. Make sure to add app_id, key and secret.", :reset => true)
|
@@ -24,18 +38,7 @@ module Guard
|
|
24
38
|
end
|
25
39
|
|
26
40
|
def run_on_change(paths)
|
27
|
-
::Pusher['guard-pusher'].trigger(@options[:event] || 'guard', {})
|
28
|
-
end
|
29
|
-
|
30
|
-
|
31
|
-
private
|
32
|
-
|
33
|
-
def config_pusher_with(credentials)
|
34
|
-
%w{app_id key secret}.each do |config|
|
35
|
-
return false unless (value = credentials[config] || credentials[config.to_sym])
|
36
|
-
::Pusher.send("#{config}=", value)
|
37
|
-
end
|
38
|
-
true
|
41
|
+
::Pusher['guard-pusher'].trigger(@options[:event] || 'guard', { :paths => paths })
|
39
42
|
end
|
40
43
|
|
41
44
|
end
|
data/spec/guard/pusher_spec.rb
CHANGED
@@ -2,70 +2,103 @@ require 'spec_helper'
|
|
2
2
|
|
3
3
|
describe Guard::Pusher do
|
4
4
|
|
5
|
+
def with_yaml(config = nil)
|
6
|
+
config ||= {
|
7
|
+
'development' => {
|
8
|
+
'app_id' => 42,
|
9
|
+
'key' => 'fake_key',
|
10
|
+
'secret' => 'fake_secret'
|
11
|
+
}
|
12
|
+
}
|
13
|
+
|
14
|
+
File.should_receive(:file?).with('config/pusher.yml').and_return(true)
|
15
|
+
File.should_receive(:read).with('config/pusher.yml')
|
16
|
+
ERB.should_receive(:new).and_return(double('erb', :result => 'erb_foo'))
|
17
|
+
YAML.should_receive(:load).with('erb_foo').and_return(config)
|
18
|
+
end
|
19
|
+
|
20
|
+
def without_yaml
|
21
|
+
File.should_receive(:file?).with('config/pusher.yml').and_return(false)
|
22
|
+
end
|
23
|
+
|
5
24
|
describe "configuration" do
|
6
|
-
|
7
|
-
|
8
|
-
|
9
|
-
|
10
|
-
|
11
|
-
|
12
|
-
|
13
|
-
|
14
|
-
|
25
|
+
|
26
|
+
context "via YAML file" do
|
27
|
+
context "when credentials are complete" do
|
28
|
+
before(:each) do
|
29
|
+
with_yaml
|
30
|
+
end
|
31
|
+
|
32
|
+
it "is successful" do
|
33
|
+
Guard::UI.should_receive(:info).with(/.*Pusher is ready.*/, :reset => true)
|
34
|
+
Guard::Pusher.new([])
|
35
|
+
end
|
15
36
|
end
|
16
37
|
|
17
|
-
|
18
|
-
|
19
|
-
|
20
|
-
|
21
|
-
|
22
|
-
|
38
|
+
context "when credentials are incomplete" do
|
39
|
+
before(:each) do
|
40
|
+
with_yaml({ 'development' => { 'key' => 'fake_key', 'secret' => 'fake_secret' }})
|
41
|
+
Pusher.app_id = nil
|
42
|
+
end
|
43
|
+
|
44
|
+
it "issues a warning" do
|
45
|
+
Guard::UI.should_receive(:info).with(/.*Pusher not properly configured.*/, :reset => true)
|
46
|
+
Guard::Pusher.new([])
|
47
|
+
end
|
23
48
|
end
|
24
49
|
end
|
25
50
|
|
26
|
-
context "
|
27
|
-
|
28
|
-
|
29
|
-
|
30
|
-
|
51
|
+
context "via options" do
|
52
|
+
context "when credentials are complete" do
|
53
|
+
before(:each) do
|
54
|
+
without_yaml
|
55
|
+
end
|
56
|
+
|
57
|
+
it "is successful" do
|
58
|
+
Guard::UI.should_receive(:info).with(/.*Pusher is ready.*/, :reset => true)
|
59
|
+
Guard::Pusher.new([], {
|
60
|
+
:app_id => 42,
|
61
|
+
:key => 'fake_key',
|
62
|
+
:secret => 'fake_secret'
|
63
|
+
})
|
64
|
+
end
|
31
65
|
end
|
32
66
|
|
33
|
-
|
34
|
-
|
35
|
-
|
36
|
-
|
37
|
-
|
38
|
-
|
39
|
-
:
|
40
|
-
|
41
|
-
|
42
|
-
|
67
|
+
context "when credentials are incomplete" do
|
68
|
+
before(:each) do
|
69
|
+
without_yaml
|
70
|
+
end
|
71
|
+
|
72
|
+
it "issues a warning" do
|
73
|
+
Guard::UI.should_receive(:info).with(/.*Pusher not properly configured.*/, :reset => true)
|
74
|
+
Guard::Pusher.new([], {
|
75
|
+
:key => 'fake_key',
|
76
|
+
:secret => 'fake_secret'
|
77
|
+
})
|
78
|
+
end
|
43
79
|
end
|
44
80
|
end
|
45
81
|
|
46
|
-
|
47
|
-
before(:each) do
|
48
|
-
File.should_receive(:file?).
|
49
|
-
with('config/pusher.yml').
|
50
|
-
and_return(false)
|
51
|
-
end
|
82
|
+
end
|
52
83
|
|
53
|
-
|
54
|
-
|
55
|
-
|
56
|
-
|
57
|
-
|
58
|
-
|
59
|
-
|
60
|
-
|
84
|
+
describe "options" do
|
85
|
+
before(:each) do
|
86
|
+
with_yaml
|
87
|
+
end
|
88
|
+
|
89
|
+
it ":event" do
|
90
|
+
channel = mock(Pusher::Channel)
|
91
|
+
Pusher.stub(:[]).and_return(channel)
|
92
|
+
channel.should_receive(:trigger).with('custom', { :paths => ['foo'] })
|
93
|
+
Guard::Pusher.new([], { :event => 'custom' }).run_on_change(['foo'])
|
61
94
|
end
|
62
95
|
end
|
63
96
|
|
64
|
-
describe "run_on_change" do
|
97
|
+
describe "#run_on_change" do
|
65
98
|
it "sends Pusher message" do
|
66
99
|
channel = mock(Pusher::Channel)
|
67
|
-
Pusher.should_receive(:[]).with('guard-pusher').and_return(channel)
|
68
|
-
channel.should_receive(:trigger).with('guard', {})
|
100
|
+
Pusher.should_receive(:[]).with('guard-pusher').twice.and_return(channel)
|
101
|
+
channel.should_receive(:trigger).with('guard', { :paths => ['foo'] })
|
69
102
|
subject.run_on_change(['foo'])
|
70
103
|
end
|
71
104
|
end
|
metadata
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: guard-pusher
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.0.
|
4
|
+
version: 0.0.2
|
5
5
|
prerelease: !!null
|
6
6
|
platform: ruby
|
7
7
|
authors:
|
@@ -9,12 +9,12 @@ authors:
|
|
9
9
|
autorequire: !!null
|
10
10
|
bindir: bin
|
11
11
|
cert_chain: []
|
12
|
-
date: 2011-
|
12
|
+
date: 2011-06-16 00:00:00.000000000 +02:00
|
13
13
|
default_executable: !!null
|
14
14
|
dependencies:
|
15
15
|
- !ruby/object:Gem::Dependency
|
16
16
|
name: guard
|
17
|
-
requirement: &
|
17
|
+
requirement: &2165084760 !ruby/object:Gem::Requirement
|
18
18
|
none: false
|
19
19
|
requirements:
|
20
20
|
- - ! '>='
|
@@ -22,10 +22,10 @@ dependencies:
|
|
22
22
|
version: '0.3'
|
23
23
|
type: :runtime
|
24
24
|
prerelease: false
|
25
|
-
version_requirements: *
|
25
|
+
version_requirements: *2165084760
|
26
26
|
- !ruby/object:Gem::Dependency
|
27
27
|
name: pusher
|
28
|
-
requirement: &
|
28
|
+
requirement: &2165084260 !ruby/object:Gem::Requirement
|
29
29
|
none: false
|
30
30
|
requirements:
|
31
31
|
- - ! '>='
|
@@ -33,10 +33,10 @@ dependencies:
|
|
33
33
|
version: '0.8'
|
34
34
|
type: :runtime
|
35
35
|
prerelease: false
|
36
|
-
version_requirements: *
|
36
|
+
version_requirements: *2165084260
|
37
37
|
- !ruby/object:Gem::Dependency
|
38
38
|
name: bundler
|
39
|
-
requirement: &
|
39
|
+
requirement: &2165083800 !ruby/object:Gem::Requirement
|
40
40
|
none: false
|
41
41
|
requirements:
|
42
42
|
- - ~>
|
@@ -44,10 +44,10 @@ dependencies:
|
|
44
44
|
version: 1.0.0
|
45
45
|
type: :development
|
46
46
|
prerelease: false
|
47
|
-
version_requirements: *
|
47
|
+
version_requirements: *2165083800
|
48
48
|
- !ruby/object:Gem::Dependency
|
49
49
|
name: rspec
|
50
|
-
requirement: &
|
50
|
+
requirement: &2165083340 !ruby/object:Gem::Requirement
|
51
51
|
none: false
|
52
52
|
requirements:
|
53
53
|
- - ~>
|
@@ -55,10 +55,10 @@ dependencies:
|
|
55
55
|
version: 2.3.0
|
56
56
|
type: :development
|
57
57
|
prerelease: false
|
58
|
-
version_requirements: *
|
58
|
+
version_requirements: *2165083340
|
59
59
|
- !ruby/object:Gem::Dependency
|
60
60
|
name: guard-rspec
|
61
|
-
requirement: &
|
61
|
+
requirement: &2165082960 !ruby/object:Gem::Requirement
|
62
62
|
none: false
|
63
63
|
requirements:
|
64
64
|
- - ! '>='
|
@@ -66,10 +66,10 @@ dependencies:
|
|
66
66
|
version: '0'
|
67
67
|
type: :development
|
68
68
|
prerelease: false
|
69
|
-
version_requirements: *
|
69
|
+
version_requirements: *2165082960
|
70
70
|
- !ruby/object:Gem::Dependency
|
71
71
|
name: rb-fsevent
|
72
|
-
requirement: &
|
72
|
+
requirement: &2165082500 !ruby/object:Gem::Requirement
|
73
73
|
none: false
|
74
74
|
requirements:
|
75
75
|
- - ! '>='
|
@@ -77,7 +77,7 @@ dependencies:
|
|
77
77
|
version: '0'
|
78
78
|
type: :development
|
79
79
|
prerelease: false
|
80
|
-
version_requirements: *
|
80
|
+
version_requirements: *2165082500
|
81
81
|
description: Pusher guard allows to automatically send a Pusher message to any number
|
82
82
|
of browsers.
|
83
83
|
email:
|