Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Bring back Repository#set_relation but deprecate it #699

Merged
merged 3 commits into from
Jan 9, 2025
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
6 changes: 6 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,3 +1,9 @@
## 5.4.1 2025-01-09

### Fixed

- [rom-repository] `set_relation` is deprecated and will be removed in 6.0.0 (issue #698 fixed via #699) (@flash-gordon)

## 5.4.0 2025-01-08

### Fixed
Expand Down
1 change: 1 addition & 0 deletions Gemfile.devtools
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@ group :test do
gem "simplecov", require: false, platforms: :ruby
gem "simplecov-cobertura", require: false, platforms: :ruby
gem "rexml", require: false
gem "tempfile"

gem "warning"
end
Expand Down
2 changes: 1 addition & 1 deletion changeset/lib/rom/changeset/version.rb
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,6 @@

module ROM
class Changeset
VERSION = '5.4.0'
VERSION = '5.4.1'
end
end
2 changes: 1 addition & 1 deletion core/lib/rom/core/version.rb
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,6 @@

module ROM
module Core
VERSION = '5.4.0'
VERSION = '5.4.1'
end
end
2 changes: 1 addition & 1 deletion lib/rom/version.rb
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
# frozen_string_literal: true

module ROM
VERSION = '5.4.0'
VERSION = '5.4.1'
end
14 changes: 11 additions & 3 deletions repository/lib/rom/repository/relation_reader.rb
Original file line number Diff line number Diff line change
Expand Up @@ -5,9 +5,11 @@ class Repository
# @api private
class RelationReader < ::Module
module InstanceMethods
extend ::Dry::Core::Deprecations[:'rom-repository']

private

# @api private
# @api public
def prepare_relation(name, **)
container
.relations[name]
Expand All @@ -17,15 +19,21 @@ def prepare_relation(name, **)
)
end

# @api private
def set_relation(name) # rubocop:disable Naming/AccessorMethodName
prepare_relation(name)
end
deprecate :set_relation, :prepare_relation

# @api private
def relation_reader(cache, ...)
cache_key = relation_cache_key(...)
cache.fetch_or_store(*cache_key) { prepare_relation(...) }
end

# @api private
def relation_cache_key(name, **)
[name, auto_struct, struct_namespace]
def relation_cache_key(name, **kwargs)
[name, auto_struct, struct_namespace, kwargs]
end
end

Expand Down
2 changes: 1 addition & 1 deletion repository/lib/rom/repository/version.rb
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,6 @@

module ROM
class Repository
VERSION = '5.4.0'
VERSION = '5.4.1'
end
end
37 changes: 37 additions & 0 deletions repository/spec/integration/repository_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -423,4 +423,41 @@ class Post < OpenStruct; end

expect(post).to be(post_from_user)
end

context 'using #prepare_relation' do
let(:repo_class) do
Class.new(ROM::Repository[:users]) do
def prepare_relation(name, custom: 'default')
super.select_append { `'#{custom}'`.as(:extra_column) }
end
end
end

it 'is uses modified relation' do
expect(repo.users.to_a.map(&:extra_column)).to eql(%w[default default])
expect(repo.users(custom: 'custom').to_a.map(&:extra_column)).to eql(%w[custom custom])
end
end

context 'using #set_relation' do
let(:log_file) do
Tempfile.new('dry_deprecations')
end

before do
Dry::Core::Deprecations.set_logger!(log_file)
end

let(:repo_class) do
Class.new(ROM::Repository[:users]) do
def custom_users
set_relation(:users).select_append { `'modified'`.as(:modified) }
end
end
end

it "constructs a relation but it's deprecated" do
expect(repo.custom_users.to_a.map(&:modified)).to eql(%w[modified modified])
end
end
end
1 change: 1 addition & 0 deletions repository/spec/spec_helper.rb
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
# frozen_string_literal: true

require 'pathname'
require 'tempfile'

SPEC_ROOT = Pathname(__FILE__).dirname

Expand Down
2 changes: 1 addition & 1 deletion spec/spec_helper.rb
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
# frozen_string_literal: true

require 'pathname'
require 'tempfile'

SPEC_ROOT = root = Pathname(__FILE__).dirname

Expand Down
Loading