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 +4 -4
- data/.circleci/config.yml +2 -2
- data/CHANGELOG.md +4 -0
- data/Gemfile.lock +2 -2
- data/app/helpers/power_api/application_helper.rb +10 -4
- data/lib/power_api/version.rb +1 -1
- data/spec/dummy/spec/helpers/power_api/application_helper_spec.rb +14 -0
- metadata +2 -2
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: f30cc23f12f0428c77e7cc2e7820a6bc4bf72d70a8a838abf282ad96b29ae42c
|
4
|
+
data.tar.gz: 55a91a55c8cafbb1b666c4c79c48ac1511d13c23efe79dbe357764bfd251b021
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 49af821bffae3dd6f23f6c89a7fcaad73ae9132237ba39b1ff9c8caf754bb7a48c2cb230b71c0bc633b241cb40afc7c34ba9458ceded143fd0e4473bebea14ba
|
7
|
+
data.tar.gz: a01937e2ca67e188cd9ea275197f4ad8a7931288c6eaf1b3189d75b66bbafe4c25a3a963c078ad0835e2ef5e749cf274c3dbd20aa37030b584d10abf969ff4de
|
data/.circleci/config.yml
CHANGED
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
@@ -4,8 +4,7 @@ module PowerApi
|
|
4
4
|
|
5
5
|
def serialize_resource(resource, options = {})
|
6
6
|
load_default_serializer_options(options)
|
7
|
-
|
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
|
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)
|
data/lib/power_api/version.rb
CHANGED
@@ -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.
|
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:
|
12
|
+
date: 2023-08-23 00:00:00.000000000 Z
|
13
13
|
dependencies:
|
14
14
|
- !ruby/object:Gem::Dependency
|
15
15
|
name: rails
|