tallty_duck_record 1.0.0 → 1.1.2

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: 45f98d3af5325759f0a61afac5487e16fadcec80c6f0516f68ddbb7d4d0beddd
4
- data.tar.gz: f4e17fdbb154b415ced973b7dcaf4546cc0264378b5d54b97bc5d784b005c99b
3
+ metadata.gz: e76c47a46726cc7d60f7386b25dd5d14fb70127f6dca09e825c745b00679ace1
4
+ data.tar.gz: 046df1437a032edf1aaf1c19866fccd84c5388435247c1cfd5c60f9f632ad321
5
5
  SHA512:
6
- metadata.gz: 6b599f24166fc44208e16e07ff8563f952bd9cc4d01561e21f7980cedb669d4c71107e4b2529372f5a765daab03c89f2b10108aec1cf533cda8ef0bc2fc414d8
7
- data.tar.gz: e09ccf3f1a5a0b400c1000738aea0a2bb21ba0980128eb873323fc69eb7d28adcf5c40484d038a9ef2c31b7f0b1e87c68a2d2d62bd7ed6c8b85bbfa69e474491
6
+ metadata.gz: 523d863290eec53bb5edc68fa360499b631a7301a193c17f63f43602548e45e2064be496b8e60bcaacefff8d35b4b34ecff3d682b4b5d8bf2b4c32832721df18
7
+ data.tar.gz: f054891f0c2f22d10fc56c18a7bdc8d106280972a85dedb7adcde3752e9aabb6715507473336b0e50acc13ceeee7d1da59f058c1d6da6a9701aa666c64a3ef38
data/lib/duck_record.rb CHANGED
@@ -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
@@ -1,18 +1,19 @@
1
1
  require "yaml"
2
- require "active_support/benchmarkable"
3
- require "active_support/dependencies"
4
- require "active_support/descendants_tracker"
5
- require "active_support/time"
6
- require "active_support/core_ext/module/attribute_accessors"
7
- require "active_support/core_ext/array/extract_options"
8
- require "active_support/core_ext/hash/deep_merge"
9
- require "active_support/core_ext/hash/slice"
10
- require "active_support/core_ext/hash/transform_values"
11
- require "active_support/core_ext/string/behavior"
12
- require "active_support/core_ext/kernel/singleton_class"
13
- require "active_support/core_ext/module/introspection"
14
- require "active_support/core_ext/object/duplicable"
15
- require "active_support/core_ext/class/subclasses"
2
+ require 'active_support'
3
+ # require "active_support/benchmarkable"
4
+ # require "active_support/dependencies"
5
+ # require "active_support/descendants_tracker"
6
+ # require "active_support/time"
7
+ # require "active_support/core_ext/module/attribute_accessors"
8
+ # require "active_support/core_ext/array/extract_options"
9
+ # require "active_support/core_ext/hash/deep_merge"
10
+ # require "active_support/core_ext/hash/slice"
11
+ # # require "active_support/core_ext/hash/transform_values"
12
+ # require "active_support/core_ext/string/behavior"
13
+ # require "active_support/core_ext/kernel/singleton_class"
14
+ # require "active_support/core_ext/module/introspection"
15
+ # require "active_support/core_ext/object/duplicable"
16
+ # require "active_support/core_ext/class/subclasses"
16
17
  require "duck_record/define_callbacks"
17
18
  require "duck_record/errors"
18
19
  require "duck_record/attributes"
@@ -0,0 +1,9 @@
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
7
+ end
8
+ end
9
+ end
@@ -0,0 +1,39 @@
1
+ module DuckRecord
2
+ class MetaStrictRecord < DuckRecord::Base
3
+ attr_accessor :raw_attributes
4
+
5
+ def serializable_hash(options = {})
6
+ options = (options || {}).reverse_merge include: self.class._embeds_reflections.keys
7
+ super options
8
+ end
9
+
10
+ class << self
11
+ def _embeds_reflections
12
+ _reflections.select { |_, v| v.is_a? DuckRecord::Reflection::EmbedsAssociationReflection }
13
+ end
14
+
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
36
+ end
37
+ end
38
+ end
39
+ end
@@ -1,3 +1,3 @@
1
1
  module DuckRecord
2
- VERSION = "1.0.0"
2
+ VERSION = "1.1.2"
3
3
  end
metadata CHANGED
@@ -1,57 +1,57 @@
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.1.2
5
5
  platform: ruby
6
6
  authors:
7
7
  - tallty
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2020-11-18 00:00:00.000000000 Z
11
+ date: 2021-06-03 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: activesupport
15
15
  requirement: !ruby/object:Gem::Requirement
16
16
  requirements:
17
- - - "~>"
17
+ - - ">="
18
18
  - !ruby/object:Gem::Version
19
- version: 6.0.3
19
+ version: '5.0'
20
20
  type: :runtime
21
21
  prerelease: false
22
22
  version_requirements: !ruby/object:Gem::Requirement
23
23
  requirements:
24
- - - "~>"
24
+ - - ">="
25
25
  - !ruby/object:Gem::Version
26
- version: 6.0.3
26
+ version: '5.0'
27
27
  - !ruby/object:Gem::Dependency
28
28
  name: activemodel
29
29
  requirement: !ruby/object:Gem::Requirement
30
30
  requirements:
31
- - - "~>"
31
+ - - ">="
32
32
  - !ruby/object:Gem::Version
33
- version: 6.0.3
33
+ version: '5.0'
34
34
  type: :runtime
35
35
  prerelease: false
36
36
  version_requirements: !ruby/object:Gem::Requirement
37
37
  requirements:
38
- - - "~>"
38
+ - - ">="
39
39
  - !ruby/object:Gem::Version
40
- version: 6.0.3
40
+ version: '5.0'
41
41
  - !ruby/object:Gem::Dependency
42
42
  name: rails
43
43
  requirement: !ruby/object:Gem::Requirement
44
44
  requirements:
45
- - - "~>"
45
+ - - ">="
46
46
  - !ruby/object:Gem::Version
47
- version: 6.0.3
47
+ version: '5.0'
48
48
  type: :development
49
49
  prerelease: false
50
50
  version_requirements: !ruby/object:Gem::Requirement
51
51
  requirements:
52
- - - "~>"
52
+ - - ">="
53
53
  - !ruby/object:Gem::Version
54
- version: 6.0.3
54
+ version: '5.0'
55
55
  - !ruby/object:Gem::Dependency
56
56
  name: sqlite3
57
57
  requirement: !ruby/object:Gem::Requirement
@@ -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