guard-pusher 0.0.1

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
data/.gitignore ADDED
@@ -0,0 +1,5 @@
1
+ pkg/*
2
+ *.gem
3
+ .bundle
4
+ Gemfile.lock
5
+ .rvmrc
data/Gemfile ADDED
@@ -0,0 +1,4 @@
1
+ source "http://rubygems.org"
2
+
3
+ # Specify your gem's dependencies in guard-pusher.gemspec
4
+ gemspec
data/Guardfile ADDED
@@ -0,0 +1,5 @@
1
+ guard 'rspec', :version => 2 do
2
+ watch(%r{^spec/(.*)_spec.rb})
3
+ watch(%r{^lib/(.*)\.rb}) { |m| "spec/#{m[1]}_spec.rb" }
4
+ watch(%r{^spec/spec_helper.rb}) { "spec" }
5
+ end
data/LICENSE ADDED
@@ -0,0 +1,20 @@
1
+ Copyright (c) 2011 Klaus Hartl
2
+
3
+ Permission is hereby granted, free of charge, to any person obtaining
4
+ a copy of this software and associated documentation files (the
5
+ "Software"), to deal in the Software without restriction, including
6
+ without limitation the rights to use, copy, modify, merge, publish,
7
+ distribute, sublicense, and/or sell copies of the Software, and to
8
+ permit persons to whom the Software is furnished to do so, subject to
9
+ the following conditions:
10
+
11
+ The above copyright notice and this permission notice shall be
12
+ included in all copies or substantial portions of the Software.
13
+
14
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
15
+ EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
16
+ MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
17
+ NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
18
+ LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
19
+ OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
20
+ WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
data/README.rdoc ADDED
@@ -0,0 +1,80 @@
1
+ = guard-pusher
2
+
3
+ Pusher guard allows to automatically send a Pusher message to any number of browserswhen files are modified. That message can for instance be used to reload a page
4
+ during development. Sort of Livereload but for iPad, iPhone etc. without the ability to install the necessary extension.
5
+
6
+ - Tested on Ruby 1.8.7 & 1.9.2.
7
+
8
+ == Install
9
+
10
+ Please be sure to have {Guard}[https://github.com/guard/guard] installed before continue.
11
+
12
+ Install the gem:
13
+
14
+ gem install guard-pusher
15
+
16
+ Or add it to your Gemfile
17
+
18
+ gem 'guard-pusher'
19
+
20
+ and run
21
+
22
+ bundle install
23
+
24
+ Add guard definition to your Guardfile by running this command:
25
+
26
+ guard init pusher
27
+
28
+ Get a free Pusher developer account: http://pusherapp.com (also available as Heroku add-on).
29
+
30
+ Create a YAML file containing your API credentials for the development environment and save it in the config directory:
31
+
32
+ # config/pusher.yml
33
+ development:
34
+ app_id: ...
35
+ key: ...
36
+ secret: ...
37
+
38
+ You can also pass these credentials as option in your guard definition, see Options below.
39
+
40
+ Include the following JavaScript:
41
+
42
+ <script src="http://js.pusherapp.com/1.8/pusher.min.js"></script>
43
+ <script>
44
+ new Pusher(<key>).subscribe('guard-pusher').bind('guard', function() {
45
+ // do something - for instance simply reload the page:
46
+ location.reload();
47
+ });
48
+ </script>
49
+
50
+ == Usage
51
+
52
+ Please read {Guard usage doc}[https://github.com/guard/guard#readme]
53
+
54
+ == Options
55
+
56
+ Pass Pusher API credentials as option:
57
+
58
+ guard 'pusher', :app_id => ..., :key => '...', :secret => '...' do
59
+ ...
60
+ end
61
+
62
+ Set the name of the event you're binding to:
63
+
64
+ guard 'pusher', :event => 'ping' do
65
+ ...
66
+ end
67
+
68
+ new Pusher(...).subscribe('guard-pusher').bind('ping', function() { ... });
69
+
70
+ == Development
71
+
72
+ - Source hosted at {GitHub}[https://github.com/guard/guard-pusher]
73
+ - Report issues, questions, feature requests on {GitHub Issues}[https://github.com/guard/guard-pusher/issues]
74
+
75
+ Pull requests are very welcome! Make sure your patches are well tested. Please create a topic branch for every separate change you make.
76
+
77
+ == Authors
78
+
79
+ {Klaus Hartl}[https://github.com/carhartl]
80
+
data/Rakefile ADDED
@@ -0,0 +1,21 @@
1
+ require 'bundler'
2
+ Bundler::GemHelper.install_tasks
3
+
4
+ require 'rspec/core/rake_task'
5
+ RSpec::Core::RakeTask.new(:spec)
6
+ task :default => :spec
7
+
8
+ namespace(:spec) do
9
+ desc "Run all specs on multiple ruby versions (requires rvm)"
10
+ task(:portability) do
11
+ %w[1.8.6 1.8.7 1.9.2].each do |version|
12
+ system <<-BASH
13
+ bash -c 'source ~/.rvm/scripts/rvm;
14
+ rvm #{version};
15
+ echo "--------- version #{version} ----------\n";
16
+ bundle install;
17
+ rake spec'
18
+ BASH
19
+ end
20
+ end
21
+ end
@@ -0,0 +1,29 @@
1
+ # -*- encoding: utf-8 -*-
2
+ $:.push File.expand_path("../lib", __FILE__)
3
+ require "guard/pusher/version"
4
+
5
+ Gem::Specification.new do |s|
6
+ s.name = "guard-pusher"
7
+ s.version = Guard::PusherVersion::VERSION
8
+ s.platform = Gem::Platform::RUBY
9
+ s.authors = ["Klaus Hartl"]
10
+ s.email = ["klaus.hartl@gmail.com"]
11
+ s.homepage = "http://github.com/carhartl/guard-pusher"
12
+ s.summary = "Guard gem for Pusher"
13
+ s.description = "Pusher guard allows to automatically send a Pusher message to any number of browsers."
14
+
15
+ s.rubyforge_project = "guard-pusher"
16
+
17
+ s.add_dependency "guard", ">= 0.3"
18
+ s.add_dependency "pusher", ">= 0.8"
19
+
20
+ s.add_development_dependency "bundler", "~> 1.0.0"
21
+ s.add_development_dependency "rspec", "~> 2.3.0"
22
+ s.add_development_dependency "guard-rspec"
23
+ s.add_development_dependency "rb-fsevent"
24
+
25
+ s.files = `git ls-files`.split("\n")
26
+ s.test_files = `git ls-files -- {test,spec,features}/*`.split("\n")
27
+ s.executables = `git ls-files -- bin/*`.split("\n").map{ |f| File.basename(f) }
28
+ s.require_paths = ["lib"]
29
+ end
@@ -0,0 +1,4 @@
1
+ guard 'pusher' do
2
+ # Rails example
3
+ watch(%r{public/.+\.(css|js)})
4
+ end
@@ -0,0 +1,5 @@
1
+ module Guard
2
+ module PusherVersion
3
+ VERSION = "0.0.1"
4
+ end
5
+ end
@@ -0,0 +1,42 @@
1
+ require 'guard'
2
+ require 'guard/guard'
3
+ require 'pusher'
4
+
5
+ module Guard
6
+ class Pusher < Guard
7
+
8
+ def initialize(watchers = [], options = {})
9
+ super
10
+
11
+ @options = options
12
+
13
+ config = if File.file?('config/pusher.yml')
14
+ YAML.load_file('config/pusher.yml')['development']
15
+ else
16
+ options
17
+ end
18
+
19
+ if config_pusher_with(config)
20
+ UI.info('Pusher is ready.', :reset => true)
21
+ else
22
+ UI.info("D'oh! Pusher not properly configured. Make sure to add app_id, key and secret.", :reset => true)
23
+ end
24
+ end
25
+
26
+ 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
39
+ end
40
+
41
+ end
42
+ end
@@ -0,0 +1,73 @@
1
+ require 'spec_helper'
2
+
3
+ describe Guard::Pusher do
4
+
5
+ describe "configuration" do
6
+ context "provided through YAML file" do
7
+ before(:each) do
8
+ File.should_receive(:file?).
9
+ with('config/pusher.yml').
10
+ and_return(true)
11
+
12
+ YAML.should_receive(:load_file).
13
+ with('config/pusher.yml').
14
+ and_return({ "development" => { "app_id" => 42, "key" => "fake_key", "secret" => "fake_secret" }})
15
+ end
16
+
17
+ it "requires 'app_id', 'key' and 'secret'" do
18
+ Pusher.should_receive(:app_id=).with(42)
19
+ Pusher.should_receive(:key=).with('fake_key')
20
+ Pusher.should_receive(:secret=).with('fake_secret')
21
+ Guard::UI.should_receive(:info).with(/.*Pusher is ready.*/, :reset => true)
22
+ Guard::Pusher.new([])
23
+ end
24
+ end
25
+
26
+ context "provided through options" do
27
+ before(:each) do
28
+ File.should_receive(:file?).
29
+ with('config/pusher.yml').
30
+ and_return(false)
31
+ end
32
+
33
+ it "requires 'app_id', 'key' and 'secret'" do
34
+ Pusher.should_receive(:app_id=).with(42)
35
+ Pusher.should_receive(:key=).with('fake_key')
36
+ Pusher.should_receive(:secret=).with('fake_secret')
37
+ Guard::UI.should_receive(:info).with(/.*Pusher is ready.*/, :reset => true)
38
+ Guard::Pusher.new([], {
39
+ :app_id => 42,
40
+ :key => 'fake_key',
41
+ :secret => 'fake_secret'
42
+ })
43
+ end
44
+ end
45
+
46
+ context "missing the necessery keys" do
47
+ before(:each) do
48
+ File.should_receive(:file?).
49
+ with('config/pusher.yml').
50
+ and_return(false)
51
+ end
52
+
53
+ it "does not attempt to configure Pusher and issues a warning" do
54
+ Pusher.should_not_receive(:app_id=)
55
+ Guard::UI.should_receive(:info).with(/.*Pusher not properly configured.*/, :reset => true)
56
+ Guard::Pusher.new([], {
57
+ :key => 'fake_key',
58
+ :secret => 'fake_secret'
59
+ })
60
+ end
61
+ end
62
+ end
63
+
64
+ describe "run_on_change" do
65
+ it "sends Pusher message" do
66
+ channel = mock(Pusher::Channel)
67
+ Pusher.should_receive(:[]).with('guard-pusher').and_return(channel)
68
+ channel.should_receive(:trigger).with('guard', {})
69
+ subject.run_on_change(['foo'])
70
+ end
71
+ end
72
+
73
+ end
@@ -0,0 +1,12 @@
1
+ $LOAD_PATH.unshift(File.join(File.dirname(__FILE__), '..', 'lib'))
2
+ $LOAD_PATH.unshift(File.dirname(__FILE__))
3
+ require 'rspec'
4
+ require 'guard/pusher'
5
+
6
+ # Requires supporting files with custom matchers and macros, etc,
7
+ # in ./support/ and its subdirectories.
8
+ Dir["#{File.dirname(__FILE__)}/support/**/*.rb"].each {|f| require f}
9
+
10
+ RSpec.configure do |config|
11
+
12
+ end
metadata ADDED
@@ -0,0 +1,128 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: guard-pusher
3
+ version: !ruby/object:Gem::Version
4
+ version: 0.0.1
5
+ prerelease: !!null
6
+ platform: ruby
7
+ authors:
8
+ - Klaus Hartl
9
+ autorequire: !!null
10
+ bindir: bin
11
+ cert_chain: []
12
+ date: 2011-03-01 00:00:00.000000000 +01:00
13
+ default_executable: !!null
14
+ dependencies:
15
+ - !ruby/object:Gem::Dependency
16
+ name: guard
17
+ requirement: &2156752380 !ruby/object:Gem::Requirement
18
+ none: false
19
+ requirements:
20
+ - - ! '>='
21
+ - !ruby/object:Gem::Version
22
+ version: '0.3'
23
+ type: :runtime
24
+ prerelease: false
25
+ version_requirements: *2156752380
26
+ - !ruby/object:Gem::Dependency
27
+ name: pusher
28
+ requirement: &2156751880 !ruby/object:Gem::Requirement
29
+ none: false
30
+ requirements:
31
+ - - ! '>='
32
+ - !ruby/object:Gem::Version
33
+ version: '0.8'
34
+ type: :runtime
35
+ prerelease: false
36
+ version_requirements: *2156751880
37
+ - !ruby/object:Gem::Dependency
38
+ name: bundler
39
+ requirement: &2156751420 !ruby/object:Gem::Requirement
40
+ none: false
41
+ requirements:
42
+ - - ~>
43
+ - !ruby/object:Gem::Version
44
+ version: 1.0.0
45
+ type: :development
46
+ prerelease: false
47
+ version_requirements: *2156751420
48
+ - !ruby/object:Gem::Dependency
49
+ name: rspec
50
+ requirement: &2156750960 !ruby/object:Gem::Requirement
51
+ none: false
52
+ requirements:
53
+ - - ~>
54
+ - !ruby/object:Gem::Version
55
+ version: 2.3.0
56
+ type: :development
57
+ prerelease: false
58
+ version_requirements: *2156750960
59
+ - !ruby/object:Gem::Dependency
60
+ name: guard-rspec
61
+ requirement: &2156750580 !ruby/object:Gem::Requirement
62
+ none: false
63
+ requirements:
64
+ - - ! '>='
65
+ - !ruby/object:Gem::Version
66
+ version: '0'
67
+ type: :development
68
+ prerelease: false
69
+ version_requirements: *2156750580
70
+ - !ruby/object:Gem::Dependency
71
+ name: rb-fsevent
72
+ requirement: &2156750120 !ruby/object:Gem::Requirement
73
+ none: false
74
+ requirements:
75
+ - - ! '>='
76
+ - !ruby/object:Gem::Version
77
+ version: '0'
78
+ type: :development
79
+ prerelease: false
80
+ version_requirements: *2156750120
81
+ description: Pusher guard allows to automatically send a Pusher message to any number
82
+ of browsers.
83
+ email:
84
+ - klaus.hartl@gmail.com
85
+ executables: []
86
+ extensions: []
87
+ extra_rdoc_files: []
88
+ files:
89
+ - .gitignore
90
+ - Gemfile
91
+ - Guardfile
92
+ - LICENSE
93
+ - README.rdoc
94
+ - Rakefile
95
+ - guard-pusher.gemspec
96
+ - lib/guard/pusher.rb
97
+ - lib/guard/pusher/templates/Guardfile
98
+ - lib/guard/pusher/version.rb
99
+ - spec/guard/pusher_spec.rb
100
+ - spec/spec_helper.rb
101
+ has_rdoc: true
102
+ homepage: http://github.com/carhartl/guard-pusher
103
+ licenses: []
104
+ post_install_message: !!null
105
+ rdoc_options: []
106
+ require_paths:
107
+ - lib
108
+ required_ruby_version: !ruby/object:Gem::Requirement
109
+ none: false
110
+ requirements:
111
+ - - ! '>='
112
+ - !ruby/object:Gem::Version
113
+ version: '0'
114
+ required_rubygems_version: !ruby/object:Gem::Requirement
115
+ none: false
116
+ requirements:
117
+ - - ! '>='
118
+ - !ruby/object:Gem::Version
119
+ version: '0'
120
+ requirements: []
121
+ rubyforge_project: guard-pusher
122
+ rubygems_version: 1.5.0
123
+ signing_key: !!null
124
+ specification_version: 3
125
+ summary: Guard gem for Pusher
126
+ test_files:
127
+ - spec/guard/pusher_spec.rb
128
+ - spec/spec_helper.rb