data_maps 0.3.1 → 0.3.2
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/Gemfile.lock +1 -1
- data/README.md +4 -2
- data/lib/data_maps/converter/base.rb +2 -0
- data/lib/data_maps/version.rb +1 -1
- data/spec/data_maps/converter/base_spec.rb +29 -0
- metadata +1 -1
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: ebe915f7b5f801872ab46b936f29fe3795f54c07
|
4
|
+
data.tar.gz: 2f48bb7ccd56f9f00a7ed91f643e2ffb135dc6b5
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 47482d74f606f03a5c251a3a2738f52ec4a02be926aef629358fc92dac17a30af59fd8f654df0268b629dbad460982c27e2ccdfb478ca9da3e8176120ce6e9c7
|
7
|
+
data.tar.gz: 5721c74ceb2b55b51842d229a828f1689b298382f50782782653c66ef0644ad290bc0672c945cb352eb0f5208bb22b3c1c7ff206af4587a11a3f76c7c5c76c89
|
data/Gemfile.lock
CHANGED
data/README.md
CHANGED
@@ -255,6 +255,8 @@ Apply one or many converters to the input data. Converters applied procedural.
|
|
255
255
|
convert: [
|
256
256
|
{ apply: :map, option: { 1: 'A', 2: 'B' } }
|
257
257
|
]
|
258
|
+
# or in short, when no option is needed
|
259
|
+
convert: [ :string ]
|
258
260
|
}
|
259
261
|
```
|
260
262
|
|
@@ -334,7 +336,7 @@ Apply one or many converters to the input data. Converters applied procedural.
|
|
334
336
|
You have to extend the `DataMaps::Converter::Base` class. Then all options are available via the `option` attribute reader.
|
335
337
|
|
336
338
|
```ruby
|
337
|
-
class DataMaps::Converter::
|
339
|
+
class DataMaps::Converter::PersonObject < DataMaps::Converter::Base
|
338
340
|
def execute(data)
|
339
341
|
Person.new(data, option)
|
340
342
|
end
|
@@ -342,7 +344,7 @@ Apply one or many converters to the input data. Converters applied procedural.
|
|
342
344
|
```
|
343
345
|
|
344
346
|
```ruby
|
345
|
-
apply:
|
347
|
+
apply: person_object,
|
346
348
|
option: { as: :importer } # passed value are available via option
|
347
349
|
```
|
348
350
|
|
@@ -10,6 +10,8 @@ module DataMaps
|
|
10
10
|
raise ArgumentError.new('Converter mapping has to be an array') unless mapping.is_a?(Array)
|
11
11
|
|
12
12
|
mapping.map do |converter|
|
13
|
+
converter = { apply: converter } unless converter.is_a? Hash
|
14
|
+
|
13
15
|
raise ArgumentError.new('Converter must be specified with the apply key') unless converter.key?(:apply)
|
14
16
|
self.factory(converter[:apply], converter[:option])
|
15
17
|
end
|
data/lib/data_maps/version.rb
CHANGED
@@ -10,6 +10,35 @@ describe DataMaps::Converter do
|
|
10
10
|
DataMaps::Converter.factory_from_map(mapping)
|
11
11
|
end
|
12
12
|
end
|
13
|
+
|
14
|
+
describe '::create_from_map' do
|
15
|
+
it 'creates new converter from an array of hashes' do
|
16
|
+
mapping = [ { apply: :ruby, option: :upcase }, { apply: :string } ]
|
17
|
+
|
18
|
+
expect(DataMaps::Converter).to receive(:factory).ordered.with(:ruby, :upcase).and_call_original
|
19
|
+
expect(DataMaps::Converter).to receive(:factory).ordered.with(:string, nil).and_call_original
|
20
|
+
|
21
|
+
DataMaps::Converter.create_from_map(mapping)
|
22
|
+
end
|
23
|
+
|
24
|
+
it 'creates new converter from an array of converter names without options' do
|
25
|
+
mapping = [ :string, :numeric ]
|
26
|
+
|
27
|
+
expect(DataMaps::Converter).to receive(:factory).ordered.with(:string, nil).and_call_original
|
28
|
+
expect(DataMaps::Converter).to receive(:factory).ordered.with(:numeric, nil).and_call_original
|
29
|
+
|
30
|
+
DataMaps::Converter.create_from_map(mapping)
|
31
|
+
end
|
32
|
+
|
33
|
+
it 'creates new converter from an array of mixed types' do
|
34
|
+
mapping = [ { apply: :ruby, option: :upcase }, :string ]
|
35
|
+
|
36
|
+
expect(DataMaps::Converter).to receive(:factory).ordered.with(:ruby, :upcase).and_call_original
|
37
|
+
expect(DataMaps::Converter).to receive(:factory).ordered.with(:string, nil).and_call_original
|
38
|
+
|
39
|
+
DataMaps::Converter.create_from_map(mapping)
|
40
|
+
end
|
41
|
+
end
|
13
42
|
end
|
14
43
|
|
15
44
|
describe DataMaps::Converter::Base do
|