philiprehberger-data_mapper 0.3.6 → 0.5.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 +4 -4
- data/CHANGELOG.md +15 -0
- data/README.md +26 -0
- data/lib/philiprehberger/data_mapper/mapping.rb +11 -0
- data/lib/philiprehberger/data_mapper/version.rb +1 -1
- metadata +4 -4
checksums.yaml
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
---
|
|
2
2
|
SHA256:
|
|
3
|
-
metadata.gz:
|
|
4
|
-
data.tar.gz:
|
|
3
|
+
metadata.gz: 28a193815c02260ca5a5f0e32cf1bb8e41c80ac915ae230d238ea17cbf98b5e1
|
|
4
|
+
data.tar.gz: 70dc78f072bb23f692d009561bb3865a3bb5b4e7937b51440a8e4999f7af7db3
|
|
5
5
|
SHA512:
|
|
6
|
-
metadata.gz:
|
|
7
|
-
data.tar.gz:
|
|
6
|
+
metadata.gz: f391be6c263d16d60b917a1c7ae8a77cf74d4a0e5c9625df29f44efbeb21dff068253a15c7c50a323d70fcb132071dbf0a297e8d46574e0bb149c7a290d30f15
|
|
7
|
+
data.tar.gz: 981703bef28308069940c19bc5b5eea7192b37553de840b23d60b5c2c3969f5657ff919d2d6e286149ce766e3d190477a9870bcb20e09f1a03ea008c9b6db973
|
data/CHANGELOG.md
CHANGED
|
@@ -7,6 +7,21 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0
|
|
|
7
7
|
|
|
8
8
|
## [Unreleased]
|
|
9
9
|
|
|
10
|
+
## [0.5.0] - 2026-04-18
|
|
11
|
+
|
|
12
|
+
### Added
|
|
13
|
+
- `Mapping#map_lazy(enumerable)` — returns a `Lazy` Enumerator that applies `#map` per-element; suitable for streaming large inputs without materialization
|
|
14
|
+
|
|
15
|
+
## [0.4.0] - 2026-04-15
|
|
16
|
+
|
|
17
|
+
### Added
|
|
18
|
+
- `Mapping#field_names` — introspection accessor returning all declared field and computed targets
|
|
19
|
+
|
|
20
|
+
## [0.3.7] - 2026-03-31
|
|
21
|
+
|
|
22
|
+
### Added
|
|
23
|
+
- Add GitHub issue templates, dependabot config, and PR template
|
|
24
|
+
|
|
10
25
|
## [0.3.6] - 2026-03-31
|
|
11
26
|
|
|
12
27
|
### Changed
|
data/README.md
CHANGED
|
@@ -55,6 +55,20 @@ mapping.map_all(input)
|
|
|
55
55
|
# => [{ full_name: "Alice", years: 30, role: "member" }, ...]
|
|
56
56
|
```
|
|
57
57
|
|
|
58
|
+
### Lazy streaming
|
|
59
|
+
|
|
60
|
+
Use `map_lazy` to pipe huge datasets without materializing an intermediate array. It returns an `Enumerator::Lazy` that applies `#map` per-element, so it composes with `.first`, `.select`, `.reject`, and works on infinite enumerables:
|
|
61
|
+
|
|
62
|
+
```ruby
|
|
63
|
+
mapping = Philiprehberger::DataMapper.define do
|
|
64
|
+
field :id
|
|
65
|
+
end
|
|
66
|
+
|
|
67
|
+
infinite = (1..).lazy.map { |i| { "id" => i } }
|
|
68
|
+
mapping.map_lazy(infinite).first(3)
|
|
69
|
+
# => [{ id: 1 }, { id: 2 }, { id: 3 }]
|
|
70
|
+
```
|
|
71
|
+
|
|
58
72
|
### Parse CSV
|
|
59
73
|
|
|
60
74
|
```ruby
|
|
@@ -169,6 +183,16 @@ mapping.reverse(output)
|
|
|
169
183
|
# => { name: "Alice", age: 30 }
|
|
170
184
|
```
|
|
171
185
|
|
|
186
|
+
### Introspection
|
|
187
|
+
|
|
188
|
+
```ruby
|
|
189
|
+
mapping = Philiprehberger::DataMapper.define do
|
|
190
|
+
field(:name, from: :Name)
|
|
191
|
+
computed(:upper) { |r| r[:Name].upcase }
|
|
192
|
+
end
|
|
193
|
+
mapping.field_names # => [:name, :upper]
|
|
194
|
+
```
|
|
195
|
+
|
|
172
196
|
### Validation
|
|
173
197
|
|
|
174
198
|
Validate mapped values using the `validate:` parameter. Use `map_with_validation` to collect errors:
|
|
@@ -201,6 +225,8 @@ result.errors # => [{ field: :age, value: -1 }, { field: :name, value: "" }]
|
|
|
201
225
|
| `Mapping#map(hash)` | Apply mapping to a single hash |
|
|
202
226
|
| `Mapping#map_with_validation(hash)` | Apply mapping and return a `MappingResult` with errors |
|
|
203
227
|
| `Mapping#map_all(array)` | Apply mapping to an array of hashes |
|
|
228
|
+
| `Mapping#map_lazy(enumerable)` | Return a `Lazy` Enumerator applying `#map` per-element for streaming |
|
|
229
|
+
| `Mapping#field_names` | Array of symbol targets for declared fields and computed fields |
|
|
204
230
|
| `Mapping#reverse(hash)` | Transform output hash back to input schema |
|
|
205
231
|
| `Mapping#from_csv(string, headers: true)` | Parse CSV and map each row |
|
|
206
232
|
| `Mapping#from_json(json_string)` | Parse JSON string and map the result |
|
|
@@ -44,6 +44,17 @@ module Philiprehberger
|
|
|
44
44
|
array.map { |hash| map(hash) }
|
|
45
45
|
end
|
|
46
46
|
|
|
47
|
+
def map_lazy(enumerable)
|
|
48
|
+
enumerable.lazy.map { |hash| map(hash) }
|
|
49
|
+
end
|
|
50
|
+
|
|
51
|
+
# Names (targets) of every declared field, including computed fields.
|
|
52
|
+
#
|
|
53
|
+
# @return [Array<Symbol>]
|
|
54
|
+
def field_names
|
|
55
|
+
@fields.map(&:target) + @computed_fields.map(&:target)
|
|
56
|
+
end
|
|
57
|
+
|
|
47
58
|
private
|
|
48
59
|
|
|
49
60
|
def map_fields(hash)
|
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.5.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-19 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
|