tallty_duck_record 1.0.1 → 1.0.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/lib/duck_record/meta_record.rb +6 -4
- data/lib/duck_record/meta_strict_record.rb +31 -30
- data/lib/duck_record/version.rb +1 -1
- metadata +1 -1
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: cdacef587e1cfa12ab54ac67ab5fb6ce307e31a6ac0c8050a0244027a9893054
|
4
|
+
data.tar.gz: 70901e85b01c40941c75d69393d71e8d661154e5038d5f704d4736c00deb4bd6
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 54f125385506413b6d1a9a338b701c348408e36e3d4b2c26e7c1df91eabe5baab2be770731c9f03d69eac36dbf50f0223c435606df649139f1192f785df37581
|
7
|
+
data.tar.gz: 83bc69b8e73ac5788dc327b795ec65440f1642f0c6b10114d866953e257590e1e44eb7a97ecbc0e30ce864fc519cbf081714ad9145531626e2cb7d0cff603243
|
@@ -1,7 +1,9 @@
|
|
1
|
-
|
2
|
-
|
3
|
-
|
4
|
-
|
1
|
+
module DuckRecord
|
2
|
+
class MetaRecord < MetaStrictRecord
|
3
|
+
def _assign_attribute(k, v)
|
4
|
+
if respond_to?("#{k}=")
|
5
|
+
public_send("#{k}=", v)
|
6
|
+
end
|
5
7
|
end
|
6
8
|
end
|
7
9
|
end
|
@@ -1,38 +1,39 @@
|
|
1
|
-
|
2
|
-
|
1
|
+
module DuckRecord
|
2
|
+
class MetaStrictRecord < DuckRecord::Base
|
3
|
+
attr_accessor :raw_attributes
|
3
4
|
|
4
|
-
|
5
|
-
|
6
|
-
|
7
|
-
end
|
8
|
-
|
9
|
-
class << self
|
10
|
-
def _embeds_reflections
|
11
|
-
_reflections.select { |_, v| v.is_a? DuckRecord::Reflection::EmbedsAssociationReflection }
|
5
|
+
def serializable_hash(options = {})
|
6
|
+
options = (options || {}).reverse_merge include: self.class._embeds_reflections.keys
|
7
|
+
super options
|
12
8
|
end
|
13
9
|
|
14
|
-
|
15
|
-
|
16
|
-
|
17
|
-
|
18
|
-
elsif obj.respond_to?(:to_hash)
|
19
|
-
obj.to_hash
|
20
|
-
else
|
21
|
-
raise ArgumentError, "`obj` required can be cast to `Hash` -- #{obj.class}"
|
22
|
-
end.stringify_keys
|
23
|
-
return serializable_hash
|
24
|
-
end
|
10
|
+
class << self
|
11
|
+
def _embeds_reflections
|
12
|
+
_reflections.select { |_, v| v.is_a? DuckRecord::Reflection::EmbedsAssociationReflection }
|
13
|
+
end
|
25
14
|
|
26
|
-
|
27
|
-
|
28
|
-
|
29
|
-
|
30
|
-
|
31
|
-
|
32
|
-
|
33
|
-
|
15
|
+
def dump(obj)
|
16
|
+
serializable_hash =
|
17
|
+
if obj.respond_to?(:serializable_hash)
|
18
|
+
obj.serializable_hash
|
19
|
+
elsif obj.respond_to?(:to_hash)
|
20
|
+
obj.to_hash
|
21
|
+
else
|
22
|
+
raise ArgumentError, "`obj` required can be cast to `Hash` -- #{obj.class}"
|
23
|
+
end.stringify_keys
|
24
|
+
return serializable_hash
|
25
|
+
end
|
26
|
+
|
27
|
+
def load(hash)
|
28
|
+
case hash
|
29
|
+
when Hash
|
30
|
+
record = new hash
|
31
|
+
record.raw_attributes = hash.with_indifferent_access
|
32
|
+
return record
|
33
|
+
else
|
34
|
+
new
|
35
|
+
end
|
34
36
|
end
|
35
37
|
end
|
36
38
|
end
|
37
39
|
end
|
38
|
-
|
data/lib/duck_record/version.rb
CHANGED