transproc 1.0.2 → 1.0.3
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 +5 -5
- data/.travis.yml +11 -7
- data/CHANGELOG.md +10 -1
- data/Gemfile +7 -8
- data/README.md +3 -5
- data/Rakefile +1 -0
- data/lib/transproc/array.rb +3 -3
- data/lib/transproc/hash.rb +60 -42
- data/lib/transproc/version.rb +1 -1
- data/spec/spec_helper.rb +10 -4
- data/transproc.gemspec +1 -1
- metadata +4 -4
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
|
-
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
2
|
+
SHA256:
|
3
|
+
metadata.gz: 0d88691992987b997ac6deeec1affc3a04a1657fc4ed3521f84c6b26adcce5a1
|
4
|
+
data.tar.gz: dc1f06315b9c3a039c6694a14e4cd379b6836b1710fafe0123a05e985441eca8
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: a2288e68392270823d3dcc4543534553c0d1ac504d95f84f4f9ccc54f52f682dfb64118aecfa913226247c24cc1d77d367193df29ef89a14255f9870c6ae3425
|
7
|
+
data.tar.gz: 65b3916bc564ad16fab85fd84bb66a75544ee7924b4df50673727f212cbc551dc2106a594a052b47093dff1653c7e92e1e464e74facc9cd1aa51ae7c8084e3d0
|
data/.travis.yml
CHANGED
@@ -3,16 +3,20 @@ language: ruby
|
|
3
3
|
sudo: required
|
4
4
|
cache: bundler
|
5
5
|
bundler_args: --without tools
|
6
|
+
before_script: gem update --system
|
6
7
|
script: 'bundle exec rake spec'
|
7
8
|
after_success:
|
8
|
-
- '[
|
9
|
+
- '[ -d coverage ] && bundle exec codeclimate-test-reporter'
|
9
10
|
rvm:
|
10
|
-
- 2.
|
11
|
-
- 2.
|
12
|
-
- 2.
|
13
|
-
- 2.
|
14
|
-
-
|
15
|
-
|
11
|
+
- 2.3.8
|
12
|
+
- 2.4.5
|
13
|
+
- 2.5.3
|
14
|
+
- 2.6
|
15
|
+
- jruby-9.2.4.1
|
16
|
+
env:
|
17
|
+
global:
|
18
|
+
- JRUBY_OPTS='--dev -J-Xmx1024M'
|
19
|
+
- COVERAGE='true'
|
16
20
|
notifications:
|
17
21
|
webhooks:
|
18
22
|
urls:
|
data/CHANGELOG.md
CHANGED
@@ -1,3 +1,12 @@
|
|
1
|
+
# v1.0.3 to-be-released
|
2
|
+
|
3
|
+
## Changed
|
4
|
+
|
5
|
+
* [BREAKING] Added minimal Ruby version to the gemspec file. Transproc now works with Ruby 2.3 and above (flash-gordon)
|
6
|
+
* Performance improvements introduced by using new built-in methods in `Hash` (v-kolesnikov + flash-gordon)
|
7
|
+
|
8
|
+
[Compare v1.0.2...master](https://github.com/solnic/transproc/compare/v1.0.2...master)
|
9
|
+
|
1
10
|
# v1.0.2 2017-02-25
|
2
11
|
|
3
12
|
## Fixed
|
@@ -8,7 +17,7 @@
|
|
8
17
|
|
9
18
|
# v1.0.1 2017-02-25
|
10
19
|
|
11
|
-
* `combine` is now multiple times faster, depending on the level of nesting (Kukunin + splattael)
|
20
|
+
* `combine` is now multiple times faster, depending on the level of nesting (Kukunin + splattael)
|
12
21
|
* `nest` (thus `wrap` too) is ~2x faster now (solnic)
|
13
22
|
|
14
23
|
[Compare v1.0.0...v1.0.1](https://github.com/solnic/transproc/compare/v1.0.0...v1.0.1)
|
data/Gemfile
CHANGED
@@ -5,17 +5,16 @@ gemspec
|
|
5
5
|
group :test do
|
6
6
|
gem 'equalizer'
|
7
7
|
|
8
|
-
|
9
|
-
|
10
|
-
|
8
|
+
gem 'anima'
|
9
|
+
|
10
|
+
platform :mri do
|
11
|
+
if RUBY_VERSION >= '2.5'
|
11
12
|
gem 'mutant', github: 'mbj/mutant', branch: 'master'
|
12
13
|
gem 'mutant-rspec'
|
13
|
-
|
14
|
-
gem 'codeclimate-test-reporter', require: false
|
15
|
-
gem 'simplecov', require: false
|
16
14
|
end
|
17
|
-
|
18
|
-
gem '
|
15
|
+
|
16
|
+
gem 'codeclimate-test-reporter', require: false
|
17
|
+
gem 'simplecov', require: false
|
19
18
|
end
|
20
19
|
end
|
21
20
|
|
data/README.md
CHANGED
@@ -1,6 +1,5 @@
|
|
1
1
|
[gem]: https://rubygems.org/gems/transproc
|
2
2
|
[travis]: https://travis-ci.org/solnic/transproc
|
3
|
-
[gemnasium]: https://gemnasium.com/solnic/transproc
|
4
3
|
[codeclimate]: https://codeclimate.com/github/solnic/transproc
|
5
4
|
[coveralls]: https://coveralls.io/r/solnic/transproc
|
6
5
|
[inchpages]: http://inch-ci.org/github/solnic/transproc
|
@@ -9,7 +8,6 @@
|
|
9
8
|
|
10
9
|
[][gem]
|
11
10
|
[][travis]
|
12
|
-
[][gemnasium]
|
13
11
|
[][codeclimate]
|
14
12
|
[][codeclimate]
|
15
13
|
[][inchpages]
|
@@ -197,9 +195,9 @@ transformation = t(:camel_case)
|
|
197
195
|
transformation.call 'i_am_a_camel'
|
198
196
|
# => "IAmACamel"
|
199
197
|
|
200
|
-
transformation = t(:map_array,
|
201
|
-
|
202
|
-
|
198
|
+
transformation = t(:map_array, (
|
199
|
+
t(:symbolize_keys).>> t(:rename_keys, user_name: :user)
|
200
|
+
)).>> t(:wrap, :address, [:city, :street, :zipcode])
|
203
201
|
|
204
202
|
transformation.call(
|
205
203
|
[
|
data/Rakefile
CHANGED
data/lib/transproc/array.rb
CHANGED
@@ -65,7 +65,7 @@ module Transproc
|
|
65
65
|
# Group array values using provided root key and value keys
|
66
66
|
#
|
67
67
|
# @example
|
68
|
-
# fn = Transproc(:group, :tags, [:
|
68
|
+
# fn = Transproc(:group, :tags, [:tag])
|
69
69
|
#
|
70
70
|
# fn.call [
|
71
71
|
# { task: 'Group it', tag: 'task' },
|
@@ -98,10 +98,10 @@ module Transproc
|
|
98
98
|
# Ungroup array values using provided root key and value keys
|
99
99
|
#
|
100
100
|
# @example
|
101
|
-
# fn = Transproc(:
|
101
|
+
# fn = Transproc(:ungroup, :tags, [:tag])
|
102
102
|
#
|
103
103
|
# fn.call [
|
104
|
-
# { task: 'Group it', tags: [{ tag: 'task' }, { tag: 'important' }]
|
104
|
+
# { task: 'Group it', tags: [{ tag: 'task' }, { tag: 'important' }] }
|
105
105
|
# ]
|
106
106
|
# # => [
|
107
107
|
# { task: 'Group it', tag: 'task' },
|
data/lib/transproc/hash.rb
CHANGED
@@ -17,20 +17,26 @@ module Transproc
|
|
17
17
|
module HashTransformations
|
18
18
|
extend Registry
|
19
19
|
|
20
|
-
|
21
|
-
|
22
|
-
|
23
|
-
|
24
|
-
|
25
|
-
|
26
|
-
|
27
|
-
|
28
|
-
|
29
|
-
|
30
|
-
|
31
|
-
|
32
|
-
|
33
|
-
|
20
|
+
if RUBY_VERSION >= '2.5'
|
21
|
+
# Map all keys in a hash with the provided transformation function
|
22
|
+
#
|
23
|
+
# @example
|
24
|
+
# Transproc(:map_keys, -> s { s.upcase })['name' => 'Jane']
|
25
|
+
# # => {"NAME" => "Jane"}
|
26
|
+
#
|
27
|
+
# @param [Hash]
|
28
|
+
#
|
29
|
+
# @return [Hash]
|
30
|
+
#
|
31
|
+
# @api public
|
32
|
+
def self.map_keys(source_hash, fn)
|
33
|
+
Hash[source_hash].transform_keys!(&fn)
|
34
|
+
end
|
35
|
+
else
|
36
|
+
def self.map_keys(source_hash, fn)
|
37
|
+
Hash[source_hash].tap do |hash|
|
38
|
+
hash.keys.each { |key| hash[fn[key]] = hash.delete(key) }
|
39
|
+
end
|
34
40
|
end
|
35
41
|
end
|
36
42
|
|
@@ -94,20 +100,26 @@ module Transproc
|
|
94
100
|
map_keys(hash, Coercions[:to_string].fn)
|
95
101
|
end
|
96
102
|
|
97
|
-
|
98
|
-
|
99
|
-
|
100
|
-
|
101
|
-
|
102
|
-
|
103
|
-
|
104
|
-
|
105
|
-
|
106
|
-
|
107
|
-
|
108
|
-
|
109
|
-
|
110
|
-
|
103
|
+
if RUBY_VERSION >= '2.4'
|
104
|
+
# Map all values in a hash using transformation function
|
105
|
+
#
|
106
|
+
# @example
|
107
|
+
# Transproc(:map_values, -> v { v.upcase })[:name => 'Jane']
|
108
|
+
# # => {"name" => "JANE"}
|
109
|
+
#
|
110
|
+
# @param [Hash]
|
111
|
+
#
|
112
|
+
# @return [Hash]
|
113
|
+
#
|
114
|
+
# @api public
|
115
|
+
def self.map_values(source_hash, fn)
|
116
|
+
Hash[source_hash].transform_values!(&fn)
|
117
|
+
end
|
118
|
+
else
|
119
|
+
def self.map_values(source_hash, fn)
|
120
|
+
Hash[source_hash].tap do |hash|
|
121
|
+
hash.each { |key, value| hash[key] = fn[value] }
|
122
|
+
end
|
111
123
|
end
|
112
124
|
end
|
113
125
|
|
@@ -167,20 +179,26 @@ module Transproc
|
|
167
179
|
Hash[hash].reject { |k, _| keys.include?(k) }
|
168
180
|
end
|
169
181
|
|
170
|
-
|
171
|
-
|
172
|
-
|
173
|
-
|
174
|
-
|
175
|
-
|
176
|
-
|
177
|
-
|
178
|
-
|
179
|
-
|
180
|
-
|
181
|
-
|
182
|
-
|
183
|
-
|
182
|
+
if RUBY_VERSION >= '2.5'
|
183
|
+
# Accepts specified keys from a hash
|
184
|
+
#
|
185
|
+
# @example
|
186
|
+
# Transproc(:accept_keys, [:name])[name: 'Jane', email: 'jane@doe.org']
|
187
|
+
# # => {:name=>"Jane"}
|
188
|
+
#
|
189
|
+
# @param [Hash] hash The input hash
|
190
|
+
# @param [Array] keys The keys to be accepted
|
191
|
+
#
|
192
|
+
# @return [Hash]
|
193
|
+
#
|
194
|
+
# @api public
|
195
|
+
def self.accept_keys(hash, keys)
|
196
|
+
Hash[hash].slice(*keys)
|
197
|
+
end
|
198
|
+
else
|
199
|
+
def self.accept_keys(hash, keys)
|
200
|
+
reject_keys(hash, hash.keys - keys)
|
201
|
+
end
|
184
202
|
end
|
185
203
|
|
186
204
|
# Map a key in a hash with the provided transformation function
|
data/lib/transproc/version.rb
CHANGED
data/spec/spec_helper.rb
CHANGED
@@ -1,7 +1,13 @@
|
|
1
|
-
if RUBY_ENGINE == 'ruby' &&
|
2
|
-
require '
|
3
|
-
|
4
|
-
|
1
|
+
if RUBY_ENGINE == 'ruby' && ENV['COVERAGE'] == 'true'
|
2
|
+
require 'yaml'
|
3
|
+
rubies = YAML.load(File.read(File.join(__dir__, '..', '.travis.yml')))['rvm']
|
4
|
+
latest_mri = rubies.select { |v| v =~ /\A\d+\.\d+.\d+\z/ }.max
|
5
|
+
|
6
|
+
if RUBY_VERSION == latest_mri
|
7
|
+
require 'simplecov'
|
8
|
+
SimpleCov.start do
|
9
|
+
add_filter '/spec/'
|
10
|
+
end
|
5
11
|
end
|
6
12
|
end
|
7
13
|
|
data/transproc.gemspec
CHANGED
@@ -1,4 +1,3 @@
|
|
1
|
-
# coding: utf-8
|
2
1
|
lib = File.expand_path('../lib', __FILE__)
|
3
2
|
$LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
|
4
3
|
require 'transproc/version'
|
@@ -17,6 +16,7 @@ Gem::Specification.new do |spec|
|
|
17
16
|
spec.executables = spec.files.grep(%r{^bin/}) { |f| File.basename(f) }
|
18
17
|
spec.test_files = spec.files.grep(%r{^(test|spec|features)/})
|
19
18
|
spec.require_paths = ['lib']
|
19
|
+
spec.required_ruby_version = '>= 2.3.0'
|
20
20
|
|
21
21
|
spec.add_development_dependency 'bundler', '~> 1.7'
|
22
22
|
spec.add_development_dependency 'rake', '~> 10.0'
|
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: 1.0.
|
4
|
+
version: 1.0.3
|
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: 2018-12-01 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: bundler
|
@@ -123,7 +123,7 @@ required_ruby_version: !ruby/object:Gem::Requirement
|
|
123
123
|
requirements:
|
124
124
|
- - ">="
|
125
125
|
- !ruby/object:Gem::Version
|
126
|
-
version:
|
126
|
+
version: 2.3.0
|
127
127
|
required_rubygems_version: !ruby/object:Gem::Requirement
|
128
128
|
requirements:
|
129
129
|
- - ">="
|
@@ -131,7 +131,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
|
|
131
131
|
version: '0'
|
132
132
|
requirements: []
|
133
133
|
rubyforge_project:
|
134
|
-
rubygems_version: 2.6
|
134
|
+
rubygems_version: 2.7.6
|
135
135
|
signing_key:
|
136
136
|
specification_version: 4
|
137
137
|
summary: Transform Ruby objects in functional style
|