grape-msgpack 0.0.1 → 0.1.0
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/.coveralls.yml +1 -0
- data/Gemfile +2 -0
- data/README.md +1 -1
- data/lib/grape/msgpack.rb +20 -6
- data/lib/grape/msgpack/version.rb +1 -1
- data/spec/grape/msgpack_spec.rb +20 -3
- data/spec/spec_helper.rb +3 -0
- metadata +2 -1
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 8d57fed528cc20e364e3a0f876d892891c3a4d5d
|
4
|
+
data.tar.gz: cf68377db5ba1fd4d26a131d563e59d3b8a99b31
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: c983d61542f1adbc1fe08e158bb999757c773db64a6cde0f4c96939c71414ca9a0a3dc0cfda1343821dda47de962aa3208b633a6345ccb709641f7be56936f9c
|
7
|
+
data.tar.gz: 5f0c6637a5528e5723877a05056bbeb22147e22f838af2dcabbc3981cea52389f8967dd6f0703eb05c7decfb180cd162cd8e32da068ab755c30cb8cc5461ac67
|
data/.coveralls.yml
ADDED
@@ -0,0 +1 @@
|
|
1
|
+
service_name: travis-ci
|
data/Gemfile
CHANGED
data/README.md
CHANGED
@@ -1,6 +1,6 @@
|
|
1
1
|
# Grape::Msgpack
|
2
2
|
|
3
|
-
[![Build Status](https://travis-ci.org/rosylilly/grape-msgpack.png?branch=master)](https://travis-ci.org/rosylilly/grape-msgpack)
|
3
|
+
[![Gem Version](https://badge.fury.io/rb/grape-msgpack.png)](http://badge.fury.io/rb/grape-msgpack) [![Build Status](https://travis-ci.org/rosylilly/grape-msgpack.png?branch=master)](https://travis-ci.org/rosylilly/grape-msgpack) [![Coverage Status](https://coveralls.io/repos/rosylilly/grape-msgpack/badge.png?branch=master)](https://coveralls.io/r/rosylilly/grape-msgpack?branch=master)
|
4
4
|
|
5
5
|
Message pack formatter for grape.
|
6
6
|
|
data/lib/grape/msgpack.rb
CHANGED
@@ -5,21 +5,35 @@ require 'grape/msgpack/version'
|
|
5
5
|
module Grape
|
6
6
|
# Message pack formatter for Grape
|
7
7
|
module Msgpack
|
8
|
-
|
9
|
-
|
10
|
-
|
11
|
-
|
8
|
+
module Formatter
|
9
|
+
class << self
|
10
|
+
def call(obj, env)
|
11
|
+
return obj.to_msgpack if obj.respond_to?(:to_msgpack)
|
12
|
+
MessagePack.pack(obj)
|
13
|
+
end
|
14
|
+
end
|
15
|
+
end
|
16
|
+
|
17
|
+
module ErrorFormatter
|
18
|
+
class << self
|
19
|
+
def call(message, backtrace, options = {}, env = nil)
|
20
|
+
result = message.is_a?(Hash) ? message : { error: message }
|
21
|
+
if (options[:rescue_options] || {})[:backtrace] && backtrace && !backtrace.empty?
|
22
|
+
result = result.merge(backtrace: backtrace)
|
23
|
+
end
|
24
|
+
MessagePack.pack(result)
|
25
|
+
end
|
12
26
|
end
|
13
27
|
end
|
14
28
|
end
|
15
29
|
end
|
16
30
|
|
17
31
|
class << Grape::Formatter::Base
|
18
|
-
FORMATTERS[:msgpack] = Grape::Msgpack
|
32
|
+
FORMATTERS[:msgpack] = Grape::Msgpack::Formatter
|
19
33
|
end
|
20
34
|
|
21
35
|
class << Grape::ErrorFormatter::Base
|
22
|
-
FORMATTERS[:msgpack] = Grape::Msgpack
|
36
|
+
FORMATTERS[:msgpack] = Grape::Msgpack::ErrorFormatter
|
23
37
|
end
|
24
38
|
|
25
39
|
Grape::ContentTypes::CONTENT_TYPES[:msgpack] = 'application/x-msgpack'
|
data/spec/grape/msgpack_spec.rb
CHANGED
@@ -16,6 +16,8 @@ class MockEntity < Grape::Entity
|
|
16
16
|
end
|
17
17
|
|
18
18
|
class MockAPI < Grape::API
|
19
|
+
rescue_from :all
|
20
|
+
|
19
21
|
default_format :msgpack
|
20
22
|
|
21
23
|
get :test do
|
@@ -25,6 +27,10 @@ class MockAPI < Grape::API
|
|
25
27
|
get :model do
|
26
28
|
present MockModel.new('test_user', 21), with: MockEntity
|
27
29
|
end
|
30
|
+
|
31
|
+
get :exception do
|
32
|
+
raise StandardError, 'an error occurred'
|
33
|
+
end
|
28
34
|
end
|
29
35
|
|
30
36
|
describe MockAPI do
|
@@ -41,7 +47,7 @@ describe MockAPI do
|
|
41
47
|
end
|
42
48
|
|
43
49
|
it { expect(response.status).to eq(200) }
|
44
|
-
it { expect(response.headers[
|
50
|
+
it { expect(response.headers['Content-Type']).to eq('application/x-msgpack') }
|
45
51
|
it { expect(MessagePack.unpack(response.body)).to eq([1, 2, 3]) }
|
46
52
|
end
|
47
53
|
|
@@ -52,7 +58,18 @@ describe MockAPI do
|
|
52
58
|
end
|
53
59
|
|
54
60
|
it { expect(response.status).to eq(200) }
|
55
|
-
it { expect(response.headers[
|
56
|
-
it { expect(MessagePack.unpack(response.body)).to eq(
|
61
|
+
it { expect(response.headers['Content-Type']).to eq('application/x-msgpack') }
|
62
|
+
it { expect(MessagePack.unpack(response.body)).to eq('name' => 'test_user') }
|
63
|
+
end
|
64
|
+
|
65
|
+
describe 'GET /exception' do
|
66
|
+
subject(:response) do
|
67
|
+
get '/exception'
|
68
|
+
last_response
|
69
|
+
end
|
70
|
+
|
71
|
+
it { expect(response.status).to eq(403) }
|
72
|
+
it { expect(response.headers['Content-Type']).to eq('application/x-msgpack') }
|
73
|
+
it { expect(MessagePack.unpack(response.body)).to eq('error' => 'an error occurred') }
|
57
74
|
end
|
58
75
|
end
|
data/spec/spec_helper.rb
CHANGED
metadata
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: grape-msgpack
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.0
|
4
|
+
version: 0.1.0
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Sho Kusano
|
@@ -115,6 +115,7 @@ executables: []
|
|
115
115
|
extensions: []
|
116
116
|
extra_rdoc_files: []
|
117
117
|
files:
|
118
|
+
- .coveralls.yml
|
118
119
|
- .gitignore
|
119
120
|
- .rspec
|
120
121
|
- .travis.yml
|