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 CHANGED
@@ -5,7 +5,7 @@
5
5
 
6
6
  Gem::Specification.new do |s|
7
7
  s.name = "dubdubdub"
8
- s.version = "0.2.5"
8
+ s.version = "0.2.6"
9
9
 
10
10
  s.required_rubygems_version = Gem::Requirement.new(">= 0") if s.respond_to? :required_rubygems_version=
11
11
  s.authors = ["James Hu"]
data/lib/dubdubdub.rb CHANGED
@@ -1,13 +1,9 @@
1
1
  class DubDubDub
2
2
  # Version
3
- VERSION = "0.2.5"
3
+ VERSION = "0.2.6"
4
4
 
5
5
  attr_accessor :client
6
6
 
7
- class << self
8
- attr_accessor :proxies
9
- end
10
-
11
7
  def self.configure
12
8
  yield(configuration)
13
9
  end
@@ -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 and we have a proxy list, use a random one from the list
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
- if DubDubDub.proxies and DubDubDub.proxies.is_a?(Array) and DubDubDub.proxies.any?
21
- self.proxy = DubDubDub.proxies.sample
22
- else
23
- raise DubDubDub::Exception, "No proxies have been specified!" unless DubDubDub.configuration.ignore_proxies
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.ignore_proxies
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 :ignore_proxies
3
+ attr_accessor :ignore_proxy
4
4
 
5
5
  def initialize
6
6
  # Default config values
7
- self.ignore_proxies = false
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
@@ -31,27 +31,31 @@ describe DubDubDub do
31
31
  www.proxy_port.should == 80
32
32
  end
33
33
 
34
- it "can specify to use a random proxy from list of proxies set" do
35
- proxies = ["localhost:8000", "localhost:4000", "12.12.12.12:3000"]
36
- DubDubDub.proxies = proxies
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 from the list but there are none" do
45
- DubDubDub.proxies = []
46
- lambda { DubDubDub.new(proxy: true) }.should raise_error(DubDubDub::Exception)
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 from the list but there are none" do
53
- DubDubDub.configuration.ignore_proxies = true
54
- DubDubDub.proxies = nil
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.ignore_proxies.should be_false
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.ignore_proxies = true
82
+ config.ignore_proxy = true
78
83
  end
79
84
 
80
- DubDubDub.configuration.ignore_proxies.should be_true
85
+ DubDubDub.configuration.ignore_proxy.should be_true
81
86
 
82
87
  DubDubDub.reset_configuration!
83
88
 
84
- DubDubDub.configuration.ignore_proxies.should be_false
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.ignore_proxies = true
96
+ config.ignore_proxy = true
92
97
  end
93
98
 
94
- DubDubDub.configuration.ignore_proxies.should be_true
99
+ DubDubDub.configuration.ignore_proxy.should be_true
95
100
  end
96
- end
97
101
 
98
- describe '::proxies' do
99
- it "is nil by default" do
100
- DubDubDub.proxies.should be_nil
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 be set" do
104
- DubDubDub.proxies = ["localhost:8000"]
105
- DubDubDub.proxies.should be == ["localhost:8000"]
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.ignore_proxies = true
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.5
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: 1311831286708000735
211
+ hash: 172753336999949758
212
212
  required_rubygems_version: !ruby/object:Gem::Requirement
213
213
  none: false
214
214
  requirements: