tallty_duck_record 1.0.0 → 1.0.1
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/lib/duck_record.rb +2 -0
- data/lib/duck_record/meta_record.rb +7 -0
- data/lib/duck_record/meta_strict_record.rb +38 -0
- data/lib/duck_record/version.rb +1 -1
- metadata +3 -1
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 13519264c45683755376962602255447fa0c917fa664135794691b73883cb494
|
4
|
+
data.tar.gz: f28955103e902cba1ee4b89de063eeea2031f07e902ede4883133c05c1c7c058
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 865d2b950b25104831ab58ff1476701ea7460217009f36e5062af8c502f5a58007041e113297d0e64d898c9f5037d1696a704ba035f9b3e5c860ccbafa6522c9
|
7
|
+
data.tar.gz: 439833d5a4fc1bc51a35c21f0363fa9852e59c11bc5a4df296286a4753028249dbc3f38a18c52420ab28774887d2b652cc0f44df9406d93e804a9209e6004ffe
|
data/lib/duck_record.rb
CHANGED
@@ -0,0 +1,38 @@
|
|
1
|
+
class MetaStrictRecord < DuckRecord::Base
|
2
|
+
attr_accessor :raw_attributes
|
3
|
+
|
4
|
+
def serializable_hash(options = {})
|
5
|
+
options = (options || {}).reverse_merge include: self.class._embeds_reflections.keys
|
6
|
+
super options
|
7
|
+
end
|
8
|
+
|
9
|
+
class << self
|
10
|
+
def _embeds_reflections
|
11
|
+
_reflections.select { |_, v| v.is_a? DuckRecord::Reflection::EmbedsAssociationReflection }
|
12
|
+
end
|
13
|
+
|
14
|
+
def dump(obj)
|
15
|
+
serializable_hash =
|
16
|
+
if obj.respond_to?(:serializable_hash)
|
17
|
+
obj.serializable_hash
|
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
|
25
|
+
|
26
|
+
def load(hash)
|
27
|
+
case hash
|
28
|
+
when Hash
|
29
|
+
record = new hash
|
30
|
+
record.raw_attributes = hash.with_indifferent_access
|
31
|
+
return record
|
32
|
+
else
|
33
|
+
new
|
34
|
+
end
|
35
|
+
end
|
36
|
+
end
|
37
|
+
end
|
38
|
+
|
data/lib/duck_record/version.rb
CHANGED
metadata
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: tallty_duck_record
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 1.0.
|
4
|
+
version: 1.0.1
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- tallty
|
@@ -127,6 +127,8 @@ files:
|
|
127
127
|
- lib/duck_record/errors.rb
|
128
128
|
- lib/duck_record/inheritance.rb
|
129
129
|
- lib/duck_record/locale/en.yml
|
130
|
+
- lib/duck_record/meta_record.rb
|
131
|
+
- lib/duck_record/meta_strict_record.rb
|
130
132
|
- lib/duck_record/model_schema.rb
|
131
133
|
- lib/duck_record/nested_attributes.rb
|
132
134
|
- lib/duck_record/nested_validate_association.rb
|