philiprehberger-data_mapper 0.3.3 → 0.4.0
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:
|
|
4
|
-
data.tar.gz:
|
|
3
|
+
metadata.gz: e5404a0cdcc13d6351546a1eba5afde88afd31ea3a26fb02884166918aee9cb0
|
|
4
|
+
data.tar.gz: 0e7d36ecf87018ebce2eb8bcfe2decaee35c120f79c006a954883cd8cb4d2b20
|
|
5
5
|
SHA512:
|
|
6
|
-
metadata.gz:
|
|
7
|
-
data.tar.gz:
|
|
6
|
+
metadata.gz: 61416ea1c4083f22dee9c828f585b19d7d6dbce1b57f3d0e3100d27b72890bdb44be2fd7e216bfaa5b99a8c75ec5a1e19c012be55bb55e2c2f7080845d9fc806
|
|
7
|
+
data.tar.gz: 64d3f10c97e693f882ba0e52e0661d2b26e19a32759478f43fcf5013b8124204e546c08bf3eefdd9f713c7d8e9c616e9e54ab7e876a18b981c52f4564dc90b83
|
data/CHANGELOG.md
CHANGED
|
@@ -7,6 +7,32 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0
|
|
|
7
7
|
|
|
8
8
|
## [Unreleased]
|
|
9
9
|
|
|
10
|
+
## [0.4.0] - 2026-04-15
|
|
11
|
+
|
|
12
|
+
### Added
|
|
13
|
+
- `Mapping#field_names` — introspection accessor returning all declared field and computed targets
|
|
14
|
+
|
|
15
|
+
## [0.3.7] - 2026-03-31
|
|
16
|
+
|
|
17
|
+
### Added
|
|
18
|
+
- Add GitHub issue templates, dependabot config, and PR template
|
|
19
|
+
|
|
20
|
+
## [0.3.6] - 2026-03-31
|
|
21
|
+
|
|
22
|
+
### Changed
|
|
23
|
+
- Standardize README badges, support section, and license format
|
|
24
|
+
|
|
25
|
+
## [0.3.5] - 2026-03-26
|
|
26
|
+
|
|
27
|
+
### Fixed
|
|
28
|
+
- Add Sponsor badge to README
|
|
29
|
+
- Fix license section link format
|
|
30
|
+
|
|
31
|
+
## [0.3.4] - 2026-03-24
|
|
32
|
+
|
|
33
|
+
### Changed
|
|
34
|
+
- Expand test coverage to 55+ examples covering edge cases and error paths
|
|
35
|
+
|
|
10
36
|
## [0.3.3] - 2026-03-24
|
|
11
37
|
|
|
12
38
|
### Fixed
|
data/README.md
CHANGED
|
@@ -2,7 +2,7 @@
|
|
|
2
2
|
|
|
3
3
|
[](https://github.com/philiprehberger/rb-data-mapper/actions/workflows/ci.yml)
|
|
4
4
|
[](https://rubygems.org/gems/philiprehberger-data_mapper)
|
|
5
|
-
[](https://github.com/philiprehberger/rb-data-mapper/commits/main)
|
|
6
6
|
|
|
7
7
|
Data transformation DSL for mapping hashes and CSV rows
|
|
8
8
|
|
|
@@ -169,6 +169,16 @@ mapping.reverse(output)
|
|
|
169
169
|
# => { name: "Alice", age: 30 }
|
|
170
170
|
```
|
|
171
171
|
|
|
172
|
+
### Introspection
|
|
173
|
+
|
|
174
|
+
```ruby
|
|
175
|
+
mapping = Philiprehberger::DataMapper.define do
|
|
176
|
+
field(:name, from: :Name)
|
|
177
|
+
computed(:upper) { |r| r[:Name].upcase }
|
|
178
|
+
end
|
|
179
|
+
mapping.field_names # => [:name, :upper]
|
|
180
|
+
```
|
|
181
|
+
|
|
172
182
|
### Validation
|
|
173
183
|
|
|
174
184
|
Validate mapped values using the `validate:` parameter. Use `map_with_validation` to collect errors:
|
|
@@ -201,6 +211,7 @@ result.errors # => [{ field: :age, value: -1 }, { field: :name, value: "" }]
|
|
|
201
211
|
| `Mapping#map(hash)` | Apply mapping to a single hash |
|
|
202
212
|
| `Mapping#map_with_validation(hash)` | Apply mapping and return a `MappingResult` with errors |
|
|
203
213
|
| `Mapping#map_all(array)` | Apply mapping to an array of hashes |
|
|
214
|
+
| `Mapping#field_names` | Array of symbol targets for declared fields and computed fields |
|
|
204
215
|
| `Mapping#reverse(hash)` | Transform output hash back to input schema |
|
|
205
216
|
| `Mapping#from_csv(string, headers: true)` | Parse CSV and map each row |
|
|
206
217
|
| `Mapping#from_json(json_string)` | Parse JSON string and map the result |
|
|
@@ -213,6 +224,24 @@ bundle exec rspec
|
|
|
213
224
|
bundle exec rubocop
|
|
214
225
|
```
|
|
215
226
|
|
|
227
|
+
## Support
|
|
228
|
+
|
|
229
|
+
If you find this project useful:
|
|
230
|
+
|
|
231
|
+
⭐ [Star the repo](https://github.com/philiprehberger/rb-data-mapper)
|
|
232
|
+
|
|
233
|
+
🐛 [Report issues](https://github.com/philiprehberger/rb-data-mapper/issues?q=is%3Aissue+is%3Aopen+label%3Abug)
|
|
234
|
+
|
|
235
|
+
💡 [Suggest features](https://github.com/philiprehberger/rb-data-mapper/issues?q=is%3Aissue+is%3Aopen+label%3Aenhancement)
|
|
236
|
+
|
|
237
|
+
❤️ [Sponsor development](https://github.com/sponsors/philiprehberger)
|
|
238
|
+
|
|
239
|
+
🌐 [All Open Source Projects](https://philiprehberger.com/open-source-packages)
|
|
240
|
+
|
|
241
|
+
💻 [GitHub Profile](https://github.com/philiprehberger)
|
|
242
|
+
|
|
243
|
+
🔗 [LinkedIn Profile](https://www.linkedin.com/in/philiprehberger)
|
|
244
|
+
|
|
216
245
|
## License
|
|
217
246
|
|
|
218
|
-
MIT
|
|
247
|
+
[MIT](LICENSE)
|
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
# frozen_string_literal: true
|
|
2
2
|
|
|
3
|
-
require_relative
|
|
4
|
-
require_relative
|
|
3
|
+
require_relative 'parsable'
|
|
4
|
+
require_relative 'reversible'
|
|
5
5
|
|
|
6
6
|
module Philiprehberger
|
|
7
7
|
module DataMapper
|
|
@@ -23,8 +23,8 @@ module Philiprehberger
|
|
|
23
23
|
@computed_fields << ComputedDefinition.new(target, &)
|
|
24
24
|
end
|
|
25
25
|
|
|
26
|
-
def array_field(target,
|
|
27
|
-
field(target,
|
|
26
|
+
def array_field(target, split: ',', **opts, &transform)
|
|
27
|
+
field(target, split: split, **opts, &transform)
|
|
28
28
|
end
|
|
29
29
|
|
|
30
30
|
def map(hash)
|
|
@@ -44,6 +44,13 @@ module Philiprehberger
|
|
|
44
44
|
array.map { |hash| map(hash) }
|
|
45
45
|
end
|
|
46
46
|
|
|
47
|
+
# Names (targets) of every declared field, including computed fields.
|
|
48
|
+
#
|
|
49
|
+
# @return [Array<Symbol>]
|
|
50
|
+
def field_names
|
|
51
|
+
@fields.map(&:target) + @computed_fields.map(&:target)
|
|
52
|
+
end
|
|
53
|
+
|
|
47
54
|
private
|
|
48
55
|
|
|
49
56
|
def map_fields(hash)
|
|
@@ -78,9 +85,9 @@ module Philiprehberger
|
|
|
78
85
|
key_str = source.to_s
|
|
79
86
|
return hash[source] if hash.key?(source)
|
|
80
87
|
return hash[key_str] if hash.key?(key_str)
|
|
81
|
-
return unless key_str.include?(
|
|
88
|
+
return unless key_str.include?('.')
|
|
82
89
|
|
|
83
|
-
dig_nested(hash, key_str.split(
|
|
90
|
+
dig_nested(hash, key_str.split('.'))
|
|
84
91
|
end
|
|
85
92
|
|
|
86
93
|
def dig_nested(hash, keys)
|
|
@@ -1,10 +1,10 @@
|
|
|
1
1
|
# frozen_string_literal: true
|
|
2
2
|
|
|
3
|
-
require_relative
|
|
4
|
-
require_relative
|
|
5
|
-
require_relative
|
|
6
|
-
require_relative
|
|
7
|
-
require_relative
|
|
3
|
+
require_relative 'data_mapper/version'
|
|
4
|
+
require_relative 'data_mapper/field_definition'
|
|
5
|
+
require_relative 'data_mapper/computed_definition'
|
|
6
|
+
require_relative 'data_mapper/mapping_result'
|
|
7
|
+
require_relative 'data_mapper/mapping'
|
|
8
8
|
|
|
9
9
|
module Philiprehberger
|
|
10
10
|
module DataMapper
|
metadata
CHANGED
|
@@ -1,14 +1,14 @@
|
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
|
2
2
|
name: philiprehberger-data_mapper
|
|
3
3
|
version: !ruby/object:Gem::Version
|
|
4
|
-
version: 0.
|
|
4
|
+
version: 0.4.0
|
|
5
5
|
platform: ruby
|
|
6
6
|
authors:
|
|
7
7
|
- Philip Rehberger
|
|
8
8
|
autorequire:
|
|
9
9
|
bindir: bin
|
|
10
10
|
cert_chain: []
|
|
11
|
-
date: 2026-
|
|
11
|
+
date: 2026-04-15 00:00:00.000000000 Z
|
|
12
12
|
dependencies: []
|
|
13
13
|
description: A zero-dependency Ruby gem for transforming data between formats with
|
|
14
14
|
a mapping DSL, field renaming, type conversion, validation, and CSV support.
|
|
@@ -29,11 +29,11 @@ files:
|
|
|
29
29
|
- lib/philiprehberger/data_mapper/parsable.rb
|
|
30
30
|
- lib/philiprehberger/data_mapper/reversible.rb
|
|
31
31
|
- lib/philiprehberger/data_mapper/version.rb
|
|
32
|
-
homepage: https://
|
|
32
|
+
homepage: https://philiprehberger.com/open-source-packages/ruby/philiprehberger-data_mapper
|
|
33
33
|
licenses:
|
|
34
34
|
- MIT
|
|
35
35
|
metadata:
|
|
36
|
-
homepage_uri: https://
|
|
36
|
+
homepage_uri: https://philiprehberger.com/open-source-packages/ruby/philiprehberger-data_mapper
|
|
37
37
|
source_code_uri: https://github.com/philiprehberger/rb-data-mapper
|
|
38
38
|
changelog_uri: https://github.com/philiprehberger/rb-data-mapper/blob/main/CHANGELOG.md
|
|
39
39
|
bug_tracker_uri: https://github.com/philiprehberger/rb-data-mapper/issues
|