data_maps 0.3.4 → 0.3.5
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/.gitignore +1 -0
- data/.travis.yml +1 -0
- data/README.md +7 -2
- data/data_maps.gemspec +1 -1
- data/lib/data_maps/dsl/mapping/conditions_dsl.rb +14 -1
- data/lib/data_maps/dsl/mapping/field_dsl.rb +3 -2
- data/lib/data_maps/version.rb +1 -1
- data/spec/data_maps/converter/affixes_spec.rb +2 -2
- data/spec/data_maps/converter/map_spec.rb +1 -1
- data/spec/data_maps/dsl/mapping/conditions_dsl_spec.rb +18 -0
- data/spec/data_maps/dsl/mapping/field_dsl_spec.rb +5 -5
- data/spec/data_maps/dsl/mapping_dsl_spec.rb +30 -0
- metadata +2 -9
- data/Gemfile.lock +0 -48
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 5a16f9e0450a56553c020366bffdbed04c85531c
|
4
|
+
data.tar.gz: 15288d671c8908e573f9af7cefecc887c14c22b1
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 32246884e5a56a4b30299ce6caf435598ba48d6b5a48778b2c2411307cef50cf590177ea98279706e880b8332f8c5138a25f6fca420f2ccd2ac1bbaa872cff2a
|
7
|
+
data.tar.gz: 6611c2fdfe9e0ec8740f24cf8b28657eed598ee27011c637129e187843ace3cbe18d04742b9cacc2f34bf56f4633fcf411816eda9771992a383615aca533dfbd
|
data/.gitignore
CHANGED
data/.travis.yml
CHANGED
data/README.md
CHANGED
@@ -264,8 +264,8 @@ Apply one or many converters to the input data. Converters applied procedural.
|
|
264
264
|
|
265
265
|
- **Converter: map**
|
266
266
|
A simple value mapping. Maps are converted to a `HashWithIndifferentAccess`.
|
267
|
-
Works with
|
268
|
-
For arrays and hashes it returns nil if the value is not in the mapping. For
|
267
|
+
Works with scalar values, hashes and arrays.
|
268
|
+
For arrays and hashes it returns nil if the value is not in the mapping. For scalar values it returns the original data.
|
269
269
|
|
270
270
|
```ruby
|
271
271
|
apply: :map,
|
@@ -348,4 +348,9 @@ Apply one or many converters to the input data. Converters applied procedural.
|
|
348
348
|
option: { as: :importer } # passed value are available via option
|
349
349
|
```
|
350
350
|
|
351
|
+
## ToDos:
|
352
|
+
- DSL to describe mappings
|
353
|
+
- Better error handling during the converter process
|
354
|
+
|
355
|
+
|
351
356
|
Have fun using the `DataMaps` gem :)
|
data/data_maps.gemspec
CHANGED
@@ -20,7 +20,7 @@ Gem::Specification.new do |spec|
|
|
20
20
|
|
21
21
|
spec.required_ruby_version = '>= 1.9.2'
|
22
22
|
|
23
|
-
spec.add_runtime_dependency 'activesupport', '
|
23
|
+
spec.add_runtime_dependency 'activesupport', '>= 3.2.21'
|
24
24
|
|
25
25
|
spec.add_development_dependency 'bundler', '~> 1.8'
|
26
26
|
spec.add_development_dependency 'rake', '~> 10.0'
|
@@ -10,9 +10,22 @@ module DataMaps
|
|
10
10
|
self.thens = {}
|
11
11
|
end
|
12
12
|
|
13
|
+
def when(condition, option)
|
14
|
+
self.whens[condition] = option
|
15
|
+
end
|
16
|
+
alias_method :is, :when
|
17
|
+
|
18
|
+
def then(action, option)
|
19
|
+
self.thens[action] = option
|
20
|
+
end
|
21
|
+
alias_method :so, :then
|
22
|
+
|
13
23
|
# Serialize DSL to an Hash
|
14
24
|
def to_h
|
15
|
-
data =
|
25
|
+
data = {
|
26
|
+
when: whens,
|
27
|
+
then: thens
|
28
|
+
}
|
16
29
|
data.stringify_keys
|
17
30
|
end
|
18
31
|
end
|
@@ -11,19 +11,20 @@ module DataMaps
|
|
11
11
|
self.converter = []
|
12
12
|
end
|
13
13
|
|
14
|
-
def
|
14
|
+
def condition(&block)
|
15
15
|
dsl = DataMaps::Dsl::Mapping::ConditionsDsl.new
|
16
16
|
dsl.configure(&block) if block_given?
|
17
17
|
self.conditions << dsl.to_h
|
18
18
|
end
|
19
19
|
|
20
|
-
def
|
20
|
+
def convert(converter, options = nil)
|
21
21
|
self.converter << { apply: converter, option: options }
|
22
22
|
end
|
23
23
|
|
24
24
|
# Serialize DSL to an Hash
|
25
25
|
def to_h
|
26
26
|
data = super
|
27
|
+
data[:convert] = data.delete(:converter)
|
27
28
|
data.stringify_keys
|
28
29
|
end
|
29
30
|
end
|
data/lib/data_maps/version.rb
CHANGED
@@ -42,7 +42,7 @@ describe DataMaps::Converter::Prefix do
|
|
42
42
|
end
|
43
43
|
end
|
44
44
|
|
45
|
-
describe 'for
|
45
|
+
describe 'for scalar values' do
|
46
46
|
it 'cast value to string' do
|
47
47
|
data = double(Object)
|
48
48
|
|
@@ -101,7 +101,7 @@ describe DataMaps::Converter::Postfix do
|
|
101
101
|
end
|
102
102
|
end
|
103
103
|
|
104
|
-
describe 'for
|
104
|
+
describe 'for scalar values' do
|
105
105
|
it 'cast value to string' do
|
106
106
|
data = double(Object)
|
107
107
|
|
@@ -12,4 +12,22 @@ describe DataMaps::Dsl::Mapping::ConditionsDsl do
|
|
12
12
|
expect(subject.thens).to eq({})
|
13
13
|
end
|
14
14
|
end
|
15
|
+
|
16
|
+
describe '#when' do
|
17
|
+
it 'adds a when with correct options to the whens hash' do
|
18
|
+
expect{ subject.when(:regex, /[0-9]/) }.to change{ subject.whens.length }.from(0).to(1)
|
19
|
+
|
20
|
+
expect(subject.whens.key?(:regex)).to be_truthy
|
21
|
+
expect(subject.whens[:regex]).to eq /[0-9]/
|
22
|
+
end
|
23
|
+
end
|
24
|
+
|
25
|
+
describe '#then' do
|
26
|
+
it 'adds a then with correct options to the thens hash' do
|
27
|
+
expect{ subject.then(:filter, true) }.to change{ subject.thens.length }.from(0).to(1)
|
28
|
+
|
29
|
+
expect(subject.thens.key?(:filter)).to be_truthy
|
30
|
+
expect(subject.thens[:filter]).to be_truthy
|
31
|
+
end
|
32
|
+
end
|
15
33
|
end
|
@@ -17,24 +17,24 @@ describe DataMaps::Dsl::Mapping::FieldMappingDsl do
|
|
17
17
|
end
|
18
18
|
end
|
19
19
|
|
20
|
-
describe '#
|
20
|
+
describe '#condition' do
|
21
21
|
it 'creates a new ConditionsDsl object' do
|
22
22
|
dsl = DataMaps::Dsl::Mapping::ConditionsDsl.new
|
23
23
|
|
24
24
|
expect(DataMaps::Dsl::Mapping::ConditionsDsl).to receive(:new).with(no_args).and_return(dsl)
|
25
|
-
subject.
|
25
|
+
subject.condition
|
26
26
|
end
|
27
27
|
|
28
28
|
it 'calls configure with given block' do
|
29
29
|
expect do |block|
|
30
|
-
subject.
|
30
|
+
subject.condition(&block)
|
31
31
|
end.to yield_control
|
32
32
|
end
|
33
33
|
end
|
34
34
|
|
35
|
-
describe '#
|
35
|
+
describe '#convert' do
|
36
36
|
it 'adds the defined converter to converter hash' do
|
37
|
-
expect{ subject.
|
37
|
+
expect{ subject.convert(:ruby, :downcase) }.to change{ subject.converter.count }.from(0).to(1)
|
38
38
|
expect(subject.converter.first).to eq({ apply: :ruby, option: :downcase })
|
39
39
|
end
|
40
40
|
end
|
@@ -34,4 +34,34 @@ describe DataMaps::Dsl::Mapping do
|
|
34
34
|
expect(subject.mapping_hash.key?('myfield')).to be_truthy
|
35
35
|
end
|
36
36
|
end
|
37
|
+
|
38
|
+
describe 'full integration' do
|
39
|
+
it 'generates correct mapping hash' do
|
40
|
+
mapping = DataMaps::Mapping.new.configure do
|
41
|
+
field :myfield, from: :source_field do
|
42
|
+
condition do
|
43
|
+
is :empty, true
|
44
|
+
so :filter, true
|
45
|
+
end
|
46
|
+
|
47
|
+
convert :ruby, [:join, ',']
|
48
|
+
end
|
49
|
+
end
|
50
|
+
|
51
|
+
expect(mapping.mapping_hash).not_to be_empty
|
52
|
+
expect(mapping.mapping_hash).to eq(
|
53
|
+
{
|
54
|
+
'myfield' => {
|
55
|
+
'from' => :source_field,
|
56
|
+
'conditions' => [
|
57
|
+
{ 'when' => { 'empty' => true }, 'then' => { 'filter' => true } }
|
58
|
+
],
|
59
|
+
'convert' => [
|
60
|
+
{ 'apply' => :ruby, 'option' => [:join, ','] }
|
61
|
+
]
|
62
|
+
}
|
63
|
+
}
|
64
|
+
)
|
65
|
+
end
|
66
|
+
end
|
37
67
|
end
|
metadata
CHANGED
@@ -1,22 +1,19 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: data_maps
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.3.
|
4
|
+
version: 0.3.5
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Axel Wahlen
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date: 2015-
|
11
|
+
date: 2015-04-01 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: activesupport
|
15
15
|
requirement: !ruby/object:Gem::Requirement
|
16
16
|
requirements:
|
17
|
-
- - "~>"
|
18
|
-
- !ruby/object:Gem::Version
|
19
|
-
version: '3.2'
|
20
17
|
- - ">="
|
21
18
|
- !ruby/object:Gem::Version
|
22
19
|
version: 3.2.21
|
@@ -24,9 +21,6 @@ dependencies:
|
|
24
21
|
prerelease: false
|
25
22
|
version_requirements: !ruby/object:Gem::Requirement
|
26
23
|
requirements:
|
27
|
-
- - "~>"
|
28
|
-
- !ruby/object:Gem::Version
|
29
|
-
version: '3.2'
|
30
24
|
- - ">="
|
31
25
|
- !ruby/object:Gem::Version
|
32
26
|
version: 3.2.21
|
@@ -111,7 +105,6 @@ files:
|
|
111
105
|
- ".rspec"
|
112
106
|
- ".travis.yml"
|
113
107
|
- Gemfile
|
114
|
-
- Gemfile.lock
|
115
108
|
- LICENSE.txt
|
116
109
|
- README.md
|
117
110
|
- Rakefile
|
data/Gemfile.lock
DELETED
@@ -1,48 +0,0 @@
|
|
1
|
-
PATH
|
2
|
-
remote: .
|
3
|
-
specs:
|
4
|
-
data_maps (0.3.4)
|
5
|
-
activesupport (~> 3.2, >= 3.2.21)
|
6
|
-
|
7
|
-
GEM
|
8
|
-
remote: https://rubygems.org/
|
9
|
-
specs:
|
10
|
-
activesupport (3.2.21)
|
11
|
-
i18n (~> 0.6, >= 0.6.4)
|
12
|
-
multi_json (~> 1.0)
|
13
|
-
codeclimate-test-reporter (0.4.7)
|
14
|
-
simplecov (>= 0.7.1, < 1.0.0)
|
15
|
-
diff-lcs (1.2.5)
|
16
|
-
docile (1.1.5)
|
17
|
-
i18n (0.7.0)
|
18
|
-
multi_json (1.10.1)
|
19
|
-
rake (10.4.2)
|
20
|
-
rspec (3.2.0)
|
21
|
-
rspec-core (~> 3.2.0)
|
22
|
-
rspec-expectations (~> 3.2.0)
|
23
|
-
rspec-mocks (~> 3.2.0)
|
24
|
-
rspec-core (3.2.1)
|
25
|
-
rspec-support (~> 3.2.0)
|
26
|
-
rspec-expectations (3.2.0)
|
27
|
-
diff-lcs (>= 1.2.0, < 2.0)
|
28
|
-
rspec-support (~> 3.2.0)
|
29
|
-
rspec-mocks (3.2.1)
|
30
|
-
diff-lcs (>= 1.2.0, < 2.0)
|
31
|
-
rspec-support (~> 3.2.0)
|
32
|
-
rspec-support (3.2.2)
|
33
|
-
simplecov (0.9.2)
|
34
|
-
docile (~> 1.1.0)
|
35
|
-
multi_json (~> 1.0)
|
36
|
-
simplecov-html (~> 0.9.0)
|
37
|
-
simplecov-html (0.9.0)
|
38
|
-
|
39
|
-
PLATFORMS
|
40
|
-
ruby
|
41
|
-
|
42
|
-
DEPENDENCIES
|
43
|
-
bundler (~> 1.8)
|
44
|
-
codeclimate-test-reporter (~> 0.4.7)
|
45
|
-
data_maps!
|
46
|
-
rake (~> 10.0)
|
47
|
-
rspec (~> 3.2)
|
48
|
-
simplecov (~> 0.9.2)
|