hash_mapper 0.2.7 → 0.2.8
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/.github/workflows/tests.yml +19 -0
- data/README.md +19 -1
- data/lib/hash_mapper/version.rb +1 -1
- data/lib/hash_mapper.rb +4 -0
- data/spec/hash_mapper_spec.rb +27 -8
- metadata +4 -3
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 48c1f85ef574a126509499c46c0cd4022022acf58b74c262bc680eb6e9a472ce
|
4
|
+
data.tar.gz: 37eeb0e69111e1e0b0da2f3fe463adca1202e7dd5310715564f9c955dadbb56c
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 4203160fe7ed6480638532b928ad6477b981b23ecb471d9a442e4ff764b8485079b3a1a4b85cab15e67da8ed97f3d5deadc894666939b2d369ed4d9443647940
|
7
|
+
data.tar.gz: c31c08907811d20e6b240505b54579364b8c9c8d55607bde2d482ba75dd729fcb44593aa2c64930089c00c87bcfcbb92d04c08b487d41b5afa950581b316c912
|
@@ -0,0 +1,19 @@
|
|
1
|
+
name: Tests
|
2
|
+
|
3
|
+
on: push
|
4
|
+
|
5
|
+
jobs:
|
6
|
+
rspec:
|
7
|
+
runs-on: ubuntu-latest
|
8
|
+
strategy:
|
9
|
+
matrix:
|
10
|
+
ruby:
|
11
|
+
- '3.2.2'
|
12
|
+
name: Ruby ${{ matrix.ruby }} RSpec
|
13
|
+
steps:
|
14
|
+
- uses: actions/checkout@v4
|
15
|
+
- uses: ruby/setup-ruby@v1
|
16
|
+
with:
|
17
|
+
bundler-cache: true
|
18
|
+
ruby-version: ${{ matrix.ruby }}
|
19
|
+
- run: bundle exec rspec
|
data/README.md
CHANGED
@@ -1,4 +1,4 @@
|
|
1
|
-
[
|
1
|
+
[![GitHub Actions status](https://github.com/ismasan/hash_mapper/workflows/Tests/badge.svg?123)](https://github.com/ismasan/hash_mapper)
|
2
2
|
|
3
3
|
# hash_mapper
|
4
4
|
|
@@ -306,6 +306,24 @@ EggMapper.normalize({}, options: { no_default: true })
|
|
306
306
|
EggMapper.denormalize({fried: 4})
|
307
307
|
```
|
308
308
|
|
309
|
+
#### Importing mappings from another mapper
|
310
|
+
|
311
|
+
Use `.import_mapper(another_mapper)` to import mappings from another mapper. This is useful when you want to reuse mappings from another mapper.
|
312
|
+
|
313
|
+
```ruby
|
314
|
+
class Mapper1
|
315
|
+
extend HashMapper
|
316
|
+
map from('/name'), to('/name')
|
317
|
+
end
|
318
|
+
|
319
|
+
class Mapper2
|
320
|
+
extend HashMapper
|
321
|
+
import_mapper Mapper1
|
322
|
+
map from('/age'), to('/age')
|
323
|
+
end
|
324
|
+
|
325
|
+
# Mapper2 will have mappings from Mapper1 ('/name' => '/name') and its own mappings ('/age' => '/age')
|
326
|
+
```
|
309
327
|
|
310
328
|
## REQUIREMENTS:
|
311
329
|
|
data/lib/hash_mapper/version.rb
CHANGED
data/lib/hash_mapper.rb
CHANGED
data/spec/hash_mapper_spec.rb
CHANGED
@@ -156,7 +156,7 @@ end
|
|
156
156
|
|
157
157
|
class PersonWithBlock
|
158
158
|
extend HashMapper
|
159
|
-
def self.normalize(
|
159
|
+
def self.normalize(...)
|
160
160
|
super
|
161
161
|
end
|
162
162
|
map from('/names/first'){|n| n.gsub('+','')}, to('/first_name'){|n| "+++#{n}+++"}
|
@@ -396,7 +396,7 @@ describe "inherited mappers" do
|
|
396
396
|
end
|
397
397
|
|
398
398
|
it "should not affect other mappers" do
|
399
|
-
expect(NotRelated.normalize('n' => 'nn')).to eq({n: {n: 'nn'}})
|
399
|
+
expect(NotRelated.normalize({'n' => 'nn'})).to eq({n: {n: 'nn'}})
|
400
400
|
end
|
401
401
|
end
|
402
402
|
|
@@ -409,17 +409,17 @@ end
|
|
409
409
|
describe "dealing with strings and symbols" do
|
410
410
|
|
411
411
|
it "should be able to normalize from a nested hash with string keys" do
|
412
|
-
expect(MixedMappings.normalize(
|
412
|
+
expect(MixedMappings.normalize({
|
413
413
|
'big' => {'jobs' => 5},
|
414
414
|
'timble' => 3.2
|
415
|
-
)).to eq({dodo: 5, bingo: {biscuit: 3.2}})
|
415
|
+
})).to eq({dodo: 5, bingo: {biscuit: 3.2}})
|
416
416
|
end
|
417
417
|
|
418
418
|
it "should not symbolized keys in value hashes" do
|
419
|
-
expect(MixedMappings.normalize(
|
419
|
+
expect(MixedMappings.normalize({
|
420
420
|
'big' => {'jobs' => 5},
|
421
421
|
'timble' => {'string key' => 'value'}
|
422
|
-
)).to eq({dodo: 5, bingo: {biscuit: {'string key' => 'value'}}})
|
422
|
+
})).to eq({dodo: 5, bingo: {biscuit: {'string key' => 'value'}}})
|
423
423
|
end
|
424
424
|
|
425
425
|
end
|
@@ -433,9 +433,9 @@ end
|
|
433
433
|
|
434
434
|
describe "default values" do
|
435
435
|
it "should use a default value whenever a key is not set" do
|
436
|
-
expect(DefaultValues.normalize(
|
436
|
+
expect(DefaultValues.normalize({
|
437
437
|
'without_default' => 'some_value'
|
438
|
-
)).to eq({ not_defaulted: 'some_value', defaulted: 'the_default_value' })
|
438
|
+
})).to eq({ not_defaulted: 'some_value', defaulted: 'the_default_value' })
|
439
439
|
end
|
440
440
|
|
441
441
|
it "should not use a default if a key is set (even if the value is falsy)" do
|
@@ -446,6 +446,25 @@ describe "default values" do
|
|
446
446
|
end
|
447
447
|
end
|
448
448
|
|
449
|
+
describe '.import_mapper(another_mapper)' do
|
450
|
+
let(:mapper) do
|
451
|
+
Class.new do
|
452
|
+
extend HashMapper
|
453
|
+
|
454
|
+
import_mapper DefaultValues
|
455
|
+
map from('/name'), to('/nombre')
|
456
|
+
end
|
457
|
+
end
|
458
|
+
|
459
|
+
it 'imports the mappings from another mapper' do
|
460
|
+
expect(mapper.maps.size).to eq(3)
|
461
|
+
expect(mapper.normalize({
|
462
|
+
'without_default' => 'some_value',
|
463
|
+
'name' => 'ismael'
|
464
|
+
})).to eq({ not_defaulted: 'some_value', defaulted: 'the_default_value', nombre: 'ismael' })
|
465
|
+
end
|
466
|
+
end
|
467
|
+
|
449
468
|
class MultiBeforeFilter
|
450
469
|
extend HashMapper
|
451
470
|
|
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: hash_mapper
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.2.
|
4
|
+
version: 0.2.8
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Ismael Celis
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date:
|
11
|
+
date: 2024-05-24 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: activesupport
|
@@ -59,6 +59,7 @@ executables: []
|
|
59
59
|
extensions: []
|
60
60
|
extra_rdoc_files: []
|
61
61
|
files:
|
62
|
+
- ".github/workflows/tests.yml"
|
62
63
|
- ".gitignore"
|
63
64
|
- Gemfile
|
64
65
|
- History.txt
|
@@ -88,7 +89,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
|
|
88
89
|
- !ruby/object:Gem::Version
|
89
90
|
version: '0'
|
90
91
|
requirements: []
|
91
|
-
rubygems_version: 3.
|
92
|
+
rubygems_version: 3.4.22
|
92
93
|
signing_key:
|
93
94
|
specification_version: 4
|
94
95
|
summary: Maps input hashes to a normalized format
|