couch_potato 1.22.1 → 1.22.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/CHANGES.md +3 -0
- data/lib/couch_potato/persistence/simple_property.rb +3 -3
- data/lib/couch_potato/persistence/type_caster.rb +5 -5
- data/lib/couch_potato/version.rb +1 -1
- data/spec/property_spec.rb +28 -2
- metadata +2 -46
checksums.yaml
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
---
|
|
2
2
|
SHA256:
|
|
3
|
-
metadata.gz:
|
|
4
|
-
data.tar.gz:
|
|
3
|
+
metadata.gz: 666f7dd052f1c9fbaa75382ed1bca8103b41603950087f1081cf62ff184964bc
|
|
4
|
+
data.tar.gz: b6ac16b525eebb35e27d92c5546dcb4ff1359a15991d760ab5c5c39490664b88
|
|
5
5
|
SHA512:
|
|
6
|
-
metadata.gz:
|
|
7
|
-
data.tar.gz:
|
|
6
|
+
metadata.gz: 537ff4580ebe58fe9d5b29e10bae273ee70b3b85b7762af94448b70c11b213fc800ca434b6ef47156c62c436b6b398ec162344983fa0d508b2b95611c7560696
|
|
7
|
+
data.tar.gz: ccb0b54672f83d83762aa900887dbfd950e2d9f8a4fe92790cf01355d3945534fc4a969d9337ba9816dee8715c58a02657795c59074e8a8c553a67a76f9b0f00
|
data/CHANGES.md
CHANGED
|
@@ -13,9 +13,9 @@ module CouchPotato
|
|
|
13
13
|
end
|
|
14
14
|
end
|
|
15
15
|
|
|
16
|
-
def assign_attribute(name, value)
|
|
16
|
+
def assign_attribute(name, value, from_json: false)
|
|
17
17
|
property = self.class.properties.find_property(name)
|
|
18
|
-
typecasted_value = type_caster.cast(value, property.type)
|
|
18
|
+
typecasted_value = type_caster.cast(value, property.type, from_json:)
|
|
19
19
|
send("#{name}_will_change!") unless @skip_dirty_tracking || typecasted_value == send(name)
|
|
20
20
|
instance_variable_set("@#{name}", typecasted_value)
|
|
21
21
|
end
|
|
@@ -35,7 +35,7 @@ module CouchPotato
|
|
|
35
35
|
end
|
|
36
36
|
|
|
37
37
|
def build(object, json)
|
|
38
|
-
object.send(:assign_attribute, name, json[name])
|
|
38
|
+
object.send(:assign_attribute, name, json[name], from_json: true)
|
|
39
39
|
end
|
|
40
40
|
|
|
41
41
|
def serialize(json, object)
|
|
@@ -6,14 +6,14 @@ module CouchPotato
|
|
|
6
6
|
class TypeCaster #:nodoc:
|
|
7
7
|
NUMBER_REGEX = /-?\d*\.?\d*/.freeze
|
|
8
8
|
|
|
9
|
-
def cast(value, type)
|
|
9
|
+
def cast(value, type, from_json: false)
|
|
10
10
|
if type == :boolean
|
|
11
11
|
cast_boolean(value)
|
|
12
12
|
elsif type.instance_of?(Array)
|
|
13
13
|
nested_type = type.first
|
|
14
|
-
value&.map { |val| cast_native(val, nested_type) }
|
|
14
|
+
value&.map { |val| cast_native(val, nested_type, from_json:) }
|
|
15
15
|
else
|
|
16
|
-
cast_native(value, type)
|
|
16
|
+
cast_native(value, type, from_json:)
|
|
17
17
|
end
|
|
18
18
|
end
|
|
19
19
|
|
|
@@ -29,7 +29,7 @@ module CouchPotato
|
|
|
29
29
|
end
|
|
30
30
|
end
|
|
31
31
|
|
|
32
|
-
def cast_native(value, type)
|
|
32
|
+
def cast_native(value, type, from_json:)
|
|
33
33
|
if type && !value.is_a?(type)
|
|
34
34
|
|
|
35
35
|
if %w[Integer Bignum].include?(type.to_s)
|
|
@@ -40,7 +40,7 @@ module CouchPotato
|
|
|
40
40
|
value.to_d unless value.blank?
|
|
41
41
|
elsif type == Hash
|
|
42
42
|
value.to_hash unless value.blank?
|
|
43
|
-
elsif type.ancestors.include?(CouchPotato::Persistence)
|
|
43
|
+
elsif type.ancestors.include?(CouchPotato::Persistence) && !from_json
|
|
44
44
|
type.new value unless value.blank?
|
|
45
45
|
else
|
|
46
46
|
type.json_create value unless value.blank?
|
data/lib/couch_potato/version.rb
CHANGED
data/spec/property_spec.rb
CHANGED
|
@@ -132,8 +132,8 @@ describe 'properties' do
|
|
|
132
132
|
expect(w.custom_address[0]).to be_an_instance_of Address2
|
|
133
133
|
end
|
|
134
134
|
|
|
135
|
-
it 'initializes
|
|
136
|
-
w = Watch.new(custom_address: [{
|
|
135
|
+
it 'initializes a typed array property from an array of hashes' do
|
|
136
|
+
w = Watch.new(custom_address: [{_id: 'a1', city: 'Berlin'}])
|
|
137
137
|
|
|
138
138
|
expect(w.custom_address.map(&:class)).to eq([Address])
|
|
139
139
|
expect(w.custom_address.map(&:id)).to eq(['a1'])
|
|
@@ -198,6 +198,32 @@ describe 'properties' do
|
|
|
198
198
|
expect(p.ship_address).to be_nil
|
|
199
199
|
end
|
|
200
200
|
|
|
201
|
+
it "persists a nested object with non-couch potato attributes delegating to properties" do
|
|
202
|
+
class PersonWithName
|
|
203
|
+
include CouchPotato::Persistence
|
|
204
|
+
|
|
205
|
+
property :first_name
|
|
206
|
+
property :last_name
|
|
207
|
+
|
|
208
|
+
def name=(value)
|
|
209
|
+
self.first_name = value.split(' ').first
|
|
210
|
+
self.last_name = value.split(' ').last
|
|
211
|
+
end
|
|
212
|
+
end
|
|
213
|
+
class PersonContainer
|
|
214
|
+
include CouchPotato::Persistence
|
|
215
|
+
|
|
216
|
+
property :person, type: PersonWithName
|
|
217
|
+
end
|
|
218
|
+
|
|
219
|
+
container = PersonContainer.new(person: {name: 'John Doe'})
|
|
220
|
+
CouchPotato.database.save_document!(container)
|
|
221
|
+
container = CouchPotato.database.load_document(container.id)
|
|
222
|
+
|
|
223
|
+
expect(container.person.first_name).to eq('John')
|
|
224
|
+
expect(container.person.last_name).to eq('Doe')
|
|
225
|
+
end
|
|
226
|
+
|
|
201
227
|
it "should actually pass the null value down in the JSON document " do
|
|
202
228
|
p = Person.new
|
|
203
229
|
p.ship_address = nil
|
metadata
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
|
2
2
|
name: couch_potato
|
|
3
3
|
version: !ruby/object:Gem::Version
|
|
4
|
-
version: 1.22.
|
|
4
|
+
version: 1.22.2
|
|
5
5
|
platform: ruby
|
|
6
6
|
authors:
|
|
7
7
|
- Alexander Lang
|
|
@@ -249,48 +249,4 @@ requirements: []
|
|
|
249
249
|
rubygems_version: 3.6.9
|
|
250
250
|
specification_version: 4
|
|
251
251
|
summary: Ruby persistence layer for CouchDB
|
|
252
|
-
test_files:
|
|
253
|
-
- spec/attachments_spec.rb
|
|
254
|
-
- spec/callbacks_spec.rb
|
|
255
|
-
- spec/conflict_handling_spec.rb
|
|
256
|
-
- spec/create_spec.rb
|
|
257
|
-
- spec/default_property_spec.rb
|
|
258
|
-
- spec/destroy_spec.rb
|
|
259
|
-
- spec/fixtures/address.rb
|
|
260
|
-
- spec/fixtures/person.rb
|
|
261
|
-
- spec/property_spec.rb
|
|
262
|
-
- spec/rails_spec.rb
|
|
263
|
-
- spec/railtie_spec.rb
|
|
264
|
-
- spec/reload_spec.rb
|
|
265
|
-
- spec/revisions_spec.rb
|
|
266
|
-
- spec/single_design_document_spec.rb
|
|
267
|
-
- spec/spec.opts
|
|
268
|
-
- spec/spec_helper.rb
|
|
269
|
-
- spec/unit/active_model_compliance_spec.rb
|
|
270
|
-
- spec/unit/attributes_spec.rb
|
|
271
|
-
- spec/unit/base_view_spec_spec.rb
|
|
272
|
-
- spec/unit/caching_spec.rb
|
|
273
|
-
- spec/unit/callbacks_spec.rb
|
|
274
|
-
- spec/unit/couch_potato_spec.rb
|
|
275
|
-
- spec/unit/create_spec.rb
|
|
276
|
-
- spec/unit/custom_view_spec_spec.rb
|
|
277
|
-
- spec/unit/custom_views_spec.rb
|
|
278
|
-
- spec/unit/database_spec.rb
|
|
279
|
-
- spec/unit/date_spec.rb
|
|
280
|
-
- spec/unit/dirty_attributes_spec.rb
|
|
281
|
-
- spec/unit/flex_view_spec_spec.rb
|
|
282
|
-
- spec/unit/forbidden_attributes_protection_spec.rb
|
|
283
|
-
- spec/unit/initialize_spec.rb
|
|
284
|
-
- spec/unit/json_spec.rb
|
|
285
|
-
- spec/unit/model_view_spec_spec.rb
|
|
286
|
-
- spec/unit/persistence_spec.rb
|
|
287
|
-
- spec/unit/properties_view_spec_spec.rb
|
|
288
|
-
- spec/unit/rspec_stub_db_spec.rb
|
|
289
|
-
- spec/unit/string_spec.rb
|
|
290
|
-
- spec/unit/time_spec.rb
|
|
291
|
-
- spec/unit/validation_spec.rb
|
|
292
|
-
- spec/unit/view_query_spec.rb
|
|
293
|
-
- spec/update_spec.rb
|
|
294
|
-
- spec/validation_context_spec.rb
|
|
295
|
-
- spec/view_updates_spec.rb
|
|
296
|
-
- spec/views_spec.rb
|
|
252
|
+
test_files: []
|