grape-msgpack 0.0.1 → 0.1.0

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.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: cd48218f961f5483fe6ee240467e0c94f98c6063
4
- data.tar.gz: 29de7ae2759c8f0bfdd97a7c0a23259e6db0c920
3
+ metadata.gz: 8d57fed528cc20e364e3a0f876d892891c3a4d5d
4
+ data.tar.gz: cf68377db5ba1fd4d26a131d563e59d3b8a99b31
5
5
  SHA512:
6
- metadata.gz: a25e281c2bc76cfb875609ddc37fdb6989cf371e9eb109b94bad133eb3ed3b3b52c560e01df2cf48d393d710c8a984fe44df6760838d3dd64f2f285d458940a2
7
- data.tar.gz: bb42efd5b3ced23b92e2690afd34177c3c042515b21e482d2a9e7b947e8f56e374b27443be5bb1b46bd592fc9bb826aba3ad6064bdf7b675d75a5fdc10713aa7
6
+ metadata.gz: c983d61542f1adbc1fe08e158bb999757c773db64a6cde0f4c96939c71414ca9a0a3dc0cfda1343821dda47de962aa3208b633a6345ccb709641f7be56936f9c
7
+ data.tar.gz: 5f0c6637a5528e5723877a05056bbeb22147e22f838af2dcabbc3981cea52389f8967dd6f0703eb05c7decfb180cd162cd8e32da068ab755c30cb8cc5461ac67
data/.coveralls.yml ADDED
@@ -0,0 +1 @@
1
+ service_name: travis-ci
data/Gemfile CHANGED
@@ -2,3 +2,5 @@ source 'https://rubygems.org'
2
2
 
3
3
  # Specify your gem's dependencies in grape-msgpack.gemspec
4
4
  gemspec
5
+
6
+ gem 'coveralls', require: false
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
- class << self
9
- def call(obj, env)
10
- return obj.to_msgpack if obj.respond_to?(:to_msgpack)
11
- MessagePack.pack(obj)
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'
@@ -1,5 +1,5 @@
1
1
  module Grape
2
2
  module Msgpack
3
- VERSION = '0.0.1'
3
+ VERSION = '0.1.0'
4
4
  end
5
5
  end
@@ -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["Content-Type"]).to eq('application/x-msgpack') }
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["Content-Type"]).to eq('application/x-msgpack') }
56
- it { expect(MessagePack.unpack(response.body)).to eq("name" => "test_user") }
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
@@ -1,3 +1,6 @@
1
+ require 'coveralls'
2
+ Coveralls.wear!
3
+
1
4
  RSpec.configure do |config|
2
5
  config.treat_symbols_as_metadata_keys_with_true_values = true
3
6
  config.run_all_when_everything_filtered = true
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.1
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