ar2dto 0.2.0 → 0.2.2

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: 7ed18118a357d7325f1cd52ff5e7ee98db4948ef37c43c2a7c17ed2268f8f7fc
4
+ data.tar.gz: 8908094a4f17e86025b34bc9c2134cad4dc3080dcc76818b026e81ba48c666b6
5
5
  SHA512:
6
- metadata.gz: 02bfec7158a5b692f9189a5d4b203f036d86bedfaeb46e1482f66e0ba3afc654c770caba5818f373cba17904c5f8451c5ba39dbf7af5b3147bbf4d0363825b4c
7
- data.tar.gz: 668c867c313107e43c562b87e94f4725cac425af24ab2190f8f3adc8db2fe51c3aae6fcf7a35538fe072a94754e1cc573e0d8d91f2a11c6b0c4e70702d31ff48
6
+ metadata.gz: 58f7ecc1fe49f7936aa441f7bbf2c0dce04f1e0e2ee12d9223e33024e7c0787cdf0e1962109618f906e7a0f3ad19436f5503aa50923c234616c55606b1d70f88
7
+ data.tar.gz: b03ec11afd326e0fea07bc25946b2419fe6ee3c2c487eb4cfbc6ea96700b7dbd09555ef62e291d7426ef4efa2c4cdc04900f7f7a2314e75c380eeccb4522bd2f
data/README.md CHANGED
@@ -15,6 +15,7 @@ AR2DTO (ActiveRecord to DTO, pronounced R2-D2 or Artoo-Detoo) is a gem that lets
15
15
  - [DTO class](#dto-class)
16
16
  - [#to_dto](#to_dto)
17
17
  - [.to_dto](#to_dto-1)
18
+ - [Examples](#examples)
18
19
  - [Development](#development)
19
20
  - [Contributing](#contributing)
20
21
  - [License](#license)
@@ -159,6 +160,16 @@ It accepts the same options as `#to_dto` and uses them create each DTO.
159
160
 
160
161
  :warning: **Warning!** Given that this method executes the query and brings records into memory, you have to be careful when and how to use it. You may not want to bring all records from a large table into memory. Consider combining it with things such as pagination or batch processing.
161
162
 
163
+ ## Examples
164
+ If you want to look into examples of usages and configurations, you can find:
165
+ - [Option `methods` examples](docs/examples/methods.md)
166
+ - [Option `except` examples](docs/examples/except.md)
167
+ - [Option `only` examples](docs/examples/only.md)
168
+ - [Option `include` examples](docs/examples/include.md)
169
+ - [Option `add_suffix` and `delete_suffix` examples](docs/examples/add_suffix_delete_suffix.md)
170
+ - [Option `active_model_compliance` examples](docs/examples/active_model_compliance.md)
171
+ - [Custom DTO examples](docs/examples/custom_dto.md)
172
+
162
173
  ## Development
163
174
 
164
175
  After checking out the repo, run `bin/setup` to install dependencies. Then, run `rake spec` to run the tests. You can also run `bin/console` for an interactive prompt that will allow you to experiment.
@@ -2,8 +2,11 @@
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
+ ALLOWED_TYPES = [
6
+ Symbol, BigDecimal, Regexp, IO, Range, Time, Date, DateTime,
7
+ URI::Generic, Pathname, IPAddr, Process::Status, Exception,
8
+ ActiveSupport::TimeWithZone
9
+ ].freeze
7
10
  attr_reader :model, :options
8
11
 
9
12
  def initialize(model, options)
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.2"
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.2.0
4
+ version: 0.2.2
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 00:00:00.000000000 Z
13
+ date: 2025-11-20 00:00:00.000000000 Z
14
14
  dependencies:
15
15
  - !ruby/object:Gem::Dependency
16
16
  name: activemodel
@@ -46,14 +46,14 @@ dependencies:
46
46
  requirements:
47
47
  - - "~>"
48
48
  - !ruby/object:Gem::Version
49
- version: 1.8.0
49
+ version: 2.1.0
50
50
  type: :development
51
51
  prerelease: false
52
52
  version_requirements: !ruby/object:Gem::Requirement
53
53
  requirements:
54
54
  - - "~>"
55
55
  - !ruby/object:Gem::Version
56
- version: 1.8.0
56
+ version: 2.1.0
57
57
  - !ruby/object:Gem::Dependency
58
58
  name: rake
59
59
  requirement: !ruby/object:Gem::Requirement
@@ -100,16 +100,16 @@ dependencies:
100
100
  name: sqlite3
101
101
  requirement: !ruby/object:Gem::Requirement
102
102
  requirements:
103
- - - "~>"
103
+ - - ">="
104
104
  - !ruby/object:Gem::Version
105
- version: 1.4.2
105
+ version: '0'
106
106
  type: :development
107
107
  prerelease: false
108
108
  version_requirements: !ruby/object:Gem::Requirement
109
109
  requirements:
110
- - - "~>"
110
+ - - ">="
111
111
  - !ruby/object:Gem::Version
112
- version: 1.4.2
112
+ version: '0'
113
113
  - !ruby/object:Gem::Dependency
114
114
  name: zeitwerk
115
115
  requirement: !ruby/object:Gem::Requirement
@@ -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.1.6
170
+ rubygems_version: 3.5.9
171
171
  signing_key:
172
172
  specification_version: 4
173
173
  summary: Easing the creation of DTOs from your ActiveRecord models.