grape-active_model_serializers 1.2.1 → 1.3.1

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: 5e9d5adc2e060c4ff6cb0ff20b716af5ac60b65f
4
- data.tar.gz: 1175bcd15b520733dca73731304eb07c1ef41ff1
3
+ metadata.gz: 3d1fc34293532a51eb2a8694d46c26d874b56d3c
4
+ data.tar.gz: dd6d159497a55ee86f431402f02e0991cfae55c9
5
5
  SHA512:
6
- metadata.gz: 2253fc66827baafc811df441f44e6d44119a19a6c5b3c926d3a643259a6cafe3059eb9cf2c9523a973900884093dd30ba374de6c178d333477462e67efc501d3
7
- data.tar.gz: e5e75c33e502cd1b41d1e94ad2b9489cd26cc47f3dfff68e1692445d7366f61d1eb4bb91bd681bf5391b78dce23c315f1a93166790a9f99e77408a1b061a93f3
6
+ metadata.gz: 1012cd5e379a6dd9b988cb23d02d84bc12e6c95a4a2b61390762f7f8bccab6cf4c55254bee506bb8d59a8ca82ab581e30c411a2bfdf09a6e78c979660007c06a
7
+ data.tar.gz: 4b9d9dbbd00137e3ed063ccc357efd36aeaabe6a446c2960022c951417cd2abf0b2bd1b175283da38af0bc67f568792b2e589edbbb5b999ff7898fd6282fe5c6
data/.gitignore CHANGED
@@ -16,3 +16,4 @@ rerun.txt
16
16
  pickle-email-*.html
17
17
  Gemfile.lock
18
18
  .DS_Store
19
+ *.gem
data/Gemfile CHANGED
@@ -1,7 +1,3 @@
1
1
  source 'https://rubygems.org'
2
2
 
3
3
  gemspec
4
-
5
- group :test do
6
- gem 'jazz_hands', git: 'https://github.com/jrhe/jazz_hands.git', branch: 'without_rails'
7
- end
data/README.md CHANGED
@@ -82,18 +82,18 @@ end
82
82
 
83
83
  ```ruby
84
84
  # Serializer options can be specified on routes or namespaces.
85
- namespace 'foo', :serializer => :bar do
85
+ namespace 'foo', :serializer => BarSerializer do
86
86
  get "/" do
87
87
  # will use "bar" serializer
88
88
  end
89
89
 
90
90
  # Options specified on a route or namespace override those of the containing namespace.
91
- get "/home", :serializer => :home do
91
+ get "/home", :serializer => HomeSerializer do
92
92
  # will use "home" serializer
93
93
  end
94
94
 
95
95
  # All standard options for `ActiveModel::Serializers` are supported.
96
- get "/fancy_homes", :root => 'world', :each_serializer => :fancy_homes
96
+ get "/fancy_homes", :root => 'world', :each_serializer => FancyHomesSerializer
97
97
  ...
98
98
  end
99
99
  end
@@ -109,6 +109,16 @@ get "/homes"
109
109
  end
110
110
  ```
111
111
 
112
+ ### Support for `default_serializer_options`
113
+
114
+ ```ruby
115
+ helper do
116
+ def default_serializer_options
117
+ {only: params[:only], except: params[:except]}
118
+ end
119
+ end
120
+ ```
121
+
112
122
  ### current_user
113
123
 
114
124
  One of the nice features of ActiveModel::Serializers is that it
@@ -170,6 +180,10 @@ Enjoy :)
170
180
 
171
181
  ## Changelog
172
182
 
183
+ #### v1.2.1
184
+ * Adds support for active model serializer 0.9.x
185
+
186
+
173
187
  #### v1.0.0
174
188
  * Released on rubygems.org
175
189
  * *BREAKING* Changes behaviour of root keys when serialising arrays. See [Array roots](https://github.com/jrhe/grape-active_model_serializers#array-roots)
@@ -17,11 +17,10 @@ Gem::Specification.new do |gem|
17
17
  gem.licenses = ['MIT']
18
18
 
19
19
  gem.add_dependency "grape", "~> 0.3"
20
- gem.add_dependency "active_model_serializers", ">= 0.9.0.alpha1"
20
+ gem.add_dependency "active_model_serializers", ">= 0.9.0"
21
21
 
22
22
  gem.add_development_dependency "rspec"
23
23
  gem.add_development_dependency "rack-test"
24
24
  gem.add_development_dependency "rake"
25
- gem.add_development_dependency "jazz_hands"
26
- gem.add_development_dependency 'guard-rspec'
25
+ gem.add_development_dependency "guard-rspec"
27
26
  end
@@ -1,8 +1,10 @@
1
1
  rvm:
2
2
  - 1.9.2
3
3
  - 1.9.3
4
+ - 2.0.0
5
+ - 2.1.2
4
6
  - ruby-head
5
7
  - rbx-19mode
6
8
 
7
9
  env:
8
- - JRUBY_OPTS="--1.9"
10
+ - JRUBY_OPTS="--1.9"
@@ -17,7 +17,7 @@ module Grape
17
17
  options = build_options_from_endpoint(endpoint)
18
18
 
19
19
  if serializer = options.fetch(:serializer, ActiveModel::Serializer.serializer_for(resource))
20
- options[:scope] = serialization_scope unless options.has_key?(:scope)
20
+ options[:scope] = endpoint unless options.has_key?(:scope)
21
21
  # ensure we have an root to fallback on
22
22
  options[:resource_name] = default_root(endpoint) if resource.respond_to?(:to_ary)
23
23
  serializer.new(resource, options.merge(other_options))
@@ -56,7 +56,7 @@ module Grape
56
56
  end
57
57
 
58
58
  def build_options_from_endpoint(endpoint)
59
- endpoint.namespace_options.merge(endpoint.route_options)
59
+ [endpoint.default_serializer_options || {}, endpoint.namespace_options, endpoint.route_options].reduce(:merge)
60
60
  end
61
61
 
62
62
  # array root is the innermost namespace name ('space') if there is one,
@@ -70,10 +70,6 @@ module Grape
70
70
  endpoint.options[:path][0].to_s.split('/')[-1]
71
71
  end
72
72
  end
73
-
74
- def serialization_scope
75
- :current_user
76
- end
77
73
  end
78
74
  end
79
75
  end
@@ -1,5 +1,5 @@
1
1
  module Grape
2
2
  module ActiveModelSerializers
3
- VERSION = '1.2.1'
3
+ VERSION = '1.3.1'
4
4
  end
5
5
  end
@@ -1,7 +1,4 @@
1
1
  require 'spec_helper'
2
- require 'support/models/user'
3
- require 'support/serializers/user_serializer'
4
- require 'grape-active_model_serializers'
5
2
  require 'securerandom'
6
3
 
7
4
  describe '#render' do
@@ -2,17 +2,17 @@ require 'spec_helper'
2
2
 
3
3
  describe 'Grape::EndpointExtension' do
4
4
 
5
- subject { Grape::Endpoint.new(nil, {path: '/', method: 'foo'}) }
5
+ subject { Grape::Endpoint.new({}, {path: '/', method: 'foo'}) }
6
6
 
7
7
  let(:serializer) { Grape::Formatter::ActiveModelSerializers }
8
8
 
9
9
  let(:user) do
10
- Object.new do
11
- def name
12
- 'sven'
13
- end
14
- end
15
- end
10
+ Object.new do
11
+ def name
12
+ 'sven'
13
+ end
14
+ end
15
+ end
16
16
 
17
17
  let(:users) { [user, user] }
18
18
 
@@ -31,4 +31,33 @@ describe Grape::Formatter::ActiveModelSerializers do
31
31
  expect(subject.meta_key).to eq({ meta_key: :custom_key_name })
32
32
  end
33
33
  end
34
+
35
+ describe '.fetch_serializer' do
36
+ let(:user) { User.new(first_name: 'John') }
37
+ let(:endpoint) { Grape::Endpoint.new({}, {path: '/', method: 'foo'}) }
38
+ let(:env) { { 'api.endpoint' => endpoint } }
39
+
40
+ before do
41
+ def endpoint.current_user
42
+ @current_user ||= User.new(first_name: 'Current user')
43
+ end
44
+
45
+ def endpoint.default_serializer_options
46
+ { only: :only, except: :except }
47
+ end
48
+ end
49
+
50
+ subject { described_class.fetch_serializer(user, env) }
51
+
52
+ it { should be_a UserSerializer }
53
+
54
+ it 'should have correct scope set' do
55
+ expect(subject.scope.current_user).to eq(endpoint.current_user)
56
+ end
57
+
58
+ it 'should read default serializer options' do
59
+ expect(subject.instance_variable_get('@only')).to eq([:only])
60
+ expect(subject.instance_variable_get('@except')).to eq([:except])
61
+ end
62
+ end
34
63
  end
@@ -9,8 +9,7 @@ require 'active_support/core_ext/hash/conversions'
9
9
  require "active_support/json"
10
10
  require 'rspec'
11
11
  require 'rack/test'
12
-
13
- require 'jazz_hands'
12
+ require 'grape-active_model_serializers'
14
13
 
15
14
  RSpec.configure do |config|
16
15
  config.include Rack::Test::Methods
metadata CHANGED
@@ -1,111 +1,97 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: grape-active_model_serializers
3
3
  version: !ruby/object:Gem::Version
4
- version: 1.2.1
4
+ version: 1.3.1
5
5
  platform: ruby
6
6
  authors:
7
7
  - Jonathan Richard Henry Evans
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2014-07-23 00:00:00.000000000 Z
11
+ date: 2014-11-20 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: grape
15
15
  requirement: !ruby/object:Gem::Requirement
16
16
  requirements:
17
- - - "~>"
17
+ - - ~>
18
18
  - !ruby/object:Gem::Version
19
19
  version: '0.3'
20
20
  type: :runtime
21
21
  prerelease: false
22
22
  version_requirements: !ruby/object:Gem::Requirement
23
23
  requirements:
24
- - - "~>"
24
+ - - ~>
25
25
  - !ruby/object:Gem::Version
26
26
  version: '0.3'
27
27
  - !ruby/object:Gem::Dependency
28
28
  name: active_model_serializers
29
29
  requirement: !ruby/object:Gem::Requirement
30
30
  requirements:
31
- - - ">="
31
+ - - '>='
32
32
  - !ruby/object:Gem::Version
33
- version: 0.9.0.alpha1
33
+ version: 0.9.0
34
34
  type: :runtime
35
35
  prerelease: false
36
36
  version_requirements: !ruby/object:Gem::Requirement
37
37
  requirements:
38
- - - ">="
38
+ - - '>='
39
39
  - !ruby/object:Gem::Version
40
- version: 0.9.0.alpha1
40
+ version: 0.9.0
41
41
  - !ruby/object:Gem::Dependency
42
42
  name: rspec
43
43
  requirement: !ruby/object:Gem::Requirement
44
44
  requirements:
45
- - - ">="
45
+ - - '>='
46
46
  - !ruby/object:Gem::Version
47
47
  version: '0'
48
48
  type: :development
49
49
  prerelease: false
50
50
  version_requirements: !ruby/object:Gem::Requirement
51
51
  requirements:
52
- - - ">="
52
+ - - '>='
53
53
  - !ruby/object:Gem::Version
54
54
  version: '0'
55
55
  - !ruby/object:Gem::Dependency
56
56
  name: rack-test
57
57
  requirement: !ruby/object:Gem::Requirement
58
58
  requirements:
59
- - - ">="
59
+ - - '>='
60
60
  - !ruby/object:Gem::Version
61
61
  version: '0'
62
62
  type: :development
63
63
  prerelease: false
64
64
  version_requirements: !ruby/object:Gem::Requirement
65
65
  requirements:
66
- - - ">="
66
+ - - '>='
67
67
  - !ruby/object:Gem::Version
68
68
  version: '0'
69
69
  - !ruby/object:Gem::Dependency
70
70
  name: rake
71
71
  requirement: !ruby/object:Gem::Requirement
72
72
  requirements:
73
- - - ">="
73
+ - - '>='
74
74
  - !ruby/object:Gem::Version
75
75
  version: '0'
76
76
  type: :development
77
77
  prerelease: false
78
78
  version_requirements: !ruby/object:Gem::Requirement
79
79
  requirements:
80
- - - ">="
81
- - !ruby/object:Gem::Version
82
- version: '0'
83
- - !ruby/object:Gem::Dependency
84
- name: jazz_hands
85
- requirement: !ruby/object:Gem::Requirement
86
- requirements:
87
- - - ">="
88
- - !ruby/object:Gem::Version
89
- version: '0'
90
- type: :development
91
- prerelease: false
92
- version_requirements: !ruby/object:Gem::Requirement
93
- requirements:
94
- - - ">="
80
+ - - '>='
95
81
  - !ruby/object:Gem::Version
96
82
  version: '0'
97
83
  - !ruby/object:Gem::Dependency
98
84
  name: guard-rspec
99
85
  requirement: !ruby/object:Gem::Requirement
100
86
  requirements:
101
- - - ">="
87
+ - - '>='
102
88
  - !ruby/object:Gem::Version
103
89
  version: '0'
104
90
  type: :development
105
91
  prerelease: false
106
92
  version_requirements: !ruby/object:Gem::Requirement
107
93
  requirements:
108
- - - ">="
94
+ - - '>='
109
95
  - !ruby/object:Gem::Version
110
96
  version: '0'
111
97
  description: Provides a Formatter for the Grape API DSL to emit objects serialized
@@ -116,7 +102,7 @@ executables: []
116
102
  extensions: []
117
103
  extra_rdoc_files: []
118
104
  files:
119
- - ".gitignore"
105
+ - .gitignore
120
106
  - Gemfile
121
107
  - Guardfile
122
108
  - LICENSE.txt
@@ -149,17 +135,17 @@ require_paths:
149
135
  - lib
150
136
  required_ruby_version: !ruby/object:Gem::Requirement
151
137
  requirements:
152
- - - ">="
138
+ - - '>='
153
139
  - !ruby/object:Gem::Version
154
140
  version: '0'
155
141
  required_rubygems_version: !ruby/object:Gem::Requirement
156
142
  requirements:
157
- - - ">="
143
+ - - '>='
158
144
  - !ruby/object:Gem::Version
159
145
  version: '0'
160
146
  requirements: []
161
147
  rubyforge_project:
162
- rubygems_version: 2.2.0
148
+ rubygems_version: 2.0.14
163
149
  signing_key:
164
150
  specification_version: 4
165
151
  summary: Use active_model_serializer in grape
@@ -174,4 +160,3 @@ test_files:
174
160
  - spec/support/models/user.rb
175
161
  - spec/support/serializers/blog_post_serializer.rb
176
162
  - spec/support/serializers/user_serializer.rb
177
- has_rdoc: