datory 1.0.0.rc13 → 1.0.0.rc14
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/README.md +14 -2
- data/lib/datory/attributes/form.rb +28 -0
- data/lib/datory/context/callable.rb +4 -0
- data/lib/datory/version.rb +1 -1
- metadata +3 -2
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 7c1b9b4a2fbe194c484a57960111c07b2285db29c889406a9e6e29571866b4f0
|
4
|
+
data.tar.gz: ecafad6097d0ba8867b2aa5b332c4c7d91e959728cf24393eb9356131c5fe437
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 97dfe2487f3fb9859d4cbde74f4473d5c2c993ac91f6804afc2bf7d1441d871b90c5400c0911691231587e258db6047cd880289c7449feafaf93af8a0fd82a00
|
7
|
+
data.tar.gz: 9bf01b58328bbe3c6c5822523c34d8383aacf8aa21736a64da8435730f553a8dfa3bf8a147a4e07bb5b86c2b872ab23973f013058802be28f2d443e7678ef185
|
data/README.md
CHANGED
@@ -22,13 +22,25 @@ gem "datory"
|
|
22
22
|
```ruby
|
23
23
|
user = User.find(...)
|
24
24
|
|
25
|
-
UserDto.serialize(user)
|
25
|
+
UserDto.serialize(user) # => { ... }
|
26
|
+
```
|
27
|
+
|
28
|
+
For serialization, the `form` method is also available.
|
29
|
+
This prepares a `Form` object, which has a set of additional methods such as `valid?` and `invalid?`.
|
30
|
+
|
31
|
+
```ruby
|
32
|
+
form = UserDto.form(user)
|
33
|
+
|
34
|
+
form.valid? # => true
|
35
|
+
form.invalid? # => false
|
36
|
+
|
37
|
+
form.serialize # => { ... }
|
26
38
|
```
|
27
39
|
|
28
40
|
#### Deserialize
|
29
41
|
|
30
42
|
```ruby
|
31
|
-
UserDto.deserialize(json)
|
43
|
+
UserDto.deserialize(json) # => Datory::Result
|
32
44
|
```
|
33
45
|
|
34
46
|
#### Examples
|
@@ -0,0 +1,28 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
module Datory
|
4
|
+
module Attributes
|
5
|
+
class Form
|
6
|
+
def initialize(context, model)
|
7
|
+
@context = context
|
8
|
+
@model = model
|
9
|
+
end
|
10
|
+
|
11
|
+
def serialize
|
12
|
+
@serialize ||= @context.serialize(@model)
|
13
|
+
end
|
14
|
+
|
15
|
+
def valid?
|
16
|
+
serialize
|
17
|
+
|
18
|
+
true
|
19
|
+
rescue Datory::Exceptions::SerializationError
|
20
|
+
false
|
21
|
+
end
|
22
|
+
|
23
|
+
def invalid?
|
24
|
+
!valid?
|
25
|
+
end
|
26
|
+
end
|
27
|
+
end
|
28
|
+
end
|
data/lib/datory/version.rb
CHANGED
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: datory
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 1.0.0.
|
4
|
+
version: 1.0.0.rc14
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Anton Sokolov
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date: 2024-04-
|
11
|
+
date: 2024-04-30 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: activesupport
|
@@ -216,6 +216,7 @@ files:
|
|
216
216
|
- lib/datory/attributes/deserialization/service_builder.rb
|
217
217
|
- lib/datory/attributes/deserialization/service_factory.rb
|
218
218
|
- lib/datory/attributes/dsl.rb
|
219
|
+
- lib/datory/attributes/form.rb
|
219
220
|
- lib/datory/attributes/options/base.rb
|
220
221
|
- lib/datory/attributes/options/from.rb
|
221
222
|
- lib/datory/attributes/options/to.rb
|