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 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
@@ -69,6 +69,11 @@ class Tank
69
69
  get '/overheat' do
70
70
  raise Overheat
71
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
72
77
  end
73
78
 
74
79
  class Heater
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.2"
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-20"
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|
@@ -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
- @request = Rack::Request.new(env)
10
- @params = force_encoding(indifferent_params(
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)
@@ -1,4 +1,4 @@
1
1
 
2
2
  module Jellyfish
3
- VERSION = '0.5.2'
3
+ VERSION = '0.5.3'
4
4
  end
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.2
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-20 00:00:00.000000000 Z
12
+ date: 2012-10-26 00:00:00.000000000 Z
13
13
  dependencies:
14
14
  - !ruby/object:Gem::Dependency
15
15
  name: rack