store_model 1.2.0 → 1.3.0
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/store_model/model.rb +18 -1
- data/lib/store_model/types/one_polymorphic.rb +2 -9
- data/lib/store_model/version.rb +1 -1
- metadata +2 -2
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: f464327535385fc17ade5f91d0c88ac4cc09233f995bc48d4e926ecd6cab4b67
|
4
|
+
data.tar.gz: 4497217fa0c66f0e8587e1e66e7ace5a83209835901ed300f15bab8a6651990b
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: b19c7f3fa44d7fc49925d450d1b97318002174b38dff46ae84611d61eb857833fd660570a1a4244eb8b21b60d9242d33c7e6e2e62471a3306bd8c46389308727
|
7
|
+
data.tar.gz: b710ea76a0ecb1ac7193dc5e536b947456895c1839b6efd92b5e06a5dec560d7d67f019c7c92e5c92ab5cd36df96ef730ff03fb638cbff933419fd066e3583df
|
data/lib/store_model/model.rb
CHANGED
@@ -23,7 +23,7 @@ module StoreModel
|
|
23
23
|
|
24
24
|
attr_accessor :parent
|
25
25
|
|
26
|
-
delegate :each_value,
|
26
|
+
delegate :each_value, to: :attributes
|
27
27
|
|
28
28
|
# Returns a hash representing the model. Some configuration can be
|
29
29
|
# passed through +options+.
|
@@ -43,6 +43,21 @@ module StoreModel
|
|
43
43
|
result.as_json(options)
|
44
44
|
end
|
45
45
|
|
46
|
+
# Returns an Object, similar to Hash#fetch, raises
|
47
|
+
# a KeyError if attr_name doesn't exist.
|
48
|
+
# @param attr_name [String, Symbol]
|
49
|
+
#
|
50
|
+
# @return Object
|
51
|
+
def fetch(attr_name)
|
52
|
+
stringified_key = attr_name.to_s
|
53
|
+
if attribute_names.include?(stringified_key) || attribute_aliases.key?(stringified_key)
|
54
|
+
public_send(stringified_key)
|
55
|
+
else
|
56
|
+
message = attr_name.is_a?(Symbol) ? "key not found: :#{attr_name}" : "key not found: #{attr_name}"
|
57
|
+
raise KeyError, message
|
58
|
+
end
|
59
|
+
end
|
60
|
+
|
46
61
|
# Compares two StoreModel::Model instances
|
47
62
|
#
|
48
63
|
# @param other [StoreModel::Model]
|
@@ -57,6 +72,8 @@ module StoreModel
|
|
57
72
|
|
58
73
|
# Accessing attribute using brackets
|
59
74
|
#
|
75
|
+
# @param attr_name [String, Symbol]
|
76
|
+
#
|
60
77
|
# @return [Object]
|
61
78
|
def [](attr_name)
|
62
79
|
@attributes.fetch_value(attr_name.to_s)
|
@@ -50,16 +50,9 @@ module StoreModel
|
|
50
50
|
#
|
51
51
|
# @return [String] serialized value
|
52
52
|
def serialize(value)
|
53
|
-
|
54
|
-
when Hash
|
55
|
-
ActiveSupport::JSON.encode(value, serialize_unknown_attributes: true)
|
56
|
-
else
|
57
|
-
if implements_model?(value.class)
|
58
|
-
return ActiveSupport::JSON.encode(value, serialize_unknown_attributes: true)
|
59
|
-
end
|
53
|
+
return super unless value.is_a?(Hash) || implements_model?(value.class)
|
60
54
|
|
61
|
-
|
62
|
-
end
|
55
|
+
ActiveSupport::JSON.encode(value, serialize_unknown_attributes: true)
|
63
56
|
end
|
64
57
|
|
65
58
|
protected
|
data/lib/store_model/version.rb
CHANGED
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: store_model
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 1.
|
4
|
+
version: 1.3.0
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- DmitryTsepelev
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date: 2022-
|
11
|
+
date: 2022-10-21 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: activerecord
|