sitediff 0.0.1 → 0.0.2

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml DELETED
@@ -1,7 +0,0 @@
1
- ---
2
- SHA1:
3
- metadata.gz: 1dc3a624b91cd4b7ef1c926116630cd795532024
4
- data.tar.gz: e49f227ae303f574b704ffe3a226f79a120ae30f
5
- SHA512:
6
- metadata.gz: 90ca5508b834d32ac7c96aa6a94a6aa8488921e978e76890e142b1249da20bc620ddcfa237f3defc1e6928d83dd0a22583c9dded150855c320f94140e1bffdf1
7
- data.tar.gz: 24bf7969b6f17c269bb407d1ff1684f6556318d0cfa7c6c92a8327ddd0d86ee4f153778affa4d1ef115e47a3b69b31b4dac5f01ed8b7f464a05fd98f9f98212b
@@ -1,32 +0,0 @@
1
- class SiteDiff
2
- module Util
3
- # A typhoeus cache, backed by DBM
4
- class Cache
5
- def initialize(file)
6
- # Default to GDBM, if we have it, we don't want pag/dir files
7
- begin
8
- require 'gdbm'
9
- @dbm = GDBM.new(file)
10
- rescue LoadError
11
- require 'dbm'
12
- @dbm = DBM.new(file)
13
- end
14
- end
15
-
16
- # Older Typhoeus doesn't have cache_key
17
- def cache_key(req)
18
- return req.cache_key if req.respond_to?(:cache_key)
19
- return Marshal.dump([req.base_url, req.options])
20
- end
21
-
22
- def get(req)
23
- resp = @dbm[cache_key(req)] or return nil
24
- Marshal.load(resp)
25
- end
26
-
27
- def set(req, resp)
28
- @dbm[cache_key(req)] = Marshal.dump(resp)
29
- end
30
- end
31
- end
32
- end
@@ -1,77 +0,0 @@
1
- require 'webrick'
2
-
3
- class SiteDiff
4
- module Util
5
- # Simple webserver for testing purposes
6
- class Webserver
7
- DEFAULT_PORT = 13080
8
-
9
- attr_accessor :ports
10
-
11
- # Serve a list of directories
12
- def initialize(start_port, dirs, params = {})
13
- start_port ||= DEFAULT_PORT
14
- @ports = (start_port...(start_port + dirs.size)).to_a
15
-
16
- if params[:announce]
17
- puts "Serving at #{uris.join(", ")}"
18
- end
19
-
20
- opts = {}
21
- if params[:quiet]
22
- opts[:Logger] = WEBrick::Log.new(IO::NULL)
23
- opts[:AccessLog] = []
24
- end
25
-
26
- @threads = []
27
- dirs.each_with_index do |dir, idx|
28
- opts[:Port] = @ports[idx]
29
- opts[:DocumentRoot] = dir
30
- server = WEBrick::HTTPServer.new(opts)
31
- @threads << Thread.new { server.start }
32
- end
33
-
34
- if block_given?
35
- yield self
36
- kill
37
- end
38
- end
39
-
40
- def kill
41
- @threads.each { |t| t.kill }
42
- end
43
-
44
- def wait
45
- @threads.each { |t| t.join }
46
- end
47
-
48
- def uris
49
- ports.map { |p| "http://localhost:#{p}" }
50
- end
51
-
52
-
53
- # Helper to serve one dir
54
- def self.serve(port, dir, params = {})
55
- new(port, [dir], params)
56
- end
57
- end
58
-
59
- class FixtureServer < Webserver
60
- PORT = DEFAULT_PORT + 1
61
- BASE = 'spec/fixtures/ruby-doc.org'
62
- NAMES = %w[core-1.9.3 core-2.0]
63
-
64
- def initialize(port = PORT, base = BASE, names = NAMES)
65
- dirs = names.map { |n| File.join(base, n) }
66
- super(port, dirs, :quiet => true)
67
- end
68
-
69
- def before
70
- uris.first
71
- end
72
- def after
73
- uris.last
74
- end
75
- end
76
- end
77
- end