proxy_pac_rb 0.2.4 → 0.2.5

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/files/sample2.pac CHANGED
@@ -1,5 +1,5 @@
1
1
  function FindProxyForURL(url, host) {
2
- if ( MyIpAddress() == '127.0.0.2' ) {
2
+ if ( myIpAddress() == '127.0.0.2' ) {
3
3
  return "DIRECT";
4
4
  } else {
5
5
  return "PROXY localhost:8080";
@@ -28,12 +28,8 @@ module ProxyPacRb
28
28
  :isResolvable,
29
29
  :isInNet,
30
30
  :dnsResolve,
31
- # :MyIpAddress ,
32
31
  :dnsDomainLevels,
33
32
  :shExpMatch,
34
- # :weekdayRange,
35
- # :dateRange,
36
- # :timeRange,
37
33
  ]
38
34
  end
39
35
 
@@ -65,10 +61,6 @@ module ProxyPacRb
65
61
  resolve_host(host)
66
62
  end
67
63
 
68
- def myIpAddress
69
- IPAddr.new(client_ip).to_s
70
- end
71
-
72
64
  def dnsDomainLevels(host)
73
65
  host.scan(".").size
74
66
  end
@@ -77,90 +69,8 @@ module ProxyPacRb
77
69
  ::File.fnmatch(shexp, str)
78
70
  end
79
71
 
80
- def weekdayRange(wd1, wd2 = nil, gmt = nil)
81
- fail Exceptions::InvalidArgument, "wd1 needs to be one of #{days.keys.collect {|k| "\"#{k}\""}.join(', ')}" unless days.key?(wd1)
82
- fail Exceptions::InvalidArgument, "wd2 needs to be one of #{days.keys.collect {|k| "\"#{k}\""}.join(', ')}" if wd2 and !days.key?(wd2)
83
-
84
- if gmt == "GMT"
85
- local_time = time.utc
86
- else
87
- local_time = time
88
- end
89
-
90
- (days[wd1]..days[wd2 || wd1]).include? local_time.wday
91
- end
92
-
93
- def dateRange(*args)
94
- fail Exceptions::InvalidArgument, "range needs to be one of #{months.keys.collect {|k| "\"#{k}\""}.join(', ')}" if args.any? { |a| !months.key?(a) }
95
-
96
- if args.last == "GMT" and args.pop
97
- local_time = time.utc
98
- else
99
- local_time = time
100
- end
101
-
102
- case args.size
103
- when 1
104
- check_date_part(local_time, args[0])
105
- when 2
106
- check_date_part(local_time, args[0]..args[1])
107
- when 4
108
- check_date_part(local_time, args[0]..args[2]) and
109
- check_date_part(local_time, args[1]..args[3])
110
- when 6
111
- check_date_part(local_time, args[0]..args[3]) and
112
- check_date_part(local_time, args[1]..args[4]) and
113
- check_date_part(local_time, args[2]..args[5])
114
- else
115
- fail ArgumentError, "wrong number of arguments"
116
- end
117
- end
118
-
119
- def timeRange(*args)
120
- fail Exceptions::InvalidArgument, "args need to be integer values" if args.any? { |a| !a.kind_of? Fixnum }
121
-
122
- if args.last == "GMT" and args.pop
123
- local_time = time.utc
124
- else
125
- local_time = time
126
- end
127
-
128
- case args.size
129
- when 1
130
- local_time.hour == args[0]
131
- when 2
132
- (args[0]..args[1]).include? local_time.hour
133
- when 4
134
- (args[0]..args[2]).include? local_time.hour and
135
- (args[1]..args[3]).include? local_time.min
136
- when 6
137
- (args[0]..args[3]).include? local_time.hour and
138
- (args[1]..args[4]).include? local_time.min and
139
- (args[2]..args[5]).include? local_time.sec
140
- else
141
- fail ArgumentError, "wrong number of arguments"
142
- end
143
- end
144
-
145
72
  private
146
73
 
147
- def check_date_part(time, part, operation = :==)
148
- case part
149
- when String
150
- time.month.send(operation, months[part])
151
- when Integer
152
- if part < 100
153
- time.day.send(operation, part)
154
- else
155
- time.year.send(operation, part)
156
- end
157
- when Range
158
- check_date_part(time, part.begin, :>=) and check_date_part(time, part.end, :<=)
159
- else
160
- fail ArgumentError, "wrong type"
161
- end
162
- end
163
-
164
74
  def resolve_host(host)
165
75
  Resolv.each_address(host) do |address|
166
76
  begin
@@ -4,7 +4,7 @@ module ProxyPacRb
4
4
  class << self
5
5
  def my_ip_address_template(value)
6
6
  <<-EOS.strip_heredoc
7
- function MyIpAddress() {
7
+ function myIpAddress() {
8
8
  return "#{value}";
9
9
  }
10
10
  EOS
@@ -1,4 +1,4 @@
1
1
  #main ProxyPacRb
2
2
  module ProxyPacRb
3
- VERSION = '0.2.4'
3
+ VERSION = '0.2.5'
4
4
  end
@@ -77,15 +77,6 @@ describe ProxyPacRb::Environment do
77
77
  end
78
78
  end
79
79
 
80
- describe '#myIpAddress ' do
81
- it 'returns the given ip address' do
82
- ip = '127.0.0.1'
83
- environment = Environment.new(client_ip: ip, time: Time.now)
84
-
85
- expect(environment.myIpAddress).to eq(ip)
86
- end
87
- end
88
-
89
80
  describe '#dnsDomainLevels' do
90
81
  it 'returns the count of domain levels (dots)' do
91
82
  result = environment.dnsDomainLevels('maps.google.com')
@@ -105,67 +96,6 @@ describe ProxyPacRb::Environment do
105
96
  end
106
97
  end
107
98
 
108
- describe '#weekdayRange' do
109
- let(:environment) { Environment.new(client_ip: '127.0.0.1', time: Time.parse('1991-08-25 12:00')) }
110
-
111
- it 'returns true for SUN - MON' do
112
- result = environment.weekdayRange("SUN", "MON")
113
- expect(result).to be_true
114
- end
115
-
116
- it 'returns false for FR' do
117
- result = environment.weekdayRange("FRI")
118
- expect(result).to be_false
119
- end
120
-
121
- it 'fails if wd1 or wd2 are not valid, e.g. German SO for Sunday' do
122
- expect {
123
- environment.weekdayRange("SO")
124
- }.to raise_error Exceptions::InvalidArgument
125
- end
126
-
127
- end
128
-
129
- describe '#dateRange' do
130
- let(:environment) { Environment.new(client_ip: '127.0.0.1', time: Time.parse('1991-08-25 12:00')) }
131
-
132
- it 'returns true for JUL - SEP' do
133
- result = environment.dateRange("JUL", "SEP")
134
- expect(result).to be_true
135
- end
136
-
137
- it 'returns false for MAR' do
138
- result = environment.dateRange("MAR")
139
- expect(result).to be_false
140
- end
141
-
142
- it 'fails if range is not valid' do
143
- expect {
144
- environment.dateRange("SEPT")
145
- }.to raise_error Exceptions::InvalidArgument
146
- end
147
- end
148
-
149
- describe '#timeRange' do
150
- let(:environment) { Environment.new(client_ip: '127.0.0.1', time: Time.parse('1991-08-25 12:00')) }
151
-
152
- it 'returns true for 8 - 18h' do
153
- result = environment.timeRange(8, 18)
154
- expect(result).to be_true
155
- end
156
-
157
- it 'returns false for MAR' do
158
- result = environment.timeRange(13,14)
159
- expect(result).to be_false
160
- end
161
-
162
- it 'fails if range is not valid' do
163
- expect {
164
- environment.timeRange("SEPT")
165
- }.to raise_error Exceptions::InvalidArgument
166
- end
167
- end
168
-
169
99
  describe '#alert' do
170
100
  it 'outputs msg' do
171
101
  result = capture(:stderr) do
@@ -182,7 +112,7 @@ describe ProxyPacRb::Environment do
182
112
  environment.prepare(string)
183
113
 
184
114
  %w[
185
- MyIpAddress
115
+ myIpAddress
186
116
  weekdayRange
187
117
  dateRange
188
118
  timeRange
data/spec/file_spec.rb CHANGED
@@ -13,7 +13,7 @@ describe File do
13
13
  let(:client_ip_pac) do
14
14
  <<-EOS.strip_heredoc
15
15
  function FindProxyForURL(url, host) {
16
- if ( MyIpAddress() == '127.0.0.2' ) {
16
+ if ( myIpAddress() == '127.0.0.2' ) {
17
17
  return "DIRECT";
18
18
  } else {
19
19
  return "PROXY localhost:8080";
data/spec/parser_spec.rb CHANGED
@@ -35,7 +35,7 @@ describe ProxyPacRb::Parser do
35
35
  it 'supports a changeable ip address' do
36
36
  string = <<-EOS
37
37
  function FindProxyForURL(url, host) {
38
- if ( MyIpAddress() == '127.0.0.2' ) {
38
+ if ( myIpAddress() == '127.0.0.2' ) {
39
39
  return "DIRECT";
40
40
  } else {
41
41
  return "PROXY localhost:8080";
data/tmp/script.rb CHANGED
@@ -5,7 +5,7 @@ require 'proxy_pac_rb'
5
5
 
6
6
  string = <<-EOS
7
7
  function FindProxyForURL(url, host) {
8
- if ( MyIpAddress() == '127.0.0.2' ) {
8
+ if ( myIpAddress() == '127.0.0.2' ) {
9
9
  return "DIRECT";
10
10
  } else {
11
11
  return "PROXY localhost:8080";
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: proxy_pac_rb
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.2.4
4
+ version: 0.2.5
5
5
  prerelease:
6
6
  platform: ruby
7
7
  authors:
@@ -121,7 +121,7 @@ required_ruby_version: !ruby/object:Gem::Requirement
121
121
  version: '0'
122
122
  segments:
123
123
  - 0
124
- hash: -2077589213194333842
124
+ hash: 2846235873076525490
125
125
  required_rubygems_version: !ruby/object:Gem::Requirement
126
126
  none: false
127
127
  requirements:
@@ -130,7 +130,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
130
130
  version: '0'
131
131
  segments:
132
132
  - 0
133
- hash: -2077589213194333842
133
+ hash: 2846235873076525490
134
134
  requirements: []
135
135
  rubyforge_project:
136
136
  rubygems_version: 1.8.23