activeresource_connections 0.1.0
Sign up to get free protection for your applications and to get access to all the features.
@@ -0,0 +1,11 @@
|
|
1
|
+
require 'active_resource'
|
2
|
+
|
3
|
+
module ActiveResource::Connections
|
4
|
+
autoload :Retryable, 'active_resource/connections/retryable'
|
5
|
+
autoload :CoreExt, 'active_resource/connections/core_ext'
|
6
|
+
|
7
|
+
unless ActiveResource::Base.respond_to?(:connection_class)
|
8
|
+
ActiveResource::Base.send :include, CoreExt
|
9
|
+
end
|
10
|
+
end
|
11
|
+
|
@@ -0,0 +1,45 @@
|
|
1
|
+
module ActiveResource::Connections::CoreExt
|
2
|
+
extend ActiveSupport::Concern
|
3
|
+
|
4
|
+
included do
|
5
|
+
|
6
|
+
# @overload
|
7
|
+
def self.connection(refresh = false)
|
8
|
+
if defined?(@connection) || superclass == Object
|
9
|
+
@connection = connection_class.new(site, format) if refresh || @connection.nil?
|
10
|
+
@connection.proxy = proxy if proxy
|
11
|
+
@connection.user = user if user
|
12
|
+
@connection.password = password if password
|
13
|
+
@connection.auth_type = auth_type if auth_type
|
14
|
+
@connection.timeout = timeout if timeout
|
15
|
+
@connection.ssl_options = ssl_options if ssl_options
|
16
|
+
@connection
|
17
|
+
else
|
18
|
+
superclass.connection
|
19
|
+
end
|
20
|
+
end
|
21
|
+
|
22
|
+
end
|
23
|
+
|
24
|
+
module ClassMethods
|
25
|
+
|
26
|
+
# Gets the class used to establish connection.
|
27
|
+
def connection_class
|
28
|
+
if defined?(@connection_class) && @connection_class
|
29
|
+
@connection_class
|
30
|
+
elsif superclass != Object
|
31
|
+
superclass.connection_class
|
32
|
+
else
|
33
|
+
ActiveResource::Connection
|
34
|
+
end
|
35
|
+
end
|
36
|
+
|
37
|
+
# Sets the connection class for this model to the value in the +klass+ argument.
|
38
|
+
# The +klass+ should inherit from ActiveResource::Connection.
|
39
|
+
def connection_class=(klass)
|
40
|
+
@connection = nil
|
41
|
+
@connection_class = klass
|
42
|
+
end
|
43
|
+
|
44
|
+
end
|
45
|
+
end
|
@@ -0,0 +1,34 @@
|
|
1
|
+
require 'active_resource/connections'
|
2
|
+
begin
|
3
|
+
require 'retryable'
|
4
|
+
rescue LoadError
|
5
|
+
warn "Unable to find `retryable`. Please add `gem 'retryable'` to your Gemfile."
|
6
|
+
raise
|
7
|
+
end
|
8
|
+
|
9
|
+
class ActiveResource::Connections::Retryable < ActiveResource::Connection
|
10
|
+
|
11
|
+
# @return [Hash] options
|
12
|
+
# @option [Float] :sleep
|
13
|
+
# The number of seconds to wait between retries
|
14
|
+
# @option [Integer] :tries
|
15
|
+
# The number attempts
|
16
|
+
# @option [Array] :on
|
17
|
+
# A list of error classes to retry on
|
18
|
+
# @option [Regexp] :match
|
19
|
+
# Retries if error message matches given expression
|
20
|
+
class_attribute :retriable_options
|
21
|
+
self.retriable_options = {
|
22
|
+
:sleep => 0.5,
|
23
|
+
:tries => 3,
|
24
|
+
:on => [ ActiveResource::TimeoutError, ActiveResource::SSLError, Timeout::Error, OpenSSL::SSL::SSLError,
|
25
|
+
Errno::ETIMEDOUT, Errno::ECONNRESET, Errno::EHOSTUNREACH, EOFError, SocketError ]
|
26
|
+
}
|
27
|
+
|
28
|
+
protected
|
29
|
+
|
30
|
+
def request(*)
|
31
|
+
retryable(retriable_options) { super }
|
32
|
+
end
|
33
|
+
|
34
|
+
end
|
@@ -0,0 +1 @@
|
|
1
|
+
require 'active_resource/connections'
|
metadata
ADDED
@@ -0,0 +1,117 @@
|
|
1
|
+
--- !ruby/object:Gem::Specification
|
2
|
+
name: activeresource_connections
|
3
|
+
version: !ruby/object:Gem::Version
|
4
|
+
version: 0.1.0
|
5
|
+
prerelease:
|
6
|
+
platform: ruby
|
7
|
+
authors:
|
8
|
+
- Dimitrij Denissenko
|
9
|
+
autorequire:
|
10
|
+
bindir: bin
|
11
|
+
cert_chain: []
|
12
|
+
date: 2012-01-12 00:00:00.000000000Z
|
13
|
+
dependencies:
|
14
|
+
- !ruby/object:Gem::Dependency
|
15
|
+
name: activeresource
|
16
|
+
requirement: &12816280 !ruby/object:Gem::Requirement
|
17
|
+
none: false
|
18
|
+
requirements:
|
19
|
+
- - ! '>='
|
20
|
+
- !ruby/object:Gem::Version
|
21
|
+
version: 3.1.0
|
22
|
+
- - <
|
23
|
+
- !ruby/object:Gem::Version
|
24
|
+
version: 3.3.0
|
25
|
+
type: :runtime
|
26
|
+
prerelease: false
|
27
|
+
version_requirements: *12816280
|
28
|
+
- !ruby/object:Gem::Dependency
|
29
|
+
name: rake
|
30
|
+
requirement: &12815000 !ruby/object:Gem::Requirement
|
31
|
+
none: false
|
32
|
+
requirements:
|
33
|
+
- - ! '>='
|
34
|
+
- !ruby/object:Gem::Version
|
35
|
+
version: '0'
|
36
|
+
type: :development
|
37
|
+
prerelease: false
|
38
|
+
version_requirements: *12815000
|
39
|
+
- !ruby/object:Gem::Dependency
|
40
|
+
name: bundler
|
41
|
+
requirement: &12814100 !ruby/object:Gem::Requirement
|
42
|
+
none: false
|
43
|
+
requirements:
|
44
|
+
- - ! '>='
|
45
|
+
- !ruby/object:Gem::Version
|
46
|
+
version: '0'
|
47
|
+
type: :development
|
48
|
+
prerelease: false
|
49
|
+
version_requirements: *12814100
|
50
|
+
- !ruby/object:Gem::Dependency
|
51
|
+
name: rspec
|
52
|
+
requirement: &12813540 !ruby/object:Gem::Requirement
|
53
|
+
none: false
|
54
|
+
requirements:
|
55
|
+
- - ! '>='
|
56
|
+
- !ruby/object:Gem::Version
|
57
|
+
version: '0'
|
58
|
+
type: :development
|
59
|
+
prerelease: false
|
60
|
+
version_requirements: *12813540
|
61
|
+
- !ruby/object:Gem::Dependency
|
62
|
+
name: retryable
|
63
|
+
requirement: &12812700 !ruby/object:Gem::Requirement
|
64
|
+
none: false
|
65
|
+
requirements:
|
66
|
+
- - ! '>='
|
67
|
+
- !ruby/object:Gem::Version
|
68
|
+
version: '0'
|
69
|
+
type: :development
|
70
|
+
prerelease: false
|
71
|
+
version_requirements: *12812700
|
72
|
+
- !ruby/object:Gem::Dependency
|
73
|
+
name: webmock
|
74
|
+
requirement: &12811420 !ruby/object:Gem::Requirement
|
75
|
+
none: false
|
76
|
+
requirements:
|
77
|
+
- - ! '>='
|
78
|
+
- !ruby/object:Gem::Version
|
79
|
+
version: '0'
|
80
|
+
type: :development
|
81
|
+
prerelease: false
|
82
|
+
version_requirements: *12811420
|
83
|
+
description: Extend your ActiveResource model's connections
|
84
|
+
email: dimitrij@blacksquaremedia.com
|
85
|
+
executables: []
|
86
|
+
extensions: []
|
87
|
+
extra_rdoc_files: []
|
88
|
+
files:
|
89
|
+
- lib/active_resource/connections/core_ext.rb
|
90
|
+
- lib/active_resource/connections/retryable.rb
|
91
|
+
- lib/active_resource/connections.rb
|
92
|
+
- lib/activeresource_connections.rb
|
93
|
+
homepage: https://github.com/bsm/activeresource_connections
|
94
|
+
licenses: []
|
95
|
+
post_install_message:
|
96
|
+
rdoc_options: []
|
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
|
+
version: 1.9.0
|
105
|
+
required_rubygems_version: !ruby/object:Gem::Requirement
|
106
|
+
none: false
|
107
|
+
requirements:
|
108
|
+
- - ! '>='
|
109
|
+
- !ruby/object:Gem::Version
|
110
|
+
version: 1.3.6
|
111
|
+
requirements: []
|
112
|
+
rubyforge_project:
|
113
|
+
rubygems_version: 1.8.10
|
114
|
+
signing_key:
|
115
|
+
specification_version: 3
|
116
|
+
summary: Custom connections for ActiveResource models
|
117
|
+
test_files: []
|