jellyfish 0.6.0 → 0.8.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.
@@ -0,0 +1,88 @@
1
+
2
+ require 'jellyfish/test'
3
+
4
+ describe 'Inheritance' do
5
+ behaves_like :jellyfish
6
+
7
+ should 'inherit routes' do
8
+ sup = Class.new{
9
+ include Jellyfish
10
+ get('/0'){ 'a' }
11
+ }
12
+ app = Class.new(sup){
13
+ get('/1'){ 'b' }
14
+ }.new
15
+
16
+ [['/0', 'a'], ['/1', 'b']].each do |(path, expect)|
17
+ _, _, body = get(path, app)
18
+ body.should.eq [expect]
19
+ end
20
+
21
+ _, _, body = get('/0', sup.new)
22
+ body.should.eq ['a']
23
+ status, _, _ = get('/1', sup.new)
24
+ status.should.eq 404
25
+
26
+ sup .routes['get'].size.should.eq 1
27
+ app.class.routes['get'].size.should.eq 2
28
+ end
29
+
30
+ should 'inherit handlers' do
31
+ sup = Class.new{
32
+ include Jellyfish
33
+ handle(TypeError){ 'a' }
34
+ get('/type') { raise TypeError }
35
+ get('/argue'){ raise ArgumentError }
36
+ }
37
+ app = Class.new(sup){
38
+ handle(ArgumentError){ 'b' }
39
+ }.new
40
+
41
+ [['/type', 'a'], ['/argue', 'b']].each do |(path, expect)|
42
+ _, _, body = get(path, app)
43
+ body.should.eq [expect]
44
+ end
45
+
46
+ sup .handlers.size.should.eq 1
47
+ app.class.handlers.size.should.eq 2
48
+ end
49
+
50
+ should 'inherit controller' do
51
+ sup = Class.new{
52
+ include Jellyfish
53
+ controller_include Module.new{ def f; 'a'; end }
54
+ get('/0'){ f }
55
+ }
56
+ app = Class.new(sup){
57
+ get('/1'){ f }
58
+ }.new
59
+
60
+ [['/0', 'a'], ['/1', 'a']].each do |(path, expect)|
61
+ _, _, body = get(path, app)
62
+ body.should.eq [expect]
63
+ end
64
+
65
+ sup .controller_include.size.should.eq 1
66
+ app.class.controller_include.size.should.eq 1
67
+ end
68
+
69
+ should 'inherit handle_exceptions' do
70
+ sup = Class.new{
71
+ include Jellyfish
72
+ handle_exceptions false
73
+ }
74
+ app = Class.new(sup)
75
+
76
+ sup.handle_exceptions.should.eq false
77
+ app.handle_exceptions.should.eq false
78
+
79
+ sup.handle_exceptions true
80
+ sup.handle_exceptions.should.eq true
81
+ app.handle_exceptions.should.eq false
82
+
83
+ sup.handle_exceptions false
84
+ app.handle_exceptions true
85
+ sup.handle_exceptions.should.eq false
86
+ app.handle_exceptions.should.eq true
87
+ end
88
+ end
metadata CHANGED
@@ -1,51 +1,46 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: jellyfish
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.6.0
5
- prerelease:
4
+ version: 0.8.0
6
5
  platform: ruby
7
6
  authors:
8
7
  - Lin Jen-Shin (godfat)
9
8
  autorequire:
10
9
  bindir: bin
11
10
  cert_chain: []
12
- date: 2012-11-02 00:00:00.000000000 Z
11
+ date: 2013-06-15 00:00:00.000000000 Z
13
12
  dependencies:
14
13
  - !ruby/object:Gem::Dependency
15
14
  name: rack
16
15
  requirement: !ruby/object:Gem::Requirement
17
- none: false
18
16
  requirements:
19
- - - ! '>='
17
+ - - '>='
20
18
  - !ruby/object:Gem::Version
21
19
  version: '0'
22
20
  type: :development
23
21
  prerelease: false
24
22
  version_requirements: !ruby/object:Gem::Requirement
25
- none: false
26
23
  requirements:
27
- - - ! '>='
24
+ - - '>='
28
25
  - !ruby/object:Gem::Version
29
26
  version: '0'
30
27
  - !ruby/object:Gem::Dependency
31
28
  name: bacon
32
29
  requirement: !ruby/object:Gem::Requirement
33
- none: false
34
30
  requirements:
35
- - - ! '>='
31
+ - - '>='
36
32
  - !ruby/object:Gem::Version
37
33
  version: '0'
38
34
  type: :development
39
35
  prerelease: false
40
36
  version_requirements: !ruby/object:Gem::Requirement
41
- none: false
42
37
  requirements:
43
- - - ! '>='
38
+ - - '>='
44
39
  - !ruby/object:Gem::Version
45
40
  version: '0'
46
- description: ! 'Pico web framework for building API-centric web applications.
47
-
48
- For Rack applications or Rack middlewares. Under 200 lines of code.'
41
+ description: |-
42
+ Pico web framework for building API-centric web applications.
43
+ For Rack applications or Rack middlewares. Around 200 lines of code.
49
44
  email:
50
45
  - godfat (XD) godfat.org
51
46
  executables: []
@@ -61,13 +56,14 @@ files:
61
56
  - README.md
62
57
  - Rakefile
63
58
  - TODO.md
64
- - example/config.ru
65
- - example/rainbows.rb
66
- - example/server.sh
67
59
  - jellyfish.gemspec
68
60
  - jellyfish.png
69
61
  - lib/jellyfish.rb
62
+ - lib/jellyfish/chunked_body.rb
63
+ - lib/jellyfish/multi_actions.rb
70
64
  - lib/jellyfish/newrelic.rb
65
+ - lib/jellyfish/normalized_params.rb
66
+ - lib/jellyfish/normalized_path.rb
71
67
  - lib/jellyfish/public/302.html
72
68
  - lib/jellyfish/public/404.html
73
69
  - lib/jellyfish/public/500.html
@@ -77,30 +73,41 @@ files:
77
73
  - task/.gitignore
78
74
  - task/gemgem.rb
79
75
  - test/sinatra/test_base.rb
76
+ - test/sinatra/test_chunked_body.rb
77
+ - test/sinatra/test_error.rb
78
+ - test/sinatra/test_multi_actions.rb
79
+ - test/sinatra/test_routing.rb
80
+ - test/test_from_readme.rb
81
+ - test/test_inheritance.rb
80
82
  homepage: https://github.com/godfat/jellyfish
81
- licenses: []
83
+ licenses:
84
+ - Apache License 2.0
85
+ metadata: {}
82
86
  post_install_message:
83
87
  rdoc_options: []
84
88
  require_paths:
85
89
  - lib
86
90
  required_ruby_version: !ruby/object:Gem::Requirement
87
- none: false
88
91
  requirements:
89
- - - ! '>='
92
+ - - '>='
90
93
  - !ruby/object:Gem::Version
91
94
  version: '0'
92
95
  required_rubygems_version: !ruby/object:Gem::Requirement
93
- none: false
94
96
  requirements:
95
- - - ! '>='
97
+ - - '>='
96
98
  - !ruby/object:Gem::Version
97
99
  version: '0'
98
100
  requirements: []
99
101
  rubyforge_project:
100
- rubygems_version: 1.8.24
102
+ rubygems_version: 2.0.3
101
103
  signing_key:
102
- specification_version: 3
104
+ specification_version: 4
103
105
  summary: Pico web framework for building API-centric web applications.
104
106
  test_files:
105
107
  - test/sinatra/test_base.rb
106
- has_rdoc:
108
+ - test/sinatra/test_chunked_body.rb
109
+ - test/sinatra/test_error.rb
110
+ - test/sinatra/test_multi_actions.rb
111
+ - test/sinatra/test_routing.rb
112
+ - test/test_from_readme.rb
113
+ - test/test_inheritance.rb
data/example/config.ru DELETED
@@ -1,118 +0,0 @@
1
-
2
- require 'jellyfish'
3
-
4
- Overheat = Class.new(RuntimeError)
5
-
6
- class Tank
7
- include Jellyfish
8
- handle_exceptions false
9
-
10
- get '/' do
11
- "Jelly Kelly\n"
12
- end
13
-
14
- get %r{^/(?<id>\d+)$} do |match|
15
- "Jelly ##{match[:id]}\n"
16
- end
17
-
18
- post '/' do
19
- headers 'X-Jellyfish-Life' => '100'
20
- headers_merge 'X-Jellyfish-Mana' => '200'
21
- body "Jellyfish 100/200\n"
22
- status 201
23
- 'return is ignored if body has already been set'
24
- end
25
-
26
- get '/env' do
27
- "#{env.inspect}\n"
28
- end
29
-
30
- get '/lookup' do
31
- found "#{env['rack.url_scheme']}://#{env['HTTP_HOST']}/"
32
- end
33
-
34
- get '/crash' do
35
- raise 'crash'
36
- end
37
-
38
- handle NameError do |e|
39
- status 403
40
- "No one hears you: #{e.backtrace.first}\n"
41
- end
42
-
43
- get '/yell' do
44
- yell
45
- end
46
-
47
- class Matcher
48
- def match path
49
- path.reverse == 'match/'
50
- end
51
- end
52
- get Matcher.new do |match|
53
- "#{match}\n"
54
- end
55
-
56
- class Body
57
- def each
58
- if Object.const_defined?(:Rainbows)
59
- (0..4).each{ |i| yield "#{i}\n"; Rainbows.sleep(0.1) }
60
- else
61
- yield "You need Rainbows + FiberSpawn (or so) for this\n"
62
- end
63
- end
64
- end
65
- get '/chunked' do
66
- Body.new
67
- end
68
-
69
- get '/overheat' do
70
- raise Overheat
71
- end
72
-
73
- # get a hint that use `next' instead;
74
- get '/return' do; return; end
75
- get '/break' do; break ; end
76
- get '/next' do; next ; end # this works
77
- end
78
-
79
- class Heater
80
- include Jellyfish
81
- handle Overheat do
82
- status 500
83
- "It's overheated\n"
84
- end
85
-
86
- get '/status' do
87
- temperature
88
- end
89
-
90
- get %r{^/sinatra/(?<id>\d+)$} do
91
- "#{params[:id]}\n"
92
- end
93
-
94
- def controller; Controller; end
95
- class Controller < Jellyfish::Controller
96
- include Jellyfish::Sinatra
97
- include Jellyfish::NewRelic
98
- def temperature
99
- "30\u{2103}\n"
100
- end
101
- end
102
- end
103
-
104
- HugeTank = Rack::Builder.new do
105
- use Rack::Chunked # order does matter, need to check Content-Length first
106
- use Rack::ContentLength
107
- use Rack::ContentType, 'text/plain'
108
- use Heater
109
- run Tank.new
110
- end
111
-
112
- require 'cgi' # newrelic needs this
113
- require 'new_relic/rack/developer_mode'
114
- use NewRelic::Rack::DeveloperMode
115
-
116
- run HugeTank
117
-
118
- NewRelic::Agent.manual_start(:developer_mode => true)
data/example/rainbows.rb DELETED
@@ -1,4 +0,0 @@
1
-
2
- Rainbows! do
3
- use :FiberSpawn
4
- end
data/example/server.sh DELETED
@@ -1,3 +0,0 @@
1
- #!/bin/sh
2
-
3
- rainbows -Ilib -c example/rainbows.rb example/config.ru