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 CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: 8fe570160f2f117c13449f5f01426d574260ee1d
4
- data.tar.gz: b4d2ec3d08fb692d060511c801d44999426a4288
3
+ metadata.gz: ebe915f7b5f801872ab46b936f29fe3795f54c07
4
+ data.tar.gz: 2f48bb7ccd56f9f00a7ed91f643e2ffb135dc6b5
5
5
  SHA512:
6
- metadata.gz: 1ac33afae90cf7459ebf40c6be43d5c0765ef01613d6f75fff76aed1b595952f149997d3faf7d11b31147c4e2c74bead6dbb017e397e5b7390bfa2e2f10b078a
7
- data.tar.gz: d21d42c59d26c43d6481a7ad1e33205f04bb6504fa7aab5cb0acd7f63e018f4ee2586313141f164dc67cadf283edb6528a1c2e8974138951e7575b995f9f325a
6
+ metadata.gz: 47482d74f606f03a5c251a3a2738f52ec4a02be926aef629358fc92dac17a30af59fd8f654df0268b629dbad460982c27e2ccdfb478ca9da3e8176120ce6e9c7
7
+ data.tar.gz: 5721c74ceb2b55b51842d229a828f1689b298382f50782782653c66ef0644ad290bc0672c945cb352eb0f5208bb22b3c1c7ff206af4587a11a3f76c7c5c76c89
data/Gemfile.lock CHANGED
@@ -1,7 +1,7 @@
1
1
  PATH
2
2
  remote: .
3
3
  specs:
4
- data_maps (0.3.1)
4
+ data_maps (0.3.2)
5
5
  activesupport (~> 3.2, >= 3.2.21)
6
6
 
7
7
  GEM
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::ToPersonObject < DataMaps::Converter::Base
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: to_person_object,
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
@@ -1,3 +1,3 @@
1
1
  module DataMaps
2
- VERSION = '0.3.1'
2
+ VERSION = '0.3.2'
3
3
  end
@@ -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
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: data_maps
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.3.1
4
+ version: 0.3.2
5
5
  platform: ruby
6
6
  authors:
7
7
  - Axel Wahlen