rack_format_response 0.0.1 → 0.0.2
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.
- data/README +1 -1
- data/Rakefile +1 -1
- data/lib/rack/format_response.rb +4 -16
- metadata +3 -3
data/README
CHANGED
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.
|
9
|
+
GEM_VERSION = "0.0.2"
|
10
10
|
|
11
11
|
spec = Gem::Specification.new do |s|
|
12
12
|
s.rubyforge_project = 'asakusarb'
|
data/lib/rack/format_response.rb
CHANGED
@@ -48,20 +48,16 @@ module Rack
|
|
48
48
|
|
49
49
|
def call(env)
|
50
50
|
@status, @headers, body = @app.call(env)
|
51
|
-
body =
|
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 =
|
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
|
-
-
|
9
|
-
version: 0.0.
|
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-
|
17
|
+
date: 2010-09-15 00:00:00 +09:00
|
18
18
|
default_executable:
|
19
19
|
dependencies: []
|
20
20
|
|