dubdubdub 0.2.5 → 0.2.6
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/dubdubdub.gemspec +1 -1
- data/lib/dubdubdub.rb +1 -5
- data/lib/dubdubdub/client.rb +8 -7
- data/lib/dubdubdub/configuration.rb +19 -2
- data/spec/dubdubdub_spec.rb +38 -26
- metadata +2 -2
data/dubdubdub.gemspec
CHANGED
data/lib/dubdubdub.rb
CHANGED
data/lib/dubdubdub/client.rb
CHANGED
|
@@ -14,14 +14,15 @@ class DubDubDub::Client
|
|
|
14
14
|
|
|
15
15
|
# If we want to use a proxy
|
|
16
16
|
if options[:proxy]
|
|
17
|
-
# If true
|
|
18
|
-
# or ignore and don't use a proxy at all
|
|
17
|
+
# If true, refer to global proxy config
|
|
19
18
|
if options[:proxy] == true
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
raise DubDubDub::Exception, "No
|
|
19
|
+
proxy = DubDubDub.configuration.proxy
|
|
20
|
+
|
|
21
|
+
if proxy.nil? and !DubDubDub.configuration.ignore_proxy
|
|
22
|
+
raise DubDubDub::Exception, "No proxy has been configured or provided!"
|
|
24
23
|
end
|
|
24
|
+
|
|
25
|
+
self.proxy = proxy
|
|
25
26
|
# Otherwise, it should be a proxy url
|
|
26
27
|
else
|
|
27
28
|
self.proxy = options[:proxy]
|
|
@@ -46,7 +47,7 @@ class DubDubDub::Client
|
|
|
46
47
|
end
|
|
47
48
|
|
|
48
49
|
def proxy?
|
|
49
|
-
return false if DubDubDub.configuration.
|
|
50
|
+
return false if DubDubDub.configuration.ignore_proxy
|
|
50
51
|
|
|
51
52
|
!!proxy
|
|
52
53
|
end
|
|
@@ -1,9 +1,26 @@
|
|
|
1
1
|
class DubDubDub::Configuration
|
|
2
2
|
# Ignores all attempts to use proxies
|
|
3
|
-
attr_accessor :
|
|
3
|
+
attr_accessor :ignore_proxy
|
|
4
4
|
|
|
5
5
|
def initialize
|
|
6
6
|
# Default config values
|
|
7
|
-
self.
|
|
7
|
+
self.ignore_proxy = false
|
|
8
|
+
end
|
|
9
|
+
|
|
10
|
+
# Can be used as callable-setter when block provided.
|
|
11
|
+
def proxy(&block)
|
|
12
|
+
if block_given?
|
|
13
|
+
@proxy = block
|
|
14
|
+
else
|
|
15
|
+
if @proxy.is_a? Proc
|
|
16
|
+
@proxy.call
|
|
17
|
+
else
|
|
18
|
+
@proxy
|
|
19
|
+
end
|
|
20
|
+
end
|
|
21
|
+
end
|
|
22
|
+
|
|
23
|
+
def proxy=(proxy)
|
|
24
|
+
@proxy = proxy
|
|
8
25
|
end
|
|
9
26
|
end
|
data/spec/dubdubdub_spec.rb
CHANGED
|
@@ -31,27 +31,31 @@ describe DubDubDub do
|
|
|
31
31
|
www.proxy_port.should == 80
|
|
32
32
|
end
|
|
33
33
|
|
|
34
|
-
it "can
|
|
35
|
-
|
|
36
|
-
|
|
34
|
+
it "can configure to use a proxy globally" do
|
|
35
|
+
DubDubDub.configure do |config|
|
|
36
|
+
config.proxy = "localhost:8000"
|
|
37
|
+
end
|
|
37
38
|
|
|
38
39
|
www = DubDubDub.new(proxy: true)
|
|
39
40
|
www.should be_proxy
|
|
40
|
-
|
|
41
|
-
proxies.include?(www.proxy).should be_true
|
|
41
|
+
www.proxy.should == "localhost:8000"
|
|
42
42
|
end
|
|
43
43
|
|
|
44
|
-
it "raises an error if we have specified to use a proxy
|
|
45
|
-
DubDubDub.
|
|
46
|
-
|
|
44
|
+
it "raises an error if we have specified to use a proxy but none has been set globally" do
|
|
45
|
+
DubDubDub.configure do |config|
|
|
46
|
+
config.ignore_proxy = false
|
|
47
|
+
config.proxy = nil
|
|
48
|
+
end
|
|
47
49
|
|
|
48
|
-
DubDubDub.proxies = nil
|
|
49
50
|
lambda { DubDubDub.new(proxy: true) }.should raise_error(DubDubDub::Exception)
|
|
50
51
|
end
|
|
51
52
|
|
|
52
|
-
it "doesn't raise an error if configured to ignore proxies and we have specified to use a proxy
|
|
53
|
-
DubDubDub.
|
|
54
|
-
|
|
53
|
+
it "doesn't raise an error if configured to ignore proxies and we have specified to use a global proxy that hasn't been set" do
|
|
54
|
+
DubDubDub.configure do |config|
|
|
55
|
+
config.ignore_proxy = true
|
|
56
|
+
config.proxy = nil
|
|
57
|
+
end
|
|
58
|
+
|
|
55
59
|
lambda { DubDubDub.new(proxy: true) }.should_not raise_error(DubDubDub::Exception)
|
|
56
60
|
end
|
|
57
61
|
|
|
@@ -67,42 +71,50 @@ describe DubDubDub do
|
|
|
67
71
|
end
|
|
68
72
|
|
|
69
73
|
it "has default config values" do
|
|
70
|
-
DubDubDub.configuration.
|
|
74
|
+
DubDubDub.configuration.ignore_proxy.should be_false
|
|
75
|
+
DubDubDub.configuration.proxy.should be_nil
|
|
71
76
|
end
|
|
72
77
|
end
|
|
73
78
|
|
|
74
79
|
describe '::reset_configuration!' do
|
|
75
80
|
it "resets configuration by to defaults" do
|
|
76
81
|
DubDubDub.configure do |config|
|
|
77
|
-
config.
|
|
82
|
+
config.ignore_proxy = true
|
|
78
83
|
end
|
|
79
84
|
|
|
80
|
-
DubDubDub.configuration.
|
|
85
|
+
DubDubDub.configuration.ignore_proxy.should be_true
|
|
81
86
|
|
|
82
87
|
DubDubDub.reset_configuration!
|
|
83
88
|
|
|
84
|
-
DubDubDub.configuration.
|
|
89
|
+
DubDubDub.configuration.ignore_proxy.should be_false
|
|
85
90
|
end
|
|
86
91
|
end
|
|
87
92
|
|
|
88
93
|
describe '::configure' do
|
|
89
94
|
it "sets config attributes" do
|
|
90
95
|
DubDubDub.configure do |config|
|
|
91
|
-
config.
|
|
96
|
+
config.ignore_proxy = true
|
|
92
97
|
end
|
|
93
98
|
|
|
94
|
-
DubDubDub.configuration.
|
|
99
|
+
DubDubDub.configuration.ignore_proxy.should be_true
|
|
95
100
|
end
|
|
96
|
-
end
|
|
97
101
|
|
|
98
|
-
|
|
99
|
-
|
|
100
|
-
|
|
102
|
+
it "can pass a string to proxy config" do
|
|
103
|
+
DubDubDub.configure do |config|
|
|
104
|
+
config.proxy = "localhost:8000"
|
|
105
|
+
end
|
|
106
|
+
|
|
107
|
+
DubDubDub.configuration.proxy.should == "localhost:8000"
|
|
101
108
|
end
|
|
102
109
|
|
|
103
|
-
it "can
|
|
104
|
-
DubDubDub.
|
|
105
|
-
|
|
110
|
+
it "can pass a block to proxy config with the block being called when accessing it" do
|
|
111
|
+
DubDubDub.configure do |config|
|
|
112
|
+
config.proxy do
|
|
113
|
+
"localhost:8000"
|
|
114
|
+
end
|
|
115
|
+
end
|
|
116
|
+
|
|
117
|
+
DubDubDub.configuration.proxy.should == "localhost:8000"
|
|
106
118
|
end
|
|
107
119
|
end
|
|
108
120
|
|
|
@@ -125,7 +137,7 @@ describe DubDubDub do
|
|
|
125
137
|
end
|
|
126
138
|
|
|
127
139
|
it "ignores proxy if configured" do
|
|
128
|
-
DubDubDub.configuration.
|
|
140
|
+
DubDubDub.configuration.ignore_proxy = true
|
|
129
141
|
|
|
130
142
|
www.proxy = "localhost:8000"
|
|
131
143
|
agent = www.mechanize
|
metadata
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
|
2
2
|
name: dubdubdub
|
|
3
3
|
version: !ruby/object:Gem::Version
|
|
4
|
-
version: 0.2.
|
|
4
|
+
version: 0.2.6
|
|
5
5
|
prerelease:
|
|
6
6
|
platform: ruby
|
|
7
7
|
authors:
|
|
@@ -208,7 +208,7 @@ required_ruby_version: !ruby/object:Gem::Requirement
|
|
|
208
208
|
version: '0'
|
|
209
209
|
segments:
|
|
210
210
|
- 0
|
|
211
|
-
hash:
|
|
211
|
+
hash: 172753336999949758
|
|
212
212
|
required_rubygems_version: !ruby/object:Gem::Requirement
|
|
213
213
|
none: false
|
|
214
214
|
requirements:
|