power_api 2.1.0 → 2.1.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
  SHA256:
3
- metadata.gz: 5f9ac70fd373bcfa86774718053e2a050a63cf01edaf3b795ae32974f84d4316
4
- data.tar.gz: 987dfb777a07a02ceffb510d2e958e66295a2a7b032f4b59589c7b46466f9554
3
+ metadata.gz: f30cc23f12f0428c77e7cc2e7820a6bc4bf72d70a8a838abf282ad96b29ae42c
4
+ data.tar.gz: 55a91a55c8cafbb1b666c4c79c48ac1511d13c23efe79dbe357764bfd251b021
5
5
  SHA512:
6
- metadata.gz: 91645d4b96ce2956214e9520a17111907935507a756b15a6b76c6a1703deb39b5a6b70da33432c4dce90b8d3407c89e3639082311c311013f64230904b9f1031
7
- data.tar.gz: a7fc3106279ad4b52c8da096e9367e9c4c90e6ea10d504e4f7f3f54d07bfdfdc764b2512a432a4597aebd1fbcdda560590bb9df9e288beffbf0adeb28d179e62
6
+ metadata.gz: 49af821bffae3dd6f23f6c89a7fcaad73ae9132237ba39b1ff9c8caf754bb7a48c2cb230b71c0bc633b241cb40afc7c34ba9458ceded143fd0e4473bebea14ba
7
+ data.tar.gz: a01937e2ca67e188cd9ea275197f4ad8a7931288c6eaf1b3189d75b66bbafe4c25a3a963c078ad0835e2ef5e749cf274c3dbd20aa37030b584d10abf969ff4de
data/.circleci/config.yml CHANGED
@@ -94,11 +94,11 @@ workflows:
94
94
  - test:
95
95
  matrix:
96
96
  parameters:
97
- ruby-version: ["2.6", "2.7"]
97
+ ruby-version: ["2.7"]
98
98
  - deploy:
99
99
  context: org-global
100
100
  filters:
101
101
  tags:
102
102
  only: /.*/
103
103
  branches:
104
- ignore: /.*/
104
+ ignore: /.*/
data/CHANGELOG.md CHANGED
@@ -2,6 +2,10 @@
2
2
  All notable changes to this project will be documented in this file.
3
3
  This project adheres to [Semantic Versioning](http://semver.org/).
4
4
 
5
+ ### v2.1.1
6
+
7
+ * Fix: add `nil` handling in the `serialize_resource` view helper.
8
+
5
9
  ### v2.1.0
6
10
 
7
11
  * Swagger has been deleted from the Exposed Api version.
data/Gemfile.lock CHANGED
@@ -1,7 +1,7 @@
1
1
  PATH
2
2
  remote: .
3
3
  specs:
4
- power_api (2.1.0)
4
+ power_api (2.1.1)
5
5
  active_model_serializers (~> 0.10.0)
6
6
  api-pagination
7
7
  kaminari
@@ -315,4 +315,4 @@ DEPENDENCIES
315
315
  sqlite3 (~> 1.4.2)
316
316
 
317
317
  BUNDLED WITH
318
- 2.2.24
318
+ 2.4.10
@@ -4,8 +4,7 @@ module PowerApi
4
4
 
5
5
  def serialize_resource(resource, options = {})
6
6
  load_default_serializer_options(options)
7
- serializable = ActiveModelSerializers::SerializableResource.new(resource, options)
8
- serialized_data = serializable.serializable_hash
7
+ serialized_data = serialize_data(resource, options)
9
8
  render_serialized_data(serialized_data, options)
10
9
  rescue NoMethodError => e
11
10
  if e.message.include?("undefined method `serializable_hash'")
@@ -19,12 +18,19 @@ module PowerApi
19
18
 
20
19
  private
21
20
 
21
+ def serialize_data(resource, options)
22
+ return {} if resource.nil?
23
+
24
+ serializable = ActiveModelSerializers::SerializableResource.new(resource, options)
25
+ serializable.serializable_hash
26
+ end
27
+
22
28
  def render_serialized_data(serialized_data, options)
23
29
  output_format = options.delete(:output_format)
24
- serialized_data = serialized_data[:root] if options[:root] == :root
30
+ serialized_data = serialized_data.fetch(:root, serialized_data)
25
31
  return serialized_data if output_format == :hash
26
32
 
27
- serialized_data.to_json
33
+ serialized_data.presence.to_json
28
34
  end
29
35
 
30
36
  def load_default_serializer_options(options)
@@ -1,3 +1,3 @@
1
1
  module PowerApi
2
- VERSION = '2.1.0'
2
+ VERSION = '2.1.1'
3
3
  end
@@ -97,6 +97,13 @@ describe PowerApi::ApplicationHelper do
97
97
  it { expect(data).to eq(expected_serialized_data) }
98
98
  end
99
99
 
100
+ context "with nil resource" do
101
+ let(:resource) { nil }
102
+ let(:expected_serialized_data) { "null" }
103
+
104
+ it { expect(data).to eq(expected_serialized_data) }
105
+ end
106
+
100
107
  context "with invalid resource" do
101
108
  let(:resource) do
102
109
  { invalid: "resource" }
@@ -130,6 +137,13 @@ describe PowerApi::ApplicationHelper do
130
137
 
131
138
  it { expect(data).to eq(expected_serialized_data) }
132
139
  end
140
+
141
+ context "with nil resource" do
142
+ let(:resource) { nil }
143
+ let(:expected_serialized_data) { {} }
144
+
145
+ it { expect(data).to eq(expected_serialized_data) }
146
+ end
133
147
  end
134
148
 
135
149
  context "with invalid output option" do
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: power_api
3
3
  version: !ruby/object:Gem::Version
4
- version: 2.1.0
4
+ version: 2.1.1
5
5
  platform: ruby
6
6
  authors:
7
7
  - Platanus
@@ -9,7 +9,7 @@ authors:
9
9
  autorequire:
10
10
  bindir: exe
11
11
  cert_chain: []
12
- date: 2022-05-20 00:00:00.000000000 Z
12
+ date: 2023-08-23 00:00:00.000000000 Z
13
13
  dependencies:
14
14
  - !ruby/object:Gem::Dependency
15
15
  name: rails