jellyfish 0.5.2 → 0.5.3
Sign up to get free protection for your applications and to get access to all the features.
- data/CHANGES.md +47 -0
- data/example/config.ru +5 -0
- data/jellyfish.gemspec +2 -2
- data/lib/jellyfish.rb +11 -0
- data/lib/jellyfish/sinatra.rb +8 -4
- data/lib/jellyfish/version.rb +1 -1
- metadata +2 -2
data/CHANGES.md
CHANGED
@@ -1,5 +1,52 @@
|
|
1
1
|
# CHANGES
|
2
2
|
|
3
|
+
## Jellyfish 0.5.3 -- 2012-10-26
|
4
|
+
|
5
|
+
### Enhancements for Jellyfish core
|
6
|
+
|
7
|
+
* Respond an empty string response if the block gives a nil.
|
8
|
+
* Added Jellyfish#log method which allow you to use the same
|
9
|
+
way as Jellyfish log things.
|
10
|
+
* rescue LocalJumpError and give a hint if you're trying to
|
11
|
+
return or break from the block. You should use `next` instead.
|
12
|
+
Or you can simply pass lambda which you can safely `return`.
|
13
|
+
For example: `get '/path', &lambda{ return "body" }`
|
14
|
+
|
15
|
+
### Enhancements for Sinatra flavored controller
|
16
|
+
|
17
|
+
* Introduced `initialize_params` and only initialize them whenever
|
18
|
+
it's not yet set, giving you the ability to initialize params
|
19
|
+
before calling `block_call`, thus you can customize params more
|
20
|
+
easily. An example for making NewRelic work would be like this:
|
21
|
+
|
22
|
+
``` ruby
|
23
|
+
class Controller < Api::Controller
|
24
|
+
include NewRelic::Agent::Instrumentation::ControllerInstrumentation
|
25
|
+
|
26
|
+
def block_call argument, block
|
27
|
+
path = if argument.respond_to?(:regexp)
|
28
|
+
argument.regexp
|
29
|
+
else
|
30
|
+
argument
|
31
|
+
end.to_s[1..-1]
|
32
|
+
name = "#{env['REQUEST_METHOD']} #{path}"
|
33
|
+
initialize_params(argument) # magic category, see:
|
34
|
+
# NewRelic::MetricParser::WebTransaction::Jellyfish
|
35
|
+
perform_action_with_newrelic_trace(:category => 'Controller/Jellyfish',
|
36
|
+
:path => path ,
|
37
|
+
:name => name ,
|
38
|
+
:request => request ,
|
39
|
+
:params => params ){ super }
|
40
|
+
end
|
41
|
+
end
|
42
|
+
|
43
|
+
module NewRelic::MetricParser::WebTransaction::Jellyfish
|
44
|
+
include NewRelic::MetricParser::WebTransaction::Pattern
|
45
|
+
def is_web_transaction?; true; end
|
46
|
+
def category ; 'Jellyfish'; end
|
47
|
+
end
|
48
|
+
```
|
49
|
+
|
3
50
|
## Jellyfish 0.5.2 -- 2012-10-20
|
4
51
|
|
5
52
|
### Incompatible changes
|
data/example/config.ru
CHANGED
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.
|
5
|
+
s.version = "0.5.3"
|
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-10-
|
9
|
+
s.date = "2012-10-26"
|
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 = [
|
data/lib/jellyfish.rb
CHANGED
@@ -42,7 +42,13 @@ module Jellyfish
|
|
42
42
|
def block_call argument, block
|
43
43
|
ret = instance_exec(argument, &block)
|
44
44
|
body ret if body.nil? # prefer explicitly set values
|
45
|
+
body '' if body.nil? # at least give an empty string
|
45
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
|
46
52
|
end
|
47
53
|
|
48
54
|
def forward ; raise(Jellyfish::NotFound.new) ; end
|
@@ -152,6 +158,11 @@ module Jellyfish
|
|
152
158
|
stderr.puts("[#{self.class.name}] #{e.inspect} #{e.backtrace}")
|
153
159
|
end
|
154
160
|
|
161
|
+
def log msg, stderr
|
162
|
+
return unless stderr
|
163
|
+
stderr.puts("[#{self.class.name}] #{msg}")
|
164
|
+
end
|
165
|
+
|
155
166
|
private
|
156
167
|
def handle ctrl, e, stderr=nil
|
157
168
|
handler = self.class.handlers.find{ |klass, block|
|
data/lib/jellyfish/sinatra.rb
CHANGED
@@ -6,18 +6,22 @@ module Jellyfish
|
|
6
6
|
class Sinatra < Controller
|
7
7
|
attr_reader :request, :params
|
8
8
|
def block_call argument, block
|
9
|
-
|
10
|
-
|
9
|
+
initialize_params(argument)
|
10
|
+
super
|
11
|
+
end
|
12
|
+
|
13
|
+
private
|
14
|
+
def initialize_params argument
|
15
|
+
@request ||= Rack::Request.new(env)
|
16
|
+
@params ||= force_encoding(indifferent_params(
|
11
17
|
if argument.kind_of?(MatchData)
|
12
18
|
# merge captured data from matcher into params as sinatra
|
13
19
|
request.params.merge(Hash[argument.names.zip(argument.captures)])
|
14
20
|
else
|
15
21
|
request.params
|
16
22
|
end))
|
17
|
-
super
|
18
23
|
end
|
19
24
|
|
20
|
-
private
|
21
25
|
# stolen from sinatra
|
22
26
|
# Enable string or symbol key access to the nested params hash.
|
23
27
|
def indifferent_params(params)
|
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.5.
|
4
|
+
version: 0.5.3
|
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-10-
|
12
|
+
date: 2012-10-26 00:00:00.000000000 Z
|
13
13
|
dependencies:
|
14
14
|
- !ruby/object:Gem::Dependency
|
15
15
|
name: rack
|