philiprehberger-data_mapper 0.6.0 → 0.7.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 +5 -0
- data/README.md +5 -0
- data/lib/philiprehberger/data_mapper/mapping.rb +13 -0
- data/lib/philiprehberger/data_mapper/version.rb +1 -1
- metadata +2 -2
checksums.yaml
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
---
|
|
2
2
|
SHA256:
|
|
3
|
-
metadata.gz:
|
|
4
|
-
data.tar.gz:
|
|
3
|
+
metadata.gz: '08f4e17d177ee25cbc161e5873c41623a8f774b0a2c36faa1e43776cbea3c5a2'
|
|
4
|
+
data.tar.gz: 133251c11f08fd0204a5672fa78c60a1bec5b3225648e49d1c67ffc01b4102cd
|
|
5
5
|
SHA512:
|
|
6
|
-
metadata.gz:
|
|
7
|
-
data.tar.gz:
|
|
6
|
+
metadata.gz: 294795cf41fadc25753f7f951fa584b6c09a934e5ba10cdd4f4a95439e3e5161487d69d1916fd58ac890e796569d0c69c2ba418fbf3165b1d10462658f8820ec
|
|
7
|
+
data.tar.gz: 50a8a7eccca2e2822014b57b1d670588ec5595db505e53e37506718475b3e1a2621d79e1f6e07d4e1288165bd58fd111066f5743a5290643a752fe898c29bf98
|
data/CHANGELOG.md
CHANGED
|
@@ -7,6 +7,11 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0
|
|
|
7
7
|
|
|
8
8
|
## [Unreleased]
|
|
9
9
|
|
|
10
|
+
## [0.7.0] - 2026-05-01
|
|
11
|
+
|
|
12
|
+
### Added
|
|
13
|
+
- `Mapping#has_field?(name)` — boolean predicate for whether the mapping declares an output field with that name (covers both regular and computed fields)
|
|
14
|
+
|
|
10
15
|
## [0.6.0] - 2026-04-21
|
|
11
16
|
|
|
12
17
|
### Added
|
data/README.md
CHANGED
|
@@ -205,6 +205,10 @@ mapping = Philiprehberger::DataMapper.define do
|
|
|
205
205
|
computed(:upper) { |r| r[:Name].upcase }
|
|
206
206
|
end
|
|
207
207
|
mapping.field_names # => [:name, :upper]
|
|
208
|
+
|
|
209
|
+
mapping.has_field?(:name) # => true
|
|
210
|
+
mapping.has_field?(:upper) # => true
|
|
211
|
+
mapping.has_field?(:missing) # => false
|
|
208
212
|
```
|
|
209
213
|
|
|
210
214
|
### Validation
|
|
@@ -243,6 +247,7 @@ result.errors # => [{ field: :age, value: -1 }, { field: :name, value: "" }]
|
|
|
243
247
|
| `Mapping#map_all(array)` | Apply mapping to an array of hashes |
|
|
244
248
|
| `Mapping#map_lazy(enumerable)` | Return a `Lazy` Enumerator applying `#map` per-element for streaming |
|
|
245
249
|
| `Mapping#field_names` | Array of symbol targets for declared fields and computed fields |
|
|
250
|
+
| `Mapping#has_field?(name)` | Whether the mapping declares an output field with that name |
|
|
246
251
|
| `Mapping#reverse(hash)` | Transform output hash back to input schema |
|
|
247
252
|
| `Mapping#from_csv(string, headers: true)` | Parse CSV and map each row |
|
|
248
253
|
| `Mapping#from_json(json_string)` | Parse JSON string and map the result |
|
|
@@ -71,6 +71,19 @@ module Philiprehberger
|
|
|
71
71
|
@fields.map(&:target) + @computed_fields.map(&:target)
|
|
72
72
|
end
|
|
73
73
|
|
|
74
|
+
# Whether the mapping declares an output field with the given name.
|
|
75
|
+
#
|
|
76
|
+
# Matches both regular and computed fields. Comparison is exact
|
|
77
|
+
# (no symbol/string coercion beyond `to_sym` on the input).
|
|
78
|
+
#
|
|
79
|
+
# @param name [Symbol, String] the target field name to check
|
|
80
|
+
# @return [Boolean]
|
|
81
|
+
def has_field?(name)
|
|
82
|
+
target = name.to_sym
|
|
83
|
+
@fields.any? { |f| f.target == target } ||
|
|
84
|
+
@computed_fields.any? { |c| c.target == target }
|
|
85
|
+
end
|
|
86
|
+
|
|
74
87
|
private
|
|
75
88
|
|
|
76
89
|
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.7.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-05-02 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.
|