iknow_view_models 2.8.6 → 2.8.7

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: d8f4644f2bf2710cf5f455959e820599c3452b2e460888fefeb2abd78f356db8
4
- data.tar.gz: ec9f0b4cb3009b4e64fa3c77cfea24c716062220ba2de95d566ac0a758a10836
3
+ metadata.gz: f43951463af8b4ed1a7de702c16736beb1b94b89cb90cf9ea13cff64d1f2de2e
4
+ data.tar.gz: c3b76cbc92f47a2584be1722c6ea5efc2b9d723b42ee76b07acffa7f23291318
5
5
  SHA512:
6
- metadata.gz: 1a268fef9e337366301b6d4bbc72138a06b8e6fdcc4929091550be15a36867d533d2a7394de88cdeb2d98a719572b0f1d9f6d7210eca5150f8b0ae40f959ed47
7
- data.tar.gz: e327ca86167c3b94de129ffac178c6188c7a86ec5251c2a6779e6d85a820f6b518740264ffcd8a417e4d46ad7a78ebb2770ce25a95e74af6f42ba8904932a890
6
+ metadata.gz: ba99a68fe5d752c6b75f117928374f4f10f5075adef4df43c1292d172d2d7820d1900bf97416913672f9a7a59f082c4f402f8fe4ff166309695f009aa09c9d2a
7
+ data.tar.gz: b19b5d89503ce5e2000951d7389e327d5c24d55eee6118910a0df09c3be3c597d2349cc065f42a4df69273547ac32e5255fcf8b4ba1b7bc3489513dee7ee2b5d
@@ -1,5 +1,5 @@
1
1
  # frozen_string_literal: true
2
2
 
3
3
  module IknowViewModels
4
- VERSION = '2.8.6'
4
+ VERSION = '2.8.7'
5
5
  end
@@ -110,14 +110,7 @@ module ViewModel::Controller
110
110
  yield json
111
111
  end
112
112
 
113
- # Jbuilder#encode no longer uses MultiJson, but instead calls `.to_json`. In
114
- # the context of ActiveSupport, we don't want this, because AS replaces the
115
- # .to_json interface with its own .as_json, which demands that everything is
116
- # reduced to a Hash before it can be JSON encoded. Using this is not only
117
- # slightly more expensive in terms of allocations, but also defeats the
118
- # purpose of our precompiled `CompiledJson` terminals. Instead serialize
119
- # using OJ with options equivalent to those used by MultiJson.
120
- Oj.dump(builder.attributes!, mode: :compat, time_format: :ruby, use_to_json: true)
113
+ ViewModel.encode_json(builder.attributes!)
121
114
  end
122
115
 
123
116
  def render_jbuilder(status:)
data/lib/view_model.rb CHANGED
@@ -155,6 +155,17 @@ class ViewModel
155
155
  Jbuilder.new { |json| serialize(viewmodel, json, serialize_context: serialize_context) }.attributes!
156
156
  end
157
157
 
158
+ def encode_json(value)
159
+ # Jbuilder#encode no longer uses MultiJson, but instead calls `.to_json`. In
160
+ # the context of ActiveSupport, we don't want this, because AS replaces the
161
+ # .to_json interface with its own .as_json, which demands that everything is
162
+ # reduced to a Hash before it can be JSON encoded. Using this is not only
163
+ # slightly more expensive in terms of allocations, but also defeats the
164
+ # purpose of our precompiled `CompiledJson` terminals. Instead serialize
165
+ # using OJ with options equivalent to those used by MultiJson.
166
+ Oj.dump(value, mode: :compat, time_format: :ruby, use_to_json: true)
167
+ end
168
+
158
169
  # Rebuild this viewmodel from a serialized hash.
159
170
  def deserialize_from_view(hash_data, references: {}, deserialize_context: new_deserialize_context)
160
171
  viewmodel = self.new
@@ -241,6 +252,10 @@ class ViewModel
241
252
  Jbuilder.new { |json| serialize(json, serialize_context: serialize_context) }.attributes!
242
253
  end
243
254
 
255
+ def to_json(serialize_context: self.class.new_serialize_context)
256
+ ViewModel.encode_json(self.to_hash(serialize_context: serialize_context))
257
+ end
258
+
244
259
  # Render this viewmodel to a jBuilder. Usually overridden in subclasses.
245
260
  # Default implementation visits each attribute with Viewmodel.serialize.
246
261
  def serialize_view(json, serialize_context: self.class.new_serialize_context)
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: iknow_view_models
3
3
  version: !ruby/object:Gem::Version
4
- version: 2.8.6
4
+ version: 2.8.7
5
5
  platform: ruby
6
6
  authors:
7
7
  - iKnow Team