rasti-model 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 +4 -4
- data/lib/rasti/model.rb +11 -5
- data/lib/rasti/model/version.rb +1 -1
- data/spec/model_spec.rb +18 -12
- 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: 5d85d0034827688a0aea67f255e2ac0ea95a273da7a38dc66c823f032cf95830
|
4
|
+
data.tar.gz: 63fed2869a50ba059f73f878c1eace99b00068df719a1d373bcbe627edac7e16
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 8934c038b6dabbf06f6c6405751fe9691a75495089ba3c2c177f82dd5c486dbd14954a39a757232774fe6e36b6a631529286db3a9427d79bc857ddddd8852596
|
7
|
+
data.tar.gz: 4b967d4b0cfae3cd0b1cf4c405a8422230f01836554108bd4f3e27756d2d50c7bcea46ead161b7066c570296fc3aa2799faafba636d1c8f54ccdc48a7655ebb4
|
data/lib/rasti/model.rb
CHANGED
@@ -175,22 +175,28 @@ module Rasti
|
|
175
175
|
@serialized_attributes ||= begin
|
176
176
|
cast_attributes!
|
177
177
|
|
178
|
-
|
179
|
-
|
178
|
+
self.class.attributes.each_with_object({}) do |attribute, hash|
|
179
|
+
if __cache__.key? attribute.name
|
180
|
+
hash[attribute.name] = serialize_value __cache__[attribute.name], attribute.type
|
181
|
+
end
|
180
182
|
end
|
181
183
|
end
|
182
184
|
end
|
183
185
|
|
184
|
-
def serialize_value(value)
|
186
|
+
def serialize_value(value, type=nil)
|
185
187
|
case value
|
186
188
|
when Model
|
187
189
|
value.to_h
|
188
190
|
when Array
|
189
|
-
|
191
|
+
t = type.is_a?(Rasti::Types::Array) ? type.type : nil
|
192
|
+
value.map { |v| serialize_value v, t }
|
190
193
|
when Hash
|
194
|
+
t = type.is_a?(Rasti::Types::Hash) ? type.value_type : nil
|
191
195
|
value.each_with_object({}) do |(k,v), h|
|
192
|
-
h[k.to_sym] = serialize_value v
|
196
|
+
h[k.to_sym] = serialize_value v, t
|
193
197
|
end
|
198
|
+
when Time
|
199
|
+
type.is_a?(Rasti::Types::Time) ? value.strftime(type.format) : value
|
194
200
|
else
|
195
201
|
value
|
196
202
|
end
|
data/lib/rasti/model/version.rb
CHANGED
data/spec/model_spec.rb
CHANGED
@@ -164,12 +164,14 @@ describe Rasti::Model do
|
|
164
164
|
|
165
165
|
let :contact_class do
|
166
166
|
Rasti::Model[
|
167
|
-
id:
|
168
|
-
name:
|
169
|
-
birthday:
|
170
|
-
phones:
|
171
|
-
addresses:
|
172
|
-
labels:
|
167
|
+
id: T::Integer,
|
168
|
+
name: T::String,
|
169
|
+
birthday: T::Model[birthday_class],
|
170
|
+
phones: T::Hash[T::Symbol, T::Integer],
|
171
|
+
addresses: T::Array[T::Model[address_class]],
|
172
|
+
labels: T::Array[T::String],
|
173
|
+
created_at: T::Time['%d/%m/%Y %H:%M:%S %z'],
|
174
|
+
updated_at: nil
|
173
175
|
]
|
174
176
|
end
|
175
177
|
|
@@ -190,7 +192,9 @@ describe Rasti::Model do
|
|
190
192
|
{street: 'Lexington Avenue', number: 123},
|
191
193
|
{street: 'Park Avenue', number: 456}
|
192
194
|
],
|
193
|
-
labels: ['Friend', 'Work']
|
195
|
+
labels: ['Friend', 'Work'],
|
196
|
+
created_at: '16/03/2021 09:30:10 -0300',
|
197
|
+
updated_at: Time.parse('2021-03-16T11:45:20-03:00')
|
194
198
|
}
|
195
199
|
end
|
196
200
|
|
@@ -209,11 +213,13 @@ describe Rasti::Model do
|
|
209
213
|
it 'Except' do
|
210
214
|
contact = contact_class.new attributes
|
211
215
|
|
212
|
-
|
213
|
-
|
214
|
-
|
215
|
-
|
216
|
-
|
216
|
+
excluded_attributes = [:age, :addresses, :created_at, :updated_at]
|
217
|
+
|
218
|
+
contact.to_h(except: excluded_attributes).must_equal id: attributes[:id],
|
219
|
+
name: attributes[:name],
|
220
|
+
birthday: attributes[:birthday],
|
221
|
+
phones: attributes[:phones],
|
222
|
+
labels: attributes[:labels]
|
217
223
|
end
|
218
224
|
|
219
225
|
it 'Ignore not assigned attributes' do
|
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: rasti-model
|
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
|
- Gabriel Naiman
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date: 2021-03-
|
11
|
+
date: 2021-03-16 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: multi_require
|