datory 1.0.0.rc4 → 1.0.0.rc5
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/README.md +3 -3
- data/lib/datory/attributes/attribute.rb +50 -0
- data/lib/datory/attributes/dsl.rb +18 -13
- data/lib/datory/attributes/serialization/serializator.rb +2 -0
- data/lib/datory/attributes/tools/service_factory.rb +7 -43
- data/lib/datory/service/base.rb +8 -0
- data/lib/datory/utils.rb +23 -0
- data/lib/datory/version.rb +1 -1
- metadata +5 -4
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 6f0d3dcd343bb011dc9a4f364a9d62b14deaa0920c48495a48c36ed23d08143e
|
4
|
+
data.tar.gz: c299b7365488894f8467c094f3e11445fde073eab82b14d45ff63c284a98f67f
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: b7a458af89e5be1b6ca35f1064da7deb50a8da75751cce60d4c7bf5b93cc559c20ab6ea13156667e2be8e0d984ebebef82c2bc1a08f5c2f6fc7bccca9d9d6dfd
|
7
|
+
data.tar.gz: abaf617dcbcaf4d8e6661cca45fb39ec17d1f69f656f2afc85ee42ccf3beb197c56c60acc07a82d0818d4a5af425b8b2e080bbdecf76815fadb966d08ed70706
|
data/README.md
CHANGED
@@ -35,11 +35,11 @@ UserDto.deserialize(json)
|
|
35
35
|
|
36
36
|
```ruby
|
37
37
|
class UserDto < Datory::Base
|
38
|
-
|
38
|
+
uuid :id
|
39
39
|
string :firstname, to: :first_name
|
40
40
|
string :lastname, to: :last_name
|
41
41
|
string :email
|
42
|
-
string :birthDate, to: :birth_date,
|
42
|
+
string :birthDate, to: :birth_date, as: Date
|
43
43
|
|
44
44
|
one :login, include: UserLoginDto
|
45
45
|
|
@@ -59,7 +59,7 @@ class UserLoginDto < Datory::Base
|
|
59
59
|
string :password
|
60
60
|
string :md5
|
61
61
|
string :sha1
|
62
|
-
string :registered
|
62
|
+
string :registered, to: :registered_at, as: DateTime
|
63
63
|
end
|
64
64
|
```
|
65
65
|
|
@@ -9,6 +9,56 @@ module Datory
|
|
9
9
|
@name = name
|
10
10
|
@options = options
|
11
11
|
end
|
12
|
+
|
13
|
+
def input_options # rubocop:disable Metrics/MethodLength, Metrics/AbcSize
|
14
|
+
hash = {
|
15
|
+
as: options.fetch(:to, name),
|
16
|
+
type: options.fetch(:from),
|
17
|
+
required: options.fetch(:required, true),
|
18
|
+
consists_of: options.fetch(:consists_of, false),
|
19
|
+
prepare: (lambda do |value:|
|
20
|
+
include_class = options.fetch(:include, nil)
|
21
|
+
return value unless include_class.present?
|
22
|
+
|
23
|
+
from_type = options.fetch(:from, nil)
|
24
|
+
|
25
|
+
if [Set, Array].include?(from_type)
|
26
|
+
value.map { |item| include_class.build(**item) }
|
27
|
+
else
|
28
|
+
include_class.build(**value)
|
29
|
+
end
|
30
|
+
end)
|
31
|
+
}
|
32
|
+
|
33
|
+
if (format = options.fetch(:format, nil)).present?
|
34
|
+
hash[:format] = format
|
35
|
+
end
|
36
|
+
|
37
|
+
hash
|
38
|
+
end
|
39
|
+
|
40
|
+
def output_options # rubocop:disable Metrics/MethodLength
|
41
|
+
hash = {
|
42
|
+
consists_of: if (consists_of_type = options.fetch(:consists_of, false)) == Hash
|
43
|
+
Datory::Result
|
44
|
+
else
|
45
|
+
consists_of_type
|
46
|
+
end,
|
47
|
+
type: if (from_type = options.fetch(:from)) == Hash
|
48
|
+
Datory::Result
|
49
|
+
elsif (option_as = options.fetch(:as, nil)).present?
|
50
|
+
option_as
|
51
|
+
else
|
52
|
+
from_type
|
53
|
+
end
|
54
|
+
}
|
55
|
+
|
56
|
+
if (format = options.fetch(:format, nil)).present?
|
57
|
+
hash[:format] = format
|
58
|
+
end
|
59
|
+
|
60
|
+
hash
|
61
|
+
end
|
12
62
|
end
|
13
63
|
end
|
14
64
|
end
|
@@ -17,18 +17,29 @@ module Datory
|
|
17
17
|
|
18
18
|
private
|
19
19
|
|
20
|
-
def
|
21
|
-
|
20
|
+
def attribute(name, **options)
|
21
|
+
collection_of_attributes << Attribute.new(name, **options)
|
22
22
|
end
|
23
23
|
|
24
|
-
|
25
|
-
|
24
|
+
########################################################################
|
25
|
+
|
26
|
+
def one(name, include:, to: nil)
|
27
|
+
attribute(name, to: to.presence || name, from: Hash, include: include)
|
26
28
|
end
|
27
29
|
|
28
|
-
def
|
29
|
-
|
30
|
+
def many(name, include:, to: nil)
|
31
|
+
attribute(name, to: to.presence || name, from: Array, consists_of: Hash, include: include)
|
32
|
+
end
|
33
|
+
|
34
|
+
########################################################################
|
35
|
+
|
36
|
+
def uuid(name, **options)
|
37
|
+
options = options.merge(format: :uuid)
|
38
|
+
string(name, **options)
|
30
39
|
end
|
31
40
|
|
41
|
+
########################################################################
|
42
|
+
|
32
43
|
def symbol(name, **options)
|
33
44
|
options = options.merge(from: Symbol)
|
34
45
|
attribute(name, **options)
|
@@ -64,13 +75,7 @@ module Datory
|
|
64
75
|
attribute(name, **options)
|
65
76
|
end
|
66
77
|
|
67
|
-
|
68
|
-
attribute(name, to: to.presence || name, from: Hash, include: include)
|
69
|
-
end
|
70
|
-
|
71
|
-
def many(name, include:, to: nil)
|
72
|
-
attribute(name, to: to.presence || name, from: Array, consists_of: Hash, include: include)
|
73
|
-
end
|
78
|
+
########################################################################
|
74
79
|
|
75
80
|
def collection_of_attributes
|
76
81
|
@collection_of_attributes ||= Collection.new
|
@@ -13,47 +13,19 @@ module Datory
|
|
13
13
|
@collection_of_attributes = collection_of_attributes
|
14
14
|
end
|
15
15
|
|
16
|
-
# rubocop:disable Metrics/MethodLength, Metrics/AbcSize
|
16
|
+
# rubocop:disable Metrics/MethodLength, Metrics/AbcSize
|
17
17
|
def create
|
18
18
|
return if @model_class.const_defined?(ServiceBuilder::SERVICE_CLASS_NAME)
|
19
19
|
|
20
20
|
collection_of_attributes = @collection_of_attributes
|
21
21
|
|
22
22
|
class_sample = Class.new(Datory::Service::Builder) do
|
23
|
-
collection_of_attributes.each do |attribute|
|
23
|
+
collection_of_attributes.each do |attribute|
|
24
24
|
input_internal_name = attribute.options.fetch(:to, attribute.name)
|
25
25
|
|
26
|
-
input attribute.name,
|
27
|
-
|
28
|
-
|
29
|
-
required: attribute.options.fetch(:required, true),
|
30
|
-
consists_of: attribute.options.fetch(:consists_of, false),
|
31
|
-
prepare: (lambda do |value:|
|
32
|
-
include_class = attribute.options.fetch(:include, nil)
|
33
|
-
return value unless include_class.present?
|
34
|
-
|
35
|
-
from_type = attribute.options.fetch(:from, nil)
|
36
|
-
|
37
|
-
if [Set, Array].include?(from_type)
|
38
|
-
value.map { |item| include_class.build(**item) }
|
39
|
-
else
|
40
|
-
include_class.build(**value)
|
41
|
-
end
|
42
|
-
end)
|
43
|
-
|
44
|
-
output input_internal_name,
|
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
|
51
|
-
Datory::Result
|
52
|
-
elsif (option_as = attribute.options.fetch(:as, nil)).present?
|
53
|
-
option_as
|
54
|
-
else
|
55
|
-
from_type
|
56
|
-
end
|
26
|
+
input attribute.name, **attribute.input_options
|
27
|
+
|
28
|
+
output input_internal_name, **attribute.output_options
|
57
29
|
|
58
30
|
make :"assign_#{input_internal_name}_output"
|
59
31
|
|
@@ -62,15 +34,7 @@ module Datory
|
|
62
34
|
|
63
35
|
option_as = attribute.options.fetch(:as, nil)
|
64
36
|
|
65
|
-
|
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
|
37
|
+
value = Datory::Utils.transform_value_with(value, option_as)
|
74
38
|
|
75
39
|
outputs.public_send(:"#{input_internal_name}=", value)
|
76
40
|
end
|
@@ -92,7 +56,7 @@ module Datory
|
|
92
56
|
|
93
57
|
@model_class.const_set(ServiceBuilder::SERVICE_CLASS_NAME, class_sample)
|
94
58
|
end
|
95
|
-
# rubocop:enable Metrics/MethodLength, Metrics/AbcSize
|
59
|
+
# rubocop:enable Metrics/MethodLength, Metrics/AbcSize
|
96
60
|
end
|
97
61
|
end
|
98
62
|
end
|
data/lib/datory/service/base.rb
CHANGED
@@ -13,6 +13,14 @@ module Datory
|
|
13
13
|
failure_class Datory::Service::Exceptions::Failure
|
14
14
|
|
15
15
|
result_class Datory::Result
|
16
|
+
|
17
|
+
input_option_helpers [
|
18
|
+
Servactory::ToolKit::DynamicOptions::Format.use
|
19
|
+
]
|
20
|
+
|
21
|
+
output_option_helpers [
|
22
|
+
Servactory::ToolKit::DynamicOptions::Format.use
|
23
|
+
]
|
16
24
|
end
|
17
25
|
end
|
18
26
|
end
|
data/lib/datory/utils.rb
ADDED
@@ -0,0 +1,23 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
module Datory
|
4
|
+
module Utils
|
5
|
+
module_function
|
6
|
+
|
7
|
+
TRANSFORMATIONS = {
|
8
|
+
Date => ->(value) { Date.parse(value) },
|
9
|
+
Time => ->(value) { Time.parse(value) },
|
10
|
+
DateTime => ->(value) { DateTime.parse(value) },
|
11
|
+
Symbol => ->(value) { value.to_sym },
|
12
|
+
String => ->(value) { value.to_s },
|
13
|
+
Integer => ->(value) { value.to_i },
|
14
|
+
Float => ->(value) { value.to_f }
|
15
|
+
}.freeze
|
16
|
+
|
17
|
+
private_constant :TRANSFORMATIONS
|
18
|
+
|
19
|
+
def transform_value_with(value, type)
|
20
|
+
TRANSFORMATIONS.fetch(type, ->(v) { v }).call(value)
|
21
|
+
end
|
22
|
+
end
|
23
|
+
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.rc5
|
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-24 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: activesupport
|
@@ -50,14 +50,14 @@ dependencies:
|
|
50
50
|
requirements:
|
51
51
|
- - '='
|
52
52
|
- !ruby/object:Gem::Version
|
53
|
-
version: 2.5.0.
|
53
|
+
version: 2.5.0.rc5
|
54
54
|
type: :runtime
|
55
55
|
prerelease: false
|
56
56
|
version_requirements: !ruby/object:Gem::Requirement
|
57
57
|
requirements:
|
58
58
|
- - '='
|
59
59
|
- !ruby/object:Gem::Version
|
60
|
-
version: 2.5.0.
|
60
|
+
version: 2.5.0.rc5
|
61
61
|
- !ruby/object:Gem::Dependency
|
62
62
|
name: zeitwerk
|
63
63
|
requirement: !ruby/object:Gem::Requirement
|
@@ -211,6 +211,7 @@ files:
|
|
211
211
|
- lib/datory/service/base.rb
|
212
212
|
- lib/datory/service/builder.rb
|
213
213
|
- lib/datory/service/exceptions.rb
|
214
|
+
- lib/datory/utils.rb
|
214
215
|
- lib/datory/version.rb
|
215
216
|
homepage: https://github.com/servactory/datory
|
216
217
|
licenses:
|