rack_format_response 0.0.1 → 0.0.2

Sign up to get free protection for your applications and to get access to all the features.
Files changed (4) hide show
  1. data/README +1 -1
  2. data/Rakefile +1 -1
  3. data/lib/rack/format_response.rb +4 -16
  4. metadata +3 -3
data/README CHANGED
@@ -77,7 +77,7 @@ NOTE
77
77
  In default, this module converts hash to json with Yajl gem.
78
78
  Install it first for json use.
79
79
 
80
- gem install yajl
80
+ gem install yajl-ruby
81
81
 
82
82
  # Yajl is a fastest json library where I know
83
83
 
data/Rakefile CHANGED
@@ -6,7 +6,7 @@ AUTHOR = "maiha"
6
6
  EMAIL = "maiha@wota.jp"
7
7
  HOMEPAGE = "http://github.com/maiha/rack_format_response"
8
8
  SUMMARY = "A Rack middleware for automatically formatting response body"
9
- GEM_VERSION = "0.0.1"
9
+ GEM_VERSION = "0.0.2"
10
10
 
11
11
  spec = Gem::Specification.new do |s|
12
12
  s.rubyforge_project = 'asakusarb'
@@ -48,20 +48,16 @@ module Rack
48
48
 
49
49
  def call(env)
50
50
  @status, @headers, body = @app.call(env)
51
- body = [apply(body)].flatten
51
+ body = apply(body)
52
52
  [@status, @headers, @body || body]
53
53
  end
54
54
 
55
55
  private
56
- def lookup(body)
57
- body = body[0] if body.class == Array and body.size == 1
58
- MAPPINGS[body.class.name] or
59
- "format_" + body.class.name.gsub(/::/,'_').downcase
60
- end
61
-
62
56
  def apply(data)
63
- func = lookup(data)
57
+ func = MAPPINGS[data.class.name]
64
58
  case func
59
+ when NilClass
60
+ return data
65
61
  when Proc
66
62
  return func.call(data)
67
63
  when Symbol, String
@@ -75,14 +71,6 @@ module Rack
75
71
  ######################################################################
76
72
  ### Formatters
77
73
 
78
- def format_array(ary)
79
- ary
80
- end
81
-
82
- def format_string(str)
83
- str
84
- end
85
-
86
74
  def format_hash_to_json(hash)
87
75
  require 'yajl'
88
76
  @headers['Content-Type'] = "application/json;charset=utf-8"
metadata CHANGED
@@ -5,8 +5,8 @@ version: !ruby/object:Gem::Version
5
5
  segments:
6
6
  - 0
7
7
  - 0
8
- - 1
9
- version: 0.0.1
8
+ - 2
9
+ version: 0.0.2
10
10
  platform: ruby
11
11
  authors:
12
12
  - maiha
@@ -14,7 +14,7 @@ autorequire:
14
14
  bindir: bin
15
15
  cert_chain: []
16
16
 
17
- date: 2010-09-08 00:00:00 +09:00
17
+ date: 2010-09-15 00:00:00 +09:00
18
18
  default_executable:
19
19
  dependencies: []
20
20