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 CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: c868cca39990a602ad330973d246059d32672f0c7db8bf1ef20a211b666bb851
4
- data.tar.gz: 4cf8f1a39fbfb81655ab8b848502694102f1b72a14f5c5201d47cf6cad55c081
3
+ metadata.gz: 950135c759b8b25ead8662ea13df2a4370df0a97b7c52f465d7a9898f1b58bf9
4
+ data.tar.gz: eec23571ced6e8be1d35c80ad9623008bc7eed4583da2a6dc355204754237987
5
5
  SHA512:
6
- metadata.gz: 6090a77b929d7e07c5c03c256b4a29c138d977e0f97b225a76434db04daa18be4735713a39dae663d3130097ff3c6b496e7673747be3cb02062e072bc949d2a5
7
- data.tar.gz: 48be3084e1c4840b6bda5dccb572b021f0593bf83f62a70f6b48618784c127891fa66d91749ea6ff9967dda1b8197d48545447c807a61a70028ccfdbb06113db
6
+ metadata.gz: 02bfec7158a5b692f9189a5d4b203f036d86bedfaeb46e1482f66e0ba3afc654c770caba5818f373cba17904c5f8451c5ba39dbf7af5b3147bbf4d0363825b4c
7
+ data.tar.gz: 668c867c313107e43c562b87e94f4725cac425af24ab2190f8f3adc8db2fe51c3aae6fcf7a35538fe072a94754e1cc573e0d8d91f2a11c6b0c4e70702d31ff48
@@ -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
- result = model.send(method)
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)
@@ -1,5 +1,5 @@
1
1
  # frozen_string_literal: true
2
2
 
3
3
  module AR2DTO
4
- VERSION = "0.1.0"
4
+ VERSION = "0.2.0"
5
5
  end
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.1.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-07 00:00:00.000000000 Z
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.3.7
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.