datory 1.0.0.rc9 → 1.0.0.rc11
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/lib/datory/attributes/attribute.rb +42 -4
- data/lib/datory/attributes/collection.rb +4 -0
- data/lib/datory/attributes/descriptor.rb +37 -0
- data/lib/datory/attributes/{tools → deserialization}/service_builder.rb +2 -2
- data/lib/datory/attributes/{tools → deserialization}/service_factory.rb +12 -23
- data/lib/datory/attributes/dsl.rb +15 -2
- data/lib/datory/attributes/serialization/model.rb +69 -0
- data/lib/datory/attributes/serialization/serializator.rb +5 -5
- data/lib/datory/attributes/serialization/service_builder.rb +41 -0
- data/lib/datory/attributes/serialization/service_factory.rb +52 -0
- data/lib/datory/attributes/workspace.rb +21 -2
- data/lib/datory/console.rb +26 -0
- data/lib/datory/context/callable.rb +46 -15
- data/lib/datory/context/workspace.rb +25 -10
- data/lib/datory/exceptions.rb +8 -0
- data/lib/datory/utils.rb +21 -4
- data/lib/datory/version.rb +1 -1
- metadata +24 -4
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 0ef2274984450ba2915867f37000b443ffd18a51eeb497adecaaaeae7d0821ae
|
4
|
+
data.tar.gz: ddab73410ef68b0a65f02ed24f9e7177ea43f6779015aa9f5208d4583f8f2882
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 0c794e11db75f222df975ddf31d0e0c9ff2c37ed7dc33e9c6707a5addfd53c12265f45b8808a3c5d7eebbf426674ccf8442bc3f74ec367ee4f67467ed8e0ea51
|
7
|
+
data.tar.gz: 235ed83fe57e9db74fb93803e83820ecba0aea31a673ede0ae6b485a8d4c219394cf1cd0ceb04efd06048e554039105a05538fda8eb520404f9eaf7bb904c1fd
|
@@ -10,7 +10,22 @@ module Datory
|
|
10
10
|
@options = options
|
11
11
|
end
|
12
12
|
|
13
|
-
def
|
13
|
+
def input_serialization_options
|
14
|
+
hash = {
|
15
|
+
as: options.fetch(:to, name),
|
16
|
+
type: options.fetch(:as, options.fetch(:from)),
|
17
|
+
required: options.fetch(:required, true),
|
18
|
+
consists_of: options.fetch(:consists_of, false)
|
19
|
+
}
|
20
|
+
|
21
|
+
if (format = options.fetch(:format, nil)).present?
|
22
|
+
hash[:format] = format
|
23
|
+
end
|
24
|
+
|
25
|
+
hash
|
26
|
+
end
|
27
|
+
|
28
|
+
def input_deserialization_options # rubocop:disable Metrics/MethodLength, Metrics/AbcSize
|
14
29
|
hash = {
|
15
30
|
as: options.fetch(:to, name),
|
16
31
|
type: options.fetch(:from),
|
@@ -23,9 +38,9 @@ module Datory
|
|
23
38
|
from_type = options.fetch(:from, nil)
|
24
39
|
|
25
40
|
if [Set, Array].include?(from_type)
|
26
|
-
value.map { |item| include_class.
|
41
|
+
value.map { |item| include_class.deserialize(**item) }
|
27
42
|
else
|
28
|
-
include_class.
|
43
|
+
include_class.deserialize(**value)
|
29
44
|
end
|
30
45
|
end)
|
31
46
|
}
|
@@ -37,7 +52,30 @@ module Datory
|
|
37
52
|
hash
|
38
53
|
end
|
39
54
|
|
40
|
-
def
|
55
|
+
def output_serialization_options # rubocop:disable Metrics/MethodLength
|
56
|
+
hash = {
|
57
|
+
consists_of: if (consists_of_type = options.fetch(:consists_of, false)) == Hash
|
58
|
+
Datory::Result
|
59
|
+
else
|
60
|
+
consists_of_type
|
61
|
+
end,
|
62
|
+
type: if (as_type = options.fetch(:as, options.fetch(:from))) == Datory::Result
|
63
|
+
Hash
|
64
|
+
elsif (from_type = options.fetch(:from)).present?
|
65
|
+
from_type
|
66
|
+
else
|
67
|
+
as_type
|
68
|
+
end
|
69
|
+
}
|
70
|
+
|
71
|
+
if (format = options.fetch(:format, nil)).present?
|
72
|
+
hash[:format] = format
|
73
|
+
end
|
74
|
+
|
75
|
+
hash
|
76
|
+
end
|
77
|
+
|
78
|
+
def output_deserialization_options # rubocop:disable Metrics/MethodLength
|
41
79
|
hash = {
|
42
80
|
consists_of: if (consists_of_type = options.fetch(:consists_of, false)) == Hash
|
43
81
|
Datory::Result
|
@@ -0,0 +1,37 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
module Datory
|
4
|
+
module Attributes
|
5
|
+
class Descriptor
|
6
|
+
def self.describe(...)
|
7
|
+
new.describe(...)
|
8
|
+
end
|
9
|
+
|
10
|
+
def describe(service_class_name:, collection_of_attributes:) # rubocop:disable Metrics/MethodLength, Metrics/AbcSize
|
11
|
+
headings = []
|
12
|
+
rows = []
|
13
|
+
|
14
|
+
headings << "Attribute"
|
15
|
+
headings << "From"
|
16
|
+
headings << "To"
|
17
|
+
headings << "As"
|
18
|
+
|
19
|
+
collection_of_attributes.each do |attribute|
|
20
|
+
row = []
|
21
|
+
|
22
|
+
row << attribute.name
|
23
|
+
|
24
|
+
from_type = attribute.options.fetch(:from)
|
25
|
+
|
26
|
+
row << from_type
|
27
|
+
row << attribute.options.fetch(:to, attribute.name)
|
28
|
+
row << attribute.options.fetch(:as, attribute.options.fetch(:include, from_type))
|
29
|
+
|
30
|
+
rows << row
|
31
|
+
end
|
32
|
+
|
33
|
+
Datory::Console.print_table(title: service_class_name, headings: headings.uniq, rows: rows)
|
34
|
+
end
|
35
|
+
end
|
36
|
+
end
|
37
|
+
end
|
@@ -2,7 +2,7 @@
|
|
2
2
|
|
3
3
|
module Datory
|
4
4
|
module Attributes
|
5
|
-
module
|
5
|
+
module Deserialization
|
6
6
|
class ServiceFactory
|
7
7
|
def self.create(...)
|
8
8
|
new(...).create
|
@@ -13,50 +13,39 @@ module Datory
|
|
13
13
|
@collection_of_attributes = collection_of_attributes
|
14
14
|
end
|
15
15
|
|
16
|
-
# rubocop:disable Metrics/MethodLength, Metrics/AbcSize
|
17
16
|
def create
|
18
17
|
return if @model_class.const_defined?(ServiceBuilder::SERVICE_CLASS_NAME)
|
19
18
|
|
19
|
+
class_sample = create_service_class
|
20
|
+
|
21
|
+
@model_class.const_set(ServiceBuilder::SERVICE_CLASS_NAME, class_sample)
|
22
|
+
end
|
23
|
+
|
24
|
+
def create_service_class # rubocop:disable Metrics/MethodLength, Metrics/AbcSize
|
20
25
|
collection_of_attributes = @collection_of_attributes
|
21
26
|
|
22
|
-
|
27
|
+
Class.new(Datory::Service::Builder) do
|
23
28
|
collection_of_attributes.each do |attribute|
|
24
29
|
input_internal_name = attribute.options.fetch(:to, attribute.name)
|
25
30
|
|
26
|
-
input attribute.name, **attribute.
|
31
|
+
input attribute.name, **attribute.input_deserialization_options
|
27
32
|
|
28
|
-
output input_internal_name, **attribute.
|
33
|
+
output input_internal_name, **attribute.output_deserialization_options
|
29
34
|
|
30
35
|
make :"assign_#{input_internal_name}_output"
|
31
36
|
|
32
37
|
define_method(:"assign_#{input_internal_name}_output") do
|
33
38
|
value = inputs.public_send(input_internal_name)
|
34
39
|
|
35
|
-
|
40
|
+
type_as = attribute.options.fetch(:as, nil)
|
36
41
|
|
37
|
-
value = Datory::Utils.transform_value_with(value,
|
42
|
+
value = Datory::Utils.transform_value_with(:d, value, type_as)
|
38
43
|
|
39
44
|
outputs.public_send(:"#{input_internal_name}=", value)
|
40
45
|
end
|
41
46
|
end
|
42
|
-
|
43
|
-
# output :model, type: Class
|
44
|
-
|
45
|
-
# make :assign_model_name
|
46
|
-
|
47
|
-
# def assign_model_name
|
48
|
-
# model_class_name_array = self.class.name.split("::")
|
49
|
-
# model_class_name_array.pop
|
50
|
-
# model_class_name = model_class_name_array.join("::")
|
51
|
-
# model_class = model_class_name.constantize
|
52
|
-
#
|
53
|
-
# outputs.model = model_class
|
54
|
-
# end
|
55
47
|
end
|
56
|
-
|
57
|
-
@model_class.const_set(ServiceBuilder::SERVICE_CLASS_NAME, class_sample)
|
58
48
|
end
|
59
|
-
# rubocop:enable Metrics/MethodLength, Metrics/AbcSize
|
60
49
|
end
|
61
50
|
end
|
62
51
|
end
|
@@ -24,11 +24,24 @@ module Datory
|
|
24
24
|
########################################################################
|
25
25
|
|
26
26
|
def one(name, include:, to: nil)
|
27
|
-
attribute(
|
27
|
+
attribute(
|
28
|
+
name,
|
29
|
+
to: to.presence || name,
|
30
|
+
from: Hash,
|
31
|
+
include: include,
|
32
|
+
as: [Datory::Result, Hash]
|
33
|
+
)
|
28
34
|
end
|
29
35
|
|
30
36
|
def many(name, include:, to: nil)
|
31
|
-
attribute(
|
37
|
+
attribute(
|
38
|
+
name,
|
39
|
+
to: to.presence || name,
|
40
|
+
from: Array,
|
41
|
+
consists_of: [Datory::Result, Hash],
|
42
|
+
include: include,
|
43
|
+
as: Array
|
44
|
+
)
|
32
45
|
end
|
33
46
|
|
34
47
|
########################################################################
|
@@ -0,0 +1,69 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
module Datory
|
4
|
+
module Attributes
|
5
|
+
module Serialization
|
6
|
+
class Model
|
7
|
+
def self.prepare(...)
|
8
|
+
new.prepare(...)
|
9
|
+
end
|
10
|
+
|
11
|
+
def self.to_hash(...)
|
12
|
+
new.to_hash(...)
|
13
|
+
end
|
14
|
+
|
15
|
+
def prepare(data)
|
16
|
+
if data.is_a?(Hash)
|
17
|
+
build(data)
|
18
|
+
else
|
19
|
+
data
|
20
|
+
end
|
21
|
+
end
|
22
|
+
|
23
|
+
def to_hash(data)
|
24
|
+
if data.is_a?(Datory::Attributes::Serialization::Model)
|
25
|
+
parse(data)
|
26
|
+
else
|
27
|
+
data
|
28
|
+
end
|
29
|
+
end
|
30
|
+
|
31
|
+
def build(attributes = {}) # rubocop:disable Metrics/MethodLength
|
32
|
+
attributes.each do |key, value|
|
33
|
+
self.class.send(:attr_accessor, key)
|
34
|
+
|
35
|
+
instance_variable_set(:"@#{key}", value)
|
36
|
+
|
37
|
+
if value.is_a?(Array)
|
38
|
+
value.map! { |item| Datory::Attributes::Serialization::Model.prepare(item) }
|
39
|
+
instance_variable_set(:"@#{key}", value)
|
40
|
+
elsif value.is_a?(Hash)
|
41
|
+
instance_variable_set(:"@#{key}", Datory::Attributes::Serialization::Model.prepare(value))
|
42
|
+
else
|
43
|
+
instance_variable_set(:"@#{key}", value)
|
44
|
+
end
|
45
|
+
end
|
46
|
+
|
47
|
+
self
|
48
|
+
end
|
49
|
+
|
50
|
+
def parse(data) # rubocop:disable Metrics/MethodLength
|
51
|
+
data.instance_variables.to_h do |key|
|
52
|
+
value = data.instance_variable_get(key)
|
53
|
+
|
54
|
+
value =
|
55
|
+
if value.is_a?(Array)
|
56
|
+
value.map! { |item| Datory::Attributes::Serialization::Model.to_hash(item) }
|
57
|
+
elsif value.is_a?(Datory::Attributes::Serialization::Model)
|
58
|
+
Datory::Attributes::Serialization::Model.to_hash(value)
|
59
|
+
else
|
60
|
+
value
|
61
|
+
end
|
62
|
+
|
63
|
+
[key.to_s.delete_prefix("@").to_sym, value]
|
64
|
+
end
|
65
|
+
end
|
66
|
+
end
|
67
|
+
end
|
68
|
+
end
|
69
|
+
end
|
@@ -20,17 +20,17 @@ module Datory
|
|
20
20
|
end
|
21
21
|
else
|
22
22
|
@collection_of_attributes.to_h do |attribute|
|
23
|
-
|
23
|
+
attribute.options.fetch(:to, attribute.name)
|
24
24
|
include_class = attribute.options.fetch(:include, nil)
|
25
25
|
output_formatter = attribute.options.fetch(:output, nil)
|
26
26
|
|
27
|
-
value = model.public_send(
|
27
|
+
value = model.public_send(attribute.name)
|
28
28
|
|
29
29
|
value =
|
30
30
|
if include_class.present?
|
31
|
-
|
31
|
+
from_type = attribute.options.fetch(:from)
|
32
32
|
|
33
|
-
if [Set, Array].include?(
|
33
|
+
if [Set, Array].include?(from_type)
|
34
34
|
value.map { |item| include_class.serialize(item) }
|
35
35
|
else
|
36
36
|
include_class.serialize(value)
|
@@ -39,7 +39,7 @@ module Datory
|
|
39
39
|
output_formatter.call(value: value)
|
40
40
|
elsif [Date, Time, DateTime].include?(value.class)
|
41
41
|
value.to_s
|
42
|
-
elsif ActiveSupport::Duration
|
42
|
+
elsif value.instance_of?(ActiveSupport::Duration)
|
43
43
|
value.iso8601
|
44
44
|
else
|
45
45
|
value
|
@@ -0,0 +1,41 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
module Datory
|
4
|
+
module Attributes
|
5
|
+
module Serialization
|
6
|
+
class ServiceBuilder
|
7
|
+
SERVICE_CLASS_NAME = "SBuilder"
|
8
|
+
|
9
|
+
def self.build!(...)
|
10
|
+
new(...).build!
|
11
|
+
end
|
12
|
+
|
13
|
+
def initialize(context, model, collection_of_attributes)
|
14
|
+
@context = context
|
15
|
+
@model = model
|
16
|
+
@collection_of_attributes = collection_of_attributes
|
17
|
+
end
|
18
|
+
|
19
|
+
def build!
|
20
|
+
ServiceFactory.create(@context.class, @collection_of_attributes)
|
21
|
+
|
22
|
+
attributes = Datory::Attributes::Serialization::Model.to_hash(@model)
|
23
|
+
|
24
|
+
unnecessary_attributes = attributes.keys.difference(@collection_of_attributes.internal_names)
|
25
|
+
|
26
|
+
unnecessary_attributes.each do |key|
|
27
|
+
attributes.delete(key)
|
28
|
+
end
|
29
|
+
|
30
|
+
builder_class.call!(**attributes)
|
31
|
+
end
|
32
|
+
|
33
|
+
private
|
34
|
+
|
35
|
+
def builder_class
|
36
|
+
"#{@context.class.name}::#{SERVICE_CLASS_NAME}".constantize
|
37
|
+
end
|
38
|
+
end
|
39
|
+
end
|
40
|
+
end
|
41
|
+
end
|
@@ -0,0 +1,52 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
module Datory
|
4
|
+
module Attributes
|
5
|
+
module Serialization
|
6
|
+
class ServiceFactory
|
7
|
+
def self.create(...)
|
8
|
+
new(...).create
|
9
|
+
end
|
10
|
+
|
11
|
+
def initialize(model_class, collection_of_attributes)
|
12
|
+
@model_class = model_class
|
13
|
+
@collection_of_attributes = collection_of_attributes
|
14
|
+
end
|
15
|
+
|
16
|
+
def create
|
17
|
+
return if @model_class.const_defined?(ServiceBuilder::SERVICE_CLASS_NAME)
|
18
|
+
|
19
|
+
class_sample = create_service_class
|
20
|
+
|
21
|
+
@model_class.const_set(ServiceBuilder::SERVICE_CLASS_NAME, class_sample)
|
22
|
+
end
|
23
|
+
|
24
|
+
def create_service_class # rubocop:disable Metrics/MethodLength, Metrics/AbcSize
|
25
|
+
collection_of_attributes = @collection_of_attributes
|
26
|
+
|
27
|
+
Class.new(Datory::Service::Builder) do
|
28
|
+
collection_of_attributes.each do |attribute|
|
29
|
+
input_internal_name = attribute.options.fetch(:to, attribute.name)
|
30
|
+
|
31
|
+
input input_internal_name, **attribute.input_serialization_options
|
32
|
+
|
33
|
+
output attribute.name, **attribute.output_serialization_options
|
34
|
+
|
35
|
+
make :"assign_#{attribute.name}_output"
|
36
|
+
|
37
|
+
define_method(:"assign_#{attribute.name}_output") do
|
38
|
+
value = inputs.public_send(input_internal_name)
|
39
|
+
|
40
|
+
from_type = attribute.options.fetch(:from)
|
41
|
+
|
42
|
+
value = Datory::Utils.transform_value_with(:s, value, from_type)
|
43
|
+
|
44
|
+
outputs.public_send(:"#{attribute.name}=", value)
|
45
|
+
end
|
46
|
+
end
|
47
|
+
end
|
48
|
+
end
|
49
|
+
end
|
50
|
+
end
|
51
|
+
end
|
52
|
+
end
|
@@ -5,10 +5,29 @@ module Datory
|
|
5
5
|
module Workspace
|
6
6
|
private
|
7
7
|
|
8
|
-
def
|
8
|
+
def serialize(model:, collection_of_attributes:)
|
9
9
|
super
|
10
10
|
|
11
|
-
|
11
|
+
model = Serialization::ServiceBuilder.build!(self, model, collection_of_attributes)
|
12
|
+
|
13
|
+
Serialization::Serializator.serialize(
|
14
|
+
model: model,
|
15
|
+
collection_of_attributes: collection_of_attributes
|
16
|
+
)
|
17
|
+
end
|
18
|
+
|
19
|
+
def deserialize(incoming_attributes:, collection_of_attributes:)
|
20
|
+
super
|
21
|
+
|
22
|
+
Deserialization::ServiceBuilder.build!(self, incoming_attributes, collection_of_attributes)
|
23
|
+
end
|
24
|
+
|
25
|
+
def to_model(attributes:)
|
26
|
+
super
|
27
|
+
|
28
|
+
attributes.each do |attribute_name, attribute_value|
|
29
|
+
define_singleton_method(attribute_name) { attribute_value }
|
30
|
+
end
|
12
31
|
end
|
13
32
|
end
|
14
33
|
end
|
@@ -0,0 +1,26 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
require "terminal-table"
|
4
|
+
|
5
|
+
module Datory
|
6
|
+
class Console
|
7
|
+
def self.print_table(headings:, rows:, title: nil)
|
8
|
+
table = Terminal::Table.new(
|
9
|
+
title: title,
|
10
|
+
headings: headings,
|
11
|
+
rows: rows,
|
12
|
+
style: { border_x: "~", border_i: "~" }
|
13
|
+
)
|
14
|
+
|
15
|
+
new(table.to_s).print
|
16
|
+
end
|
17
|
+
|
18
|
+
def initialize(text)
|
19
|
+
@text = text
|
20
|
+
end
|
21
|
+
|
22
|
+
def print
|
23
|
+
puts @text
|
24
|
+
end
|
25
|
+
end
|
26
|
+
end
|
@@ -4,10 +4,19 @@ module Datory
|
|
4
4
|
module Context
|
5
5
|
module Callable
|
6
6
|
def serialize(model)
|
7
|
-
|
8
|
-
model
|
9
|
-
|
10
|
-
|
7
|
+
if [Set, Array].include?(model.class)
|
8
|
+
model.map do |model_item|
|
9
|
+
serialize(model_item)
|
10
|
+
end
|
11
|
+
else
|
12
|
+
context = send(:new)
|
13
|
+
model = Datory::Attributes::Serialization::Model.prepare(model)
|
14
|
+
_serialize(context, model)
|
15
|
+
end
|
16
|
+
rescue Datory::Service::Exceptions::Input,
|
17
|
+
Datory::Service::Exceptions::Internal,
|
18
|
+
Datory::Service::Exceptions::Output => e
|
19
|
+
raise Datory::Exceptions::SerializationError.new(message: e.message)
|
11
20
|
end
|
12
21
|
|
13
22
|
def deserialize(json)
|
@@ -16,32 +25,54 @@ module Datory
|
|
16
25
|
deserialize(json_item)
|
17
26
|
end
|
18
27
|
else
|
28
|
+
context = send(:new)
|
19
29
|
hash = JSON.parse(json.to_json)
|
20
|
-
|
30
|
+
|
31
|
+
_deserialize(context, **hash)
|
21
32
|
end
|
33
|
+
rescue Datory::Service::Exceptions::Input,
|
34
|
+
Datory::Service::Exceptions::Internal,
|
35
|
+
Datory::Service::Exceptions::Output => e
|
36
|
+
raise Datory::Exceptions::DeserializationError.new(message: e.message)
|
22
37
|
end
|
23
38
|
|
24
|
-
|
25
|
-
# context = send(:new)
|
26
|
-
#
|
27
|
-
# _build!(context, **attributes)
|
28
|
-
# end
|
29
|
-
|
30
|
-
def build(attributes = {})
|
39
|
+
def to_model(**attributes)
|
31
40
|
context = send(:new)
|
32
41
|
|
33
|
-
|
42
|
+
_to_model(context, **attributes)
|
43
|
+
end
|
44
|
+
|
45
|
+
def describe
|
46
|
+
Datory::Attributes::Descriptor.describe(
|
47
|
+
service_class_name: name,
|
48
|
+
collection_of_attributes: collection_of_attributes
|
49
|
+
)
|
34
50
|
end
|
35
51
|
|
36
52
|
private
|
37
53
|
|
38
|
-
def
|
54
|
+
def _serialize(context, model)
|
39
55
|
context.send(
|
40
|
-
:
|
56
|
+
:_serialize,
|
57
|
+
model: model,
|
58
|
+
collection_of_attributes: collection_of_attributes
|
59
|
+
)
|
60
|
+
end
|
61
|
+
|
62
|
+
def _deserialize(context, **attributes)
|
63
|
+
context.send(
|
64
|
+
:_deserialize,
|
41
65
|
incoming_attributes: attributes.symbolize_keys,
|
42
66
|
collection_of_attributes: collection_of_attributes
|
43
67
|
)
|
44
68
|
end
|
69
|
+
|
70
|
+
def _to_model(context, **attributes)
|
71
|
+
context.send(
|
72
|
+
:_to_model,
|
73
|
+
attributes: attributes
|
74
|
+
)
|
75
|
+
end
|
45
76
|
end
|
46
77
|
end
|
47
78
|
end
|
@@ -16,24 +16,39 @@ module Datory
|
|
16
16
|
attr_reader :incoming_attributes,
|
17
17
|
:collection_of_attributes
|
18
18
|
|
19
|
-
def
|
20
|
-
|
21
|
-
|
22
|
-
|
23
|
-
|
19
|
+
def _serialize(model:, collection_of_attributes:)
|
20
|
+
serialize(
|
21
|
+
model: model,
|
22
|
+
collection_of_attributes: collection_of_attributes
|
23
|
+
)
|
24
|
+
end
|
25
|
+
|
26
|
+
def _deserialize(incoming_attributes:, collection_of_attributes:)
|
27
|
+
deserialize(
|
24
28
|
incoming_attributes: incoming_attributes,
|
25
29
|
collection_of_attributes: collection_of_attributes
|
26
30
|
)
|
27
31
|
end
|
28
32
|
|
29
|
-
def
|
30
|
-
|
31
|
-
|
32
|
-
|
33
|
-
|
33
|
+
def _to_model(attributes:)
|
34
|
+
to_model(
|
35
|
+
attributes: attributes
|
36
|
+
)
|
37
|
+
end
|
38
|
+
|
39
|
+
def serialize(model:, collection_of_attributes:, **)
|
40
|
+
@model = model
|
41
|
+
@collection_of_attributes = collection_of_attributes
|
42
|
+
end
|
43
|
+
|
44
|
+
def deserialize(incoming_attributes:, collection_of_attributes:, **)
|
34
45
|
@incoming_attributes = incoming_attributes
|
35
46
|
@collection_of_attributes = collection_of_attributes
|
36
47
|
end
|
48
|
+
|
49
|
+
def to_model(attributes:)
|
50
|
+
@attributes = attributes
|
51
|
+
end
|
37
52
|
end
|
38
53
|
end
|
39
54
|
end
|
data/lib/datory/utils.rb
CHANGED
@@ -4,7 +4,7 @@ module Datory
|
|
4
4
|
module Utils
|
5
5
|
module_function
|
6
6
|
|
7
|
-
|
7
|
+
D_TRANSFORMATIONS = {
|
8
8
|
Symbol => ->(value) { value.to_sym },
|
9
9
|
String => ->(value) { value.to_s },
|
10
10
|
Integer => ->(value) { value.to_i },
|
@@ -15,10 +15,27 @@ module Datory
|
|
15
15
|
ActiveSupport::Duration => ->(value) { ActiveSupport::Duration.parse(value) }
|
16
16
|
}.freeze
|
17
17
|
|
18
|
-
private_constant :
|
18
|
+
private_constant :D_TRANSFORMATIONS
|
19
19
|
|
20
|
-
|
21
|
-
|
20
|
+
S_TRANSFORMATIONS = {
|
21
|
+
Symbol => ->(value, _type) { value.to_sym },
|
22
|
+
String => ->(value, _type) { value.to_s },
|
23
|
+
Integer => ->(value, _type) { value.to_i },
|
24
|
+
Float => ->(value, _type) { value.to_f },
|
25
|
+
Date => ->(value, _type) { value.to_s },
|
26
|
+
Time => ->(value, _type) { value.to_s },
|
27
|
+
DateTime => ->(value, _type) { value.to_s },
|
28
|
+
ActiveSupport::Duration => ->(value, _type) { value.iso8601 }
|
29
|
+
}.freeze
|
30
|
+
|
31
|
+
private_constant :S_TRANSFORMATIONS
|
32
|
+
|
33
|
+
def transform_value_with(format, value, type)
|
34
|
+
if format == :d
|
35
|
+
D_TRANSFORMATIONS.fetch(type, ->(v) { v }).call(value)
|
36
|
+
else
|
37
|
+
S_TRANSFORMATIONS.fetch(value.class, ->(v, _type) { v }).call(value, type)
|
38
|
+
end
|
22
39
|
end
|
23
40
|
end
|
24
41
|
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.rc11
|
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-26 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: activesupport
|
@@ -58,6 +58,20 @@ dependencies:
|
|
58
58
|
- - '='
|
59
59
|
- !ruby/object:Gem::Version
|
60
60
|
version: 2.5.0.rc6
|
61
|
+
- !ruby/object:Gem::Dependency
|
62
|
+
name: terminal-table
|
63
|
+
requirement: !ruby/object:Gem::Requirement
|
64
|
+
requirements:
|
65
|
+
- - ">="
|
66
|
+
- !ruby/object:Gem::Version
|
67
|
+
version: '3.0'
|
68
|
+
type: :runtime
|
69
|
+
prerelease: false
|
70
|
+
version_requirements: !ruby/object:Gem::Requirement
|
71
|
+
requirements:
|
72
|
+
- - ">="
|
73
|
+
- !ruby/object:Gem::Version
|
74
|
+
version: '3.0'
|
61
75
|
- !ruby/object:Gem::Dependency
|
62
76
|
name: zeitwerk
|
63
77
|
requirement: !ruby/object:Gem::Requirement
|
@@ -198,16 +212,22 @@ files:
|
|
198
212
|
- lib/datory.rb
|
199
213
|
- lib/datory/attributes/attribute.rb
|
200
214
|
- lib/datory/attributes/collection.rb
|
215
|
+
- lib/datory/attributes/descriptor.rb
|
216
|
+
- lib/datory/attributes/deserialization/service_builder.rb
|
217
|
+
- lib/datory/attributes/deserialization/service_factory.rb
|
201
218
|
- lib/datory/attributes/dsl.rb
|
219
|
+
- lib/datory/attributes/serialization/model.rb
|
202
220
|
- lib/datory/attributes/serialization/serializator.rb
|
203
|
-
- lib/datory/attributes/
|
204
|
-
- lib/datory/attributes/
|
221
|
+
- lib/datory/attributes/serialization/service_builder.rb
|
222
|
+
- lib/datory/attributes/serialization/service_factory.rb
|
205
223
|
- lib/datory/attributes/workspace.rb
|
206
224
|
- lib/datory/base.rb
|
225
|
+
- lib/datory/console.rb
|
207
226
|
- lib/datory/context/callable.rb
|
208
227
|
- lib/datory/context/dsl.rb
|
209
228
|
- lib/datory/context/workspace.rb
|
210
229
|
- lib/datory/engine.rb
|
230
|
+
- lib/datory/exceptions.rb
|
211
231
|
- lib/datory/result.rb
|
212
232
|
- lib/datory/service/base.rb
|
213
233
|
- lib/datory/service/builder.rb
|