dry-transformer 0.1.1 → 1.0.0

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: '07286bcabed176ae3f17868f5e838decc2ba0c192828b6e69da92ec18f8713e0'
4
- data.tar.gz: 3c5b577d2fc463182fd9fb28a333b594622c4afa61b276183f3247ce757c55e8
3
+ metadata.gz: 6c7c1900796125a73ede474825b9da2021aa274e9b5a34f0e45a161c6abef772
4
+ data.tar.gz: a642ff796d204314dfc2650d65f6c42bd8d25e991aa144f5d680f1d08083ea08
5
5
  SHA512:
6
- metadata.gz: e100d0e8782d778c4abf0c6f805bfbcafd1d86ce5876a898706114fa658ed3c3045345470adc6bd44a750b995a92d0033d95fadbe0e565bca5fccd52d7b4a993
7
- data.tar.gz: 41ea28575f7d9691f8e36e14920b4a65718738086a96ebc5b73cee2f3108d8884a99f6da0b933c17b1cf270a314a93fbb39c4b30eb4c51cc0736d690b22be662
6
+ metadata.gz: 5cc3a05b5a3a792da5aad7b1f57d79e5598631de33b90f67509faf6c9a4478e382d191f4359553f849012f12e5cd0452a90df5a57f2fa98021835fe594ee553c
7
+ data.tar.gz: 7aa04fae45c928ad437526dbf0161130ba2f63c3883ef664d335acb08f21a90c5fad32726d0a0e9c0e698115c7ddaa8c68b23ad03737142e6bc8657f51cd545a
data/CHANGELOG.md CHANGED
@@ -1,11 +1,25 @@
1
- # 2020-01-14
1
+ <!--- DO NOT EDIT THIS FILE - IT'S AUTOMATICALLY GENERATED VIA DEVTOOLS --->
2
2
 
3
- ## Fixed
3
+ ## 1.0.0 2022-11-20
4
4
 
5
- Fixed Dry::Transformer::HashTransformations.unwrap when hash contains root key (@AMHOL)
6
5
 
7
- [Compare v0.1.0...v0.1.1](https://github.com/dry-rb/dry-transaction/compare/v0.1.0...v0.1.1)
6
+ ### Changed
8
7
 
9
- # v0.1.0 2019-12-28
8
+ - Use Zeitwerk to auto-load the gem (via #14) (@solnic)
9
+ - Dropped dependency on dry-core (via #14) (@solnic)
10
+
11
+ [Compare v0.1.1...v1.0.0](https://github.com/dry-rb/dry-transformer/compare/v0.1.1...v1.0.0)
12
+
13
+ ## 0.1.1 2020-01-14
14
+
15
+
16
+ ### Fixed
17
+
18
+ - Fixed Dry::Transformer::HashTransformations.unwrap when hash contains root key (@AMHOL)
19
+
20
+
21
+ [Compare v0.1.0...v0.1.1](https://github.com/dry-rb/dry-transformer/compare/v0.1.0...v0.1.1)
22
+
23
+ ## 0.1.0 2019-12-28
10
24
 
11
25
  Initial port of the [transproc](https://github.com/solnic/transproc) gem.
data/LICENSE CHANGED
@@ -1,6 +1,6 @@
1
1
  The MIT License (MIT)
2
2
 
3
- Copyright (c) 2015-2020 dry-rb team
3
+ Copyright (c) 2015-2022 dry-rb team
4
4
 
5
5
  Permission is hereby granted, free of charge, to any person obtaining a copy of
6
6
  this software and associated documentation files (the "Software"), to deal in
data/README.md CHANGED
@@ -1,3 +1,4 @@
1
+ <!--- this file is synced from dry-rb/template-gem project -->
1
2
  [gem]: https://rubygems.org/gems/dry-transformer
2
3
  [actions]: https://github.com/dry-rb/dry-transformer/actions
3
4
  [codacy]: https://www.codacy.com/gh/dry-rb/dry-transformer
@@ -10,19 +11,19 @@
10
11
  [![CI Status](https://github.com/dry-rb/dry-transformer/workflows/ci/badge.svg)][actions]
11
12
  [![Codacy Badge](https://api.codacy.com/project/badge/Grade/22edf59617be4aef97cfbe4e1c99f1ce)][codacy]
12
13
  [![Codacy Badge](https://api.codacy.com/project/badge/Coverage/22edf59617be4aef97cfbe4e1c99f1ce)][codacy]
13
- [![Inline docs](http://inch-ci.org/github/dry-rb/dry-transformer.svg?branch=master)][inchpages]
14
+ [![Inline docs](http://inch-ci.org/github/dry-rb/dry-transformer.svg?branch=main)][inchpages]
14
15
 
15
16
  ## Links
16
17
 
17
- * [User documentation](http://dry-rb.org/gems/dry-transformer)
18
+ * [User documentation](https://dry-rb.org/gems/dry-transformer)
18
19
  * [API documentation](http://rubydoc.info/gems/dry-transformer)
19
20
 
20
21
  ## Supported Ruby versions
21
22
 
22
23
  This library officially supports the following Ruby versions:
23
24
 
24
- * MRI >= `2.4`
25
- * jruby >= `9.2`
25
+ * MRI `>= 2.7.0`
26
+ * jruby `>= 9.3` (postponed until 2.7 is supported)
26
27
 
27
28
  ## License
28
29
 
@@ -1,29 +1,34 @@
1
1
  # frozen_string_literal: true
2
- # this file is managed by dry-rb/devtools project
3
2
 
4
- lib = File.expand_path('lib', __dir__)
3
+ # this file is synced from dry-rb/template-gem project
4
+
5
+ lib = File.expand_path("lib", __dir__)
5
6
  $LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
6
- require 'dry/transformer/version'
7
+ require "dry/transformer/version"
7
8
 
8
9
  Gem::Specification.new do |spec|
9
- spec.name = 'dry-transformer'
10
+ spec.name = "dry-transformer"
10
11
  spec.authors = ["Piotr Solnica"]
11
12
  spec.email = ["piotr.solnica@gmail.com"]
12
- spec.license = 'MIT'
13
+ spec.license = "MIT"
13
14
  spec.version = Dry::Transformer::VERSION.dup
14
15
 
15
16
  spec.summary = "Data transformation toolkit"
16
17
  spec.description = spec.summary
17
- spec.homepage = 'https://dry-rb.org/gems/dry-transformer'
18
- spec.files = Dir['CHANGELOG.md', 'LICENSE', 'README.md', 'dry-transformer.gemspec', 'lib/**/*']
19
- spec.require_paths = ['lib']
18
+ spec.homepage = "https://dry-rb.org/gems/dry-transformer"
19
+ spec.files = Dir["CHANGELOG.md", "LICENSE", "README.md", "dry-transformer.gemspec", "lib/**/*"]
20
+ spec.bindir = "bin"
21
+ spec.executables = []
22
+ spec.require_paths = ["lib"]
20
23
 
21
- spec.metadata['allowed_push_host'] = 'https://rubygems.org'
22
- spec.metadata['changelog_uri'] = 'https://github.com/dry-rb/dry-transformer/blob/master/CHANGELOG.md'
23
- spec.metadata['source_code_uri'] = 'https://github.com/dry-rb/dry-transformer'
24
- spec.metadata['bug_tracker_uri'] = 'https://github.com/dry-rb/dry-transformer/issues'
24
+ spec.metadata["allowed_push_host"] = "https://rubygems.org"
25
+ spec.metadata["changelog_uri"] = "https://github.com/dry-rb/dry-transformer/blob/main/CHANGELOG.md"
26
+ spec.metadata["source_code_uri"] = "https://github.com/dry-rb/dry-transformer"
27
+ spec.metadata["bug_tracker_uri"] = "https://github.com/dry-rb/dry-transformer/issues"
25
28
 
26
- spec.required_ruby_version = '>= 2.4.0'
29
+ spec.required_ruby_version = ">= 2.7.0"
27
30
 
28
31
  # to update dependencies edit project.yml
32
+ spec.add_runtime_dependency "zeitwerk", "~> 2.6"
33
+
29
34
  end
@@ -1,9 +1,5 @@
1
1
  # frozen_string_literal: true
2
2
 
3
- require 'dry/transformer/coercions'
4
- require 'dry/transformer/hash'
5
- require 'dry/transformer/array/combine'
6
-
7
3
  module Dry
8
4
  module Transformer
9
5
  # Transformation functions for Array objects
@@ -163,7 +159,7 @@ module Dry
163
159
  #
164
160
  # @api public
165
161
  def self.insert_key(array, key)
166
- map_array(array, ->(v) { { key => v } })
162
+ map_array(array, ->(v) { {key => v} })
167
163
  end
168
164
 
169
165
  # Adds missing keys with nil value to all tuples in array
@@ -1,9 +1,9 @@
1
1
  # frozen_string_literal: true
2
2
 
3
- require 'date'
4
- require 'time'
5
- require 'bigdecimal'
6
- require 'bigdecimal/util'
3
+ require "date"
4
+ require "time"
5
+ require "bigdecimal"
6
+ require "bigdecimal/util"
7
7
 
8
8
  module Dry
9
9
  module Transformer
@@ -13,8 +13,8 @@ module Dry
13
13
  module Coercions
14
14
  extend Registry
15
15
 
16
- TRUE_VALUES = [true, 1, '1', 'on', 't', 'true', 'y', 'yes'].freeze
17
- FALSE_VALUES = [false, 0, '0', 'off', 'f', 'false', 'n', 'no', nil].freeze
16
+ TRUE_VALUES = [true, 1, "1", "on", "t", "true", "y", "yes"].freeze
17
+ FALSE_VALUES = [false, 0, "0", "off", "f", "false", "n", "no", nil].freeze
18
18
 
19
19
  BOOLEAN_MAP = Hash[
20
20
  TRUE_VALUES.product([true]) + FALSE_VALUES.product([false])
@@ -1,7 +1,5 @@
1
1
  # frozen_string_literal: true
2
2
 
3
- require 'dry/transformer/composite'
4
-
5
3
  module Dry
6
4
  module Transformer
7
5
  # Transformation proc wrapper allowing composition of multiple procs into
@@ -1,7 +1,5 @@
1
1
  # frozen_string_literal: true
2
2
 
3
- require 'dry/transformer/coercions'
4
-
5
3
  module Dry
6
4
  module Transformer
7
5
  # Transformation functions for Hash objects
@@ -20,27 +18,19 @@ module Dry
20
18
  module HashTransformations
21
19
  extend Registry
22
20
 
23
- if RUBY_VERSION >= '2.5'
24
- # Map all keys in a hash with the provided transformation function
25
- #
26
- # @example
27
- # Dry::Transformer(:map_keys, -> s { s.upcase })['name' => 'Jane']
28
- # # => {"NAME" => "Jane"}
29
- #
30
- # @param [Hash]
31
- #
32
- # @return [Hash]
33
- #
34
- # @api public
35
- def self.map_keys(source_hash, fn)
36
- Hash[source_hash].transform_keys!(&fn)
37
- end
38
- else
39
- def self.map_keys(source_hash, fn)
40
- Hash[source_hash].tap do |hash|
41
- hash.keys.each { |key| hash[fn[key]] = hash.delete(key) }
42
- end
43
- end
21
+ # Map all keys in a hash with the provided transformation function
22
+ #
23
+ # @example
24
+ # Dry::Transformer(: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)
44
34
  end
45
35
 
46
36
  # Symbolize all keys in a hash
@@ -76,11 +66,11 @@ module Dry
76
66
  hash.each_with_object({}) do |(key, value), output|
77
67
  output[key.to_sym] =
78
68
  case value
79
- when Hash
69
+ when ::Hash
80
70
  deep_symbolize_keys(value)
81
- when Array
71
+ when ::Array
82
72
  value.map { |item|
83
- item.is_a?(Hash) ? deep_symbolize_keys(item) : item
73
+ item.is_a?(::Hash) ? deep_symbolize_keys(item) : item
84
74
  }
85
75
  else
86
76
  value
@@ -120,9 +110,9 @@ module Dry
120
110
  hash.each_with_object({}) do |(key, value), output|
121
111
  output[key.to_s] =
122
112
  case value
123
- when Hash
113
+ when ::Hash
124
114
  deep_stringify_keys(value)
125
- when Array
115
+ when ::Array
126
116
  value.map { |item|
127
117
  item.is_a?(Hash) ? deep_stringify_keys(item) : item
128
118
  }
@@ -132,27 +122,19 @@ module Dry
132
122
  end
133
123
  end
134
124
 
135
- if RUBY_VERSION >= '2.4'
136
- # Map all values in a hash using transformation function
137
- #
138
- # @example
139
- # Dry::Transformer(:map_values, -> v { v.upcase })[:name => 'Jane']
140
- # # => {"name" => "JANE"}
141
- #
142
- # @param [Hash]
143
- #
144
- # @return [Hash]
145
- #
146
- # @api public
147
- def self.map_values(source_hash, fn)
148
- Hash[source_hash].transform_values!(&fn)
149
- end
150
- else
151
- def self.map_values(source_hash, fn)
152
- Hash[source_hash].tap do |hash|
153
- hash.each { |key, value| hash[key] = fn[value] }
154
- end
155
- end
125
+ # Map all values in a hash using transformation function
126
+ #
127
+ # @example
128
+ # Dry::Transformer(:map_values, -> v { v.upcase })[:name => 'Jane']
129
+ # # => {"name" => "JANE"}
130
+ #
131
+ # @param [Hash]
132
+ #
133
+ # @return [Hash]
134
+ #
135
+ # @api public
136
+ def self.map_values(source_hash, fn)
137
+ Hash[source_hash].transform_values!(&fn)
156
138
  end
157
139
 
158
140
  # Rename all keys in a hash using provided mapping hash
@@ -211,26 +193,20 @@ module Dry
211
193
  Hash[hash].reject { |k, _| keys.include?(k) }
212
194
  end
213
195
 
214
- if RUBY_VERSION >= '2.5'
215
- # Accepts specified keys from a hash
216
- #
217
- # @example
218
- # Dry::Transformer(:accept_keys, [:name])[name: 'Jane', email: 'jane@doe.org']
219
- # # => {:name=>"Jane"}
220
- #
221
- # @param [Hash] hash The input hash
222
- # @param [Array] keys The keys to be accepted
223
- #
224
- # @return [Hash]
225
- #
226
- # @api public
227
- def self.accept_keys(hash, keys)
228
- Hash[hash].slice(*keys)
229
- end
230
- else
231
- def self.accept_keys(hash, keys)
232
- reject_keys(hash, hash.keys - keys)
233
- end
196
+ # Accepts specified keys from a hash
197
+ #
198
+ # @example
199
+ # Dry::Transformer(:accept_keys, [:name])[name: 'Jane', email: 'jane@doe.org']
200
+ # # => {:name=>"Jane"}
201
+ #
202
+ # @param [Hash] hash The input hash
203
+ # @param [Array] keys The keys to be accepted
204
+ #
205
+ # @return [Hash]
206
+ #
207
+ # @api public
208
+ def self.accept_keys(hash, keys)
209
+ Hash[hash].slice(*keys)
234
210
  end
235
211
 
236
212
  # Map a key in a hash with the provided transformation function
@@ -301,7 +277,7 @@ module Dry
301
277
  return source_hash unless source_hash[root]
302
278
 
303
279
  add_prefix = lambda do |key|
304
- combined = [root, key].join('_')
280
+ combined = [root, key].join("_")
305
281
  root.is_a?(::Symbol) ? combined.to_sym : combined
306
282
  end
307
283
 
@@ -411,9 +387,9 @@ module Dry
411
387
  else
412
388
  value
413
389
  end
414
- when Hash
390
+ when ::Hash
415
391
  eval_values(value, args, filters)
416
- when Array
392
+ when ::Array
417
393
  value.map { |item|
418
394
  item.is_a?(Hash) ? eval_values(item, args, filters) : item
419
395
  }
@@ -1,6 +1,6 @@
1
1
  # frozen_string_literal: true
2
2
 
3
- require 'dry/transformer/pipe/dsl'
3
+ require "dry/transformer/pipe/dsl"
4
4
 
5
5
  module Dry
6
6
  module Transformer
@@ -36,7 +36,7 @@ module Dry
36
36
 
37
37
  subclass.container(@container) if defined?(@container)
38
38
 
39
- subclass.instance_variable_set('@dsl', dsl.dup) if dsl
39
+ subclass.instance_variable_set("@dsl", dsl.dup) if dsl
40
40
  end
41
41
 
42
42
  # Get or set the container to resolve transprocs from.
@@ -80,7 +80,7 @@ module Dry
80
80
  # @api public
81
81
  def new(*)
82
82
  super.tap do |transformer|
83
- transformer.instance_variable_set('@transproc', dsl.(transformer)) if dsl
83
+ transformer.instance_variable_set("@transproc", dsl.(transformer)) if dsl
84
84
  end
85
85
  end
86
86
  ruby2_keywords(:new) if respond_to?(:ruby2_keywords, true)
@@ -1,6 +1,6 @@
1
1
  # frozen_string_literal: true
2
2
 
3
- require 'dry/transformer/compiler'
3
+ require "dry/transformer/compiler"
4
4
 
5
5
  module Dry
6
6
  module Transformer
@@ -1,7 +1,5 @@
1
1
  # frozen_string_literal: true
2
2
 
3
- require 'dry/transformer/pipe/class_interface'
4
-
5
3
  module Dry
6
4
  module Transformer
7
5
  # Pipe class for defining transprocs with a class DSL.
@@ -1,7 +1,5 @@
1
1
  # frozen_string_literal: true
2
2
 
3
- require 'dry/transformer/conditional'
4
-
5
3
  module Dry
6
4
  module Transformer
7
5
  # Recursive transformation functions
@@ -2,6 +2,6 @@
2
2
 
3
3
  module Dry
4
4
  module Transformer
5
- VERSION = '0.1.1'
5
+ VERSION = "1.0.0"
6
6
  end
7
7
  end
@@ -1,16 +1,9 @@
1
1
  # frozen_string_literal: true
2
2
 
3
- require 'dry/transformer/version'
4
- require 'dry/transformer/constants'
5
- require 'dry/transformer/function'
6
- require 'dry/transformer/error'
7
- require 'dry/transformer/store'
8
- require 'dry/transformer/registry'
3
+ require "zeitwerk"
9
4
 
10
- require 'dry/transformer/array'
11
- require 'dry/transformer/hash'
12
-
13
- require 'dry/transformer/pipe'
5
+ require_relative "transformer/constants"
6
+ require_relative "transformer/error"
14
7
 
15
8
  module Dry
16
9
  module Transformer
@@ -19,5 +12,22 @@ module Dry
19
12
  def self.[](registry)
20
13
  Pipe[registry]
21
14
  end
15
+
16
+ # @api private
17
+ def self.loader
18
+ @loader ||= Zeitwerk::Loader.new.tap do |loader|
19
+ root = File.expand_path("..", __dir__)
20
+ loader.tag = "dry-transformer"
21
+ loader.inflector = Zeitwerk::GemInflector.new("#{root}/dry-transformer.rb")
22
+ loader.push_dir(root)
23
+ loader.ignore(
24
+ "#{root}/dry-transformer.rb",
25
+ "#{root}/dry/transformer/{constants,error,version}.rb"
26
+ )
27
+ loader.inflector.inflect("dsl" => "DSL")
28
+ end
29
+ end
30
+
31
+ loader.setup
22
32
  end
23
33
  end
@@ -1,3 +1,3 @@
1
1
  # frozen_string_literal: true
2
2
 
3
- require 'dry/transformer'
3
+ require "dry/transformer"
metadata CHANGED
@@ -1,15 +1,29 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: dry-transformer
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.1.1
4
+ version: 1.0.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - Piotr Solnica
8
- autorequire:
8
+ autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2020-01-14 00:00:00.000000000 Z
12
- dependencies: []
11
+ date: 2022-11-20 00:00:00.000000000 Z
12
+ dependencies:
13
+ - !ruby/object:Gem::Dependency
14
+ name: zeitwerk
15
+ requirement: !ruby/object:Gem::Requirement
16
+ requirements:
17
+ - - "~>"
18
+ - !ruby/object:Gem::Version
19
+ version: '2.6'
20
+ type: :runtime
21
+ prerelease: false
22
+ version_requirements: !ruby/object:Gem::Requirement
23
+ requirements:
24
+ - - "~>"
25
+ - !ruby/object:Gem::Version
26
+ version: '2.6'
13
27
  description: Data transformation toolkit
14
28
  email:
15
29
  - piotr.solnica@gmail.com
@@ -23,10 +37,9 @@ files:
23
37
  - dry-transformer.gemspec
24
38
  - lib/dry-transformer.rb
25
39
  - lib/dry/transformer.rb
26
- - lib/dry/transformer/all.rb
27
- - lib/dry/transformer/array.rb
28
40
  - lib/dry/transformer/array/combine.rb
29
- - lib/dry/transformer/class.rb
41
+ - lib/dry/transformer/array_transformations.rb
42
+ - lib/dry/transformer/class_transformations.rb
30
43
  - lib/dry/transformer/coercions.rb
31
44
  - lib/dry/transformer/compiler.rb
32
45
  - lib/dry/transformer/composite.rb
@@ -34,11 +47,11 @@ files:
34
47
  - lib/dry/transformer/constants.rb
35
48
  - lib/dry/transformer/error.rb
36
49
  - lib/dry/transformer/function.rb
37
- - lib/dry/transformer/hash.rb
50
+ - lib/dry/transformer/hash_transformations.rb
38
51
  - lib/dry/transformer/pipe.rb
39
52
  - lib/dry/transformer/pipe/class_interface.rb
40
53
  - lib/dry/transformer/pipe/dsl.rb
41
- - lib/dry/transformer/proc.rb
54
+ - lib/dry/transformer/proc_transformations.rb
42
55
  - lib/dry/transformer/recursion.rb
43
56
  - lib/dry/transformer/registry.rb
44
57
  - lib/dry/transformer/store.rb
@@ -48,10 +61,10 @@ licenses:
48
61
  - MIT
49
62
  metadata:
50
63
  allowed_push_host: https://rubygems.org
51
- changelog_uri: https://github.com/dry-rb/dry-transformer/blob/master/CHANGELOG.md
64
+ changelog_uri: https://github.com/dry-rb/dry-transformer/blob/main/CHANGELOG.md
52
65
  source_code_uri: https://github.com/dry-rb/dry-transformer
53
66
  bug_tracker_uri: https://github.com/dry-rb/dry-transformer/issues
54
- post_install_message:
67
+ post_install_message:
55
68
  rdoc_options: []
56
69
  require_paths:
57
70
  - lib
@@ -59,15 +72,15 @@ required_ruby_version: !ruby/object:Gem::Requirement
59
72
  requirements:
60
73
  - - ">="
61
74
  - !ruby/object:Gem::Version
62
- version: 2.4.0
75
+ version: 2.7.0
63
76
  required_rubygems_version: !ruby/object:Gem::Requirement
64
77
  requirements:
65
78
  - - ">="
66
79
  - !ruby/object:Gem::Version
67
80
  version: '0'
68
81
  requirements: []
69
- rubygems_version: 3.0.3
70
- signing_key:
82
+ rubygems_version: 3.3.7
83
+ signing_key:
71
84
  specification_version: 4
72
85
  summary: Data transformation toolkit
73
86
  test_files: []
@@ -1,11 +0,0 @@
1
- # frozen_string_literal: true
2
-
3
- require 'dry/transformer'
4
-
5
- require 'dry/transformer/class'
6
- require 'dry/transformer/coercions'
7
- require 'dry/transformer/conditional'
8
- require 'dry/transformer/array'
9
- require 'dry/transformer/hash'
10
- require 'dry/transformer/proc'
11
- require 'dry/transformer/recursion'