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 CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
- SHA1:
3
- metadata.gz: 64dbe08d203b9ac87e38de4e8f46dde2899d5cfc
4
- data.tar.gz: 6c4e2cd21783a8fea8e3f4ebfe05656ca8e1cd73
2
+ SHA256:
3
+ metadata.gz: 0d88691992987b997ac6deeec1affc3a04a1657fc4ed3521f84c6b26adcce5a1
4
+ data.tar.gz: dc1f06315b9c3a039c6694a14e4cd379b6836b1710fafe0123a05e985441eca8
5
5
  SHA512:
6
- metadata.gz: e46205bc38e87eb30fa40d1466bfb0f1cff727a945d985f22bb17ae9ac2c3be4910363403c08f2092514f15c2de6d06b8d5863ec9db530fa600465ea9782c601
7
- data.tar.gz: 964e3d01aa66e74542a79ea9844977c299cab95984959d066336b3203b67364e4728938e5412a9cde5acbc7661d5f5d744e3d42d17dc89574856f4d56e8d1aff
6
+ metadata.gz: a2288e68392270823d3dcc4543534553c0d1ac504d95f84f4f9ccc54f52f682dfb64118aecfa913226247c24cc1d77d367193df29ef89a14255f9870c6ae3425
7
+ data.tar.gz: 65b3916bc564ad16fab85fd84bb66a75544ee7924b4df50673727f212cbc551dc2106a594a052b47093dff1653c7e92e1e464e74facc9cd1aa51ae7c8084e3d0
@@ -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
- - '[ "$TRAVIS_RUBY_VERSION" = "2.3.1" ] && [ "$TRAVIS_BRANCH" = "master" ] && bundle exec codeclimate-test-reporter'
9
+ - '[ -d coverage ] && bundle exec codeclimate-test-reporter'
9
10
  rvm:
10
- - 2.0
11
- - 2.2
12
- - 2.1
13
- - 2.3.1
14
- - rbx-3
15
- - jruby-9.1.5.0
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:
@@ -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
- if RUBY_VERSION >= '2.1'
9
- gem 'anima'
10
- platform :mri do
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
- else
18
- gem 'anima', '~> 0.2.0'
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 Version](https://badge.fury.io/rb/transproc.svg)][gem]
11
10
  [![Build Status](https://travis-ci.org/solnic/transproc.svg?branch=master)][travis]
12
- [![Dependency Status](https://gemnasium.com/solnic/transproc.svg)][gemnasium]
13
11
  [![Code Climate](https://codeclimate.com/github/solnic/transproc/badges/gpa.svg)][codeclimate]
14
12
  [![Test Coverage](https://codeclimate.com/github/solnic/transproc/badges/coverage.svg)][codeclimate]
15
13
  [![Inline docs](http://inch-ci.org/github/solnic/transproc.svg?branch=master)][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, t(:symbolize_keys)
201
- .>> t(:rename_keys, user_name: :user))
202
- .>> t(:wrap, :address, [:city, :street, :zipcode])
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
@@ -1,3 +1,4 @@
1
+ require 'bundler/gem_tasks'
1
2
  require 'rspec/core/rake_task'
2
3
 
3
4
  task default: :spec
@@ -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, [:tag_name])
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(:group, :tags, [:tag_name])
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' },
@@ -17,20 +17,26 @@ module Transproc
17
17
  module HashTransformations
18
18
  extend Registry
19
19
 
20
- # Map all keys in a hash with the provided transformation function
21
- #
22
- # @example
23
- # Transproc(:map_keys, -> s { s.upcase })['name' => 'Jane']
24
- # # => {"NAME" => "Jane"}
25
- #
26
- # @param [Hash]
27
- #
28
- # @return [Hash]
29
- #
30
- # @api public
31
- def self.map_keys(source_hash, fn)
32
- Hash[source_hash].tap do |hash|
33
- hash.keys.each { |key| hash[fn[key]] = hash.delete(key) }
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
- # Map all values in a hash using transformation function
98
- #
99
- # @example
100
- # Transproc(:map_values, -> v { v.upcase })[:name => 'Jane']
101
- # # => {"name" => "JANE"}
102
- #
103
- # @param [Hash]
104
- #
105
- # @return [Hash]
106
- #
107
- # @api public
108
- def self.map_values(source_hash, fn)
109
- Hash[source_hash].tap do |hash|
110
- hash.each { |key, value| hash[key] = fn[value] }
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
- # Accepts specified keys from a hash
171
- #
172
- # @example
173
- # Transproc(:accept_keys, [:name])[name: 'Jane', email: 'jane@doe.org']
174
- # # => {:name=>"Jane"}
175
- #
176
- # @param [Hash] hash The input hash
177
- # @param [Array] keys The keys to be accepted
178
- #
179
- # @return [Hash]
180
- #
181
- # @api public
182
- def self.accept_keys(hash, keys)
183
- reject_keys(hash, hash.keys - keys)
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
@@ -1,3 +1,3 @@
1
1
  module Transproc
2
- VERSION = '1.0.2'.freeze
2
+ VERSION = '1.0.3'.freeze
3
3
  end
@@ -1,7 +1,13 @@
1
- if RUBY_ENGINE == 'ruby' && RUBY_VERSION == '2.3.1'
2
- require 'simplecov'
3
- SimpleCov.start do
4
- add_filter '/spec/'
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
 
@@ -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.2
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: 2017-02-25 00:00:00.000000000 Z
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: '0'
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.9
134
+ rubygems_version: 2.7.6
135
135
  signing_key:
136
136
  specification_version: 4
137
137
  summary: Transform Ruby objects in functional style