philiprehberger-data_mapper 0.5.0 → 0.6.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: 28a193815c02260ca5a5f0e32cf1bb8e41c80ac915ae230d238ea17cbf98b5e1
4
- data.tar.gz: 70dc78f072bb23f692d009561bb3865a3bb5b4e7937b51440a8e4999f7af7db3
3
+ metadata.gz: 1e3fb4ef570f5687ce40b83423e1a831c585718696082a00a356a005598ad446
4
+ data.tar.gz: b00a3a344096b9e678a2dea5a2e558cf70fd912fa863351704aa73ca3672d0d6
5
5
  SHA512:
6
- metadata.gz: f391be6c263d16d60b917a1c7ae8a77cf74d4a0e5c9625df29f44efbeb21dff068253a15c7c50a323d70fcb132071dbf0a297e8d46574e0bb149c7a290d30f15
7
- data.tar.gz: 981703bef28308069940c19bc5b5eea7192b37553de840b23d60b5c2c3969f5657ff919d2d6e286149ce766e3d190477a9870bcb20e09f1a03ea008c9b6db973
6
+ metadata.gz: ea73b6ed241967a0e9c544aa57635fb08c21dfe6b4d498721905cff7ff63c4f55bcbcc3839041c0f899c1857bc916dcd1bf31f96ab823438e372a76eb08b1e02
7
+ data.tar.gz: ddf8d77ec5eba001b9ffb27d0290eb5a036a9801cbabfd5c566fb9f0c25ac65d277bb90a70191126cd238e415324f38da41e18cc2c232f4fb0cd730ef6b0c925
data/CHANGELOG.md CHANGED
@@ -7,6 +7,12 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0
7
7
 
8
8
  ## [Unreleased]
9
9
 
10
+ ## [0.6.0] - 2026-04-21
11
+
12
+ ### Added
13
+ - `Mapping#call(hash)` — alias for `#map`, enabling `Mapping` instances to be used as callables
14
+ - `Mapping#to_proc` — returns a `Proc` that maps a single record, allowing idiomatic usage like `rows.map(&mapping)`
15
+
10
16
  ## [0.5.0] - 2026-04-18
11
17
 
12
18
  ### Added
data/README.md CHANGED
@@ -69,6 +69,20 @@ mapping.map_lazy(infinite).first(3)
69
69
  # => [{ id: 1 }, { id: 2 }, { id: 3 }]
70
70
  ```
71
71
 
72
+ ### Use as a callable
73
+
74
+ `Mapping#call` is an alias for `#map`, and `Mapping#to_proc` returns a proc, so a mapping can be passed wherever a callable is expected:
75
+
76
+ ```ruby
77
+ mapping = Philiprehberger::DataMapper.define do
78
+ field :name, from: :Name
79
+ end
80
+
81
+ mapping.call({ Name: "Ada" }) # => { name: "Ada" }
82
+ [{ Name: "Ada" }, { Name: "Lin" }].map(&mapping)
83
+ # => [{ name: "Ada" }, { name: "Lin" }]
84
+ ```
85
+
72
86
  ### Parse CSV
73
87
 
74
88
  ```ruby
@@ -223,6 +237,8 @@ result.errors # => [{ field: :age, value: -1 }, { field: :name, value: "" }]
223
237
  | `Mapping#computed(target, &block)` | Define a computed field derived from the full record |
224
238
  | `Mapping#array_field(target, from:, split:, &transform)` | Define a field that splits a string into an array |
225
239
  | `Mapping#map(hash)` | Apply mapping to a single hash |
240
+ | `Mapping#call(hash)` | Alias for `#map` — lets a `Mapping` be used as a callable |
241
+ | `Mapping#to_proc` | Return a `Proc` that calls `#map`, usable with `array.map(&mapping)` |
226
242
  | `Mapping#map_with_validation(hash)` | Apply mapping and return a `MappingResult` with errors |
227
243
  | `Mapping#map_all(array)` | Apply mapping to an array of hashes |
228
244
  | `Mapping#map_lazy(enumerable)` | Return a `Lazy` Enumerator applying `#map` per-element for streaming |
@@ -48,6 +48,22 @@ module Philiprehberger
48
48
  enumerable.lazy.map { |hash| map(hash) }
49
49
  end
50
50
 
51
+ # Proc conversion so a `Mapping` can be passed wherever a callable is expected
52
+ # (e.g. `rows.map(&mapping)`).
53
+ #
54
+ # @return [Proc] a proc that calls `#map` on its argument
55
+ def to_proc
56
+ method(:map).to_proc
57
+ end
58
+
59
+ # Alias of `#map` so a Mapping instance can be invoked like a function.
60
+ #
61
+ # @param hash [Hash] the record to map
62
+ # @return [Hash]
63
+ def call(hash)
64
+ map(hash)
65
+ end
66
+
51
67
  # Names (targets) of every declared field, including computed fields.
52
68
  #
53
69
  # @return [Array<Symbol>]
@@ -2,6 +2,6 @@
2
2
 
3
3
  module Philiprehberger
4
4
  module DataMapper
5
- VERSION = '0.5.0'
5
+ VERSION = '0.6.0'
6
6
  end
7
7
  end
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.5.0
4
+ version: 0.6.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-04-19 00:00:00.000000000 Z
11
+ date: 2026-04-21 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.