Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
15 changes: 7 additions & 8 deletions .github/workflows/ci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -26,19 +26,18 @@ jobs:
fail-fast: false
matrix:
ruby:
- "3.3"
- "3.2"
- "3.1"
- "3.0"
- "3.4"
- "3.3"
- "3.2"
include:
- ruby: "3.2"
- ruby: "3.4"
coverage: "true"
env:
COVERAGE: ${{matrix.coverage}}
COVERAGE_TOKEN: ${{secrets.CODACY_PROJECT_TOKEN}}
steps:
- name: Checkout
uses: actions/checkout@v3
uses: actions/checkout@v4
- name: Install package dependencies
run: "[ -e $APT_DEPS ] || sudo apt-get install -y --no-install-recommends $APT_DEPS"
- name: Set up Ruby
Expand All @@ -56,13 +55,13 @@ jobs:
GITHUB_LOGIN: dry-bot
GITHUB_TOKEN: ${{secrets.GH_PAT}}
steps:
- uses: actions/checkout@v3
- uses: actions/checkout@v4
- name: Install package dependencies
run: "[ -e $APT_DEPS ] || sudo apt-get install -y --no-install-recommends $APT_DEPS"
- name: Set up Ruby
uses: ruby/setup-ruby@v1
with:
ruby-version: 3.0
ruby-version: 3.4
- name: Install dependencies
run: gem install ossy --no-document
- name: Trigger release workflow
Expand Down
1 change: 1 addition & 0 deletions Gemfile
Original file line number Diff line number Diff line change
Expand Up @@ -11,5 +11,6 @@ group :test do
end

group :tools do
gem "base64"
gem "benchmark-ips"
end
2 changes: 1 addition & 1 deletion dry-transformer.gemspec
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,6 @@ Gem::Specification.new do |spec|
spec.required_ruby_version = ">= 3.0.0"

# to update dependencies edit project.yml
spec.add_runtime_dependency "bigdecimal"
spec.add_runtime_dependency "zeitwerk", "~> 2.6"

end
3 changes: 2 additions & 1 deletion lib/dry/transformer/array_transformations.rb
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,8 @@ module Transformer
# { 'city' => 'NYC', 'zipcode' => '312' }
# ]
# )
# # => [{:address=>{:city=>"Boston", :zipcode=>"123"}}, {:address=>{:city=>"NYC", :zipcode=>"312"}}]
# # => [{:address=>{:city=>"Boston", :zipcode=>"123"}},
# # {:address=>{:city=>"NYC", :zipcode=>"312"}}]
#
# @api public
module ArrayTransformations
Expand Down
3 changes: 2 additions & 1 deletion lib/dry/transformer/conditional.rb
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,8 @@ def self.not(value, fn)
!fn[value]
end

# Apply the transformation function to subject if the predicate returns true, or return un-modified
# Apply the transformation function to subject if the predicate returns true,
# or return un-modified
#
# @example
# [2, 'Jane'].map do |subject|
Expand Down
8 changes: 5 additions & 3 deletions lib/dry/transformer/error.rb
Original file line number Diff line number Diff line change
Expand Up @@ -7,9 +7,11 @@ module Transformer

class FunctionNotFoundError < Error
def initialize(function, source = nil)
return super "No registered function #{source}[:#{function}]" if source

super "No globally registered function for #{function}"
if source
super "No registered function #{source}[:#{function}]"
else
super "No globally registered function for #{function}"
end
end
end
end
Expand Down
10 changes: 9 additions & 1 deletion lib/dry/transformer/hash_transformations.rb
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@ module Transformer
# # => {:address => {:street => "Street 1", :zipcode => "123"}}
#
# @api public
# rubocop:disable Metrics/ModuleLength
module HashTransformations
extend Registry

Expand Down Expand Up @@ -260,7 +261,9 @@ def self.nest(hash, root, keys)
# Collapse a nested hash from a specified key
#
# @example
# Dry::Transformer(:unwrap, :address, [:street, :zipcode])[address: { street: 'Street', zipcode: '123' }]
# Dry::Transformer(
# :unwrap, :address, [:street, :zipcode]
# )[address: { street: 'Street', zipcode: '123' }]
# # => {street: "Street", zipcode: "123"}
#
# @param [Hash] source_hash
Expand All @@ -273,6 +276,7 @@ def self.nest(hash, root, keys)
# @return [Hash]
#
# @api public
# rubocop:disable Metrics/AbcSize, Metrics/PerceivedComplexity
def self.unwrap(source_hash, root, selected = nil, prefix: false)
return source_hash unless source_hash[root]

Expand All @@ -292,6 +296,7 @@ def self.unwrap(source_hash, root, selected = nil, prefix: false)
hash.delete(root) if nested_hash.empty? && !nested_contains_root_key
end
end
# rubocop:enable Metrics/AbcSize, Metrics/PerceivedComplexity

# Folds array of tuples to array of values from a specified key
#
Expand Down Expand Up @@ -377,6 +382,7 @@ def self.split(hash, key, keys)
# @param [Array] filters A list of attribute names that should be evaluated
#
# @api public
# rubocop:disable Metrics/PerceivedComplexity
def self.eval_values(hash, args, filters = [])
hash.each_with_object({}) do |(key, value), output|
output[key] =
Expand All @@ -398,6 +404,7 @@ def self.eval_values(hash, args, filters = [])
end
end
end
# rubocop:enable Metrics/PerceivedComplexity

# Merge a hash recursively
#
Expand Down Expand Up @@ -427,4 +434,5 @@ def self.deep_merge(hash, other)
end
end
end
# rubocop:enable Metrics/ModuleLength
end
4 changes: 3 additions & 1 deletion lib/dry/transformer/recursion.rb
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,9 @@ module Recursion
# Recursively apply the provided transformation function to an enumerable
#
# @example
# Dry::Transformer(:recursion, Dry::Transformer(:is, ::Hash, Dry::Transformer(:symbolize_keys)))[
# Dry::Transformer(
# :recursion, Dry::Transformer(:is, ::Hash, Dry::Transformer(:symbolize_keys))
# )[
# {
# 'id' => 1,
# 'name' => 'Jane',
Expand Down
2 changes: 1 addition & 1 deletion project.yml
Original file line number Diff line number Diff line change
Expand Up @@ -5,5 +5,5 @@ gemspec:
email: ["piotr.solnica@gmail.com"]
summary: "Data transformation toolkit"
runtime_dependencies:
- ["bigdecimal"]
- ["zeitwerk", "~> 2.6"]

12 changes: 6 additions & 6 deletions spec/unit/store_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@
it "does not freeze the source hash" do
expect { store }.not_to change { methods.frozen? }
end
end # describe .new
end

describe "#methods" do
it "returns the hash from the initializer" do
Expand All @@ -26,7 +26,7 @@
it "is immutable" do
expect(store.methods).to be_frozen
end
end # describe #methods
end

describe "#fetch" do
it "returns a registered proc" do
Expand All @@ -40,7 +40,7 @@
it "raises KeyError if requested proc is unknown" do
expect { store.fetch(:bar) }.to raise_error KeyError
end
end # describe #fetch
end

describe "#contain?" do
it "returns true for registered proc" do
Expand All @@ -50,7 +50,7 @@
it "returns false if requested proc is unknown" do
expect(store.contain?(:bar)).to be false
end
end # describe #fetch
end

describe "#register" do
subject { new_store }
Expand Down Expand Up @@ -194,5 +194,5 @@ def self.qux
after do
%w[Bar Baz Qux].each { |name| Object.send :remove_const, name }
end
end # describe #import
end # describe Dry::Transformer::Store
end
end
1 change: 1 addition & 0 deletions spec/unit/transformer/class_interface_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,7 @@
end

def initialize(good)
super()
@good = good
end

Expand Down