datory 1.0.0.rc10 → 1.0.0.rc11
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/lib/datory/attributes/attribute.rb +42 -4
- data/lib/datory/attributes/collection.rb +4 -0
- data/lib/datory/attributes/descriptor.rb +2 -2
- 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 +31 -10
- data/lib/datory/attributes/serialization/serializator.rb +4 -4
- 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 +2 -1
- data/lib/datory/context/callable.rb +39 -26
- 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 +7 -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
|
@@ -7,7 +7,7 @@ module Datory
|
|
7
7
|
new.describe(...)
|
8
8
|
end
|
9
9
|
|
10
|
-
def describe(collection_of_attributes:) # rubocop:disable Metrics/MethodLength, Metrics/AbcSize
|
10
|
+
def describe(service_class_name:, collection_of_attributes:) # rubocop:disable Metrics/MethodLength, Metrics/AbcSize
|
11
11
|
headings = []
|
12
12
|
rows = []
|
13
13
|
|
@@ -30,7 +30,7 @@ module Datory
|
|
30
30
|
rows << row
|
31
31
|
end
|
32
32
|
|
33
|
-
Datory::Console.print_table(headings.uniq, rows)
|
33
|
+
Datory::Console.print_table(title: service_class_name, headings: headings.uniq, rows: rows)
|
34
34
|
end
|
35
35
|
end
|
36
36
|
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
|
########################################################################
|
@@ -8,22 +8,26 @@ module Datory
|
|
8
8
|
new.prepare(...)
|
9
9
|
end
|
10
10
|
|
11
|
-
def
|
12
|
-
|
13
|
-
|
14
|
-
|
15
|
-
|
16
|
-
|
17
|
-
item
|
18
|
-
end
|
19
|
-
end
|
20
|
-
elsif data.is_a?(Hash)
|
11
|
+
def self.to_hash(...)
|
12
|
+
new.to_hash(...)
|
13
|
+
end
|
14
|
+
|
15
|
+
def prepare(data)
|
16
|
+
if data.is_a?(Hash)
|
21
17
|
build(data)
|
22
18
|
else
|
23
19
|
data
|
24
20
|
end
|
25
21
|
end
|
26
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
|
+
|
27
31
|
def build(attributes = {}) # rubocop:disable Metrics/MethodLength
|
28
32
|
attributes.each do |key, value|
|
29
33
|
self.class.send(:attr_accessor, key)
|
@@ -42,6 +46,23 @@ module Datory
|
|
42
46
|
|
43
47
|
self
|
44
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
|
45
66
|
end
|
46
67
|
end
|
47
68
|
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)
|
@@ -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
|
data/lib/datory/console.rb
CHANGED
@@ -4,8 +4,9 @@ require "terminal-table"
|
|
4
4
|
|
5
5
|
module Datory
|
6
6
|
class Console
|
7
|
-
def self.print_table(headings
|
7
|
+
def self.print_table(headings:, rows:, title: nil)
|
8
8
|
table = Terminal::Table.new(
|
9
|
+
title: title,
|
9
10
|
headings: headings,
|
10
11
|
rows: rows,
|
11
12
|
style: { border_x: "~", border_i: "~" }
|
@@ -4,12 +4,19 @@ module Datory
|
|
4
4
|
module Context
|
5
5
|
module Callable
|
6
6
|
def serialize(model)
|
7
|
-
|
8
|
-
|
9
|
-
|
10
|
-
|
11
|
-
|
12
|
-
|
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)
|
13
20
|
end
|
14
21
|
|
15
22
|
def deserialize(json)
|
@@ -18,48 +25,54 @@ module Datory
|
|
18
25
|
deserialize(json_item)
|
19
26
|
end
|
20
27
|
else
|
28
|
+
context = send(:new)
|
21
29
|
hash = JSON.parse(json.to_json)
|
22
|
-
build(**hash)
|
23
|
-
end
|
24
|
-
end
|
25
|
-
|
26
|
-
def to_model(**attributes)
|
27
|
-
context = send(:new)
|
28
30
|
|
29
|
-
|
30
|
-
context.define_singleton_method(attribute_name) { attribute_value }
|
31
|
+
_deserialize(context, **hash)
|
31
32
|
end
|
32
|
-
|
33
|
-
|
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)
|
34
37
|
end
|
35
38
|
|
36
|
-
|
37
|
-
# context = send(:new)
|
38
|
-
#
|
39
|
-
# _build!(context, **attributes)
|
40
|
-
# end
|
41
|
-
|
42
|
-
def build(attributes = {})
|
39
|
+
def to_model(**attributes)
|
43
40
|
context = send(:new)
|
44
41
|
|
45
|
-
|
42
|
+
_to_model(context, **attributes)
|
46
43
|
end
|
47
44
|
|
48
45
|
def describe
|
49
46
|
Datory::Attributes::Descriptor.describe(
|
47
|
+
service_class_name: name,
|
50
48
|
collection_of_attributes: collection_of_attributes
|
51
49
|
)
|
52
50
|
end
|
53
51
|
|
54
52
|
private
|
55
53
|
|
56
|
-
def
|
54
|
+
def _serialize(context, model)
|
55
|
+
context.send(
|
56
|
+
:_serialize,
|
57
|
+
model: model,
|
58
|
+
collection_of_attributes: collection_of_attributes
|
59
|
+
)
|
60
|
+
end
|
61
|
+
|
62
|
+
def _deserialize(context, **attributes)
|
57
63
|
context.send(
|
58
|
-
:
|
64
|
+
:_deserialize,
|
59
65
|
incoming_attributes: attributes.symbolize_keys,
|
60
66
|
collection_of_attributes: collection_of_attributes
|
61
67
|
)
|
62
68
|
end
|
69
|
+
|
70
|
+
def _to_model(context, **attributes)
|
71
|
+
context.send(
|
72
|
+
:_to_model,
|
73
|
+
attributes: attributes
|
74
|
+
)
|
75
|
+
end
|
63
76
|
end
|
64
77
|
end
|
65
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
|
@@ -213,11 +213,13 @@ files:
|
|
213
213
|
- lib/datory/attributes/attribute.rb
|
214
214
|
- lib/datory/attributes/collection.rb
|
215
215
|
- lib/datory/attributes/descriptor.rb
|
216
|
+
- lib/datory/attributes/deserialization/service_builder.rb
|
217
|
+
- lib/datory/attributes/deserialization/service_factory.rb
|
216
218
|
- lib/datory/attributes/dsl.rb
|
217
219
|
- lib/datory/attributes/serialization/model.rb
|
218
220
|
- lib/datory/attributes/serialization/serializator.rb
|
219
|
-
- lib/datory/attributes/
|
220
|
-
- lib/datory/attributes/
|
221
|
+
- lib/datory/attributes/serialization/service_builder.rb
|
222
|
+
- lib/datory/attributes/serialization/service_factory.rb
|
221
223
|
- lib/datory/attributes/workspace.rb
|
222
224
|
- lib/datory/base.rb
|
223
225
|
- lib/datory/console.rb
|
@@ -225,6 +227,7 @@ files:
|
|
225
227
|
- lib/datory/context/dsl.rb
|
226
228
|
- lib/datory/context/workspace.rb
|
227
229
|
- lib/datory/engine.rb
|
230
|
+
- lib/datory/exceptions.rb
|
228
231
|
- lib/datory/result.rb
|
229
232
|
- lib/datory/service/base.rb
|
230
233
|
- lib/datory/service/builder.rb
|