jsonapi.rb 1.5.7 → 1.6.0

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
- SHA1:
3
- metadata.gz: 521d608a58983b2c99246e34faf27eae9bb38b32
4
- data.tar.gz: 02a2e7a0086ede91a907d8c7d097150f0222b768
2
+ SHA256:
3
+ metadata.gz: dc1e0239230a7a14a008b6344be8857fccd4db574af564a9b49342842fcc316d
4
+ data.tar.gz: 16615a0a1e0bd8b6f0a84ae9f2adcc16005a16b6413577b3ee945fddb6ce90c5
5
5
  SHA512:
6
- metadata.gz: 23f3ebb21b586e5995b6cb4f2c2ae8f3636f93f5f0e11b9fdbbabdb4087c32850bcda172aeda4aabb8f58f762a23e8c034128f4b48bb7ed38d5ee2c573778ff4
7
- data.tar.gz: b0cdb369d4265dd306a1af8206a46f837322ec00142ec2fac9c40c0ebcc6010cd4f2b7982e05f7ff2f489a960def72431ffc140f3460bffcf9ebecf65aee710d
6
+ metadata.gz: 2c65ee96100a9179205b0f8e220f4f42dc5cd0f03fb8c7c645cb1c70933f848e2e0fe11d600259f2001fe1a9d8760b821c4748009ee3451156e2b07a660df783
7
+ data.tar.gz: 26c49d61c04f3bc03eaee260137905886a421c31d6bb669c063eb4cca9bea15a77327a07e90eb63ede9bb4b0d5e4b153aa38eb6dd6167c2eeabf10a1d7fb8fd6
data/Gemfile CHANGED
@@ -2,5 +2,3 @@ source 'https://rubygems.org'
2
2
 
3
3
  # Specify your gem's dependencies in jsonapi.gemspec
4
4
  gemspec
5
-
6
- gem 'jsonapi-rspec', git: 'https://github.com/jsonapi-rb/jsonapi-rspec.git'
data/README.md CHANGED
@@ -31,7 +31,7 @@ Main goals:
31
31
 
32
32
  The available features include:
33
33
 
34
- * object serialization (powered by Fast JSON API)
34
+ * object serialization (powered by JSON:API Serializer, was `fast_jsonapi`)
35
35
  * [error handling](https://jsonapi.org/format/#errors) (parameters,
36
36
  validation, generic errors)
37
37
  * fetching of the data (support for
@@ -44,7 +44,7 @@ The available features include:
44
44
 
45
45
  ## But how?
46
46
 
47
- Mainly by leveraging [Fast JSON API](https://github.com/Netflix/fast_jsonapi)
47
+ Mainly by leveraging [JSON:API Serializer](https://github.com/jsonapi-serializer/jsonapi-serializer)
48
48
  and [Ransack](https://github.com/activerecord-hackery/ransack).
49
49
 
50
50
  Thanks to everyone who worked on these amazing projects!
@@ -100,7 +100,7 @@ The naming scheme follows the `ModuleName::ClassNameSerializer` for an instance
100
100
  of the `ModuleName::ClassName`.
101
101
 
102
102
  Please follow the
103
- [Fast JSON API guide](https://github.com/Netflix/fast_jsonapi#serializer-definition)
103
+ [JSON:API Serializer guide](https://github.com/jsonapi-serializer/jsonapi-serializer#serializer-definition)
104
104
  on how to define a serializer.
105
105
 
106
106
  To provide a different naming scheme implement the `jsonapi_serializer_class`
data/Rakefile CHANGED
@@ -24,7 +24,11 @@ RuboCop::RakeTask.new('qa:code') do |task|
24
24
  end
25
25
 
26
26
  desc('Run CI QA tasks')
27
- task(qa: ['qa:docs', 'qa:code'])
27
+ if ENV['RAILS_VERSION'].to_s.include?('4')
28
+ task(qa: ['qa:docs'])
29
+ else
30
+ task(qa: ['qa:docs', 'qa:code'])
31
+ end
28
32
 
29
33
  RSpec::Core::RakeTask.new(spec: :qa)
30
34
  task(default: :spec)
@@ -21,7 +21,7 @@ Gem::Specification.new do |spec|
21
21
  end
22
22
  spec.require_paths = ['lib']
23
23
 
24
- spec.add_dependency 'fast_jsonapi', '~> 1.5'
24
+ spec.add_dependency 'jsonapi-serializer', '~> 2.0'
25
25
  spec.add_dependency 'ransack'
26
26
  spec.add_dependency 'rack'
27
27
 
@@ -1,9 +1,9 @@
1
- require 'fast_jsonapi'
1
+ require 'jsonapi/serializer'
2
2
 
3
3
  module JSONAPI
4
4
  # A simple error serializer
5
5
  class ErrorSerializer
6
- include FastJsonapi::ObjectSerializer
6
+ include JSONAPI::Serializer
7
7
 
8
8
  set_id :object_id
9
9
  set_type :error
@@ -42,8 +42,9 @@ module JSONAPI
42
42
  many = JSONAPI::Rails.is_collection?(resource, options[:is_collection])
43
43
  resource = [resource] unless many
44
44
 
45
- return JSONAPI::ErrorSerializer.new(resource, options)
46
- .serialized_json unless resource.is_a?(ActiveModel::Errors)
45
+ return JSONAPI::Rails.serializer_to_json(
46
+ JSONAPI::ErrorSerializer.new(resource, options)
47
+ ) unless resource.is_a?(ActiveModel::Errors)
47
48
 
48
49
  errors = []
49
50
  model = resource.instance_variable_get('@base')
@@ -66,9 +67,11 @@ module JSONAPI
66
67
  end
67
68
  end
68
69
 
69
- JSONAPI::ActiveModelErrorSerializer.new(
70
- errors, params: { model: model, model_serializer: model_serializer }
71
- ).serialized_json
70
+ JSONAPI::Rails.serializer_to_json(
71
+ JSONAPI::ActiveModelErrorSerializer.new(
72
+ errors, params: { model: model, model_serializer: model_serializer }
73
+ )
74
+ )
72
75
  end
73
76
  end
74
77
 
@@ -100,13 +103,15 @@ module JSONAPI
100
103
  serializer_class = JSONAPI::Rails.serializer_class(resource, many)
101
104
  end
102
105
 
103
- serializer_class.new(resource, options).serialized_json
106
+ JSONAPI::Rails.serializer_to_json(
107
+ serializer_class.new(resource, options)
108
+ )
104
109
  end
105
110
  end
106
111
 
107
112
  # Checks if an object is a collection
108
113
  #
109
- # Stolen from [FastJsonapi::ObjectSerializer], instance method.
114
+ # Stolen from [JSONAPI::Serializer], instance method.
110
115
  #
111
116
  # @param resource [Object] to check
112
117
  # @param force_is_collection [NilClass] flag to overwrite
@@ -126,5 +131,17 @@ module JSONAPI
126
131
 
127
132
  "#{klass.name}Serializer".constantize
128
133
  end
134
+
135
+ # Lazily returns the serializer JSON
136
+ #
137
+ # @param serializer [Object] to evaluate
138
+ # @return [String]
139
+ def self.serializer_to_json(serializer)
140
+ if serializer.respond_to?(:serialized_json)
141
+ serializer.serialized_json
142
+ else
143
+ serializer.serializable_hash.to_json
144
+ end
145
+ end
129
146
  end
130
147
  end
@@ -1,3 +1,3 @@
1
1
  module JSONAPI
2
- VERSION = '1.5.7'
2
+ VERSION = '1.6.0'
3
3
  end
metadata CHANGED
@@ -1,29 +1,29 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: jsonapi.rb
3
3
  version: !ruby/object:Gem::Version
4
- version: 1.5.7
4
+ version: 1.6.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - Stas Suscov
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2020-03-17 00:00:00.000000000 Z
11
+ date: 2020-07-09 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
- name: fast_jsonapi
14
+ name: jsonapi-serializer
15
15
  requirement: !ruby/object:Gem::Requirement
16
16
  requirements:
17
17
  - - "~>"
18
18
  - !ruby/object:Gem::Version
19
- version: '1.5'
19
+ version: '2.0'
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
- version: '1.5'
26
+ version: '2.0'
27
27
  - !ruby/object:Gem::Dependency
28
28
  name: ransack
29
29
  requirement: !ruby/object:Gem::Requirement
@@ -269,8 +269,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
269
269
  - !ruby/object:Gem::Version
270
270
  version: '0'
271
271
  requirements: []
272
- rubyforge_project:
273
- rubygems_version: 2.5.2.2
272
+ rubygems_version: 3.1.2
274
273
  signing_key:
275
274
  specification_version: 4
276
275
  summary: So you say you need JSON:API support in your API...