ar2dto 0.1.0 → 0.2.0
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/lib/ar2dto/converter.rb +13 -7
- data/lib/ar2dto/version.rb +1 -1
- metadata +3 -3
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 950135c759b8b25ead8662ea13df2a4370df0a97b7c52f465d7a9898f1b58bf9
|
4
|
+
data.tar.gz: eec23571ced6e8be1d35c80ad9623008bc7eed4583da2a6dc355204754237987
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 02bfec7158a5b692f9189a5d4b203f036d86bedfaeb46e1482f66e0ba3afc654c770caba5818f373cba17904c5f8451c5ba39dbf7af5b3147bbf4d0363825b4c
|
7
|
+
data.tar.gz: 668c867c313107e43c562b87e94f4725cac425af24ab2190f8f3adc8db2fe51c3aae6fcf7a35538fe072a94754e1cc573e0d8d91f2a11c6b0c4e70702d31ff48
|
data/lib/ar2dto/converter.rb
CHANGED
@@ -2,6 +2,8 @@
|
|
2
2
|
|
3
3
|
module AR2DTO
|
4
4
|
class Converter
|
5
|
+
ALLOWED_TYPES = [Symbol, BigDecimal, Regexp, IO, Range, Time, Date, DateTime,
|
6
|
+
URI::Generic, Pathname, IPAddr, Process::Status, Exception].freeze
|
5
7
|
attr_reader :model, :options
|
6
8
|
|
7
9
|
def initialize(model, options)
|
@@ -24,17 +26,21 @@ module AR2DTO
|
|
24
26
|
|
25
27
|
def add_methods(hash)
|
26
28
|
options&.dig(:methods)&.each do |method|
|
27
|
-
|
28
|
-
result = if result.respond_to?(:to_dto)
|
29
|
-
result.to_dto
|
30
|
-
else
|
31
|
-
result.as_json
|
32
|
-
end
|
33
|
-
hash[method.to_s] = result
|
29
|
+
hash[method.to_s] = data_only(model.send(method))
|
34
30
|
end
|
35
31
|
hash
|
36
32
|
end
|
37
33
|
|
34
|
+
def data_only(object)
|
35
|
+
if object.respond_to?(:to_dto)
|
36
|
+
object.to_dto
|
37
|
+
elsif object.is_a?(::AR2DTO::DTO) || ALLOWED_TYPES.include?(object.class)
|
38
|
+
object
|
39
|
+
else
|
40
|
+
object.as_json
|
41
|
+
end
|
42
|
+
end
|
43
|
+
|
38
44
|
def add_associations(hash)
|
39
45
|
includes.each do |association, opts|
|
40
46
|
records = model.send(association)
|
data/lib/ar2dto/version.rb
CHANGED
metadata
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: ar2dto
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.
|
4
|
+
version: 0.2.0
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Santiago Bartesaghi
|
@@ -10,7 +10,7 @@ authors:
|
|
10
10
|
autorequire:
|
11
11
|
bindir: bin
|
12
12
|
cert_chain: []
|
13
|
-
date: 2022-07-
|
13
|
+
date: 2022-07-13 00:00:00.000000000 Z
|
14
14
|
dependencies:
|
15
15
|
- !ruby/object:Gem::Dependency
|
16
16
|
name: activemodel
|
@@ -167,7 +167,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
|
|
167
167
|
- !ruby/object:Gem::Version
|
168
168
|
version: '0'
|
169
169
|
requirements: []
|
170
|
-
rubygems_version: 3.
|
170
|
+
rubygems_version: 3.1.6
|
171
171
|
signing_key:
|
172
172
|
specification_version: 4
|
173
173
|
summary: Easing the creation of DTOs from your ActiveRecord models.
|