ar2dto 0.2.0 → 0.2.1

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 CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: 950135c759b8b25ead8662ea13df2a4370df0a97b7c52f465d7a9898f1b58bf9
4
- data.tar.gz: eec23571ced6e8be1d35c80ad9623008bc7eed4583da2a6dc355204754237987
3
+ metadata.gz: 5cd53b73405906d2f5110639476b122164c9ed031ee9c790738060616e8b37d9
4
+ data.tar.gz: 01c473e3681f934e0fca8991d0dd49f637a93920134c4a7baedaefed344e325b
5
5
  SHA512:
6
- metadata.gz: 02bfec7158a5b692f9189a5d4b203f036d86bedfaeb46e1482f66e0ba3afc654c770caba5818f373cba17904c5f8451c5ba39dbf7af5b3147bbf4d0363825b4c
7
- data.tar.gz: 668c867c313107e43c562b87e94f4725cac425af24ab2190f8f3adc8db2fe51c3aae6fcf7a35538fe072a94754e1cc573e0d8d91f2a11c6b0c4e70702d31ff48
6
+ metadata.gz: 65921f1573108b6cb20bcd39457a51e6e71bd9c1c49e44247f799534c827a362980438aaad65350cf107e627f915ebfd2996c32e4d1969f3aa07196cfe159482
7
+ data.tar.gz: 8a659e862bafd7fc0165f4b7f38ae385fa22b9550194df05cbb42f11ce0709f8bd5a443cb61c874b7096b41e9e48a3d6dd28379c94899e3ddff2aa67fed1edc8
data/lib/ar2dto/dto.rb CHANGED
@@ -9,14 +9,19 @@ module AR2DTO
9
9
  end
10
10
  end
11
11
 
12
- def initialize(attributes = {})
13
- attributes.each { |key, value| define_singleton_method(key) { value } }
14
- super()
15
- end
16
-
17
- def as_json(options = nil)
12
+ def initialize(data = {})
18
13
  attribute_names = self.class.original_model.attribute_names
19
- attribute_names.map { |name| [name.to_sym, send(name)] }.to_h.as_json(options)
14
+
15
+ data.each do |key, value|
16
+ if attribute_names.include?(key)
17
+ instance_variable_set("@#{key}", value)
18
+ singleton_class.attr_reader(key)
19
+ else
20
+ define_singleton_method(key) { value }
21
+ end
22
+ end
23
+
24
+ super()
20
25
  end
21
26
 
22
27
  def ==(other)
@@ -1,5 +1,5 @@
1
1
  # frozen_string_literal: true
2
2
 
3
3
  module AR2DTO
4
- VERSION = "0.2.0"
4
+ VERSION = "0.2.1"
5
5
  end
metadata CHANGED
@@ -1,16 +1,16 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: ar2dto
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.2.0
4
+ version: 0.2.1
5
5
  platform: ruby
6
6
  authors:
7
7
  - Santiago Bartesaghi
8
8
  - Martín Jaime Morón
9
9
  - Sebastian Herrera
10
- autorequire:
10
+ autorequire:
11
11
  bindir: bin
12
12
  cert_chain: []
13
- date: 2022-07-13 00:00:00.000000000 Z
13
+ date: 2022-07-26 00:00:00.000000000 Z
14
14
  dependencies:
15
15
  - !ruby/object:Gem::Dependency
16
16
  name: activemodel
@@ -124,7 +124,7 @@ dependencies:
124
124
  - - "~>"
125
125
  - !ruby/object:Gem::Version
126
126
  version: 2.6.0
127
- description:
127
+ description:
128
128
  email:
129
129
  - santib@hey.com
130
130
  - martinmoron7@gmail.com
@@ -152,7 +152,7 @@ metadata:
152
152
  bug_tracker_uri: https://github.com/santib/ar2dto/issues
153
153
  changelog_uri: https://github.com/santib/ar2dto/releases
154
154
  rubygems_mfa_required: 'true'
155
- post_install_message:
155
+ post_install_message:
156
156
  rdoc_options: []
157
157
  require_paths:
158
158
  - lib
@@ -167,8 +167,8 @@ required_rubygems_version: !ruby/object:Gem::Requirement
167
167
  - !ruby/object:Gem::Version
168
168
  version: '0'
169
169
  requirements: []
170
- rubygems_version: 3.1.6
171
- signing_key:
170
+ rubygems_version: 3.0.3
171
+ signing_key:
172
172
  specification_version: 4
173
173
  summary: Easing the creation of DTOs from your ActiveRecord models.
174
174
  test_files: []