transproc 0.1.0 → 0.1.1
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/CHANGELOG.md +16 -2
- data/Gemfile +9 -1
- data/lib/transproc/array.rb +3 -2
- data/lib/transproc/coercions.rb +1 -0
- data/lib/transproc/hash.rb +11 -6
- data/lib/transproc/version.rb +1 -1
- data/spec/integration/hash_spec.rb +25 -2
- data/spec/spec_helper.rb +5 -0
- metadata +3 -4
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 87334e10cb8bf6cccb2f48272486e54ad024260f
|
4
|
+
data.tar.gz: 58910ac82cf4b9b73567e8fe548a016777ad63ea
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 79eb35957035d51c30b9f2afce0b364bec99d5276c2f2526f6e2d3ded5d31603a21815b52e128a97090cbbc58e010cf2692afe95e8d3ba7cd4c8865a87ee6797
|
7
|
+
data.tar.gz: 23e555e0d4e2fc4dd338f74faf1eec966db459d91ce56be2203e2149609ed1003dbae437cfe220971d72b313bd57ea73d2d0487f4b16a8e4801f631772e2df27
|
data/CHANGELOG.md
CHANGED
@@ -1,4 +1,18 @@
|
|
1
|
-
## v0.1.
|
1
|
+
## v0.1.1 2015-03-13
|
2
|
+
|
3
|
+
### Changed
|
4
|
+
|
5
|
+
* `Transproc(:map_array)` performance improvements (splattael + solnic)
|
6
|
+
* hash transformation performance improvements (solnic)
|
7
|
+
|
8
|
+
### Fixed
|
9
|
+
|
10
|
+
* `Transproc(:nest)` handles falsy values correctly now (solnic)
|
11
|
+
* Missing `require "time"` added (splattael)
|
12
|
+
|
13
|
+
[Compare v0.1.0...v0.1.1](https://github.com/solnic/transproc/compare/v0.1.0...v0.1.1)
|
14
|
+
|
15
|
+
## v0.1.0 2014-12-28
|
2
16
|
|
3
17
|
### Added
|
4
18
|
|
@@ -9,7 +23,7 @@
|
|
9
23
|
* boolean coercions (solnic)
|
10
24
|
* [hash] `:nest` which wraps a set of keys under a new key (solnic)
|
11
25
|
|
12
|
-
[Compare v0.0.1...
|
26
|
+
[Compare v0.0.1...v0.1.0](https://github.com/solnic/transproc/compare/v0.0.1...v0.1.0)
|
13
27
|
|
14
28
|
## v0.0.1 2014-12-24
|
15
29
|
|
data/Gemfile
CHANGED
data/lib/transproc/array.rb
CHANGED
@@ -1,10 +1,11 @@
|
|
1
1
|
module Transproc
|
2
2
|
register(:map_array) do |array, *fns|
|
3
|
-
Transproc(:map_array!, *fns)[array
|
3
|
+
Transproc(:map_array!, *fns)[Array[*array]]
|
4
4
|
end
|
5
5
|
|
6
6
|
register(:map_array!) do |array, *fns|
|
7
|
-
|
7
|
+
fn = fns.size == 1 ? fns[0] : fns.reduce(:+)
|
8
|
+
array.map! { |value| fn[value] }
|
8
9
|
end
|
9
10
|
|
10
11
|
register(:wrap) do |array, key, keys|
|
data/lib/transproc/coercions.rb
CHANGED
data/lib/transproc/hash.rb
CHANGED
@@ -1,6 +1,6 @@
|
|
1
1
|
module Transproc
|
2
2
|
register(:symbolize_keys) do |hash|
|
3
|
-
Transproc(:symbolize_keys!)[hash
|
3
|
+
Transproc(:symbolize_keys!)[Hash[hash]]
|
4
4
|
end
|
5
5
|
|
6
6
|
register(:symbolize_keys!) do |hash|
|
@@ -9,7 +9,7 @@ module Transproc
|
|
9
9
|
end
|
10
10
|
|
11
11
|
register(:map_hash) do |hash, mapping|
|
12
|
-
Transproc(:map_hash!, mapping)[hash
|
12
|
+
Transproc(:map_hash!, mapping)[Hash[hash]]
|
13
13
|
end
|
14
14
|
|
15
15
|
register(:map_hash!) do |hash, mapping|
|
@@ -26,12 +26,17 @@ module Transproc
|
|
26
26
|
end
|
27
27
|
|
28
28
|
register(:nest) do |hash, key, keys|
|
29
|
-
Transproc(:nest!, key, keys)[hash
|
29
|
+
Transproc(:nest!, key, keys)[Hash[hash]]
|
30
30
|
end
|
31
31
|
|
32
32
|
register(:nest!) do |hash, root, keys|
|
33
|
-
|
34
|
-
|
35
|
-
|
33
|
+
nest_keys = hash.keys & keys
|
34
|
+
|
35
|
+
if nest_keys.size > 0
|
36
|
+
child = Hash[nest_keys.zip(nest_keys.map { |key| hash.delete(key) })]
|
37
|
+
hash.update(root => child)
|
38
|
+
else
|
39
|
+
hash.update(root => nil)
|
40
|
+
end
|
36
41
|
end
|
37
42
|
end
|
data/lib/transproc/version.rb
CHANGED
@@ -26,13 +26,36 @@ describe 'Hash mapping with Transproc' do
|
|
26
26
|
end
|
27
27
|
end
|
28
28
|
|
29
|
-
describe 'nest
|
29
|
+
describe 'nest' do
|
30
30
|
it 'returns new hash with keys nested under a new key' do
|
31
|
-
nest = Transproc(:nest
|
31
|
+
nest = Transproc(:nest, :baz, ['foo'])
|
32
32
|
|
33
33
|
input = { 'foo' => 'bar' }
|
34
34
|
output = { baz: { 'foo' => 'bar' } }
|
35
35
|
|
36
|
+
expect(nest[input]).to eql(output)
|
37
|
+
expect(input).to eql('foo' => 'bar')
|
38
|
+
end
|
39
|
+
end
|
40
|
+
|
41
|
+
describe 'nest!' do
|
42
|
+
it 'returns new hash with keys nested under a new key' do
|
43
|
+
nest = Transproc(:nest!, :baz, ['one', 'two', 'not-here'])
|
44
|
+
|
45
|
+
input = { 'foo' => 'bar', 'one' => nil, 'two' => false }
|
46
|
+
output = { 'foo' => 'bar', baz: { 'one' => nil, 'two' => false } }
|
47
|
+
|
48
|
+
nest[input]
|
49
|
+
|
50
|
+
expect(input).to eql(output)
|
51
|
+
end
|
52
|
+
|
53
|
+
it 'returns new hash with nil nested under a new key when nest-keys are missing' do
|
54
|
+
nest = Transproc(:nest!, :baz, ['foo'])
|
55
|
+
|
56
|
+
input = { 'bar' => 'foo' }
|
57
|
+
output = { 'bar' => 'foo', baz: nil }
|
58
|
+
|
36
59
|
nest[input]
|
37
60
|
|
38
61
|
expect(input).to eql(output)
|
data/spec/spec_helper.rb
CHANGED
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: transproc
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.1.
|
4
|
+
version: 0.1.1
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Piotr Solnica
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date:
|
11
|
+
date: 2015-03-13 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: bundler
|
@@ -103,7 +103,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
|
|
103
103
|
version: '0'
|
104
104
|
requirements: []
|
105
105
|
rubyforge_project:
|
106
|
-
rubygems_version: 2.
|
106
|
+
rubygems_version: 2.4.5
|
107
107
|
signing_key:
|
108
108
|
specification_version: 4
|
109
109
|
summary: Experimental functional transformations for Ruby
|
@@ -114,4 +114,3 @@ test_files:
|
|
114
114
|
- spec/integration/hash_spec.rb
|
115
115
|
- spec/integration/transproc_spec.rb
|
116
116
|
- spec/spec_helper.rb
|
117
|
-
has_rdoc:
|