gopher2000 0.5.3 → 0.5.4
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/bin/gopher2000 +1 -1
- data/lib/gopher2000/base.rb +7 -0
- data/lib/gopher2000/request.rb +3 -3
- data/lib/gopher2000/server.rb +10 -3
- data/lib/gopher2000/version.rb +1 -1
- data/spec/dsl_spec.rb +76 -67
- data/spec/rendering/menu_spec.rb +19 -3
- data/spec/server_spec.rb +17 -1
- metadata +2 -2
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: febb4c0d9036ca121d7ee16c85346ee7afa10ad7f09158d3b6c6c823d1256256
|
4
|
+
data.tar.gz: abfa74d3dd3742bc383a176770e0c68d24ec9ec458a0b0806a288fee7f096480
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 971a695d248ddad837c5e7ff17d36d70696729ea383842d09fa289e1d20516e75b7b5c2f40727bd45b28224b3c540af4e3c0e7bf90fb389522f616c792e7db84
|
7
|
+
data.tar.gz: b0290447843496e4cf77e435f523804824be33728ba45cc236465737f574f2e443a2cd8796dc2e01170b311ea91687e6a882a8e5b19dfda8edfc043ecc6ee80d
|
data/bin/gopher2000
CHANGED
@@ -31,7 +31,7 @@ params = {
|
|
31
31
|
|
32
32
|
opts.on('-d', '--debug', "run in debug mode") { params[:debug] = true }
|
33
33
|
opts.on('-p port', 'set the port (default is 70)') { |val| params[:port] = Integer(val) }
|
34
|
-
opts.on('-o addr', 'set the host (default is 0.0.0.0)') { |val| params[host] = val }
|
34
|
+
opts.on('-o addr', 'set the host (default is 0.0.0.0)') { |val| params[:host] = val }
|
35
35
|
opts.on('-e env', 'set the environment (default is development)') { |val| params[:env] = val.to_sym }
|
36
36
|
|
37
37
|
opts.on_tail("-h", "--help", "Show this message") do
|
data/lib/gopher2000/base.rb
CHANGED
data/lib/gopher2000/request.rb
CHANGED
@@ -8,9 +8,9 @@ module Gopher
|
|
8
8
|
|
9
9
|
def initialize(raw, ip_addr=nil)
|
10
10
|
@selector, @input = raw.chomp.split("\t")
|
11
|
-
|
12
|
-
|
13
|
-
|
11
|
+
|
12
|
+
@selector = Gopher::Application.sanitize_selector(@selector)
|
13
|
+
@ip_address = ip_addr
|
14
14
|
end
|
15
15
|
|
16
16
|
# confirm that this is actually a valid gopher request
|
data/lib/gopher2000/server.rb
CHANGED
@@ -13,7 +13,7 @@ module Gopher
|
|
13
13
|
def initialize(a)
|
14
14
|
@app = a
|
15
15
|
end
|
16
|
-
|
16
|
+
|
17
17
|
#
|
18
18
|
# @return [String] name of the host specified in our config
|
19
19
|
#
|
@@ -28,6 +28,13 @@ module Gopher
|
|
28
28
|
@app.config[:port] ||= 70
|
29
29
|
end
|
30
30
|
|
31
|
+
#
|
32
|
+
# @return [String] environment specified in config
|
33
|
+
#
|
34
|
+
def env
|
35
|
+
@app.config[:env] || 'development'
|
36
|
+
end
|
37
|
+
|
31
38
|
#
|
32
39
|
# main app loop. called via at_exit block defined in DSL
|
33
40
|
#
|
@@ -77,8 +84,8 @@ module Gopher
|
|
77
84
|
require 'optparse'
|
78
85
|
OptionParser.new { |op|
|
79
86
|
op.on('-p port', 'set the port (default is 70)') { |val| set :port, Integer(val) }
|
80
|
-
op.on('-o addr', 'set the host (default is 0.0.0.0)') { |val| set :
|
81
|
-
op.on('-e env', 'set the environment (default is development)') { |val| set :
|
87
|
+
op.on('-o addr', 'set the host (default is 0.0.0.0)') { |val| set :host, val }
|
88
|
+
op.on('-e env', 'set the environment (default is development)') { |val| set :env, val.to_sym }
|
82
89
|
}.parse!(ARGV.dup)
|
83
90
|
end
|
84
91
|
end
|
data/lib/gopher2000/version.rb
CHANGED
data/spec/dsl_spec.rb
CHANGED
@@ -14,103 +14,112 @@ describe Gopher::DSL do
|
|
14
14
|
|
15
15
|
@server = FakeServer.new(@app)
|
16
16
|
@server.send :require, 'gopher2000/dsl'
|
17
|
-
allow(@server).to receive(:application).and_return(@app)
|
18
|
-
@app.reset!
|
19
17
|
end
|
20
18
|
|
21
|
-
|
22
|
-
|
23
|
-
|
24
|
-
@server.set :foo, 'bar'
|
25
|
-
expect(@app.config[:foo]).to eq('bar')
|
19
|
+
describe "application" do
|
20
|
+
it "should return a Gopher::Application" do
|
21
|
+
expect(@server.application).to be_a(Gopher::Application)
|
26
22
|
end
|
27
23
|
end
|
28
24
|
|
29
|
-
|
30
|
-
|
31
|
-
|
32
|
-
@
|
33
|
-
|
25
|
+
context "with application" do
|
26
|
+
before do
|
27
|
+
allow(@server).to receive(:application).and_return(@app)
|
28
|
+
@app.reset!
|
29
|
+
end
|
30
|
+
|
31
|
+
describe "set" do
|
32
|
+
it "should set a config var" do
|
33
|
+
@server.set :foo, 'bar'
|
34
|
+
expect(@app.config[:foo]).to eq('bar')
|
34
35
|
end
|
35
36
|
end
|
36
|
-
end
|
37
37
|
|
38
|
-
|
39
|
-
|
40
|
-
|
41
|
-
|
42
|
-
|
38
|
+
describe "route" do
|
39
|
+
it "should pass a lookup and block to the app" do
|
40
|
+
expect(@app).to receive(:route).with('/foo')
|
41
|
+
@server.route '/foo' do
|
42
|
+
"hi"
|
43
|
+
end
|
43
44
|
end
|
44
45
|
end
|
45
|
-
end
|
46
46
|
|
47
|
-
|
48
|
-
|
49
|
-
|
50
|
-
|
47
|
+
describe "default_route" do
|
48
|
+
it "should pass a default block to the app" do
|
49
|
+
expect(@app).to receive(:default_route)
|
50
|
+
@server.default_route do
|
51
|
+
"hi"
|
52
|
+
end
|
53
|
+
end
|
51
54
|
end
|
52
55
|
|
53
|
-
|
54
|
-
|
55
|
-
|
56
|
+
describe "mount" do
|
57
|
+
it "should pass a route, path, and some opts to the app" do
|
58
|
+
expect(@app).to receive(:mount).with('/foo', {:path => "/bar"})
|
59
|
+
@server.mount "/foo" => "/bar"
|
60
|
+
end
|
61
|
+
|
62
|
+
it "should pass a route, path, filter, and some opts to the app" do
|
63
|
+
expect(@app).to receive(:mount).with('/foo', {:path => "/bar", :filter => "*.jpg"})
|
64
|
+
@server.mount "/foo" => "/bar", :filter => "*.jpg"
|
65
|
+
end
|
56
66
|
end
|
57
|
-
end
|
58
67
|
|
59
|
-
|
60
|
-
|
61
|
-
|
62
|
-
|
63
|
-
|
68
|
+
describe "menu" do
|
69
|
+
it "should pass a menu key and block to the app" do
|
70
|
+
expect(@app).to receive(:menu).with('/foo')
|
71
|
+
@server.menu '/foo' do
|
72
|
+
"hi"
|
73
|
+
end
|
64
74
|
end
|
65
75
|
end
|
66
|
-
end
|
67
76
|
|
68
|
-
|
69
|
-
|
70
|
-
|
71
|
-
|
72
|
-
|
77
|
+
describe "text" do
|
78
|
+
it "should pass a text_template key and block to the app" do
|
79
|
+
expect(@app).to receive(:text).with('/foo')
|
80
|
+
@server.text '/foo' do
|
81
|
+
"hi"
|
82
|
+
end
|
73
83
|
end
|
74
84
|
end
|
75
|
-
end
|
76
85
|
|
77
|
-
|
78
|
-
|
79
|
-
|
80
|
-
|
81
|
-
|
86
|
+
describe "helpers" do
|
87
|
+
it "should pass a block to the app" do
|
88
|
+
expect(@app).to receive(:helpers)
|
89
|
+
@server.helpers do
|
90
|
+
"hi"
|
91
|
+
end
|
82
92
|
end
|
83
93
|
end
|
84
|
-
end
|
85
94
|
|
86
|
-
|
87
|
-
|
88
|
-
|
89
|
-
|
95
|
+
describe "watch" do
|
96
|
+
it "should pass a script app for watching" do
|
97
|
+
expect(@app.scripts).to receive(:<<).with("foo")
|
98
|
+
@server.watch("foo")
|
99
|
+
end
|
90
100
|
end
|
91
|
-
end
|
92
101
|
|
93
|
-
|
94
|
-
|
95
|
-
|
96
|
-
|
97
|
-
|
102
|
+
describe "run" do
|
103
|
+
it "should set any incoming opts" do
|
104
|
+
expect(@server).to receive(:set).with(:x, 1)
|
105
|
+
expect(@server).to receive(:set).with(:y, 2)
|
106
|
+
allow(@server).to receive(:load)
|
98
107
|
|
99
|
-
|
100
|
-
|
108
|
+
@server.run("foo", {:x => 1, :y => 2})
|
109
|
+
end
|
101
110
|
|
102
|
-
|
103
|
-
|
104
|
-
|
105
|
-
|
111
|
+
it "should turn on script watching if in debug mode" do
|
112
|
+
@app.config[:debug] = true
|
113
|
+
expect(@server).to receive(:watch).with("foo.rb")
|
114
|
+
expect(@server).to receive(:load).with("foo.rb")
|
106
115
|
|
107
|
-
|
108
|
-
|
116
|
+
@server.run("foo.rb")
|
117
|
+
end
|
109
118
|
|
110
|
-
|
111
|
-
|
112
|
-
|
119
|
+
it "should load the script" do
|
120
|
+
expect(@server).to receive(:load).with("foo.rb")
|
121
|
+
@server.run("foo.rb")
|
122
|
+
end
|
113
123
|
end
|
114
124
|
end
|
115
|
-
|
116
125
|
end
|
data/spec/rendering/menu_spec.rb
CHANGED
@@ -54,9 +54,25 @@ describe Gopher::Rendering::Menu do
|
|
54
54
|
end
|
55
55
|
|
56
56
|
describe "link" do
|
57
|
-
|
58
|
-
|
59
|
-
|
57
|
+
context "with filepath" do
|
58
|
+
it "should get type with determine_type" do
|
59
|
+
expect(@ctx).to receive(:determine_type).with("foo.txt").and_return("A")
|
60
|
+
expect(@ctx.link("FILE", "thing", "external-server.com", 70, "foo.txt")).to eq("AFILE\tthing\texternal-server.com\t70\r\n")
|
61
|
+
end
|
62
|
+
end
|
63
|
+
|
64
|
+
context "without filepath" do
|
65
|
+
it "should get type with determine_type" do
|
66
|
+
expect(@ctx).to receive(:determine_type).with("foo.txt").and_return("A")
|
67
|
+
expect(@ctx.link("FILE", "foo.txt")).to eq("AFILE\tfoo.txt\thost\t1234\r\n")
|
68
|
+
end
|
69
|
+
end
|
70
|
+
|
71
|
+
end
|
72
|
+
|
73
|
+
describe "text_link" do
|
74
|
+
it "should work" do
|
75
|
+
expect(@ctx.text_link("text link", "/files/foo.txt")).to eq("0text link\t/files/foo.txt\thost\t1234\r\n")
|
60
76
|
end
|
61
77
|
end
|
62
78
|
|
data/spec/server_spec.rb
CHANGED
@@ -18,17 +18,33 @@ if ENV["WITH_SERVER_SPECS"].to_i == 1
|
|
18
18
|
|
19
19
|
@host = "0.0.0.0"
|
20
20
|
@port = 12345
|
21
|
+
@environment = 'test'
|
21
22
|
|
22
23
|
@application.config[:host] = @host
|
23
24
|
@application.config[:port] = @port
|
25
|
+
@application.config[:env] = @environment
|
24
26
|
|
25
27
|
@request = Gopher::Request.new("foo", "bar")
|
26
28
|
|
27
|
-
@response = Gopher::Response.new
|
29
|
+
@response = Gopher::Response.new
|
28
30
|
@response.code = :success
|
29
31
|
@response.body = "hi"
|
30
32
|
end
|
31
33
|
|
34
|
+
it "returns host" do
|
35
|
+
@application.config[:host] = 'gopher-site.test'
|
36
|
+
expect(@application.host).to eql('gopher-site.test')
|
37
|
+
end
|
38
|
+
|
39
|
+
it "returns port" do
|
40
|
+
expect(@application.port).to eql(@port)
|
41
|
+
end
|
42
|
+
|
43
|
+
it "returns environment" do
|
44
|
+
expect(@application.env).to eql(@environment)
|
45
|
+
end
|
46
|
+
|
47
|
+
|
32
48
|
it "should work in non-blocking mode" do
|
33
49
|
@application.fake_response = @response
|
34
50
|
allow(@application).to receive(:non_blocking?).and_return(false)
|
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: gopher2000
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.5.
|
4
|
+
version: 0.5.4
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Colin Mitchell
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date: 2020-01-
|
11
|
+
date: 2020-01-21 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: rspec
|