datory 1.0.0.rc12 → 1.0.0.rc14
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/README.md +19 -5
- data/lib/datory/attributes/attribute.rb +64 -89
- data/lib/datory/attributes/collection.rb +4 -4
- data/lib/datory/attributes/descriptor.rb +7 -10
- data/lib/datory/attributes/dsl.rb +4 -4
- data/lib/datory/attributes/form.rb +28 -0
- data/lib/datory/attributes/options/base.rb +31 -0
- data/lib/datory/attributes/options/from.rb +15 -0
- data/lib/datory/attributes/options/to.rb +27 -0
- data/lib/datory/attributes/serialization/serializator.rb +7 -10
- data/lib/datory/context/callable.rb +4 -0
- data/lib/datory/info/dsl.rb +8 -13
- data/lib/datory/service/builder.rb +5 -7
- data/lib/datory/version.rb +1 -1
- metadata +6 -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
|
@@ -44,7 +56,7 @@ class UserDto < Datory::Base
|
|
44
56
|
string :phone
|
45
57
|
string :website
|
46
58
|
|
47
|
-
|
59
|
+
date :birthDate, to: :birth_date
|
48
60
|
|
49
61
|
one :login, include: UserLoginDto
|
50
62
|
one :company, include: UserCompanyDto
|
@@ -62,8 +74,10 @@ class UserLoginDto < Datory::Base
|
|
62
74
|
|
63
75
|
string :md5
|
64
76
|
string :sha1
|
77
|
+
|
78
|
+
duration :lifetime
|
65
79
|
|
66
|
-
|
80
|
+
datetime :registered_at
|
67
81
|
end
|
68
82
|
```
|
69
83
|
|
@@ -160,7 +174,7 @@ UserDto.info
|
|
160
174
|
```
|
161
175
|
|
162
176
|
```
|
163
|
-
#<Datory::Info::Result:
|
177
|
+
#<Datory::Info::Result:0x000000011eecd7d0 @attributes={:id=>{:from=>{:name=>:id, :type=>String, :min=>nil, :max=>nil, :consists_of=>false, :format=>:uuid}, :to=>{:name=>:id, :type=>String, :min=>nil, :max=>nil, :consists_of=>false, :format=>:uuid, :required=>true, :include=>nil}}, :firstname=>{:from=>{:name=>:firstname, :type=>String, :min=>nil, :max=>nil, :consists_of=>false, :format=>nil}, :to=>{:name=>:first_name, :type=>String, :min=>nil, :max=>nil, :consists_of=>false, :format=>nil, :required=>true, :include=>nil}}, :lastname=>{:from=>{:name=>:lastname, :type=>String, :min=>nil, :max=>nil, :consists_of=>false, :format=>nil}, :to=>{:name=>:last_name, :type=>String, :min=>nil, :max=>nil, :consists_of=>false, :format=>nil, :required=>true, :include=>nil}}, :email=>{:from=>{:name=>:email, :type=>String, :min=>nil, :max=>nil, :consists_of=>false, :format=>nil}, :to=>{:name=>:email, :type=>String, :min=>nil, :max=>nil, :consists_of=>false, :format=>nil, :required=>true, :include=>nil}}, :phone=>{:from=>{:name=>:phone, :type=>String, :min=>nil, :max=>nil, :consists_of=>false, :format=>nil}, :to=>{:name=>:phone, :type=>String, :min=>nil, :max=>nil, :consists_of=>false, :format=>nil, :required=>true, :include=>nil}}, :website=>{:from=>{:name=>:website, :type=>String, :min=>nil, :max=>nil, :consists_of=>false, :format=>nil}, :to=>{:name=>:website, :type=>String, :min=>nil, :max=>nil, :consists_of=>false, :format=>nil, :required=>true, :include=>nil}}, :birthDate=>{:from=>{:name=>:birthDate, :type=>String, :min=>nil, :max=>nil, :consists_of=>false, :format=>:date}, :to=>{:name=>:birth_date, :type=>Date, :min=>nil, :max=>nil, :consists_of=>false, :format=>nil, :required=>true, :include=>nil}}, :login=>{:from=>{:name=>:login, :type=>Hash, :min=>nil, :max=>nil, :consists_of=>false, :format=>nil}, :to=>{:name=>:login, :type=>[Datory::Result, Hash], :min=>nil, :max=>nil, :consists_of=>false, :format=>nil, :required=>true, :include=>Usual::Example1::UserLogin}}, :company=>{:from=>{:name=>:company, :type=>Hash, :min=>nil, :max=>nil, :consists_of=>false, :format=>nil}, :to=>{:name=>:company, :type=>[Datory::Result, Hash], :min=>nil, :max=>nil, :consists_of=>false, :format=>nil, :required=>true, :include=>Usual::Example1::UserCompany}}, :addresses=>{:from=>{:name=>:addresses, :type=>Array, :min=>nil, :max=>nil, :consists_of=>[Datory::Result, Hash], :format=>nil}, :to=>{:name=>:addresses, :type=>Array, :min=>nil, :max=>nil, :consists_of=>[Datory::Result, Hash], :format=>nil, :required=>true, :include=>Usual::Example1::UserAddress}}}>
|
164
178
|
```
|
165
179
|
|
166
180
|
### Describe
|
@@ -2,130 +2,105 @@
|
|
2
2
|
|
3
3
|
module Datory
|
4
4
|
module Attributes
|
5
|
-
class Attribute
|
6
|
-
attr_reader :
|
5
|
+
class Attribute
|
6
|
+
attr_reader :from, :to
|
7
7
|
|
8
|
-
def initialize(name, **options)
|
9
|
-
@
|
10
|
-
|
8
|
+
def initialize(name, **options) # rubocop:disable Metrics/MethodLength
|
9
|
+
@from = Options::From.new(
|
10
|
+
name: name,
|
11
|
+
type: options.fetch(:from),
|
12
|
+
consists_of: options.fetch(:consists_of, false),
|
13
|
+
min: options.fetch(:min, nil),
|
14
|
+
max: options.fetch(:max, nil),
|
15
|
+
format: options.fetch(:format, nil)
|
16
|
+
)
|
17
|
+
|
18
|
+
@to = Options::To.new(
|
19
|
+
name: options.fetch(:to, name),
|
20
|
+
type: options.fetch(:as, @from.type),
|
21
|
+
# TODO: It is necessary to implement NilClass support for optional
|
22
|
+
required: options.fetch(:required, true),
|
23
|
+
consists_of: @from.consists_of,
|
24
|
+
min: @from.min,
|
25
|
+
max: @from.max,
|
26
|
+
format: options.fetch(:format, nil),
|
27
|
+
include_class: options.fetch(:include, nil)
|
28
|
+
)
|
11
29
|
end
|
12
30
|
|
13
|
-
|
31
|
+
##########################################################################
|
32
|
+
|
33
|
+
def input_serialization_options # rubocop:disable Metrics/AbcSize
|
14
34
|
hash = {
|
15
|
-
as:
|
16
|
-
type:
|
17
|
-
required:
|
18
|
-
consists_of:
|
35
|
+
as: to.name,
|
36
|
+
type: to.type,
|
37
|
+
required: to.required,
|
38
|
+
consists_of: to.consists_of
|
19
39
|
}
|
20
40
|
|
21
|
-
|
22
|
-
hash[:min] = min
|
23
|
-
end
|
41
|
+
hash[:min] = to.min if to.min.present?
|
24
42
|
|
25
|
-
|
26
|
-
hash[:max] = max
|
27
|
-
end
|
43
|
+
hash[:max] = to.max if to.max.present?
|
28
44
|
|
29
|
-
|
30
|
-
hash[:format] = format
|
31
|
-
end
|
45
|
+
hash[:format] = to.format if to.format.present?
|
32
46
|
|
33
47
|
hash
|
34
48
|
end
|
35
49
|
|
36
|
-
def
|
50
|
+
def output_serialization_options # rubocop:disable Metrics/AbcSize
|
37
51
|
hash = {
|
38
|
-
|
39
|
-
type:
|
40
|
-
required: options.fetch(:required, true),
|
41
|
-
consists_of: options.fetch(:consists_of, false),
|
42
|
-
prepare: (lambda do |value:|
|
43
|
-
include_class = options.fetch(:include, nil)
|
44
|
-
return value unless include_class.present?
|
45
|
-
|
46
|
-
from_type = options.fetch(:from, nil)
|
47
|
-
|
48
|
-
if [Set, Array].include?(from_type)
|
49
|
-
value.map { |item| include_class.deserialize(**item) }
|
50
|
-
else
|
51
|
-
include_class.deserialize(**value)
|
52
|
-
end
|
53
|
-
end)
|
52
|
+
consists_of: to.consists_of == Hash ? Datory::Result : from.consists_of,
|
53
|
+
type: to.type == Datory::Result ? Hash : from.type
|
54
54
|
}
|
55
55
|
|
56
|
-
|
57
|
-
hash[:min] = min
|
58
|
-
end
|
56
|
+
hash[:min] = from.min if from.min.present?
|
59
57
|
|
60
|
-
|
61
|
-
hash[:max] = max
|
62
|
-
end
|
58
|
+
hash[:max] = from.max if from.max.present?
|
63
59
|
|
64
|
-
|
65
|
-
hash[:format] = format
|
66
|
-
end
|
60
|
+
hash[:format] = from.format if from.format.present?
|
67
61
|
|
68
62
|
hash
|
69
63
|
end
|
70
64
|
|
71
|
-
|
65
|
+
##########################################################################
|
66
|
+
|
67
|
+
def input_deserialization_options # rubocop:disable Metrics/MethodLength, Metrics/AbcSize
|
72
68
|
hash = {
|
73
|
-
|
74
|
-
|
75
|
-
|
76
|
-
|
77
|
-
|
78
|
-
|
79
|
-
|
80
|
-
|
81
|
-
|
82
|
-
|
83
|
-
|
84
|
-
|
69
|
+
as: to.name,
|
70
|
+
type: from.type,
|
71
|
+
required: to.required,
|
72
|
+
consists_of: from.consists_of,
|
73
|
+
prepare: (lambda do |value:|
|
74
|
+
return value unless to.include_class.present?
|
75
|
+
|
76
|
+
if [Set, Array].include?(from.type)
|
77
|
+
value.map { |item| to.include_class.deserialize(**item) }
|
78
|
+
else
|
79
|
+
to.include_class.deserialize(**value)
|
80
|
+
end
|
81
|
+
end)
|
85
82
|
}
|
86
83
|
|
87
|
-
|
88
|
-
hash[:min] = min
|
89
|
-
end
|
84
|
+
hash[:min] = from.min if from.min.present?
|
90
85
|
|
91
|
-
|
92
|
-
hash[:max] = max
|
93
|
-
end
|
86
|
+
hash[:max] = from.max if from.max.present?
|
94
87
|
|
95
|
-
|
96
|
-
hash[:format] = format
|
97
|
-
end
|
88
|
+
hash[:format] = from.format if from.format.present?
|
98
89
|
|
99
90
|
hash
|
100
91
|
end
|
101
92
|
|
102
|
-
def output_deserialization_options # rubocop:disable Metrics/
|
93
|
+
def output_deserialization_options # rubocop:disable Metrics/AbcSize
|
103
94
|
hash = {
|
104
|
-
consists_of:
|
105
|
-
|
106
|
-
else
|
107
|
-
consists_of_type
|
108
|
-
end,
|
109
|
-
type: if (from_type = options.fetch(:from)) == Hash
|
110
|
-
Datory::Result
|
111
|
-
elsif (option_as = options.fetch(:as, nil)).present?
|
112
|
-
option_as
|
113
|
-
else
|
114
|
-
from_type
|
115
|
-
end
|
95
|
+
consists_of: from.consists_of == Hash ? Datory::Result : to.consists_of,
|
96
|
+
type: from.type == Hash ? Datory::Result : to.type
|
116
97
|
}
|
117
98
|
|
118
|
-
|
119
|
-
hash[:min] = min
|
120
|
-
end
|
99
|
+
hash[:min] = to.min if to.min.present?
|
121
100
|
|
122
|
-
|
123
|
-
hash[:max] = max
|
124
|
-
end
|
101
|
+
hash[:max] = to.max if to.max.present?
|
125
102
|
|
126
|
-
|
127
|
-
hash[:format] = format
|
128
|
-
end
|
103
|
+
hash[:format] = to.format if to.format.present?
|
129
104
|
|
130
105
|
hash
|
131
106
|
end
|
@@ -15,12 +15,12 @@ module Datory
|
|
15
15
|
end
|
16
16
|
|
17
17
|
def internal_names
|
18
|
-
map { |attribute| attribute.
|
18
|
+
map { |attribute| attribute.to.name }
|
19
19
|
end
|
20
20
|
|
21
|
-
def
|
22
|
-
@
|
23
|
-
include_class = attribute.
|
21
|
+
def include_class_exist?
|
22
|
+
@include_class_exist ||= filter do |attribute| # rubocop:disable Performance/Count
|
23
|
+
include_class = attribute.to.include_class
|
24
24
|
|
25
25
|
next false if include_class.nil?
|
26
26
|
|
@@ -15,21 +15,18 @@ module Datory
|
|
15
15
|
headings << "From"
|
16
16
|
headings << "To"
|
17
17
|
headings << "As"
|
18
|
-
headings << "Include" if collection_of_attributes.
|
18
|
+
headings << "Include" if collection_of_attributes.include_class_exist?
|
19
19
|
|
20
20
|
collection_of_attributes.each do |attribute|
|
21
21
|
row = []
|
22
22
|
|
23
|
-
|
23
|
+
include_class = attribute.to.include_class.presence || attribute.from.type
|
24
24
|
|
25
|
-
|
26
|
-
|
27
|
-
|
28
|
-
row <<
|
29
|
-
row <<
|
30
|
-
row << attribute.options.fetch(:as, include)
|
31
|
-
|
32
|
-
row << (include if include <= Datory::Base) if collection_of_attributes.include_exist?
|
25
|
+
row << attribute.from.name
|
26
|
+
row << attribute.from.type
|
27
|
+
row << attribute.to.name
|
28
|
+
row << attribute.to.type
|
29
|
+
row << (include_class if include_class <= Datory::Base) if collection_of_attributes.include_class_exist?
|
33
30
|
|
34
31
|
rows << row
|
35
32
|
end
|
@@ -60,22 +60,22 @@ module Datory
|
|
60
60
|
end
|
61
61
|
|
62
62
|
def duration(name, **options)
|
63
|
-
options = options.merge(from: String, as: ActiveSupport::Duration
|
63
|
+
options = options.merge(from: String, as: ActiveSupport::Duration, format: { from: :duration })
|
64
64
|
string(name, **options)
|
65
65
|
end
|
66
66
|
|
67
67
|
def date(name, **options)
|
68
|
-
options = options.merge(from: String, as: Date
|
68
|
+
options = options.merge(from: String, as: Date, format: { from: :date })
|
69
69
|
string(name, **options)
|
70
70
|
end
|
71
71
|
|
72
72
|
def time(name, **options)
|
73
|
-
options = options.merge(from: String, as: Time
|
73
|
+
options = options.merge(from: String, as: Time, format: { from: :time })
|
74
74
|
string(name, **options)
|
75
75
|
end
|
76
76
|
|
77
77
|
def datetime(name, **options)
|
78
|
-
options = options.merge(from: String, as: DateTime
|
78
|
+
options = options.merge(from: String, as: DateTime, format: { from: :datetime })
|
79
79
|
string(name, **options)
|
80
80
|
end
|
81
81
|
|
@@ -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
|
@@ -0,0 +1,31 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
module Datory
|
4
|
+
module Attributes
|
5
|
+
module Options
|
6
|
+
class Base
|
7
|
+
attr_reader :name, :type, :consists_of, :min, :max, :format
|
8
|
+
|
9
|
+
def initialize(name:, type:, consists_of:, min:, max:, format:)
|
10
|
+
@name = name
|
11
|
+
@type = type
|
12
|
+
@consists_of = consists_of
|
13
|
+
@min = min
|
14
|
+
@max = max
|
15
|
+
@format = format
|
16
|
+
end
|
17
|
+
|
18
|
+
def info
|
19
|
+
{
|
20
|
+
name: name,
|
21
|
+
type: type,
|
22
|
+
min: min,
|
23
|
+
max: max,
|
24
|
+
consists_of: consists_of,
|
25
|
+
format: format
|
26
|
+
}
|
27
|
+
end
|
28
|
+
end
|
29
|
+
end
|
30
|
+
end
|
31
|
+
end
|
@@ -0,0 +1,15 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
module Datory
|
4
|
+
module Attributes
|
5
|
+
module Options
|
6
|
+
class From < Base
|
7
|
+
def initialize(name:, type:, consists_of:, min:, max:, format:)
|
8
|
+
format = format.fetch(:from, nil) if format.is_a?(Hash)
|
9
|
+
|
10
|
+
super(name: name, type: type, consists_of: consists_of, min: min, max: max, format: format)
|
11
|
+
end
|
12
|
+
end
|
13
|
+
end
|
14
|
+
end
|
15
|
+
end
|
@@ -0,0 +1,27 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
module Datory
|
4
|
+
module Attributes
|
5
|
+
module Options
|
6
|
+
class To < Base
|
7
|
+
attr_reader :required, :include_class
|
8
|
+
|
9
|
+
def initialize(name:, type:, required:, consists_of:, min:, max:, format:, include_class:)
|
10
|
+
@required = required
|
11
|
+
@include_class = include_class
|
12
|
+
|
13
|
+
format = format.fetch(:to, nil) if format.is_a?(Hash)
|
14
|
+
|
15
|
+
super(name: name, type: type, consists_of: consists_of, min: min, max: max, format: format)
|
16
|
+
end
|
17
|
+
|
18
|
+
def info
|
19
|
+
super.merge(
|
20
|
+
required: required,
|
21
|
+
include: include_class
|
22
|
+
)
|
23
|
+
end
|
24
|
+
end
|
25
|
+
end
|
26
|
+
end
|
27
|
+
end
|
@@ -20,23 +20,20 @@ module Datory
|
|
20
20
|
end
|
21
21
|
else
|
22
22
|
@collection_of_attributes.to_h do |attribute|
|
23
|
-
attribute.
|
24
|
-
|
25
|
-
output_formatter = attribute.options.fetch(:output, nil)
|
23
|
+
include_class = attribute.to.include_class
|
24
|
+
# output_formatter = attribute.options.fetch(:output, nil) # TODO
|
26
25
|
|
27
|
-
value = model.public_send(attribute.name)
|
26
|
+
value = model.public_send(attribute.from.name)
|
28
27
|
|
29
28
|
value =
|
30
29
|
if include_class.present?
|
31
|
-
|
32
|
-
|
33
|
-
if [Set, Array].include?(from_type)
|
30
|
+
if [Set, Array].include?(attribute.from.type)
|
34
31
|
value.map { |item| include_class.serialize(item) }
|
35
32
|
else
|
36
33
|
include_class.serialize(value)
|
37
34
|
end
|
38
|
-
elsif output_formatter.is_a?(Proc)
|
39
|
-
|
35
|
+
# elsif output_formatter.is_a?(Proc) # TODO
|
36
|
+
# output_formatter.call(value: value)
|
40
37
|
elsif [Date, Time, DateTime].include?(value.class)
|
41
38
|
value.to_s
|
42
39
|
elsif value.instance_of?(ActiveSupport::Duration)
|
@@ -45,7 +42,7 @@ module Datory
|
|
45
42
|
value
|
46
43
|
end
|
47
44
|
|
48
|
-
[attribute.name, value]
|
45
|
+
[attribute.from.name, value]
|
49
46
|
end
|
50
47
|
end
|
51
48
|
end
|
data/lib/datory/info/dsl.rb
CHANGED
@@ -8,21 +8,16 @@ module Datory
|
|
8
8
|
end
|
9
9
|
|
10
10
|
module ClassMethods
|
11
|
-
def info # rubocop:disable Metrics/MethodLength
|
11
|
+
def info # rubocop:disable Metrics/MethodLength
|
12
12
|
Datory::Info::Result.new(
|
13
13
|
attributes: collection_of_attributes.to_h do |attribute|
|
14
|
-
|
15
|
-
|
16
|
-
|
17
|
-
|
18
|
-
|
19
|
-
|
20
|
-
|
21
|
-
max: attribute.options.fetch(:max, nil),
|
22
|
-
include: attribute.options.fetch(:include, nil)
|
23
|
-
}
|
24
|
-
|
25
|
-
[attribute.name, options]
|
14
|
+
[
|
15
|
+
attribute.from.name,
|
16
|
+
{
|
17
|
+
from: attribute.from.info,
|
18
|
+
to: attribute.to.info
|
19
|
+
}
|
20
|
+
]
|
26
21
|
end
|
27
22
|
)
|
28
23
|
end
|
@@ -29,8 +29,8 @@ module Datory
|
|
29
29
|
private_constant :TRANSFORMATIONS
|
30
30
|
|
31
31
|
def self.prepare_serialization_data_for(attribute) # rubocop:disable Metrics/MethodLength, Metrics/AbcSize
|
32
|
-
serialized_name = attribute.name
|
33
|
-
deserialized_name = attribute.
|
32
|
+
serialized_name = attribute.from.name
|
33
|
+
deserialized_name = attribute.to.name
|
34
34
|
method_name = :"assign_#{serialized_name}_output"
|
35
35
|
|
36
36
|
input deserialized_name, **attribute.input_serialization_options
|
@@ -49,8 +49,8 @@ module Datory
|
|
49
49
|
end
|
50
50
|
|
51
51
|
def self.prepare_deserialization_data_for(attribute) # rubocop:disable Metrics/MethodLength, Metrics/AbcSize
|
52
|
-
serialized_name = attribute.name
|
53
|
-
deserialized_name = attribute.
|
52
|
+
serialized_name = attribute.from.name
|
53
|
+
deserialized_name = attribute.to.name
|
54
54
|
method_name = :"assign_#{deserialized_name}_output"
|
55
55
|
|
56
56
|
input serialized_name, **attribute.input_deserialization_options
|
@@ -62,9 +62,7 @@ module Datory
|
|
62
62
|
define_method(method_name) do
|
63
63
|
value = inputs.public_send(deserialized_name)
|
64
64
|
|
65
|
-
|
66
|
-
|
67
|
-
value = TRANSFORMATIONS.fetch(:DESERIALIZATION).fetch(type_as, ->(v) { v }).call(value)
|
65
|
+
value = TRANSFORMATIONS.fetch(:DESERIALIZATION).fetch(attribute.to.type, ->(v) { v }).call(value)
|
68
66
|
|
69
67
|
outputs.public_send(:"#{deserialized_name}=", value)
|
70
68
|
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,10 @@ 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
|
220
|
+
- lib/datory/attributes/options/base.rb
|
221
|
+
- lib/datory/attributes/options/from.rb
|
222
|
+
- lib/datory/attributes/options/to.rb
|
219
223
|
- lib/datory/attributes/serialization/model.rb
|
220
224
|
- lib/datory/attributes/serialization/serializator.rb
|
221
225
|
- lib/datory/attributes/serialization/service_builder.rb
|