dry-transformer 0.1.0 → 1.0.0

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.
Files changed (54) hide show
  1. checksums.yaml +4 -4
  2. data/CHANGELOG.md +23 -1
  3. data/LICENSE +1 -1
  4. data/README.md +6 -5
  5. data/dry-transformer.gemspec +26 -14
  6. data/lib/dry/transformer/{array.rb → array_transformations.rb} +1 -5
  7. data/lib/dry/transformer/{class.rb → class_transformations.rb} +0 -0
  8. data/lib/dry/transformer/coercions.rb +6 -6
  9. data/lib/dry/transformer/function.rb +0 -2
  10. data/lib/dry/transformer/{hash.rb → hash_transformations.rb} +50 -73
  11. data/lib/dry/transformer/pipe/class_interface.rb +3 -3
  12. data/lib/dry/transformer/pipe/dsl.rb +1 -1
  13. data/lib/dry/transformer/pipe.rb +0 -2
  14. data/lib/dry/transformer/{proc.rb → proc_transformations.rb} +0 -0
  15. data/lib/dry/transformer/recursion.rb +0 -2
  16. data/lib/dry/transformer/version.rb +1 -1
  17. data/lib/dry/transformer.rb +20 -10
  18. data/lib/dry-transformer.rb +1 -1
  19. metadata +33 -66
  20. data/.codeclimate.yml +0 -12
  21. data/.github/ISSUE_TEMPLATE/----please-don-t-ask-for-support-via-issues.md +0 -10
  22. data/.github/ISSUE_TEMPLATE/---bug-report.md +0 -30
  23. data/.github/ISSUE_TEMPLATE/---feature-request.md +0 -18
  24. data/.github/workflows/custom_ci.yml +0 -66
  25. data/.github/workflows/docsite.yml +0 -34
  26. data/.github/workflows/sync_configs.yml +0 -34
  27. data/.gitignore +0 -16
  28. data/.rspec +0 -4
  29. data/.rubocop.yml +0 -95
  30. data/CODE_OF_CONDUCT.md +0 -13
  31. data/CONTRIBUTING.md +0 -29
  32. data/Gemfile +0 -19
  33. data/Rakefile +0 -6
  34. data/docsite/source/built-in-transformations.html.md +0 -47
  35. data/docsite/source/index.html.md +0 -15
  36. data/docsite/source/transformation-objects.html.md +0 -32
  37. data/docsite/source/using-standalone-functions.html.md +0 -82
  38. data/lib/dry/transformer/all.rb +0 -11
  39. data/spec/spec_helper.rb +0 -31
  40. data/spec/unit/array/combine_spec.rb +0 -224
  41. data/spec/unit/array_transformations_spec.rb +0 -233
  42. data/spec/unit/class_transformations_spec.rb +0 -50
  43. data/spec/unit/coercions_spec.rb +0 -132
  44. data/spec/unit/conditional_spec.rb +0 -48
  45. data/spec/unit/function_not_found_error_spec.rb +0 -12
  46. data/spec/unit/function_spec.rb +0 -193
  47. data/spec/unit/hash_transformations_spec.rb +0 -490
  48. data/spec/unit/proc_transformations_spec.rb +0 -20
  49. data/spec/unit/recursion_spec.rb +0 -145
  50. data/spec/unit/registry_spec.rb +0 -202
  51. data/spec/unit/store_spec.rb +0 -198
  52. data/spec/unit/transformer/class_interface_spec.rb +0 -350
  53. data/spec/unit/transformer/dsl_spec.rb +0 -15
  54. data/spec/unit/transformer/instance_methods_spec.rb +0 -25
@@ -1,30 +0,0 @@
1
- ---
2
- name: "\U0001F41B Bug report"
3
- about: See CONTRIBUTING.md for more information
4
- title: ''
5
- labels: bug
6
- assignees: ''
7
-
8
- ---
9
-
10
- **Before you submit this: WE ONLY ACCEPT BUG REPORTS AND FEATURE REQUESTS**
11
-
12
- For more information see `CONTRIBUTING.md`.
13
-
14
- **Describe the bug**
15
-
16
- A clear and concise description of what the bug is.
17
-
18
- **To Reproduce**
19
-
20
- Provide detailed steps to reproduce, an executable script would be best.
21
-
22
- **Expected behavior**
23
-
24
- A clear and concise description of what you expected to happen.
25
-
26
- **Your environment**
27
-
28
- - Affects my production application: **YES/NO**
29
- - Ruby version: ...
30
- - OS: ...
@@ -1,18 +0,0 @@
1
- ---
2
- name: "\U0001F6E0 Feature request"
3
- about: See CONTRIBUTING.md for more information
4
- title: ''
5
- labels: feature
6
- assignees: ''
7
-
8
- ---
9
-
10
- Summary of what the feature is supposed to do.
11
-
12
- ## Examples
13
-
14
- Code examples showing how the feature could be used.
15
-
16
- ## Resources
17
-
18
- Additional information, like a link to the discussion forum thread where the feature was discussed etc.
@@ -1,66 +0,0 @@
1
- # this file is managed by dry-rb/devtools project
2
-
3
- name: ci
4
-
5
- on:
6
- push:
7
- paths:
8
- - .github/workflows/custom_ci.yml
9
- - lib/**
10
- - spec/**
11
- - Gemfile
12
- - "*.gemspec"
13
-
14
- jobs:
15
- tests-mri:
16
- runs-on: ubuntu-latest
17
- strategy:
18
- fail-fast: false
19
- matrix:
20
- ruby: ["2.6.x", "2.5.x", "2.4.x"]
21
- include:
22
- - ruby: "2.6.x"
23
- coverage: "true"
24
- steps:
25
- - uses: actions/checkout@v1
26
- - name: Set up Ruby
27
- uses: actions/setup-ruby@v1
28
- with:
29
- ruby-version: ${{matrix.ruby}}
30
- - name: Download test reporter
31
- if: "matrix.coverage == 'true'"
32
- run: |
33
- mkdir -p tmp/
34
- curl -L https://codeclimate.com/downloads/test-reporter/test-reporter-latest-linux-amd64 > ./tmp/cc-test-reporter
35
- chmod +x ./tmp/cc-test-reporter
36
- ./tmp/cc-test-reporter before-build
37
- - name: Bundle install
38
- run: |
39
- gem install bundler
40
- bundle install --jobs 4 --retry 3 --without tools docs benchmarks
41
- - name: Run all tests
42
- env:
43
- COVERAGE: ${{matrix.coverage}}
44
- CODACY_PROJECT_TOKEN: ${{secrets.CODACY_PROJECT_TOKEN}}
45
- CODACY_RUN_LOCAL: true
46
- run: bundle exec rake
47
- tests-others:
48
- runs-on: ubuntu-latest
49
- strategy:
50
- fail-fast: false
51
- matrix:
52
- image: ["jruby:9.2.8", "ruby:rc"]
53
- container:
54
- image: ${{matrix.image}}
55
- steps:
56
- - uses: actions/checkout@v1
57
- - name: Install git
58
- run: |
59
- apt-get update
60
- apt-get install -y --no-install-recommends git
61
- - name: Bundle install
62
- run: |
63
- gem install bundler
64
- bundle install --jobs 4 --retry 3 --without tools docs benchmarks
65
- - name: Run all tests
66
- run: bundle exec rake
@@ -1,34 +0,0 @@
1
- # this file is managed by dry-rb/devtools project
2
-
3
- name: docsite
4
-
5
- on:
6
- push:
7
- paths:
8
- - docsite/**
9
- - .github/workflows/docsite.yml
10
- branches:
11
- - master
12
- - release-**
13
- tags:
14
-
15
- jobs:
16
- update-docs:
17
- runs-on: ubuntu-latest
18
- steps:
19
- - uses: actions/checkout@v1
20
- - name: Set up Ruby
21
- uses: actions/setup-ruby@v1
22
- with:
23
- ruby-version: "2.6.x"
24
- - name: Install dependencies
25
- run: |
26
- gem install bundler
27
- bundle install --jobs 4 --retry 3 --without benchmarks sql
28
- - name: Symlink ossy
29
- run: mkdir -p bin && ln -sf "$(bundle show ossy)/bin/ossy" bin/ossy
30
- - name: Trigger dry-rb.org deploy
31
- env:
32
- GITHUB_LOGIN: dry-bot
33
- GITHUB_TOKEN: ${{ secrets.GH_PAT }}
34
- run: bin/ossy github workflow dry-rb/dry-rb.org ci
@@ -1,34 +0,0 @@
1
- # this file is managed by dry-rb/devtools project
2
-
3
- name: sync_configs
4
-
5
- on:
6
- repository_dispatch:
7
-
8
- jobs:
9
- sync-configs:
10
- runs-on: ubuntu-latest
11
- if: github.event.action == 'sync_configs'
12
- steps:
13
- - uses: actions/checkout@v1
14
- - name: Update configuration files from devtools
15
- env:
16
- GITHUB_LOGIN: dry-bot
17
- GITHUB_TOKEN: ${{ secrets.GH_PAT }}
18
- run: |
19
- git clone https://github.com/dry-rb/devtools.git tmp/devtools
20
-
21
- if [ -f ".github/workflows/custom_ci.yml" ]; then
22
- rsync -av --exclude '.github/workflows/ci.yml' tmp/devtools/shared/ . ;
23
- else
24
- rsync -av tmp/devtools/shared/ . ;
25
- fi
26
-
27
- git config --local user.email "dry-bot@dry-rb.org"
28
- git config --local user.name "dry-bot"
29
- git add -A
30
- git commit -m "[devtools] config sync" || echo "nothing changed"
31
- - name: Push changes
32
- uses: ad-m/github-push-action@master
33
- with:
34
- github_token: ${{ secrets.GH_PAT }}
data/.gitignore DELETED
@@ -1,16 +0,0 @@
1
- /.bundle/
2
- /.yardoc
3
- /Gemfile.lock
4
- /vendor/
5
- /_yardoc/
6
- /coverage/
7
- /doc/
8
- /pkg/
9
- /spec/reports/
10
- /tmp/
11
- *.bundle
12
- *.so
13
- *.o
14
- *.a
15
- mkmf.log
16
-
data/.rspec DELETED
@@ -1,4 +0,0 @@
1
- --color
2
- --require spec_helper
3
- --order random
4
-
data/.rubocop.yml DELETED
@@ -1,95 +0,0 @@
1
- # this file is managed by dry-rb/devtools project
2
-
3
- AllCops:
4
- TargetRubyVersion: 2.4
5
-
6
- Style/EachWithObject:
7
- Enabled: false
8
-
9
- Style/StringLiterals:
10
- Enabled: true
11
- EnforcedStyle: single_quotes
12
-
13
- Style/Alias:
14
- Enabled: false
15
-
16
- Style/LambdaCall:
17
- Enabled: false
18
-
19
- Style/StabbyLambdaParentheses:
20
- Enabled: false
21
-
22
- Style/FormatString:
23
- Enabled: false
24
-
25
- Style/Documentation:
26
- Enabled: false
27
-
28
- Layout/SpaceInLambdaLiteral:
29
- Enabled: false
30
-
31
- Layout/MultilineMethodCallIndentation:
32
- Enabled: true
33
- EnforcedStyle: indented
34
-
35
- Metrics/LineLength:
36
- Max: 100
37
-
38
- Metrics/MethodLength:
39
- Max: 22
40
-
41
- Metrics/ClassLength:
42
- Max: 150
43
-
44
- Metrics/AbcSize:
45
- Max: 20
46
-
47
- Metrics/BlockLength:
48
- Enabled: false
49
-
50
- Metrics/CyclomaticComplexity:
51
- Enabled: true
52
- Max: 10
53
-
54
- Lint/BooleanSymbol:
55
- Enabled: false
56
-
57
- Style/AccessModifierDeclarations:
58
- Enabled: false
59
-
60
- Style/BlockDelimiters:
61
- Enabled: false
62
-
63
- Layout/IndentFirstArrayElement:
64
- EnforcedStyle: consistent
65
-
66
- Style/ClassAndModuleChildren:
67
- Exclude:
68
- - "spec/**/*_spec.rb"
69
-
70
- Lint/HandleExceptions:
71
- Exclude:
72
- - "spec/spec_helper.rb"
73
-
74
- Naming/FileName:
75
- Exclude:
76
- - "lib/dry-*.rb"
77
-
78
- Style/SymbolArray:
79
- Exclude:
80
- - "spec/**/*_spec.rb"
81
-
82
- Style/ConditionalAssignment:
83
- Enabled: false
84
-
85
- Naming/MethodName:
86
- Enabled: false
87
-
88
- Style/AsciiComments:
89
- Enabled: false
90
-
91
- Style/DateTime:
92
- Enabled: false
93
-
94
- Style/IfUnlessModifier:
95
- Enabled: false
data/CODE_OF_CONDUCT.md DELETED
@@ -1,13 +0,0 @@
1
- # Contributor Code of Conduct
2
-
3
- As contributors and maintainers of this project, we pledge to respect all people who contribute through reporting issues, posting feature requests, updating documentation, submitting pull requests or patches, and other activities.
4
-
5
- We are committed to making participation in this project a harassment-free experience for everyone, regardless of level of experience, gender, gender identity and expression, sexual orientation, disability, personal appearance, body size, race, age, or religion.
6
-
7
- Examples of unacceptable behavior by participants include the use of sexual language or imagery, derogatory comments or personal attacks, trolling, public or private harassment, insults, or other unprofessional conduct.
8
-
9
- Project maintainers have the right and responsibility to remove, edit, or reject comments, commits, code, wiki edits, issues, and other contributions that are not aligned to this Code of Conduct. Project maintainers who do not follow the Code of Conduct may be removed from the project team.
10
-
11
- Instances of abusive, harassing, or otherwise unacceptable behavior may be reported by opening an issue or contacting one or more of the project maintainers.
12
-
13
- This Code of Conduct is adapted from the [Contributor Covenant](http:contributor-covenant.org), version 1.4.0, available at [https://www.contributor-covenant.org/version/1/4/code-of-conduct](https://www.contributor-covenant.org/version/1/4/code-of-conduct)
data/CONTRIBUTING.md DELETED
@@ -1,29 +0,0 @@
1
- # Issue Guidelines
2
-
3
- ## Reporting bugs
4
-
5
- If you found a bug, report an issue and describe what's the expected behavior versus what actually happens. If the bug causes a crash, attach a full backtrace. If possible, a reproduction script showing the problem is highly appreciated.
6
-
7
- ## Reporting feature requests
8
-
9
- Report a feature request **only after discussing it first on [discourse.dry-rb.org](https://discourse.dry-rb.org)** where it was accepted. Please provide a concise description of the feature, don't link to a discussion thread, and instead summarize what was discussed.
10
-
11
- ## Reporting questions, support requests, ideas, concerns etc.
12
-
13
- **PLEASE DON'T** - use [discourse.dry-rb.org](http://discourse.dry-rb.org) instead.
14
-
15
- # Pull Request Guidelines
16
-
17
- A Pull Request will only be accepted if it addresses a specific issue that was reported previously, or fixes typos, mistakes in documentation etc.
18
-
19
- Other requirements:
20
-
21
- 1) Do not open a pull request if you can't provide tests along with it. If you have problems writing tests, ask for help in the related issue.
22
- 2) Follow the style conventions of the surrounding code. In most cases, this is standard ruby style.
23
- 3) Add API documentation if it's a new feature
24
- 4) Update API documentation if it changes an existing feature
25
- 5) Bonus points for sending a PR to [github.com/dry-rb/dry-rb.org](github.com/dry-rb/dry-rb.org) which updates user documentation and guides
26
-
27
- # Asking for help
28
-
29
- If these guidelines aren't helpful, and you're stuck, please post a message on [discourse.dry-rb.org](https://discourse.dry-rb.org) or join [our chat](https://dry-rb.zulipchat.com).
data/Gemfile DELETED
@@ -1,19 +0,0 @@
1
- source 'https://rubygems.org'
2
-
3
- gemspec
4
-
5
- gem 'rake'
6
- gem 'rspec', '~> 3.8'
7
- gem 'dry-equalizer', '~> 0.2'
8
-
9
- platform :mri do
10
- gem 'codacy-coverage', require: false
11
- gem 'simplecov', require: false
12
- end
13
-
14
- group :tools do
15
- gem 'pry'
16
- gem 'byebug', platform: :mri
17
- gem 'benchmark-ips'
18
- gem 'ossy', git: 'https://github.com/solnic/ossy.git', branch: 'master', platform: :mri
19
- end
data/Rakefile DELETED
@@ -1,6 +0,0 @@
1
- require 'bundler/gem_tasks'
2
- require 'rspec/core/rake_task'
3
-
4
- task default: :spec
5
-
6
- RSpec::Core::RakeTask.new(:spec)
@@ -1,47 +0,0 @@
1
- ---
2
- title: Built-in transformation
3
- layout: gem-single
4
- name: dry-transformer
5
- ---
6
-
7
- `dry-transformer` comes with a lot of built-in functions. They come in the form of modules with class methods, which you can import into a registry:
8
-
9
- * [Coercions](https://www.rubydoc.info/gems/dry-transformer/Dry/Transformer/Coercions)
10
- * [Array transformations](https://www.rubydoc.info/gems/dry-transformer/Dry/Transformer/ArrayTransformations)
11
- * [Hash transformations](https://www.rubydoc.info/gems/dry-transformer/Dry/Transformer/HashTransformations)
12
- * [Class transformations](https://www.rubydoc.info/gems/dry-transformer/Dry/Transformer/ClassTransformations)
13
- * [Proc transformations](https://www.rubydoc.info/gems/dry-transformer/Dry/Transformer/ProcTransformations)
14
- * [Conditional](https://www.rubydoc.info/gems/dry-transformer/Dry/Transformer/Conditional)
15
- * [Recursion](https://www.rubydoc.info/gems/dry-transformer/Dry/Transformer/Recursion)
16
-
17
- You can import everything with:
18
-
19
- ```ruby
20
- module T
21
- extend Dry::Transformer::Registry
22
-
23
- import Dry::Transformer::Coercions
24
- import Dry::Transformer::ArrayTransformations
25
- import Dry::Transformer::HashTransformations
26
- import Dry::Transformer::ClassTransformations
27
- import Dry::Transformer::ProcTransformations
28
- import Dry::Transformer::Conditional
29
- import Dry::Transformer::Recursion
30
- end
31
-
32
- T[:to_string].(:abc) # => 'abc'
33
- ```
34
-
35
- Or import selectively with:
36
-
37
- ```ruby
38
- module T
39
- extend Dry::Transformer::Registry
40
-
41
- import :to_string, from: Dry::Transformer::Coercions, as: :stringify
42
- end
43
-
44
- T[:stringify].(:abc) # => 'abc'
45
- T[:to_string].(:abc)
46
- # => Dry::Transformer::FunctionNotFoundError: No registered function T[:to_string]
47
- ```
@@ -1,15 +0,0 @@
1
- ---
2
- title: Introduction
3
- description: Data transformation toolkit
4
- layout: gem-single
5
- type: gem
6
- name: dry-transformer
7
- sections:
8
- - transformation-objects
9
- - built-in-transformations
10
- - using-standalone-functions
11
- ---
12
-
13
- dry-transformer is a library that allows you to compose procs into a functional pipeline using left-to-right function composition.
14
-
15
- The approach came from Functional Programming, where simple functions are composed into more complex functions in order to transform some data. It works like `|>` in Elixir or `>>` in F#. dry-transformer provides a mechanism to define and compose transformations, along with a number of built-in transformations.
@@ -1,32 +0,0 @@
1
- ---
2
- title: Transformation objects
3
- name: dry-transformer
4
- layout: gem-single
5
- ---
6
-
7
- You can define transformation classes using the DSL which converts every method call to its corresponding transformation, and composes these transformations into a transformation pipeline. Here's a simple example where the default registry is used:
8
-
9
- ```ruby
10
- class MyMapper < Dry::Transformer[Dry::Transformer::Registry]
11
- define! do
12
- map_array do
13
- symbolize_keys
14
- rename_keys user_name: :name
15
- nest :address, [:city, :street, :zipcode]
16
- end
17
- end
18
- end
19
-
20
- mapper = MyMapper.new
21
-
22
- mapper.(
23
- [
24
- { 'user_name' => 'Jane',
25
- 'city' => 'NYC',
26
- 'street' => 'Street 1',
27
- 'zipcode' => '123'
28
- }
29
- ]
30
- )
31
- # => [{:name=>"Jane", :address=>{:city=>"NYC", :street=>"Street 1", :zipcode=>"123"}}]
32
- ```
@@ -1,82 +0,0 @@
1
- ---
2
- title: Using standalone functions
3
- name: dry-transformer
4
- layout: gem-single
5
- ---
6
-
7
- You can use `dry-transformer` and its function registry feature stand-alone, without the need to define transformation classes. To do so, simply define a module and extend it with the registry API:
8
-
9
- ``` ruby
10
- require 'json'
11
- require 'dry/transformer/all'
12
-
13
- # create your own local registry for transformation functions
14
- module Functions
15
- extend Dry::Transformer::Registry
16
- end
17
-
18
- # import necessary functions from other transprocs...
19
- module Functions
20
- # import all singleton methods from a module/class
21
- import Dry::Transformer::HashTransformations
22
- import Dry::Transformer::ArrayTransformations
23
- end
24
-
25
- # ...or from any external library
26
- require 'dry-inflector'
27
-
28
- Inflector = Dry::Inflector.new
29
-
30
- module Functions
31
- # import only necessary singleton methods from a module/class
32
- # and rename them locally
33
- import :camelize, from: Inflector, as: :camel_case
34
- end
35
-
36
- def t(*args)
37
- Functions[*args]
38
- end
39
-
40
- # use imported transformation
41
- transformation = t(:camel_case)
42
-
43
- transformation.call 'i_am_a_camel'
44
- # => "IAmACamel"
45
-
46
- transformation = t(:map_array, (
47
- t(:symbolize_keys).>> t(:rename_keys, user_name: :user)
48
- )).>> t(:wrap, :address, [:city, :street, :zipcode])
49
-
50
- transformation.call(
51
- [
52
- { 'user_name' => 'Jane',
53
- 'city' => 'NYC',
54
- 'street' => 'Street 1',
55
- 'zipcode' => '123' }
56
- ]
57
- )
58
- # => [{:user=>"Jane", :address=>{:city=>"NYC", :street=>"Street 1", :zipcode=>"123"}}]
59
-
60
- # define your own composable transformation easily
61
- transformation = t(-> v { JSON.dump(v) })
62
-
63
- transformation.call(name: 'Jane')
64
- # => "{\"name\":\"Jane\"}"
65
-
66
- # ...or add it to registered functions via singleton method of the registry
67
- module Functions
68
- # ...
69
-
70
- def self.load_json(v)
71
- JSON.load(v)
72
- end
73
- end
74
-
75
- # ...or add it to registered functions via .register method
76
- Functions.register(:load_json) { |v| JSON.load(v) }
77
-
78
- transformation = t(:load_json) >> t(:map_array, t(:symbolize_keys))
79
-
80
- transformation.call('[{"name":"Jane"}]')
81
- # => [{ :name => "Jane" }]
82
- ```
@@ -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'
data/spec/spec_helper.rb DELETED
@@ -1,31 +0,0 @@
1
- # frozen_string_literal: true
2
-
3
- if ENV['COVERAGE'] == 'true'
4
- require 'codacy-coverage'
5
- Codacy::Reporter.start
6
- end
7
-
8
- begin
9
- require 'byebug'
10
- rescue LoadError;end
11
-
12
- require 'dry/transformer/all'
13
-
14
- root = Pathname(__FILE__).dirname
15
- Dir[root.join('support/*.rb').to_s].each { |f| require f }
16
-
17
- # Namespace holding all objects created during specs
18
- module Test
19
- def self.remove_constants
20
- constants.each(&method(:remove_const))
21
- end
22
- end
23
-
24
- RSpec.configure do |config|
25
- config.after do
26
- Test.remove_constants
27
- end
28
-
29
- config.disable_monkey_patching!
30
- config.warnings = true
31
- end