datory 1.0.0.rc3 → 1.0.0.rc4
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 +3 -3
- data/lib/datory/attributes/dsl.rb +11 -11
- data/lib/datory/attributes/serialization/serializator.rb +1 -1
- data/lib/datory/attributes/tools/service_factory.rb +28 -14
- data/lib/datory/version.rb +1 -1
- metadata +1 -1
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 5ca68aea305e426d629f97a3d8940e016a933e4298e56b7ab7d3f9e495fb515d
|
4
|
+
data.tar.gz: 3589f41e040965dacdbaa9f22d197c837afd96f6a5d34e6b32b93e2043ce2391
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 4b08dcadef0150c3183c5ae1458fdd4de9ddf9a1dd6303c5b7dfa1e104f7c4581826c4876660628879a432263ac4cc87de728d2948a3167dc1dd20c83b6bf176
|
7
|
+
data.tar.gz: a19f50f5e2bfe11d3092292ea2e641f546ba78bd2b2eb8efb50769f42d47753c9a6edd46460a6391b4e389c6dcd662cbaf5510f80aa7fd66ab9cf0f3233bb5f0
|
data/README.md
CHANGED
@@ -36,10 +36,10 @@ UserDto.deserialize(json)
|
|
36
36
|
```ruby
|
37
37
|
class UserDto < Datory::Base
|
38
38
|
string :id
|
39
|
-
string :firstname,
|
40
|
-
string :lastname,
|
39
|
+
string :firstname, to: :first_name
|
40
|
+
string :lastname, to: :last_name
|
41
41
|
string :email
|
42
|
-
string :birthDate,
|
42
|
+
string :birthDate, to: :birth_date, output: ->(value:) { value.to_s }
|
43
43
|
|
44
44
|
one :login, include: UserLoginDto
|
45
45
|
|
@@ -30,46 +30,46 @@ module Datory
|
|
30
30
|
end
|
31
31
|
|
32
32
|
def symbol(name, **options)
|
33
|
-
options = options.merge(
|
33
|
+
options = options.merge(from: Symbol)
|
34
34
|
attribute(name, **options)
|
35
35
|
end
|
36
36
|
|
37
37
|
def string(name, **options)
|
38
|
-
options = options.merge(
|
38
|
+
options = options.merge(from: String)
|
39
39
|
attribute(name, **options)
|
40
40
|
end
|
41
41
|
|
42
42
|
def integer(name, **options)
|
43
|
-
options = options.merge(
|
43
|
+
options = options.merge(from: Integer)
|
44
44
|
attribute(name, **options)
|
45
45
|
end
|
46
46
|
|
47
47
|
def float(name, **options)
|
48
|
-
options = options.merge(
|
48
|
+
options = options.merge(from: Float)
|
49
49
|
attribute(name, **options)
|
50
50
|
end
|
51
51
|
|
52
52
|
def date(name, **options)
|
53
|
-
options = options.merge(
|
53
|
+
options = options.merge(from: Date)
|
54
54
|
attribute(name, **options)
|
55
55
|
end
|
56
56
|
|
57
57
|
def time(name, **options)
|
58
|
-
options = options.merge(
|
58
|
+
options = options.merge(from: Time)
|
59
59
|
attribute(name, **options)
|
60
60
|
end
|
61
61
|
|
62
62
|
def datetime(name, **options)
|
63
|
-
options = options.merge(
|
63
|
+
options = options.merge(from: DateTime)
|
64
64
|
attribute(name, **options)
|
65
65
|
end
|
66
66
|
|
67
|
-
def one(name, include:,
|
68
|
-
attribute(name,
|
67
|
+
def one(name, include:, to: nil)
|
68
|
+
attribute(name, to: to.presence || name, from: Hash, include: include)
|
69
69
|
end
|
70
70
|
|
71
|
-
def many(name, include:,
|
72
|
-
attribute(name,
|
71
|
+
def many(name, include:, to: nil)
|
72
|
+
attribute(name, to: to.presence || name, from: Array, consists_of: Hash, include: include)
|
73
73
|
end
|
74
74
|
|
75
75
|
def collection_of_attributes
|
@@ -18,7 +18,7 @@ module Datory
|
|
18
18
|
end
|
19
19
|
else
|
20
20
|
@collection_of_attributes.to_h do |attribute|
|
21
|
-
internal_name = attribute.options.fetch(:
|
21
|
+
internal_name = attribute.options.fetch(:to, attribute.name)
|
22
22
|
include_class = attribute.options.fetch(:include, nil)
|
23
23
|
output_formatter = attribute.options.fetch(:output, nil)
|
24
24
|
|
@@ -21,20 +21,20 @@ module Datory
|
|
21
21
|
|
22
22
|
class_sample = Class.new(Datory::Service::Builder) do
|
23
23
|
collection_of_attributes.each do |attribute| # rubocop:disable Metrics/BlockLength
|
24
|
-
input_internal_name = attribute.options.fetch(:
|
24
|
+
input_internal_name = attribute.options.fetch(:to, attribute.name)
|
25
25
|
|
26
26
|
input attribute.name,
|
27
27
|
as: input_internal_name,
|
28
|
-
type: attribute.options.fetch(:
|
28
|
+
type: attribute.options.fetch(:from),
|
29
29
|
required: attribute.options.fetch(:required, true),
|
30
30
|
consists_of: attribute.options.fetch(:consists_of, false),
|
31
31
|
prepare: (lambda do |value:|
|
32
32
|
include_class = attribute.options.fetch(:include, nil)
|
33
33
|
return value unless include_class.present?
|
34
34
|
|
35
|
-
|
35
|
+
from_type = attribute.options.fetch(:from, nil)
|
36
36
|
|
37
|
-
if [Set, Array].include?(
|
37
|
+
if [Set, Array].include?(from_type)
|
38
38
|
value.map { |item| include_class.build(**item) }
|
39
39
|
else
|
40
40
|
include_class.build(**value)
|
@@ -42,23 +42,37 @@ module Datory
|
|
42
42
|
end)
|
43
43
|
|
44
44
|
output input_internal_name,
|
45
|
-
consists_of: (
|
46
|
-
|
47
|
-
|
48
|
-
|
49
|
-
|
50
|
-
|
51
|
-
),
|
52
|
-
type: if (type = attribute.options.fetch(:type)) == Hash
|
45
|
+
consists_of: if (consists_of_type = attribute.options.fetch(:consists_of, false)) == Hash
|
46
|
+
Datory::Result
|
47
|
+
else
|
48
|
+
consists_of_type
|
49
|
+
end,
|
50
|
+
type: if (from_type = attribute.options.fetch(:from)) == Hash
|
53
51
|
Datory::Result
|
52
|
+
elsif (option_as = attribute.options.fetch(:as, nil)).present?
|
53
|
+
option_as
|
54
54
|
else
|
55
|
-
|
55
|
+
from_type
|
56
56
|
end
|
57
57
|
|
58
58
|
make :"assign_#{input_internal_name}_output"
|
59
59
|
|
60
60
|
define_method(:"assign_#{input_internal_name}_output") do
|
61
|
-
|
61
|
+
value = inputs.public_send(input_internal_name)
|
62
|
+
|
63
|
+
option_as = attribute.options.fetch(:as, nil)
|
64
|
+
|
65
|
+
if [Date, Time, DateTime].include?(option_as)
|
66
|
+
value = option_as.parse(value)
|
67
|
+
elsif option_as == String
|
68
|
+
value = value.to_s
|
69
|
+
elsif option_as == Integer
|
70
|
+
value = value.to_i
|
71
|
+
elsif option_as == Float
|
72
|
+
value = value.to_f
|
73
|
+
end
|
74
|
+
|
75
|
+
outputs.public_send(:"#{input_internal_name}=", value)
|
62
76
|
end
|
63
77
|
end
|
64
78
|
|
data/lib/datory/version.rb
CHANGED