store_model 1.1.0 → 1.3.0
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/lib/store_model/model.rb +36 -0
- data/lib/store_model/types/one_polymorphic.rb +2 -9
- data/lib/store_model/version.rb +1 -1
- metadata +6 -6
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,6 +23,8 @@ module StoreModel
|
|
23
23
|
|
24
24
|
attr_accessor :parent
|
25
25
|
|
26
|
+
delegate :each_value, to: :attributes
|
27
|
+
|
26
28
|
# Returns a hash representing the model. Some configuration can be
|
27
29
|
# passed through +options+.
|
28
30
|
#
|
@@ -41,6 +43,21 @@ module StoreModel
|
|
41
43
|
result.as_json(options)
|
42
44
|
end
|
43
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
|
+
|
44
61
|
# Compares two StoreModel::Model instances
|
45
62
|
#
|
46
63
|
# @param other [StoreModel::Model]
|
@@ -53,6 +70,25 @@ module StoreModel
|
|
53
70
|
end
|
54
71
|
alias eql? ==
|
55
72
|
|
73
|
+
# Accessing attribute using brackets
|
74
|
+
#
|
75
|
+
# @param attr_name [String, Symbol]
|
76
|
+
#
|
77
|
+
# @return [Object]
|
78
|
+
def [](attr_name)
|
79
|
+
@attributes.fetch_value(attr_name.to_s)
|
80
|
+
end
|
81
|
+
|
82
|
+
# Setting attribute using brackets
|
83
|
+
#
|
84
|
+
# @param name [String, Symbol]
|
85
|
+
# @param value [Object]
|
86
|
+
#
|
87
|
+
# @return [Object]
|
88
|
+
def []=(attr_name, value)
|
89
|
+
@attributes.write_from_user(attr_name.to_s, value)
|
90
|
+
end
|
91
|
+
|
56
92
|
# Returns hash for a StoreModel::Model instance based on attributes hash
|
57
93
|
#
|
58
94
|
# @return [Integer]
|
@@ -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
|
-
autorequire:
|
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
|
@@ -120,7 +120,7 @@ homepage: https://github.com/DmitryTsepelev/store_model
|
|
120
120
|
licenses:
|
121
121
|
- MIT
|
122
122
|
metadata: {}
|
123
|
-
post_install_message:
|
123
|
+
post_install_message:
|
124
124
|
rdoc_options: []
|
125
125
|
require_paths:
|
126
126
|
- lib
|
@@ -135,8 +135,8 @@ required_rubygems_version: !ruby/object:Gem::Requirement
|
|
135
135
|
- !ruby/object:Gem::Version
|
136
136
|
version: '0'
|
137
137
|
requirements: []
|
138
|
-
rubygems_version: 3.
|
139
|
-
signing_key:
|
138
|
+
rubygems_version: 3.1.6
|
139
|
+
signing_key:
|
140
140
|
specification_version: 4
|
141
141
|
summary: Gem for working with JSON-backed attributes as ActiveRecord models
|
142
142
|
test_files: []
|