rasti-form 1.0.3 → 1.1.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/rasti/form/version.rb +1 -1
- data/lib/rasti/form.rb +8 -4
- data/spec/form_spec.rb +52 -24
- metadata +2 -2
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: d70488681e6a487f474d2988f6e2344795bcca7d
|
4
|
+
data.tar.gz: 79334807aac54d47c80092be57ee122fc828321b
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 5f393c30ca974a0204f6fbe3c86e92fb7df865171fbd5969fba5d3783b45214de20bbd714ff57e99750a0de484546fe748d313a80b45679ca3061c321db8e44b
|
7
|
+
data.tar.gz: 417a854f878b0ec9007b36529f93358f406019e41143a104bdf804a60528d3a9b05bf38c4ac2824341fbb44a0c025c1f00bbf7ced06790b7bf6d77e0b443a9e1
|
data/lib/rasti/form/version.rb
CHANGED
data/lib/rasti/form.rb
CHANGED
@@ -56,12 +56,16 @@ module Rasti
|
|
56
56
|
end
|
57
57
|
alias_method :inspect, :to_s
|
58
58
|
|
59
|
-
def attributes
|
60
|
-
assigned_attribute_names.
|
59
|
+
def attributes(options={})
|
60
|
+
attributes_filter = {only: assigned_attribute_names, except: []}.merge(options)
|
61
|
+
(attributes_filter[:only] - attributes_filter[:except]).each_with_object({}) do |name, hash|
|
61
62
|
hash[name] = serialize(read_attribute(name))
|
62
63
|
end
|
63
64
|
end
|
64
|
-
|
65
|
+
|
66
|
+
def to_h
|
67
|
+
attributes
|
68
|
+
end
|
65
69
|
|
66
70
|
def assigned?(name)
|
67
71
|
assigned_attribute_names.include? name
|
@@ -112,7 +116,7 @@ module Rasti
|
|
112
116
|
end
|
113
117
|
|
114
118
|
def assigned_attribute_names
|
115
|
-
self.class.attribute_names & instance_variables.map { |v| v.to_s[1..-1].to_sym }
|
119
|
+
@assigned_attribute_names ||= self.class.attribute_names & instance_variables.map { |v| v.to_s[1..-1].to_sym }
|
116
120
|
end
|
117
121
|
|
118
122
|
def serialize(value)
|
data/spec/form_spec.rb
CHANGED
@@ -262,33 +262,61 @@ describe Rasti::Form do
|
|
262
262
|
|
263
263
|
end
|
264
264
|
|
265
|
-
|
266
|
-
|
267
|
-
|
268
|
-
|
269
|
-
|
270
|
-
|
271
|
-
|
272
|
-
|
273
|
-
|
274
|
-
|
275
|
-
|
276
|
-
|
277
|
-
|
278
|
-
|
279
|
-
|
280
|
-
|
281
|
-
},
|
282
|
-
addresses: [
|
283
|
-
{street: 'Lexington Avenue', number: 123},
|
284
|
-
{street: 'Park Avenue', number: 456}
|
265
|
+
describe 'Attributes' do
|
266
|
+
|
267
|
+
let :address_class do
|
268
|
+
Rasti::Form[
|
269
|
+
street: Rasti::Form::Types::String,
|
270
|
+
number: Rasti::Form::Types::Integer
|
271
|
+
]
|
272
|
+
end
|
273
|
+
|
274
|
+
let :contact_class do
|
275
|
+
Rasti::Form[
|
276
|
+
name: Rasti::Form::Types::String,
|
277
|
+
age: Rasti::Form::Types::Integer,
|
278
|
+
phones: Rasti::Form::Types::Hash[Rasti::Form::Types::Symbol, Rasti::Form::Types::Integer],
|
279
|
+
addresses: Rasti::Form::Types::Array[Rasti::Form::Types::Form[address_class]],
|
280
|
+
hobbies: Rasti::Form::Types::Array[Rasti::Form::Types::String]
|
285
281
|
]
|
286
|
-
|
282
|
+
end
|
283
|
+
|
284
|
+
let :attributes do
|
285
|
+
{
|
286
|
+
name: 'John',
|
287
|
+
age: 24,
|
288
|
+
phones: {
|
289
|
+
office: 1234567890,
|
290
|
+
house: 456456456
|
291
|
+
},
|
292
|
+
addresses: [
|
293
|
+
{street: 'Lexington Avenue', number: 123},
|
294
|
+
{street: 'Park Avenue', number: 456}
|
295
|
+
]
|
296
|
+
}
|
297
|
+
end
|
298
|
+
|
299
|
+
it 'All (to_h)' do
|
300
|
+
contact = contact_class.new attributes
|
287
301
|
|
288
|
-
|
302
|
+
contact.attributes.must_equal attributes
|
303
|
+
contact.to_h.must_equal attributes
|
304
|
+
end
|
305
|
+
|
306
|
+
it 'Only' do
|
307
|
+
contact = contact_class.new attributes
|
308
|
+
|
309
|
+
contact.attributes(only: [:name, :age]).must_equal name: attributes[:name],
|
310
|
+
age: attributes[:age]
|
311
|
+
end
|
312
|
+
|
313
|
+
it 'Except' do
|
314
|
+
contact = contact_class.new attributes
|
315
|
+
|
316
|
+
contact.attributes(except: [:age, :addresses]).must_equal name: attributes[:name],
|
317
|
+
phones: attributes[:phones]
|
318
|
+
end
|
289
319
|
|
290
|
-
contact.attributes.must_equal attributes
|
291
|
-
contact.attributes.must_equal contact.to_h
|
292
320
|
end
|
293
321
|
|
294
322
|
it 'to_s' do
|
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: rasti-form
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 1.0
|
4
|
+
version: 1.1.0
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Gabriel Naiman
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date: 2017-12-
|
11
|
+
date: 2017-12-29 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: multi_require
|