transproc 1.1.0 → 1.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 +8 -0
- data/Gemfile +4 -0
- data/README.md +12 -12
- data/lib/transproc/hash.rb +5 -2
- data/lib/transproc/transformer/class_interface.rb +3 -2
- data/lib/transproc/transformer/deprecated/class_interface.rb +3 -2
- data/lib/transproc/version.rb +1 -1
- data/spec/spec_helper.rb +7 -0
- data/spec/unit/class_transformations_spec.rb +1 -1
- metadata +3 -3
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: c5e373dbeb3ba726459c3cf12238ba1e9fd096e308bdfcbf9799045653c053db
|
4
|
+
data.tar.gz: b761e23e9e7c630db6e08ee7e317758fe2bd53cb6a8a49bb7799902b657ffbc3
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 3aee819e93702794f280d6f5578670494fb28e3661f7c2bac311530363ac52aa83897cdc00ee2c591eadae86d3dcf4147805bfc9805f24dc6034314df2d8aacd
|
7
|
+
data.tar.gz: 55eb18ed05667309ee936ac75b6146940ca45c64cc215225a894e42b84ffddaea571d1a7675554cc8802f31b197dc2810886cdb0685c2473c9902e5c0aacf6bb
|
data/CHANGELOG.md
CHANGED
@@ -1,3 +1,11 @@
|
|
1
|
+
# v1.1.1 2019-12-21
|
2
|
+
|
3
|
+
## Fixed
|
4
|
+
|
5
|
+
- Keyword warnings on Ruby 2.7 (flash-gordon)
|
6
|
+
|
7
|
+
[Compare v1.1.0...v1.1.1](https://github.com/solnic/transproc/compare/v1.1.0...v1.1.1)
|
8
|
+
|
1
9
|
# v1.1.0 2019-07-18
|
2
10
|
|
3
11
|
This is the last transproc release before the project will be forked to `dry-transformer`.
|
data/Gemfile
CHANGED
data/README.md
CHANGED
@@ -2,7 +2,7 @@
|
|
2
2
|
[travis]: https://travis-ci.org/solnic/transproc
|
3
3
|
[codeclimate]: https://codeclimate.com/github/solnic/transproc
|
4
4
|
[coveralls]: https://coveralls.io/r/solnic/transproc
|
5
|
-
[inchpages]:
|
5
|
+
[inchpages]: https://inch-ci.org/github/solnic/transproc
|
6
6
|
|
7
7
|
# Transproc
|
8
8
|
|
@@ -10,7 +10,7 @@
|
|
10
10
|
[][travis]
|
11
11
|
[][codeclimate]
|
12
12
|
[][codeclimate]
|
13
|
-
[][inchpages]
|
14
14
|
|
15
15
|
Transproc is a small library that allows you to compose procs into a functional pipeline using left-to-right function composition.
|
16
16
|
|
@@ -20,7 +20,7 @@ or `>>` in F#.
|
|
20
20
|
`transproc` provides a mechanism to define and compose transformations,
|
21
21
|
along with a number of built-in transformations.
|
22
22
|
|
23
|
-
It's currently used as the data mapping backend in [Ruby Object Mapper](
|
23
|
+
It's currently used as the data mapping backend in [Ruby Object Mapper](https://rom-rb.org).
|
24
24
|
|
25
25
|
## Installation
|
26
26
|
|
@@ -51,7 +51,7 @@ It's easy to compose transformations:
|
|
51
51
|
|
52
52
|
```ruby
|
53
53
|
to_string = Transproc::Function.new(:to_s.to_proc)
|
54
|
-
(increment >> to_string)[1] => '2'
|
54
|
+
(increment >> to_string)[1] # => '2'
|
55
55
|
```
|
56
56
|
|
57
57
|
It's easy to pass additional arguments to transformations:
|
@@ -92,13 +92,13 @@ M[:map_array, M[:to_string]].([1, 2, 3]) # => ['1', '2', '3']
|
|
92
92
|
`transproc` comes with a lot of built-in functions. They come in the form of
|
93
93
|
modules with class methods, which you can import into a registry:
|
94
94
|
|
95
|
-
* [Coercions](
|
96
|
-
* [Array transformations](
|
97
|
-
* [Hash transformations](
|
98
|
-
* [Class transformations](
|
99
|
-
* [Proc transformations](
|
100
|
-
* [Conditional](
|
101
|
-
* [Recursion](
|
95
|
+
* [Coercions](https://www.rubydoc.info/gems/transproc/Transproc/Coercions)
|
96
|
+
* [Array transformations](https://www.rubydoc.info/gems/transproc/Transproc/ArrayTransformations)
|
97
|
+
* [Hash transformations](https://www.rubydoc.info/gems/transproc/Transproc/HashTransformations)
|
98
|
+
* [Class transformations](https://www.rubydoc.info/gems/transproc/Transproc/ClassTransformations)
|
99
|
+
* [Proc transformations](https://www.rubydoc.info/gems/transproc/Transproc/ProcTransformations)
|
100
|
+
* [Conditional](https://www.rubydoc.info/gems/transproc/Transproc/Conditional)
|
101
|
+
* [Recursion](https://www.rubydoc.info/gems/transproc/Transproc/Recursion)
|
102
102
|
|
103
103
|
You can import everything with:
|
104
104
|
|
@@ -235,7 +235,7 @@ transformation.call('[{"name":"Jane"}]')
|
|
235
235
|
|
236
236
|
## Credits
|
237
237
|
|
238
|
-
This project is inspired by the work of following people:
|
238
|
+
This project is inspired by the work of the following people:
|
239
239
|
|
240
240
|
* [Markus Schirp](https://github.com/mbj) and [morpher](https://github.com/mbj/morpher) project
|
241
241
|
* [Josep M. Bach](https://github.com/txus) and [kleisli](https://github.com/txus/kleisli) project
|
data/lib/transproc/hash.rb
CHANGED
@@ -19,6 +19,8 @@ module Transproc
|
|
19
19
|
module HashTransformations
|
20
20
|
extend Registry
|
21
21
|
|
22
|
+
EMPTY_HASH = {}.freeze
|
23
|
+
|
22
24
|
if RUBY_VERSION >= '2.5'
|
23
25
|
# Map all keys in a hash with the provided transformation function
|
24
26
|
#
|
@@ -296,8 +298,9 @@ module Transproc
|
|
296
298
|
# @return [Hash]
|
297
299
|
#
|
298
300
|
# @api public
|
299
|
-
def self.unwrap(source_hash, root, selected = nil,
|
301
|
+
def self.unwrap(source_hash, root, selected = nil, options = EMPTY_HASH)
|
300
302
|
return source_hash unless source_hash[root]
|
303
|
+
options, selected = selected, nil if options.empty? && selected.is_a?(::Hash)
|
301
304
|
|
302
305
|
add_prefix = ->(key) do
|
303
306
|
combined = [root, key].join('_')
|
@@ -308,7 +311,7 @@ module Transproc
|
|
308
311
|
nested_hash = hash[root]
|
309
312
|
keys = nested_hash.keys
|
310
313
|
keys &= selected if selected
|
311
|
-
new_keys = prefix ? keys.map(&add_prefix) : keys
|
314
|
+
new_keys = options[:prefix] ? keys.map(&add_prefix) : keys
|
312
315
|
|
313
316
|
hash.update(Hash[new_keys.zip(keys.map { |key| nested_hash.delete(key) })])
|
314
317
|
hash.delete(root) if nested_hash.empty?
|
@@ -77,11 +77,12 @@ module Transproc
|
|
77
77
|
end
|
78
78
|
|
79
79
|
# @api public
|
80
|
-
def new(*
|
81
|
-
super
|
80
|
+
def new(*)
|
81
|
+
super.tap do |transformer|
|
82
82
|
transformer.instance_variable_set('@transproc', dsl.(transformer)) if dsl
|
83
83
|
end
|
84
84
|
end
|
85
|
+
ruby2_keywords(:new) if respond_to?(:ruby2_keywords, true)
|
85
86
|
|
86
87
|
# Get a transformation from the container,
|
87
88
|
# without adding it to the transformation pipeline
|
@@ -6,11 +6,12 @@ module Transproc
|
|
6
6
|
# @api public
|
7
7
|
module ClassInterface
|
8
8
|
# @api public
|
9
|
-
def new(*
|
10
|
-
super
|
9
|
+
def new(*)
|
10
|
+
super.tap do |transformer|
|
11
11
|
transformer.instance_variable_set('@transproc', transproc) if transformations.any?
|
12
12
|
end
|
13
13
|
end
|
14
|
+
ruby2_keywords(:new) if respond_to?(:ruby2_keywords, true)
|
14
15
|
|
15
16
|
# @api private
|
16
17
|
def inherited(subclass)
|
data/lib/transproc/version.rb
CHANGED
data/spec/spec_helper.rb
CHANGED
@@ -13,6 +13,13 @@ if RUBY_ENGINE == 'ruby' && ENV['COVERAGE'] == 'true'
|
|
13
13
|
end
|
14
14
|
end
|
15
15
|
|
16
|
+
if defined? Warning
|
17
|
+
require 'warning'
|
18
|
+
|
19
|
+
Warning.ignore(/rspec/)
|
20
|
+
Warning.process { |w| raise RuntimeError, w } unless ENV['NO_WARNING']
|
21
|
+
end
|
22
|
+
|
16
23
|
begin
|
17
24
|
require 'byebug'
|
18
25
|
rescue LoadError;end
|
@@ -39,7 +39,7 @@ describe Transproc::ClassTransformations do
|
|
39
39
|
set_ivars = described_class.t(:set_ivars, klass)
|
40
40
|
|
41
41
|
input = { name: 'Jane', age: 25 }
|
42
|
-
output = klass.new(input)
|
42
|
+
output = klass.new(**input)
|
43
43
|
result = set_ivars[input]
|
44
44
|
|
45
45
|
expect(result).to eql(output)
|
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.1.
|
4
|
+
version: 1.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: 2019-
|
11
|
+
date: 2019-12-21 00:00:00.000000000 Z
|
12
12
|
dependencies: []
|
13
13
|
description: Transform Ruby objects in functional style
|
14
14
|
email:
|
@@ -91,7 +91,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
|
|
91
91
|
- !ruby/object:Gem::Version
|
92
92
|
version: '0'
|
93
93
|
requirements: []
|
94
|
-
rubygems_version: 3.0.
|
94
|
+
rubygems_version: 3.0.6
|
95
95
|
signing_key:
|
96
96
|
specification_version: 4
|
97
97
|
summary: Transform Ruby objects in functional style
|