tallty_duck_record 1.0.0 → 1.0.1

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 CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: 45f98d3af5325759f0a61afac5487e16fadcec80c6f0516f68ddbb7d4d0beddd
4
- data.tar.gz: f4e17fdbb154b415ced973b7dcaf4546cc0264378b5d54b97bc5d784b005c99b
3
+ metadata.gz: 13519264c45683755376962602255447fa0c917fa664135794691b73883cb494
4
+ data.tar.gz: f28955103e902cba1ee4b89de063eeea2031f07e902ede4883133c05c1c7c058
5
5
  SHA512:
6
- metadata.gz: 6b599f24166fc44208e16e07ff8563f952bd9cc4d01561e21f7980cedb669d4c71107e4b2529372f5a765daab03c89f2b10108aec1cf533cda8ef0bc2fc414d8
7
- data.tar.gz: e09ccf3f1a5a0b400c1000738aea0a2bb21ba0980128eb873323fc69eb7d28adcf5c40484d038a9ef2c31b7f0b1e87c68a2d2d62bd7ed6c8b85bbfa69e474491
6
+ metadata.gz: 865d2b950b25104831ab58ff1476701ea7460217009f36e5062af8c502f5a58007041e113297d0e64d898c9f5037d1696a704ba035f9b3e5c860ccbafa6522c9
7
+ data.tar.gz: 439833d5a4fc1bc51a35c21f0363fa9852e59c11bc5a4df296286a4753028249dbc3f38a18c52420ab28774887d2b652cc0f44df9406d93e804a9209e6004ffe
@@ -13,6 +13,8 @@ module DuckRecord
13
13
  autoload :Attribute
14
14
  autoload :AttributeDecorators
15
15
  autoload :Base
16
+ autoload :MetaStrictRecord
17
+ autoload :MetaRecord
16
18
  autoload :Callbacks
17
19
  autoload :Core
18
20
  autoload :Enum
@@ -0,0 +1,7 @@
1
+ class MetaRecord < MetaStrictRecord
2
+ def _assign_attribute(k, v)
3
+ if respond_to?("#{k}=")
4
+ public_send("#{k}=", v)
5
+ end
6
+ end
7
+ end
@@ -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
+
@@ -1,3 +1,3 @@
1
1
  module DuckRecord
2
- VERSION = "1.0.0"
2
+ VERSION = "1.0.1"
3
3
  end
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.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