pbbuilder 0.13.0 → 0.13.2
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- checksums.yaml +4 -4
- data/CHANGELOG.md +8 -0
- data/lib/pbbuilder/template.rb +14 -3
- data/lib/pbbuilder.rb +6 -3
- data/pbbuilder.gemspec +1 -1
- data/test/pbbuilder_template_test.rb +11 -6
- data/test/test_helper.rb +2 -1
- 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: 4ece867edfd6c367638386b6ff729160fc48869e95da675c27dcf863e114bb0f
|
4
|
+
data.tar.gz: 2ca090784cbbd677cb428f7aefe74acf350e06331f234fba62fc65266284cd46
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 8a0128aef94081281e0c8430aa4779864c5571f1d3a4e9d7d4af9f12134fce29fdea37464228b4b21cd4739c06cf8f971d8bb4d4084038acea78cbcfc7f5783b
|
7
|
+
data.tar.gz: 92a957df036ae419b6734747d503fa348462156aa369c707d270125a1d17b3fc107b92905550a594415d6c514664da066be4fcc46be27c391d532939e3f55182
|
data/CHANGELOG.md
CHANGED
@@ -3,6 +3,14 @@ All notable changes to this project will be documented in this file.
|
|
3
3
|
|
4
4
|
This format is based on [Keep a Changelog](https://keepachangelog.com/en/1.0.0/), and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0.html).
|
5
5
|
|
6
|
+
## 0.13.2 2023.02.3
|
7
|
+
### Fixed
|
8
|
+
- In case ActiveSupport::Cache::FileStore in Rails is used as a cache, File.atomic_write can have a race condition and fail to rename temporary file. We're attempting to recover from that, by catching this specific error and returning a value.
|
9
|
+
|
10
|
+
## 0.13.1 2023.01.24
|
11
|
+
### Added
|
12
|
+
- #merge! to support boolean values
|
13
|
+
|
6
14
|
## 0.13.0 2023.01.18
|
7
15
|
### Added
|
8
16
|
- #merge! method added for PbbuilderTemplate class
|
data/lib/pbbuilder/template.rb
CHANGED
@@ -108,11 +108,22 @@ class PbbuilderTemplate < Pbbuilder
|
|
108
108
|
# @param key string
|
109
109
|
# @params options hash
|
110
110
|
#
|
111
|
-
# @return string
|
111
|
+
# @return string contents of a cache
|
112
112
|
def _write_fragment_cache(key, options = nil)
|
113
|
-
@context.controller.instrument_fragment_cache :
|
113
|
+
@context.controller.instrument_fragment_cache :write_fragment, key do
|
114
114
|
yield.tap do |value|
|
115
|
-
|
115
|
+
begin
|
116
|
+
::Rails.cache.write(key, value, options)
|
117
|
+
rescue SystemCallError
|
118
|
+
# In case ActiveSupport::Cache::FileStore in Rails is used as a cache,
|
119
|
+
# File.atomic_write can have a race condition and fail to rename temporary
|
120
|
+
# file. We're attempting to recover from that, by catching this specific
|
121
|
+
# error and returning a value.
|
122
|
+
#
|
123
|
+
# @see https://github.com/rails/rails/pull/44151
|
124
|
+
# @see https://github.com/rails/rails/blob/main/activesupport/lib/active_support/core_ext/file/atomic.rb#L50
|
125
|
+
value
|
126
|
+
end
|
116
127
|
end
|
117
128
|
end
|
118
129
|
end
|
data/lib/pbbuilder.rb
CHANGED
@@ -111,11 +111,11 @@ class Pbbuilder
|
|
111
111
|
#
|
112
112
|
# @param object [Hash]
|
113
113
|
def merge!(object)
|
114
|
-
::Kernel.raise ::MergeError.build(target!, object) unless object.class == ::Hash
|
114
|
+
::Kernel.raise Pbbuilder::MergeError.build(target!, object) unless object.class == ::Hash
|
115
115
|
|
116
116
|
object.each_key do |key|
|
117
|
-
if object[key].empty?
|
118
|
-
::Kernel.raise ::MergeError.build(target!, object)
|
117
|
+
if object[key].respond_to?(:empty?) && object[key].empty?
|
118
|
+
::Kernel.raise Pbbuilder::MergeError.build(target!, object)
|
119
119
|
end
|
120
120
|
|
121
121
|
if object[key].class == ::String
|
@@ -124,6 +124,9 @@ class Pbbuilder
|
|
124
124
|
elsif object[key].class == ::Array
|
125
125
|
# pb.tags ['test', 'ok']
|
126
126
|
@message[key.to_s].replace object[key]
|
127
|
+
elsif object[key].class == ::TrueClass || object[key].class == ::FalseClass
|
128
|
+
# pb.boolean true || false
|
129
|
+
@message[key.to_s] = object[key]
|
127
130
|
elsif ( obj = object[key]).class == ::Hash
|
128
131
|
# pb.field_name do
|
129
132
|
# pb.tags ["ok", "cool"]
|
data/pbbuilder.gemspec
CHANGED
@@ -85,6 +85,11 @@ class PbbuilderTemplateTest < ActiveSupport::TestCase
|
|
85
85
|
assert_equal("suslik", result.name)
|
86
86
|
end
|
87
87
|
|
88
|
+
test "boolean support in merge! method" do
|
89
|
+
assert(render('pb.merge! "boolean_me" => true').boolean_me)
|
90
|
+
refute(render('pb.merge! "boolean_me" => false').boolean_me)
|
91
|
+
end
|
92
|
+
|
88
93
|
test "support for merge! method in a block" do
|
89
94
|
result = render(<<-PBBUILDER)
|
90
95
|
pb.best_friend do
|
@@ -115,10 +120,10 @@ class PbbuilderTemplateTest < ActiveSupport::TestCase
|
|
115
120
|
result = nil
|
116
121
|
|
117
122
|
assert_nothing_raised do
|
118
|
-
result = render(<<-
|
123
|
+
result = render(<<-PBBUILDER)
|
119
124
|
pb.name "suslik"
|
120
125
|
pb.cache! "nothing" do; end
|
121
|
-
|
126
|
+
PBBUILDER
|
122
127
|
end
|
123
128
|
|
124
129
|
assert_equal "suslik", result["name"]
|
@@ -192,7 +197,7 @@ class PbbuilderTemplateTest < ActiveSupport::TestCase
|
|
192
197
|
end
|
193
198
|
|
194
199
|
test "conditional object fragment caching" do
|
195
|
-
render(<<-
|
200
|
+
render(<<-PBBUILDER)
|
196
201
|
pb.cache_if! true, "cache-key" do
|
197
202
|
pb.name "Hit"
|
198
203
|
end
|
@@ -200,9 +205,9 @@ class PbbuilderTemplateTest < ActiveSupport::TestCase
|
|
200
205
|
pb.cache_if! false, "cache-key" do
|
201
206
|
pb.last_name "Hit"
|
202
207
|
end
|
203
|
-
|
208
|
+
PBBUILDER
|
204
209
|
|
205
|
-
result = render(<<-
|
210
|
+
result = render(<<-PBBUILDER)
|
206
211
|
pb.cache_if! true, "cache-key" do
|
207
212
|
pb.name "Miss"
|
208
213
|
end
|
@@ -210,7 +215,7 @@ class PbbuilderTemplateTest < ActiveSupport::TestCase
|
|
210
215
|
pb.cache_if! false, "cache-key" do
|
211
216
|
pb.last_name "Miss"
|
212
217
|
end
|
213
|
-
|
218
|
+
PBBUILDER
|
214
219
|
|
215
220
|
assert_equal "Hit", result["name"]
|
216
221
|
assert_equal "Miss", result["last_name"]
|
data/test/test_helper.rb
CHANGED
@@ -22,13 +22,14 @@ Google::Protobuf::DescriptorPool.generated_pool.build do
|
|
22
22
|
add_file("pbbuilder.proto", syntax: :proto3) do
|
23
23
|
add_message "pbbuildertest.Person" do
|
24
24
|
optional :name, :string, 1
|
25
|
-
optional :last_name, :string, 8
|
26
25
|
repeated :friends, :message, 2, "pbbuildertest.Person"
|
27
26
|
optional :best_friend, :message, 3, "pbbuildertest.Person"
|
28
27
|
repeated :nicknames, :string, 4
|
29
28
|
optional :field_mask, :message, 5, "google.protobuf.FieldMask"
|
30
29
|
map :favourite_foods, :string, :string, 6
|
31
30
|
repeated :tags, :string, 7
|
31
|
+
optional :last_name, :string, 8
|
32
|
+
optional :boolean_me, :bool, 9
|
32
33
|
end
|
33
34
|
end
|
34
35
|
end
|
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: pbbuilder
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.13.
|
4
|
+
version: 0.13.2
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Bouke van der Bijl
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date: 2023-
|
11
|
+
date: 2023-02-08 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: google-protobuf
|