jellyfish 0.5.3 → 0.6.0
Sign up to get free protection for your applications and to get access to all the features.
- data/CHANGES.md +40 -0
- data/README.md +27 -1
- data/example/config.ru +13 -1
- data/jellyfish.gemspec +3 -2
- data/lib/jellyfish.rb +23 -21
- data/lib/jellyfish/newrelic.rb +32 -0
- data/lib/jellyfish/sinatra.rb +3 -4
- data/lib/jellyfish/version.rb +1 -1
- metadata +3 -2
data/CHANGES.md
CHANGED
@@ -1,5 +1,45 @@
|
|
1
1
|
# CHANGES
|
2
2
|
|
3
|
+
## Jellyfish 0.6.0 -- 2012-11-02
|
4
|
+
|
5
|
+
### Enhancements for Jellyfish core
|
6
|
+
|
7
|
+
* Extracted Jellyfish::Controller#call and Jellyfish::Controller#block_call
|
8
|
+
into Jellyfish::Controller::Call so that you can have modules which can
|
9
|
+
override call and block_call. See Jellyfish::Sinatra and Jellyfish::NewRelic
|
10
|
+
for an example.
|
11
|
+
|
12
|
+
* Now you can use `request` in the controller, which is essentially:
|
13
|
+
`@request ||= Rack::Request.new(env)`. This also means you would need
|
14
|
+
Rack installed and required to use it. Other than this, there's no
|
15
|
+
strict requirement for Rack.
|
16
|
+
|
17
|
+
### Enhancements for NewRelic
|
18
|
+
|
19
|
+
* Added Jellyfish::NewRelic which makes you work easier with NewRelic.
|
20
|
+
Here's an example of how to use it: (extracted from README)
|
21
|
+
|
22
|
+
``` ruby
|
23
|
+
require 'jellyfish'
|
24
|
+
class Tank
|
25
|
+
include Jellyfish
|
26
|
+
class MyController < Jellyfish::Controller
|
27
|
+
include Jellyfish::NewRelic
|
28
|
+
end
|
29
|
+
def controller; MyController; end
|
30
|
+
get '/' do
|
31
|
+
"OK\n"
|
32
|
+
end
|
33
|
+
end
|
34
|
+
use Rack::ContentLength
|
35
|
+
use Rack::ContentType, 'text/plain'
|
36
|
+
require 'cgi' # newrelic dev mode needs this and it won't require it itself
|
37
|
+
require 'new_relic/rack/developer_mode'
|
38
|
+
use NewRelic::Rack::DeveloperMode # GET /newrelic to read stats
|
39
|
+
run Tank.new
|
40
|
+
NewRelic::Agent.manual_start(:developer_mode => true)
|
41
|
+
```
|
42
|
+
|
3
43
|
## Jellyfish 0.5.3 -- 2012-10-26
|
4
44
|
|
5
45
|
### Enhancements for Jellyfish core
|
data/README.md
CHANGED
@@ -201,7 +201,10 @@ Currently support:
|
|
201
201
|
require 'jellyfish'
|
202
202
|
class Tank
|
203
203
|
include Jellyfish
|
204
|
-
|
204
|
+
class MyController < Jellyfish::Controller
|
205
|
+
include Jellyfish::Sinatra
|
206
|
+
end
|
207
|
+
def controller; MyController; end
|
205
208
|
get %r{^/(?<id>\d+)$} do
|
206
209
|
"Jelly ##{params[:id]}\n"
|
207
210
|
end
|
@@ -211,6 +214,29 @@ use Rack::ContentType, 'text/plain'
|
|
211
214
|
run Tank.new
|
212
215
|
```
|
213
216
|
|
217
|
+
### Using NewRelic?
|
218
|
+
|
219
|
+
``` ruby
|
220
|
+
require 'jellyfish'
|
221
|
+
class Tank
|
222
|
+
include Jellyfish
|
223
|
+
class MyController < Jellyfish::Controller
|
224
|
+
include Jellyfish::NewRelic
|
225
|
+
end
|
226
|
+
def controller; MyController; end
|
227
|
+
get '/' do
|
228
|
+
"OK\n"
|
229
|
+
end
|
230
|
+
end
|
231
|
+
use Rack::ContentLength
|
232
|
+
use Rack::ContentType, 'text/plain'
|
233
|
+
require 'cgi' # newrelic dev mode needs this and it won't require it itself
|
234
|
+
require 'new_relic/rack/developer_mode'
|
235
|
+
use NewRelic::Rack::DeveloperMode # GET /newrelic to read stats
|
236
|
+
run Tank.new
|
237
|
+
NewRelic::Agent.manual_start(:developer_mode => true)
|
238
|
+
```
|
239
|
+
|
214
240
|
### Jellyfish as a middleware
|
215
241
|
|
216
242
|
``` ruby
|
data/example/config.ru
CHANGED
@@ -87,8 +87,14 @@ class Heater
|
|
87
87
|
temperature
|
88
88
|
end
|
89
89
|
|
90
|
+
get %r{^/sinatra/(?<id>\d+)$} do
|
91
|
+
"#{params[:id]}\n"
|
92
|
+
end
|
93
|
+
|
90
94
|
def controller; Controller; end
|
91
95
|
class Controller < Jellyfish::Controller
|
96
|
+
include Jellyfish::Sinatra
|
97
|
+
include Jellyfish::NewRelic
|
92
98
|
def temperature
|
93
99
|
"30\u{2103}\n"
|
94
100
|
end
|
@@ -96,11 +102,17 @@ class Heater
|
|
96
102
|
end
|
97
103
|
|
98
104
|
HugeTank = Rack::Builder.new do
|
99
|
-
use Rack::Chunked
|
105
|
+
use Rack::Chunked # order does matter, need to check Content-Length first
|
100
106
|
use Rack::ContentLength
|
101
107
|
use Rack::ContentType, 'text/plain'
|
102
108
|
use Heater
|
103
109
|
run Tank.new
|
104
110
|
end
|
105
111
|
|
112
|
+
require 'cgi' # newrelic needs this
|
113
|
+
require 'new_relic/rack/developer_mode'
|
114
|
+
use NewRelic::Rack::DeveloperMode
|
115
|
+
|
106
116
|
run HugeTank
|
117
|
+
|
118
|
+
NewRelic::Agent.manual_start(:developer_mode => true)
|
data/jellyfish.gemspec
CHANGED
@@ -2,11 +2,11 @@
|
|
2
2
|
|
3
3
|
Gem::Specification.new do |s|
|
4
4
|
s.name = "jellyfish"
|
5
|
-
s.version = "0.
|
5
|
+
s.version = "0.6.0"
|
6
6
|
|
7
7
|
s.required_rubygems_version = Gem::Requirement.new(">= 0") if s.respond_to? :required_rubygems_version=
|
8
8
|
s.authors = ["Lin Jen-Shin (godfat)"]
|
9
|
-
s.date = "2012-
|
9
|
+
s.date = "2012-11-02"
|
10
10
|
s.description = "Pico web framework for building API-centric web applications.\nFor Rack applications or Rack middlewares. Under 200 lines of code."
|
11
11
|
s.email = ["godfat (XD) godfat.org"]
|
12
12
|
s.files = [
|
@@ -25,6 +25,7 @@ Gem::Specification.new do |s|
|
|
25
25
|
"jellyfish.gemspec",
|
26
26
|
"jellyfish.png",
|
27
27
|
"lib/jellyfish.rb",
|
28
|
+
"lib/jellyfish/newrelic.rb",
|
28
29
|
"lib/jellyfish/public/302.html",
|
29
30
|
"lib/jellyfish/public/404.html",
|
30
31
|
"lib/jellyfish/public/500.html",
|
data/lib/jellyfish.rb
CHANGED
@@ -1,9 +1,8 @@
|
|
1
1
|
|
2
2
|
module Jellyfish
|
3
|
-
autoload :VERSION, 'jellyfish/version'
|
4
|
-
autoload :Sinatra, 'jellyfish/sinatra'
|
5
|
-
|
6
|
-
# -----------------------------------------------------------------
|
3
|
+
autoload :VERSION , 'jellyfish/version'
|
4
|
+
autoload :Sinatra , 'jellyfish/sinatra'
|
5
|
+
autoload :NewRelic, 'jellyfish/newrelic'
|
7
6
|
|
8
7
|
class Response < RuntimeError
|
9
8
|
def headers
|
@@ -28,29 +27,32 @@ module Jellyfish
|
|
28
27
|
# -----------------------------------------------------------------
|
29
28
|
|
30
29
|
class Controller
|
30
|
+
module Call
|
31
|
+
def call env
|
32
|
+
@env = env
|
33
|
+
block_call(*dispatch)
|
34
|
+
end
|
35
|
+
|
36
|
+
def block_call argument, block
|
37
|
+
ret = instance_exec(argument, &block)
|
38
|
+
body ret if body.nil? # prefer explicitly set values
|
39
|
+
body '' if body.nil? # at least give an empty string
|
40
|
+
[status || 200, headers || {}, body]
|
41
|
+
rescue LocalJumpError
|
42
|
+
jellyfish.log("Use `next' if you're trying to `return' or" \
|
43
|
+
" `break' from the block.", env['rack.errors'])
|
44
|
+
raise
|
45
|
+
end
|
46
|
+
end
|
47
|
+
include Call
|
48
|
+
|
31
49
|
attr_reader :routes, :jellyfish, :env
|
32
50
|
def initialize routes, jellyfish
|
33
51
|
@routes, @jellyfish = routes, jellyfish
|
34
52
|
@status, @headers, @body = nil
|
35
53
|
end
|
36
54
|
|
37
|
-
def
|
38
|
-
@env = env
|
39
|
-
block_call(*dispatch)
|
40
|
-
end
|
41
|
-
|
42
|
-
def block_call argument, block
|
43
|
-
ret = instance_exec(argument, &block)
|
44
|
-
body ret if body.nil? # prefer explicitly set values
|
45
|
-
body '' if body.nil? # at least give an empty string
|
46
|
-
[status || 200, headers || {}, body]
|
47
|
-
rescue LocalJumpError
|
48
|
-
jellyfish.log(
|
49
|
-
"Use `next' if you're trying to `return' or `break' from the block.",
|
50
|
-
env['rack.errors'])
|
51
|
-
raise
|
52
|
-
end
|
53
|
-
|
55
|
+
def request ; @request ||= Rack::Request.new(env); end
|
54
56
|
def forward ; raise(Jellyfish::NotFound.new) ; end
|
55
57
|
def found url; raise(Jellyfish:: Found.new(url)); end
|
56
58
|
alias_method :redirect, :found
|
@@ -0,0 +1,32 @@
|
|
1
|
+
|
2
|
+
require 'jellyfish'
|
3
|
+
require 'rack/request'
|
4
|
+
|
5
|
+
require 'new_relic/agent/instrumentation/controller_instrumentation'
|
6
|
+
|
7
|
+
module Jellyfish
|
8
|
+
module NewRelic
|
9
|
+
include ::NewRelic::Agent::Instrumentation::ControllerInstrumentation
|
10
|
+
|
11
|
+
def block_call argument, block
|
12
|
+
path = if argument.respond_to?(:regexp)
|
13
|
+
argument.regexp
|
14
|
+
else
|
15
|
+
argument
|
16
|
+
end.to_s[1..-1]
|
17
|
+
name = "#{env['REQUEST_METHOD']} #{path}"
|
18
|
+
# magic category: NewRelic::MetricParser::WebTransaction::Jellyfish
|
19
|
+
perform_action_with_newrelic_trace(:category => 'Controller/Jellyfish',
|
20
|
+
:path => path ,
|
21
|
+
:name => name ,
|
22
|
+
:request => request ,
|
23
|
+
:params => request.params){super}
|
24
|
+
end
|
25
|
+
end
|
26
|
+
end
|
27
|
+
|
28
|
+
module NewRelic::MetricParser::WebTransaction::Jellyfish
|
29
|
+
include NewRelic::MetricParser::WebTransaction::Pattern
|
30
|
+
def is_web_transaction?; true; end
|
31
|
+
def category ; 'Jellyfish'; end
|
32
|
+
end
|
data/lib/jellyfish/sinatra.rb
CHANGED
@@ -3,8 +3,8 @@ require 'jellyfish'
|
|
3
3
|
require 'rack/request'
|
4
4
|
|
5
5
|
module Jellyfish
|
6
|
-
|
7
|
-
attr_reader :
|
6
|
+
module Sinatra
|
7
|
+
attr_reader :params
|
8
8
|
def block_call argument, block
|
9
9
|
initialize_params(argument)
|
10
10
|
super
|
@@ -12,8 +12,7 @@ module Jellyfish
|
|
12
12
|
|
13
13
|
private
|
14
14
|
def initialize_params argument
|
15
|
-
@
|
16
|
-
@params ||= force_encoding(indifferent_params(
|
15
|
+
@params ||= force_encoding(indifferent_params(
|
17
16
|
if argument.kind_of?(MatchData)
|
18
17
|
# merge captured data from matcher into params as sinatra
|
19
18
|
request.params.merge(Hash[argument.names.zip(argument.captures)])
|
data/lib/jellyfish/version.rb
CHANGED
metadata
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: jellyfish
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.
|
4
|
+
version: 0.6.0
|
5
5
|
prerelease:
|
6
6
|
platform: ruby
|
7
7
|
authors:
|
@@ -9,7 +9,7 @@ authors:
|
|
9
9
|
autorequire:
|
10
10
|
bindir: bin
|
11
11
|
cert_chain: []
|
12
|
-
date: 2012-
|
12
|
+
date: 2012-11-02 00:00:00.000000000 Z
|
13
13
|
dependencies:
|
14
14
|
- !ruby/object:Gem::Dependency
|
15
15
|
name: rack
|
@@ -67,6 +67,7 @@ files:
|
|
67
67
|
- jellyfish.gemspec
|
68
68
|
- jellyfish.png
|
69
69
|
- lib/jellyfish.rb
|
70
|
+
- lib/jellyfish/newrelic.rb
|
70
71
|
- lib/jellyfish/public/302.html
|
71
72
|
- lib/jellyfish/public/404.html
|
72
73
|
- lib/jellyfish/public/500.html
|