fast_jsonapi 1.0.16 → 1.0.17

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: b3264df8a99356f622a1ae64d3342b4053db4034
4
- data.tar.gz: ff8f3b5f94425a792ea7e91ae71a03e37e329187
3
+ metadata.gz: c5fa6a70751601bec882ccec2e0e70b3b76fd084
4
+ data.tar.gz: 307516586bee4df357afb385ee89776bc118cd13
5
5
  SHA512:
6
- metadata.gz: 2f360b1b12b52ea8655592613fbce505d8fe79c2458ee58d2ae1e6e17f30ece72f6c9781f3dd116b1e4ddbada91f2abb36bda960c8c09ff83ba54441b089a0db
7
- data.tar.gz: 596aa63a06c578396193f55fbefaeb69c957632ad90efe270213c1fa345114fea0c2fddec419aa9b2459a09ea4ba93a03e87874995ebec5cf247b9747bd16a0c
6
+ metadata.gz: 982f868f471f0ad64e8d424ba3fe1313f0c14ee841b87ce8920d68816ef8d306f18b5b39be13eaffdf7c00ed888be3059195c7008f8541dfeefe2036ebd4c1ad
7
+ data.tar.gz: 27aef6f9b9e7fb5b94f881c190814dcc7d44d6919118cf732f42a77fe5bf941644bcfbef9986417926a68981d3c00bcfc35276504a0294b2dd2445968b4cab1e
data/Gemfile CHANGED
@@ -1,23 +1,4 @@
1
- # Add gem dependencies here.
2
- gem "activesupport", "~> 5.0"
3
- gem "multi_json", "~> 1.12"
4
- gem "oj", "~> 3.3"
1
+ source 'https://rubygems.org'
5
2
 
6
- # needed to send active support notifications to skylight
7
- gem "skylight", "~> 1.3"
8
-
9
- # needed because of the extension/has_one.rb
10
- gem "activerecord", "~> 5.0"
11
-
12
- # Add dependencies to develop and test the gem here
13
- group :development do
14
- gem "rspec", "~> 3.5.0"
15
- gem "rspec-benchmark", "~> 0.3.0"
16
- gem "rdoc", "~> 3.12"
17
- gem "bundler", "~> 1.0"
18
- gem "juwelier", "~> 2.1.0"
19
- gem "simplecov", ">= 0"
20
- gem "byebug"
21
- gem "active_model_serializers", "~> 0.10.4"
22
- gem "sqlite3", "~> 1.3"
23
- end
3
+ # Specify your gem's dependencies in fast_jsonapi.gemspec
4
+ gemspec
data/Gemfile.lock CHANGED
@@ -1,3 +1,12 @@
1
+ PATH
2
+ remote: .
3
+ specs:
4
+ fast_jsonapi (1.0.16)
5
+ activerecord (~> 5.0)
6
+ activesupport (~> 5.0)
7
+ multi_json (~> 1.12)
8
+ oj (~> 3.3)
9
+
1
10
  GEM
2
11
  remote: https://rubygems.org/
3
12
  specs:
@@ -134,13 +143,10 @@ PLATFORMS
134
143
 
135
144
  DEPENDENCIES
136
145
  active_model_serializers (~> 0.10.4)
137
- activerecord (~> 5.0)
138
- activesupport (~> 5.0)
139
146
  bundler (~> 1.0)
140
147
  byebug
148
+ fast_jsonapi!
141
149
  juwelier (~> 2.1.0)
142
- multi_json (~> 1.12)
143
- oj (~> 3.3)
144
150
  rdoc (~> 3.12)
145
151
  rspec (~> 3.5.0)
146
152
  rspec-benchmark (~> 0.3.0)
data/README.md CHANGED
@@ -4,16 +4,16 @@
4
4
 
5
5
  A lightning fast [JSON:API](http://jsonapi.org/) serializer for Ruby Objects.
6
6
 
7
- # Performance Comparision
7
+ # Performance Comparison
8
8
 
9
9
  We compare serialization times with Active Model Serializer as part of RSpec performance tests included on this library. We want to ensure that with every change on this library, serialization time is at least `25 times` faster than Active Model Serializers on up to current benchmark of 1000 records.
10
10
 
11
11
  ## Benchmark times for 250 records
12
12
 
13
13
  ```bash
14
- $ rspec
15
- Active Model Serializer serialized 250 records in 138.71 ms
16
- Fast JSON API serialized 250 records in 3.01 ms
14
+ $ rspec
15
+ Active Model Serializer serialized 250 records in 138.71 ms
16
+ Fast JSON API serialized 250 records in 3.01 ms
17
17
  ```
18
18
 
19
19
  # Table of Contents
@@ -32,8 +32,8 @@ We compare serialization times with Active Model Serializer as part of RSpec per
32
32
 
33
33
  ## Features
34
34
 
35
- * Declaration syntax similar to Active Model serializer
36
- * Support for belongs_to, has_many and has_one
35
+ * Declaration syntax similar to Active Model Serializer
36
+ * Support for `belongs_to`, `has_many` and `has_one`
37
37
  * Support for compound documents (included)
38
38
  * Optimized serialization of compound documents
39
39
  * Caching
@@ -48,7 +48,7 @@ gem 'fast_jsonapi'
48
48
 
49
49
  Execute:
50
50
 
51
- ```ruby
51
+ ```bash
52
52
  $ bundle install
53
53
  ```
54
54
 
@@ -78,13 +78,13 @@ end
78
78
  ### Sample Object
79
79
 
80
80
  ```ruby
81
- m = Movie.new
82
- m.id = 232
83
- m.name = 'test movie'
84
- m.actor_ids = [1, 2, 3]
85
- m.owner_id = 3
86
- m.movie_type_id = 1
87
- m
81
+ movie = Movie.new
82
+ movie.id = 232
83
+ movie.name = 'test movie'
84
+ movie.actor_ids = [1, 2, 3]
85
+ movie.owner_id = 3
86
+ movie.movie_type_id = 1
87
+ movie
88
88
  ```
89
89
 
90
90
  ### Object Serialization
@@ -153,15 +153,13 @@ hash = MovieSerializer.new([movie, movie], options).serializable_hash
153
153
  json_string = MovieSerializer.new([movie, movie], options).serialized_json
154
154
  ```
155
155
 
156
- [Output String](https://github.com/Netflix/fast_jsonapi/blob/master/docs/collection_serializer_output.md)
157
-
158
156
  ### Caching
159
157
 
160
158
  ```ruby
161
159
  class MovieSerializer
162
160
  include FastJsonapi::ObjectSerializer
163
161
  set_type :movie # optional
164
- cache_options enabled: true cache_length: 12.hours
162
+ cache_options enabled: true, cache_length: 12.hours
165
163
  attributes :name, :year
166
164
  end
167
165
  ```
@@ -171,12 +169,11 @@ end
171
169
  Option | Purpose | Example
172
170
  ------------ | ------------- | -------------
173
171
  set_type | Type name of Object | ```set_type :movie ```
174
- cache_options | Hash to enable caching and set cache length | ```cache_options enabled: true cache_length: 12.hours```
172
+ cache_options | Hash to enable caching and set cache length | ```cache_options enabled: true, cache_length: 12.hours```
175
173
  id_method_name | Set custom method name to get ID of an object | ```has_many :locations, id_method_name: :place_ids ```
176
174
  object_method_name | Set custom method name to get related objects | ```has_many :locations, object_method_name: :places ```
177
175
  record_type | Set custom Object Type for a relationship | ```belongs_to :owner, record_type: :user```
178
176
  serializer | Set custom Serializer for a relationship | ```has_many :actors, serializer: :custom_actor```
179
- cache_options | Hash to enable caching and set cache length | ```cache_options enabled: true cache_length: 12.hours ```
180
177
 
181
178
 
182
179
  ## Contributing
@@ -190,14 +187,14 @@ rake -T
190
187
  ```
191
188
 
192
189
  ### Updating Project information
193
- You can update the project information of the gem by updating the [Rakefile](Rakefile). Then you need to generate a new gemspec
190
+ You can update the project information of the gem by updating the [Rakefile](Rakefile). Then you need to generate a new gemspec:
194
191
 
195
192
  ```bash
196
193
  rake gemspec
197
194
  ```
198
195
 
199
196
  ### Running Tests
200
- We use rspec for testing. We have unit tests, functional tests and performance tests. To run tests use the following rake task
197
+ We use [RSpec](http://rspec.info/) for testing. We have unit tests, functional tests and performance tests. To run tests use the following rake task:
201
198
 
202
199
  ```bash
203
200
  rake spec
@@ -209,16 +206,16 @@ rake spec
209
206
  $ rake install
210
207
  ```
211
208
 
212
- The install rake task builds the gem installs it. You're all
209
+ The install rake task builds the gem and then installs it. You're all
213
210
  set if you're using [RVM](http://rvm.beginrescueend.com/), but you may
214
- need to run it with sudo if you have a system-installed ruby:
211
+ need to run it with sudo if you have a system-installed Ruby:
215
212
 
216
213
  ### Bumping Version
217
214
 
218
215
  It feels good to release code. Do it, do it often. But before that, bump
219
216
  the version. Then release it. There's a few ways to update the version:
220
217
 
221
- ```ruby
218
+ ```bash
222
219
  # version:write like before
223
220
  $ rake version:write MAJOR=0 MINOR=3 PATCH=0
224
221
 
@@ -231,3 +228,12 @@ $ rake version:bump:minor
231
228
  # bump just patch, ie 0.1.0 -> 0.1.1
232
229
  $ rake version:bump:patch
233
230
  ```
231
+
232
+ ---
233
+
234
+ ### We're Hiring!
235
+
236
+ Join the Netflix Studio Engineering team and help us build gems like this!
237
+
238
+ * [Senior Ruby Engineer](https://jobs.netflix.com/jobs/864893)
239
+ * [Senior Platform Engineer](https://jobs.netflix.com/jobs/865783)
data/README.rdoc CHANGED
@@ -1,18 +1,231 @@
1
- = fast_jsonapi
1
+ # Fast JSON API
2
2
 
3
- Description goes here.
3
+ [![NetflixOSS Lifecycle](https://img.shields.io/osslifecycle/Netflix/osstracker.svg)]()
4
4
 
5
- == Contributing to fast_jsonapi
6
-
7
- * Check out the latest master to make sure the feature hasn't been implemented or the bug hasn't been fixed yet.
8
- * Check out the issue tracker to make sure someone already hasn't requested it and/or contributed it.
9
- * Fork the project.
10
- * Start a feature/bugfix branch.
11
- * Commit and push until you are happy with your contribution.
12
- * Make sure to add tests for it. This is important so I don't break it in a future version unintentionally.
13
- * Please try not to mess with the Rakefile, version, or history. If you want to have your own version, or is otherwise necessary, that is fine, but please isolate to its own commit so I can cherry-pick around it.
5
+ A lightning fast [JSON:API](http://jsonapi.org/) serializer for Ruby Objects.
14
6
 
15
- == Copyright
7
+ # Performance Comparision
16
8
 
17
- Copyright (c) 2017 Shishir Kakaraddi. See LICENSE.txt for
18
- further details.
9
+ We compare serialization times with Active Model Serializer as part of RSpec performance tests included on this library. We want to ensure that with every change on this library, serialization time is at least `25 times` faster than Active Model Serializers on up to current benchmark of 1000 records.
10
+
11
+ ## Benchmark times for 250 records
12
+
13
+ ```bash
14
+ $ rspec
15
+ Active Model Serializer serialized 250 records in 138.71 ms
16
+ Fast JSON API serialized 250 records in 3.01 ms
17
+ ```
18
+
19
+ # Table of Contents
20
+
21
+ * [Features](#features)
22
+ * [Installation](#installation)
23
+ * [Usage](#usage)
24
+ * [Model Definition](#model-definition)
25
+ * [Serializer Definition](#serializer-definition)
26
+ * [Object Serialization](#object-serialization)
27
+ * [Compound Document](#compound-document)
28
+ * [Collection Serialization](#collection-serialization)
29
+ * [Caching](#caching)
30
+ * [Contributing](#contributing)
31
+
32
+
33
+ ## Features
34
+
35
+ * Declaration syntax similar to Active Model serializer
36
+ * Support for belongs_to, has_many and has_one
37
+ * Support for compound documents (included)
38
+ * Optimized serialization of compound documents
39
+ * Caching
40
+
41
+ ## Installation
42
+
43
+ Add this line to your application's Gemfile:
44
+
45
+ ```ruby
46
+ gem 'fast_jsonapi'
47
+ ```
48
+
49
+ Execute:
50
+
51
+ ```ruby
52
+ $ bundle install
53
+ ```
54
+
55
+ ## Usage
56
+
57
+ ### Model Definition
58
+
59
+ ```ruby
60
+ class Movie
61
+ attr_accessor :id, :name, :year, :actor_ids, :owner_id
62
+ end
63
+ ```
64
+
65
+ ### Serializer Definition
66
+
67
+ ```ruby
68
+ class MovieSerializer
69
+ include FastJsonapi::ObjectSerializer
70
+ set_type :movie # optional
71
+ attributes :name, :year
72
+ has_many :actors
73
+ belongs_to :owner, record_type: :user
74
+ belongs_to :movie_type
75
+ end
76
+ ```
77
+
78
+ ### Sample Object
79
+
80
+ ```ruby
81
+ m = Movie.new
82
+ m.id = 232
83
+ m.name = 'test movie'
84
+ m.actor_ids = [1, 2, 3]
85
+ m.owner_id = 3
86
+ m.movie_type_id = 1
87
+ m
88
+ ```
89
+
90
+ ### Object Serialization
91
+
92
+ #### Return a hash
93
+ ```ruby
94
+ hash = MovieSerializer.new(movie).serializable_hash
95
+ ```
96
+
97
+ #### Return Serialized JSON
98
+ ```ruby
99
+ json_string = MovieSerializer.new(movie).serialized_json
100
+ ```
101
+
102
+ #### Serialized Output
103
+
104
+ ```json
105
+ {
106
+ "data": {
107
+ "id": "232",
108
+ "type": "movie",
109
+ "attributes": {
110
+ "name": "test movie",
111
+ "year": null
112
+ },
113
+ "relationships": {
114
+ "actors": {
115
+ "data": [
116
+ {
117
+ "id": "1",
118
+ "type": "actor"
119
+ },
120
+ {
121
+ "id": "2",
122
+ "type": "actor"
123
+ }
124
+ ]
125
+ },
126
+ "owner": {
127
+ "data": {
128
+ "id": "3",
129
+ "type": "user"
130
+ }
131
+ }
132
+ }
133
+ }
134
+ }
135
+
136
+ ```
137
+ ### Compound Document
138
+
139
+ Support for top-level included member through ` options[:include] `.
140
+
141
+ ```ruby
142
+ options = {}
143
+ options[:meta] = { total: 2 }
144
+ options[:include] = [:actors]
145
+ MovieSerializer.new([movie, movie], options).serialized_json
146
+ ```
147
+
148
+ ### Collection Serialization
149
+
150
+ ```ruby
151
+ options[:meta] = { total: 2 }
152
+ hash = MovieSerializer.new([movie, movie], options).serializable_hash
153
+ json_string = MovieSerializer.new([movie, movie], options).serialized_json
154
+ ```
155
+
156
+ ### Caching
157
+
158
+ ```ruby
159
+ class MovieSerializer
160
+ include FastJsonapi::ObjectSerializer
161
+ set_type :movie # optional
162
+ cache_options enabled: true cache_length: 12.hours
163
+ attributes :name, :year
164
+ end
165
+ ```
166
+
167
+ ### Customizable Options
168
+
169
+ Option | Purpose | Example
170
+ ------------ | ------------- | -------------
171
+ set_type | Type name of Object | ```set_type :movie ```
172
+ cache_options | Hash to enable caching and set cache length | ```cache_options enabled: true cache_length: 12.hours```
173
+ id_method_name | Set custom method name to get ID of an object | ```has_many :locations, id_method_name: :place_ids ```
174
+ object_method_name | Set custom method name to get related objects | ```has_many :locations, object_method_name: :places ```
175
+ record_type | Set custom Object Type for a relationship | ```belongs_to :owner, record_type: :user```
176
+ serializer | Set custom Serializer for a relationship | ```has_many :actors, serializer: :custom_actor```
177
+ cache_options | Hash to enable caching and set cache length | ```cache_options enabled: true cache_length: 12.hours ```
178
+
179
+
180
+ ## Contributing
181
+
182
+ This gem is built using a gem building gem called [juwelier](https://github.com/flajann2/juwelier).
183
+
184
+ Beyond just editing source code, you’ll be interacting with the gem using rake a lot. To see all the tasks available with a brief description, you can run:
185
+
186
+ ```bash
187
+ rake -T
188
+ ```
189
+
190
+ ### Updating Project information
191
+ You can update the project information of the gem by updating the [Rakefile](Rakefile). Then you need to generate a new gemspec
192
+
193
+ ```bash
194
+ rake gemspec
195
+ ```
196
+
197
+ ### Running Tests
198
+ We use rspec for testing. We have unit tests, functional tests and performance tests. To run tests use the following rake task
199
+
200
+ ```bash
201
+ rake spec
202
+ ```
203
+
204
+ ### Installation
205
+
206
+ ```bash
207
+ $ rake install
208
+ ```
209
+
210
+ The install rake task builds the gem installs it. You're all
211
+ set if you're using [RVM](http://rvm.beginrescueend.com/), but you may
212
+ need to run it with sudo if you have a system-installed ruby:
213
+
214
+ ### Bumping Version
215
+
216
+ It feels good to release code. Do it, do it often. But before that, bump
217
+ the version. Then release it. There's a few ways to update the version:
218
+
219
+ ```ruby
220
+ # version:write like before
221
+ $ rake version:write MAJOR=0 MINOR=3 PATCH=0
222
+
223
+ # bump just major, ie 0.1.0 -> 1.0.0
224
+ $ rake version:bump:major
225
+
226
+ # bump just minor, ie 0.1.0 -> 0.2.0
227
+ $ rake version:bump:minor
228
+
229
+ # bump just patch, ie 0.1.0 -> 0.1.1
230
+ $ rake version:bump:patch
231
+ ```
data/VERSION CHANGED
@@ -1 +1 @@
1
- 1.0.16
1
+ 1.0.17
data/fast_jsonapi.gemspec CHANGED
@@ -6,7 +6,7 @@
6
6
 
7
7
  Gem::Specification.new do |s|
8
8
  s.name = "fast_jsonapi"
9
- s.version = "1.0.16"
9
+ s.version = "1.0.17"
10
10
 
11
11
  s.required_rubygems_version = Gem::Requirement.new(">= 0") if s.respond_to? :required_rubygems_version=
12
12
  s.metadata = { "allowed_push_host" => "https://rubygems.org" } if s.respond_to? :metadata=
@@ -61,8 +61,8 @@ Gem::Specification.new do |s|
61
61
  s.add_runtime_dependency(%q<activesupport>, ["~> 5.0"])
62
62
  s.add_runtime_dependency(%q<multi_json>, ["~> 1.12"])
63
63
  s.add_runtime_dependency(%q<oj>, ["~> 3.3"])
64
- s.add_runtime_dependency(%q<skylight>, ["~> 1.3"])
65
64
  s.add_runtime_dependency(%q<activerecord>, ["~> 5.0"])
65
+ s.add_development_dependency(%q<skylight>, ["~> 1.3"])
66
66
  s.add_development_dependency(%q<rspec>, ["~> 3.5.0"])
67
67
  s.add_development_dependency(%q<rspec-benchmark>, ["~> 0.3.0"])
68
68
  s.add_development_dependency(%q<rdoc>, ["~> 3.12"])
@@ -4,22 +4,30 @@ require 'active_support/inflector'
4
4
  require 'oj'
5
5
  require 'multi_json'
6
6
  require 'fast_jsonapi/serialization_core'
7
- require 'skylight'
7
+
8
+ begin
9
+ require 'skylight'
10
+ SKYLIGHT_ENABLED = true
11
+ rescue LoadError
12
+ SKYLIGHT_ENABLED = false
13
+ end
8
14
 
9
15
  module FastJsonapi
10
16
  module ObjectSerializer
11
17
  extend ActiveSupport::Concern
12
18
  include SerializationCore
13
19
 
14
- # Skylight integration
15
- # To remove Skylight
16
- # Remove the included do block
17
- # Remove the Gemfile entry
18
20
  included do
19
- include Skylight::Helpers
20
-
21
- instrument_method :serializable_hash
22
- instrument_method :to_json
21
+ # Skylight integration
22
+ # To remove Skylight
23
+ # Remove the included do block
24
+ # Remove the Gemfile entry
25
+ if SKYLIGHT_ENABLED
26
+ include Skylight::Helpers
27
+
28
+ instrument_method :serializable_hash
29
+ instrument_method :to_json
30
+ end
23
31
 
24
32
  # Set record_type based on the name of the serializer class
25
33
  set_type default_record_type if default_record_type
@@ -13,7 +13,6 @@ module FastJsonapi
13
13
  :record_type,
14
14
  :cache_length,
15
15
  :cached
16
- :record_type
17
16
  end
18
17
  end
19
18
 
@@ -62,6 +62,6 @@ describe 'active record' do
62
62
 
63
63
  # Clean up DB
64
64
  after(:all) do
65
- File.delete(@db_file) if File.exists?(@db_file)
65
+ File.delete(@db_file) if File.exist?(@db_file)
66
66
  end
67
67
  end
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: fast_jsonapi
3
3
  version: !ruby/object:Gem::Version
4
- version: 1.0.16
4
+ version: 1.0.17
5
5
  platform: ruby
6
6
  authors:
7
7
  - Shishir Kakaraddi
@@ -55,33 +55,33 @@ dependencies:
55
55
  - !ruby/object:Gem::Version
56
56
  version: '3.3'
57
57
  - !ruby/object:Gem::Dependency
58
- name: skylight
58
+ name: activerecord
59
59
  requirement: !ruby/object:Gem::Requirement
60
60
  requirements:
61
61
  - - "~>"
62
62
  - !ruby/object:Gem::Version
63
- version: '1.3'
63
+ version: '5.0'
64
64
  type: :runtime
65
65
  prerelease: false
66
66
  version_requirements: !ruby/object:Gem::Requirement
67
67
  requirements:
68
68
  - - "~>"
69
69
  - !ruby/object:Gem::Version
70
- version: '1.3'
70
+ version: '5.0'
71
71
  - !ruby/object:Gem::Dependency
72
- name: activerecord
72
+ name: skylight
73
73
  requirement: !ruby/object:Gem::Requirement
74
74
  requirements:
75
75
  - - "~>"
76
76
  - !ruby/object:Gem::Version
77
- version: '5.0'
78
- type: :runtime
77
+ version: '1.3'
78
+ type: :development
79
79
  prerelease: false
80
80
  version_requirements: !ruby/object:Gem::Requirement
81
81
  requirements:
82
82
  - - "~>"
83
83
  - !ruby/object:Gem::Version
84
- version: '5.0'
84
+ version: '1.3'
85
85
  - !ruby/object:Gem::Dependency
86
86
  name: rspec
87
87
  requirement: !ruby/object:Gem::Requirement