jellyfish 1.1.1 → 1.2.0
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.
- checksums.yaml +5 -5
- data/.travis.yml +14 -11
- data/CHANGES.md +21 -0
- data/README.md +125 -60
- data/Rakefile +4 -4
- data/TODO.md +2 -0
- data/jellyfish.gemspec +69 -69
- data/lib/jellyfish.rb +10 -8
- data/lib/jellyfish/builder.rb +11 -6
- data/lib/jellyfish/test.rb +10 -2
- data/lib/jellyfish/urlmap.rb +74 -9
- data/lib/jellyfish/version.rb +1 -1
- data/task/README.md +8 -8
- data/task/gemgem.rb +29 -7
- data/test/rack/test_builder.rb +1 -1
- data/test/rack/test_urlmap.rb +67 -9
- data/test/test_from_readme.rb +13 -10
- data/test/test_listen.rb +64 -0
- data/test/test_rewrite.rb +8 -6
- data/test/test_websocket.rb +6 -3
- metadata +6 -6
- data/jellyfish.png +0 -0
- data/lib/jellyfish/newrelic.rb +0 -24
data/test/test_from_readme.rb
CHANGED
@@ -4,6 +4,8 @@ require 'uri'
|
|
4
4
|
require 'stringio'
|
5
5
|
|
6
6
|
describe 'from README.md' do
|
7
|
+
paste :stringio
|
8
|
+
|
7
9
|
after do
|
8
10
|
[:Tank, :Heater, :Protector].each do |const|
|
9
11
|
Object.send(:remove_const, const) if Object.const_defined?(const)
|
@@ -11,20 +13,17 @@ describe 'from README.md' do
|
|
11
13
|
Muack.verify
|
12
14
|
end
|
13
15
|
|
14
|
-
readme = File.read(
|
15
|
-
"#{File.dirname(File.expand_path(__FILE__))}/../README.md")
|
16
|
+
readme = File.read("#{__dir__}/../README.md")
|
16
17
|
codes = readme.scan(
|
17
18
|
/### ([^\n]+).+?``` ruby\n(.+?)\n```\n\n<!---(.+?)-->/m)
|
18
19
|
|
19
20
|
codes.each.with_index do |(title, code, test), index|
|
20
|
-
next if title =~ /NewRelic/i
|
21
|
-
|
22
21
|
would "pass from README.md #%02d #{title}" % index do
|
23
22
|
app = Rack::Builder.app{ eval(code) }
|
24
23
|
|
25
24
|
test.split("\n\n").each do |t|
|
26
25
|
method_path, expect = t.strip.split("\n", 2)
|
27
|
-
method, path
|
26
|
+
method, path, host = method_path.split(' ')
|
28
27
|
uri = URI.parse(path)
|
29
28
|
pinfo, query = uri.path, uri.query
|
30
29
|
|
@@ -32,11 +31,15 @@ describe 'from README.md' do
|
|
32
31
|
status, headers, body = File.open(File::NULL) do |input|
|
33
32
|
app.call(
|
34
33
|
'HTTP_VERSION' => 'HTTP/1.1',
|
35
|
-
'REQUEST_METHOD' => method,
|
36
|
-
'
|
37
|
-
'
|
34
|
+
'REQUEST_METHOD' => method,
|
35
|
+
'HTTP_HOST' => host,
|
36
|
+
'PATH_INFO' => pinfo,
|
37
|
+
'SCRIPT_NAME' => '',
|
38
|
+
'QUERY_STRING' => query,
|
39
|
+
'rack.input' => input,
|
40
|
+
'rack.url_scheme'=> 'http',
|
38
41
|
'rack.hijack' => lambda{
|
39
|
-
sock =
|
42
|
+
sock = new_stringio
|
40
43
|
# or TypeError: no implicit conversion of StringIO into IO
|
41
44
|
mock(IO).select([sock]){ [[sock], [], []] }
|
42
45
|
sock
|
@@ -44,7 +47,7 @@ describe 'from README.md' do
|
|
44
47
|
end
|
45
48
|
|
46
49
|
if hijack = headers.delete('rack.hijack')
|
47
|
-
sock =
|
50
|
+
sock = new_stringio
|
48
51
|
hijack.call(sock)
|
49
52
|
body = sock.string.each_line("\n\n")
|
50
53
|
end
|
data/test/test_listen.rb
ADDED
@@ -0,0 +1,64 @@
|
|
1
|
+
|
2
|
+
require 'jellyfish/test'
|
3
|
+
require 'jellyfish/urlmap'
|
4
|
+
|
5
|
+
describe Jellyfish::URLMap do
|
6
|
+
paste :jellyfish
|
7
|
+
|
8
|
+
lam = lambda{ |env| [200, {}, ["lam #{env['HTTP_HOST']}"]] }
|
9
|
+
ram = lambda{ |env| [200, {}, ["ram #{env['HTTP_HOST']}"]] }
|
10
|
+
|
11
|
+
def call app, host, path='/'
|
12
|
+
get('/', app, 'HTTP_HOST' => host, 'PATH_INFO' => path).dig(-1, 0)
|
13
|
+
end
|
14
|
+
|
15
|
+
would 'map host' do
|
16
|
+
app = Jellyfish::Builder.app do
|
17
|
+
map '/', host: 'host' do
|
18
|
+
run lam
|
19
|
+
end
|
20
|
+
|
21
|
+
run ram
|
22
|
+
end
|
23
|
+
|
24
|
+
expect(call(app, 'host')).eq 'lam host'
|
25
|
+
expect(call(app, 'lust')).eq 'ram lust'
|
26
|
+
end
|
27
|
+
|
28
|
+
would 'listen' do
|
29
|
+
app = Jellyfish::Builder.app do
|
30
|
+
listen 'host' do
|
31
|
+
run lam
|
32
|
+
end
|
33
|
+
|
34
|
+
listen 'lust' do
|
35
|
+
run ram
|
36
|
+
end
|
37
|
+
end
|
38
|
+
|
39
|
+
expect(call(app, 'host')).eq 'lam host'
|
40
|
+
expect(call(app, 'lust')).eq 'ram lust'
|
41
|
+
expect(call(app, 'boom')).eq nil
|
42
|
+
end
|
43
|
+
|
44
|
+
would 'nest' do
|
45
|
+
app = Jellyfish::Builder.app do
|
46
|
+
listen 'host' do
|
47
|
+
map '/host' do
|
48
|
+
run lam
|
49
|
+
end
|
50
|
+
end
|
51
|
+
|
52
|
+
listen 'lust' do
|
53
|
+
map '/lust' do
|
54
|
+
run ram
|
55
|
+
end
|
56
|
+
end
|
57
|
+
end
|
58
|
+
|
59
|
+
expect(call(app, 'host', '/host')).eq 'lam host'
|
60
|
+
expect(call(app, 'lust', '/lust')).eq 'ram lust'
|
61
|
+
expect(call(app, 'boom', '/host')).eq nil
|
62
|
+
expect(call(app, 'boom', '/lust')).eq nil
|
63
|
+
end
|
64
|
+
end
|
data/test/test_rewrite.rb
CHANGED
@@ -3,10 +3,12 @@ require 'jellyfish/test'
|
|
3
3
|
require 'jellyfish/urlmap'
|
4
4
|
|
5
5
|
describe Jellyfish::Rewrite do
|
6
|
+
paste :jellyfish
|
7
|
+
|
6
8
|
lam = lambda{ |env| [200, {}, [env['PATH_INFO']]] }
|
7
9
|
|
8
|
-
def call app,
|
9
|
-
app.
|
10
|
+
def call app, path
|
11
|
+
get(path, app).dig(-1, 0)
|
10
12
|
end
|
11
13
|
|
12
14
|
would 'map to' do
|
@@ -16,7 +18,7 @@ describe Jellyfish::Rewrite do
|
|
16
18
|
end
|
17
19
|
end
|
18
20
|
|
19
|
-
expect(call(app, '
|
21
|
+
expect(call(app, '/from')).eq '/to'
|
20
22
|
end
|
21
23
|
|
22
24
|
would 'rewrite and fallback' do
|
@@ -31,8 +33,8 @@ describe Jellyfish::Rewrite do
|
|
31
33
|
end
|
32
34
|
end
|
33
35
|
|
34
|
-
expect(call(app, '
|
35
|
-
expect(call(app, '
|
36
|
-
expect(call(app, '
|
36
|
+
expect(call(app, '/from' )).eq ''
|
37
|
+
expect(call(app, '/from/inner')).eq '/to/inner'
|
38
|
+
expect(call(app, '/from/outer')).eq '/to/outer'
|
37
39
|
end
|
38
40
|
end
|
data/test/test_websocket.rb
CHANGED
@@ -2,7 +2,9 @@
|
|
2
2
|
require 'jellyfish/test'
|
3
3
|
require 'stringio'
|
4
4
|
|
5
|
-
describe Jellyfish do
|
5
|
+
describe Jellyfish::WebSocket do
|
6
|
+
paste :stringio
|
7
|
+
|
6
8
|
after do
|
7
9
|
Muack.verify
|
8
10
|
end
|
@@ -21,6 +23,7 @@ describe Jellyfish do
|
|
21
23
|
|
22
24
|
def create_env
|
23
25
|
sock = StringIO.new
|
26
|
+
sock.set_encoding('ASCII-8BIT')
|
24
27
|
mock(IO).select([sock]) do # or EOFError, not sure why?
|
25
28
|
sock << WebSocket::Message.new('pong').to_data * 2
|
26
29
|
[[sock], [], []]
|
@@ -32,13 +35,13 @@ describe Jellyfish do
|
|
32
35
|
would 'ping pong' do
|
33
36
|
env, sock = create_env
|
34
37
|
app.call(env)
|
35
|
-
sock.string.should.eq <<-HTTP.chomp
|
38
|
+
sock.string.should.eq <<-HTTP.chomp.force_encoding('ASCII-8BIT')
|
36
39
|
HTTP/1.1 101 Switching Protocols\r
|
37
40
|
Upgrade: websocket\r
|
38
41
|
Connection: Upgrade\r
|
39
42
|
Sec-WebSocket-Accept: Kfh9QIsMVZcl6xEPYxPHzW8SZ8w=\r
|
40
43
|
\r
|
41
|
-
\x81\
|
44
|
+
\x81\x04ping\x81\x04pong\x81\x04pong
|
42
45
|
HTTP
|
43
46
|
end
|
44
47
|
end
|
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: jellyfish
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 1.
|
4
|
+
version: 1.2.0
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Lin Jen-Shin (godfat)
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date:
|
11
|
+
date: 2018-07-14 00:00:00.000000000 Z
|
12
12
|
dependencies: []
|
13
13
|
description: |-
|
14
14
|
Pico web framework for building API-centric web applications.
|
@@ -35,12 +35,10 @@ files:
|
|
35
35
|
- bench/bench_builder.rb
|
36
36
|
- config.ru
|
37
37
|
- jellyfish.gemspec
|
38
|
-
- jellyfish.png
|
39
38
|
- lib/jellyfish.rb
|
40
39
|
- lib/jellyfish/builder.rb
|
41
40
|
- lib/jellyfish/chunked_body.rb
|
42
41
|
- lib/jellyfish/json.rb
|
43
|
-
- lib/jellyfish/newrelic.rb
|
44
42
|
- lib/jellyfish/normalized_params.rb
|
45
43
|
- lib/jellyfish/normalized_path.rb
|
46
44
|
- lib/jellyfish/public/302.html
|
@@ -61,6 +59,7 @@ files:
|
|
61
59
|
- test/sinatra/test_routing.rb
|
62
60
|
- test/test_from_readme.rb
|
63
61
|
- test/test_inheritance.rb
|
62
|
+
- test/test_listen.rb
|
64
63
|
- test/test_log.rb
|
65
64
|
- test/test_misc.rb
|
66
65
|
- test/test_rewrite.rb
|
@@ -68,7 +67,7 @@ files:
|
|
68
67
|
- test/test_websocket.rb
|
69
68
|
homepage: https://github.com/godfat/jellyfish
|
70
69
|
licenses:
|
71
|
-
- Apache
|
70
|
+
- Apache-2.0
|
72
71
|
metadata: {}
|
73
72
|
post_install_message:
|
74
73
|
rdoc_options: []
|
@@ -86,7 +85,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
|
|
86
85
|
version: '0'
|
87
86
|
requirements: []
|
88
87
|
rubyforge_project:
|
89
|
-
rubygems_version: 2.
|
88
|
+
rubygems_version: 2.7.7
|
90
89
|
signing_key:
|
91
90
|
specification_version: 4
|
92
91
|
summary: Pico web framework for building API-centric web applications.
|
@@ -99,6 +98,7 @@ test_files:
|
|
99
98
|
- test/sinatra/test_routing.rb
|
100
99
|
- test/test_from_readme.rb
|
101
100
|
- test/test_inheritance.rb
|
101
|
+
- test/test_listen.rb
|
102
102
|
- test/test_log.rb
|
103
103
|
- test/test_misc.rb
|
104
104
|
- test/test_rewrite.rb
|
data/jellyfish.png
DELETED
Binary file
|
data/lib/jellyfish/newrelic.rb
DELETED
@@ -1,24 +0,0 @@
|
|
1
|
-
|
2
|
-
require 'jellyfish'
|
3
|
-
require 'rack/request'
|
4
|
-
require 'new_relic/agent/instrumentation/controller_instrumentation'
|
5
|
-
|
6
|
-
module Jellyfish
|
7
|
-
module NewRelic
|
8
|
-
include ::NewRelic::Agent::Instrumentation::ControllerInstrumentation
|
9
|
-
|
10
|
-
def block_call argument, block
|
11
|
-
path = if argument.respond_to?(:regexp)
|
12
|
-
argument.regexp
|
13
|
-
else
|
14
|
-
argument
|
15
|
-
end.to_s[1..-1]
|
16
|
-
name = "#{env['REQUEST_METHOD']} #{path}"
|
17
|
-
|
18
|
-
perform_action_with_newrelic_trace(:category => :rack ,
|
19
|
-
:name => name ,
|
20
|
-
:request => request,
|
21
|
-
:params => request.params){super}
|
22
|
-
end
|
23
|
-
end
|
24
|
-
end
|