grocer-error_callback 0.0.1
Sign up to get free protection for your applications and to get access to all the features.
- data/.gitignore +17 -0
- data/Gemfile +4 -0
- data/LICENSE.txt +22 -0
- data/README.md +29 -0
- data/Rakefile +1 -0
- data/grocer-error_callback.gemspec +27 -0
- data/lib/grocer/error_callback.rb +13 -0
- data/lib/grocer/error_callback/callbacks.rb +25 -0
- data/lib/grocer/error_callback/connection.rb +28 -0
- data/lib/grocer/error_callback/version.rb +5 -0
- data/specs/callback_spec.rb +50 -0
- metadata +125 -0
data/.gitignore
ADDED
data/Gemfile
ADDED
data/LICENSE.txt
ADDED
@@ -0,0 +1,22 @@
|
|
1
|
+
Copyright (c) 2013 Jon Moses
|
2
|
+
|
3
|
+
MIT License
|
4
|
+
|
5
|
+
Permission is hereby granted, free of charge, to any person obtaining
|
6
|
+
a copy of this software and associated documentation files (the
|
7
|
+
"Software"), to deal in the Software without restriction, including
|
8
|
+
without limitation the rights to use, copy, modify, merge, publish,
|
9
|
+
distribute, sublicense, and/or sell copies of the Software, and to
|
10
|
+
permit persons to whom the Software is furnished to do so, subject to
|
11
|
+
the following conditions:
|
12
|
+
|
13
|
+
The above copyright notice and this permission notice shall be
|
14
|
+
included in all copies or substantial portions of the Software.
|
15
|
+
|
16
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
|
17
|
+
EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
|
18
|
+
MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
|
19
|
+
NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
|
20
|
+
LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
|
21
|
+
OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
|
22
|
+
WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
|
data/README.md
ADDED
@@ -0,0 +1,29 @@
|
|
1
|
+
# Grocer::ErrorCallback
|
2
|
+
|
3
|
+
TODO: Write a gem description
|
4
|
+
|
5
|
+
## Installation
|
6
|
+
|
7
|
+
Add this line to your application's Gemfile:
|
8
|
+
|
9
|
+
gem 'grocer-error_callback'
|
10
|
+
|
11
|
+
And then execute:
|
12
|
+
|
13
|
+
$ bundle
|
14
|
+
|
15
|
+
Or install it yourself as:
|
16
|
+
|
17
|
+
$ gem install grocer-error_callback
|
18
|
+
|
19
|
+
## Usage
|
20
|
+
|
21
|
+
TODO: Write usage instructions here
|
22
|
+
|
23
|
+
## Contributing
|
24
|
+
|
25
|
+
1. Fork it
|
26
|
+
2. Create your feature branch (`git checkout -b my-new-feature`)
|
27
|
+
3. Commit your changes (`git commit -am 'Add some feature'`)
|
28
|
+
4. Push to the branch (`git push origin my-new-feature`)
|
29
|
+
5. Create new Pull Request
|
data/Rakefile
ADDED
@@ -0,0 +1 @@
|
|
1
|
+
require "bundler/gem_tasks"
|
@@ -0,0 +1,27 @@
|
|
1
|
+
# coding: utf-8
|
2
|
+
lib = File.expand_path('../lib', __FILE__)
|
3
|
+
$LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
|
4
|
+
require 'grocer/error_callback/version'
|
5
|
+
|
6
|
+
Gem::Specification.new do |spec|
|
7
|
+
spec.name = "grocer-error_callback"
|
8
|
+
spec.version = Grocer::ErrorCallback::VERSION
|
9
|
+
spec.authors = ["Jon Moses"]
|
10
|
+
spec.email = ["jon@burningbush.us"]
|
11
|
+
spec.description = %q{Provide error callbacks to Grocer pushes}
|
12
|
+
spec.summary = %q{Provides error callbacks to Grocer pushes}
|
13
|
+
spec.homepage = ""
|
14
|
+
spec.license = "MIT"
|
15
|
+
|
16
|
+
spec.files = `git ls-files`.split($/)
|
17
|
+
spec.executables = spec.files.grep(%r{^bin/}) { |f| File.basename(f) }
|
18
|
+
spec.test_files = spec.files.grep(%r{^(test|spec|features)/})
|
19
|
+
spec.require_paths = ["lib"]
|
20
|
+
|
21
|
+
spec.add_dependency 'grocer', '~> 0.3.4'
|
22
|
+
|
23
|
+
spec.add_development_dependency "bundler", "~> 1.3"
|
24
|
+
spec.add_development_dependency "rake"
|
25
|
+
spec.add_development_dependency 'mocha'
|
26
|
+
spec.add_development_dependency 'rspec'
|
27
|
+
end
|
@@ -0,0 +1,13 @@
|
|
1
|
+
require "grocer/error_callback/version"
|
2
|
+
require 'grocer/error_callback/callbacks'
|
3
|
+
require 'grocer/error_callback/connection'
|
4
|
+
require 'grocer/connection'
|
5
|
+
|
6
|
+
module Grocer
|
7
|
+
module ErrorCallback
|
8
|
+
end
|
9
|
+
end
|
10
|
+
|
11
|
+
Grocer.send :extend, Grocer::ErrorCallback::Callbacks::ClassMethods
|
12
|
+
Grocer::Connection.send :include, Grocer::ErrorCallback::Callbacks::InstanceMethods
|
13
|
+
Grocer::Connection.send :include, Grocer::ErrorCallback::Connection
|
@@ -0,0 +1,25 @@
|
|
1
|
+
module Grocer::ErrorCallback::Callbacks
|
2
|
+
module ClassMethods
|
3
|
+
@@callbacks = {
|
4
|
+
connection_error: []
|
5
|
+
}
|
6
|
+
|
7
|
+
@@callbacks.keys.each do |callback|
|
8
|
+
define_method("on_#{callback}") do |&block|
|
9
|
+
@@callbacks[callback] << block
|
10
|
+
end
|
11
|
+
end
|
12
|
+
|
13
|
+
def run_callbacks(callback, *args)
|
14
|
+
@@callbacks[callback].each do |callback|
|
15
|
+
callback[*args]
|
16
|
+
end
|
17
|
+
end
|
18
|
+
end
|
19
|
+
|
20
|
+
module InstanceMethods
|
21
|
+
def run_callbacks(callback, *args)
|
22
|
+
Grocer.run_callbacks callback, *args
|
23
|
+
end
|
24
|
+
end
|
25
|
+
end
|
@@ -0,0 +1,28 @@
|
|
1
|
+
module Grocer::ErrorCallback::Connection
|
2
|
+
def self.included(base)
|
3
|
+
base.class_eval do
|
4
|
+
remove_method :with_connection
|
5
|
+
end
|
6
|
+
end
|
7
|
+
|
8
|
+
def with_connection
|
9
|
+
attempts = 1
|
10
|
+
begin
|
11
|
+
connect
|
12
|
+
yield
|
13
|
+
rescue => e
|
14
|
+
if e.class == OpenSSL::SSL::SSLError && e.message =~ /certificate expired/i
|
15
|
+
e.extend(CertificateExpiredError)
|
16
|
+
raise
|
17
|
+
end
|
18
|
+
|
19
|
+
run_callbacks :connection_error, e
|
20
|
+
|
21
|
+
raise unless attempts < retries
|
22
|
+
|
23
|
+
destroy_connection
|
24
|
+
attempts += 1
|
25
|
+
retry
|
26
|
+
end
|
27
|
+
end
|
28
|
+
end
|
@@ -0,0 +1,50 @@
|
|
1
|
+
lib = File.expand_path('../lib', __FILE__)
|
2
|
+
$LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
|
3
|
+
|
4
|
+
RSpec.configure do |config|
|
5
|
+
config.mock_with :mocha
|
6
|
+
end
|
7
|
+
|
8
|
+
require 'grocer/error_callback'
|
9
|
+
|
10
|
+
describe "Error callbacks" do
|
11
|
+
subject do
|
12
|
+
Grocer::Connection.new({
|
13
|
+
gateway: :gateway,
|
14
|
+
port: :port
|
15
|
+
})
|
16
|
+
end
|
17
|
+
|
18
|
+
context "with no callbacks" do
|
19
|
+
it "should run callbacks with no error, then raise" do
|
20
|
+
subject.stubs(destroy_connection: nil)
|
21
|
+
subject.expects(:connect).raises(ArgumentError).times(3)
|
22
|
+
|
23
|
+
expect {|b| subject.send(:with_connection, &b) }.to raise_error(ArgumentError)
|
24
|
+
end
|
25
|
+
end
|
26
|
+
|
27
|
+
context "with callbacks" do
|
28
|
+
it "runs the callback" do
|
29
|
+
@inner_called = false
|
30
|
+
@error_called = true
|
31
|
+
|
32
|
+
Grocer.on_connection_error do |error|
|
33
|
+
@error_called = true
|
34
|
+
error.should be_a(ArgumentError)
|
35
|
+
end
|
36
|
+
|
37
|
+
connection_block = proc { @called = true }
|
38
|
+
|
39
|
+
subject.stubs(destroy_connection: nil)
|
40
|
+
seq = sequence('seq')
|
41
|
+
subject.stubs(:connect).raises(ArgumentError).in_sequence(seq)
|
42
|
+
subject.stubs(:connect).returns(nil).in_sequence(seq)
|
43
|
+
|
44
|
+
subject.send(:with_connection, &connection_block)
|
45
|
+
|
46
|
+
@called.should be_true
|
47
|
+
@error_called.should be_true
|
48
|
+
end
|
49
|
+
end
|
50
|
+
end
|
metadata
ADDED
@@ -0,0 +1,125 @@
|
|
1
|
+
--- !ruby/object:Gem::Specification
|
2
|
+
name: grocer-error_callback
|
3
|
+
version: !ruby/object:Gem::Version
|
4
|
+
prerelease:
|
5
|
+
version: 0.0.1
|
6
|
+
platform: ruby
|
7
|
+
authors:
|
8
|
+
- Jon Moses
|
9
|
+
autorequire:
|
10
|
+
bindir: bin
|
11
|
+
cert_chain: []
|
12
|
+
|
13
|
+
date: 2013-03-25 00:00:00 Z
|
14
|
+
dependencies:
|
15
|
+
- !ruby/object:Gem::Dependency
|
16
|
+
name: grocer
|
17
|
+
requirement: &id001 !ruby/object:Gem::Requirement
|
18
|
+
none: false
|
19
|
+
requirements:
|
20
|
+
- - ~>
|
21
|
+
- !ruby/object:Gem::Version
|
22
|
+
version: 0.3.4
|
23
|
+
type: :runtime
|
24
|
+
prerelease: false
|
25
|
+
version_requirements: *id001
|
26
|
+
- !ruby/object:Gem::Dependency
|
27
|
+
name: bundler
|
28
|
+
requirement: &id002 !ruby/object:Gem::Requirement
|
29
|
+
none: false
|
30
|
+
requirements:
|
31
|
+
- - ~>
|
32
|
+
- !ruby/object:Gem::Version
|
33
|
+
version: "1.3"
|
34
|
+
type: :development
|
35
|
+
prerelease: false
|
36
|
+
version_requirements: *id002
|
37
|
+
- !ruby/object:Gem::Dependency
|
38
|
+
name: rake
|
39
|
+
requirement: &id003 !ruby/object:Gem::Requirement
|
40
|
+
none: false
|
41
|
+
requirements:
|
42
|
+
- - ">="
|
43
|
+
- !ruby/object:Gem::Version
|
44
|
+
version: "0"
|
45
|
+
type: :development
|
46
|
+
prerelease: false
|
47
|
+
version_requirements: *id003
|
48
|
+
- !ruby/object:Gem::Dependency
|
49
|
+
name: mocha
|
50
|
+
requirement: &id004 !ruby/object:Gem::Requirement
|
51
|
+
none: false
|
52
|
+
requirements:
|
53
|
+
- - ">="
|
54
|
+
- !ruby/object:Gem::Version
|
55
|
+
version: "0"
|
56
|
+
type: :development
|
57
|
+
prerelease: false
|
58
|
+
version_requirements: *id004
|
59
|
+
- !ruby/object:Gem::Dependency
|
60
|
+
name: rspec
|
61
|
+
requirement: &id005 !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: *id005
|
70
|
+
description: Provide error callbacks to Grocer pushes
|
71
|
+
email:
|
72
|
+
- jon@burningbush.us
|
73
|
+
executables: []
|
74
|
+
|
75
|
+
extensions: []
|
76
|
+
|
77
|
+
extra_rdoc_files: []
|
78
|
+
|
79
|
+
files:
|
80
|
+
- .gitignore
|
81
|
+
- Gemfile
|
82
|
+
- LICENSE.txt
|
83
|
+
- README.md
|
84
|
+
- Rakefile
|
85
|
+
- grocer-error_callback.gemspec
|
86
|
+
- lib/grocer/error_callback.rb
|
87
|
+
- lib/grocer/error_callback/callbacks.rb
|
88
|
+
- lib/grocer/error_callback/connection.rb
|
89
|
+
- lib/grocer/error_callback/version.rb
|
90
|
+
- specs/callback_spec.rb
|
91
|
+
homepage: ""
|
92
|
+
licenses:
|
93
|
+
- MIT
|
94
|
+
post_install_message:
|
95
|
+
rdoc_options: []
|
96
|
+
|
97
|
+
require_paths:
|
98
|
+
- lib
|
99
|
+
required_ruby_version: !ruby/object:Gem::Requirement
|
100
|
+
none: false
|
101
|
+
requirements:
|
102
|
+
- - ">="
|
103
|
+
- !ruby/object:Gem::Version
|
104
|
+
hash: -2053110038584274895
|
105
|
+
segments:
|
106
|
+
- 0
|
107
|
+
version: "0"
|
108
|
+
required_rubygems_version: !ruby/object:Gem::Requirement
|
109
|
+
none: false
|
110
|
+
requirements:
|
111
|
+
- - ">="
|
112
|
+
- !ruby/object:Gem::Version
|
113
|
+
hash: -2053110038584274895
|
114
|
+
segments:
|
115
|
+
- 0
|
116
|
+
version: "0"
|
117
|
+
requirements: []
|
118
|
+
|
119
|
+
rubyforge_project:
|
120
|
+
rubygems_version: 1.8.24
|
121
|
+
signing_key:
|
122
|
+
specification_version: 3
|
123
|
+
summary: Provides error callbacks to Grocer pushes
|
124
|
+
test_files: []
|
125
|
+
|