datory 1.0.0.rc3 → 1.0.0.rc4

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: 8562a68170d39d6d97a80eceae372d7f043cbb08db2890faa2d6d22a792748bf
4
- data.tar.gz: 89ef0b5c9a73289a3567e01202a9a83beeaefee6db2f084168c6e755da4e3044
3
+ metadata.gz: 5ca68aea305e426d629f97a3d8940e016a933e4298e56b7ab7d3f9e495fb515d
4
+ data.tar.gz: 3589f41e040965dacdbaa9f22d197c837afd96f6a5d34e6b32b93e2043ce2391
5
5
  SHA512:
6
- metadata.gz: 3c6ed842a16e265979fc1d5ebc4b517390884bac7118500d39cc48d6b180c7c842b08cadfdf853db111b2a56a8c016cbcbf9654d4b290272399f461d9eec48ba
7
- data.tar.gz: 6428856321dd65efb127aca09955e5e34eb1d3cff3cdc2f8da0fd669e4556582ecef976919b60f6808ce84a602a9dc60f332ffcc42b0421c613b0dc43d1ff429
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, as: :first_name
40
- string :lastname, as: :last_name
39
+ string :firstname, to: :first_name
40
+ string :lastname, to: :last_name
41
41
  string :email
42
- string :birthDate, as: :birth_date, output: ->(value:) { value.to_s }
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(type: Symbol)
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(type: String)
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(type: Integer)
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(type: Float)
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(type: Date)
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(type: Time)
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(type: DateTime)
63
+ options = options.merge(from: DateTime)
64
64
  attribute(name, **options)
65
65
  end
66
66
 
67
- def one(name, include:, as: nil)
68
- attribute(name, as: as.presence || name, type: Hash, include: include)
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:, as: nil)
72
- attribute(name, as: as.presence || name, type: Array, consists_of: Hash, include: include)
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(:as, attribute.name)
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(:as, attribute.name)
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(:type),
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
- type = attribute.options.fetch(:type, nil)
35
+ from_type = attribute.options.fetch(:from, nil)
36
36
 
37
- if [Set, Array].include?(type)
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
- if (type = attribute.options.fetch(:consists_of, false)) == Hash
47
- Datory::Result
48
- else
49
- type
50
- end
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
- type
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
- outputs.public_send(:"#{input_internal_name}=", inputs.public_send(input_internal_name))
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
 
@@ -5,7 +5,7 @@ module Datory
5
5
  MAJOR = 1
6
6
  MINOR = 0
7
7
  PATCH = 0
8
- PRE = "rc3"
8
+ PRE = "rc4"
9
9
 
10
10
  STRING = [MAJOR, MINOR, PATCH, PRE].compact.join(".")
11
11
  end
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: datory
3
3
  version: !ruby/object:Gem::Version
4
- version: 1.0.0.rc3
4
+ version: 1.0.0.rc4
5
5
  platform: ruby
6
6
  authors:
7
7
  - Anton Sokolov