Skip to content

Commit 1e288e3

Browse files
authored
Merge pull request #699 from rom-rb/deprecate-set_relation
Bring back Repository#set_relation but deprecate it
2 parents 05110e9 + 41e372a commit 1e288e3

File tree

10 files changed

+61
-8
lines changed

10 files changed

+61
-8
lines changed

CHANGELOG.md

+6
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,9 @@
1+
## 5.4.1 2025-01-09
2+
3+
### Fixed
4+
5+
- [rom-repository] `set_relation` is deprecated and will be removed in 6.0.0 (issue #698 fixed via #699) (@flash-gordon)
6+
17
## 5.4.0 2025-01-08
28

39
### Fixed

Gemfile.devtools

+1
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,7 @@ group :test do
88
gem "simplecov", require: false, platforms: :ruby
99
gem "simplecov-cobertura", require: false, platforms: :ruby
1010
gem "rexml", require: false
11+
gem "tempfile"
1112

1213
gem "warning"
1314
end

changeset/lib/rom/changeset/version.rb

+1-1
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,6 @@
22

33
module ROM
44
class Changeset
5-
VERSION = '5.4.0'
5+
VERSION = '5.4.1'
66
end
77
end

core/lib/rom/core/version.rb

+1-1
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,6 @@
22

33
module ROM
44
module Core
5-
VERSION = '5.4.0'
5+
VERSION = '5.4.1'
66
end
77
end

lib/rom/version.rb

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
# frozen_string_literal: true
22

33
module ROM
4-
VERSION = '5.4.0'
4+
VERSION = '5.4.1'
55
end

repository/lib/rom/repository/relation_reader.rb

+11-3
Original file line numberDiff line numberDiff line change
@@ -5,9 +5,11 @@ class Repository
55
# @api private
66
class RelationReader < ::Module
77
module InstanceMethods
8+
extend ::Dry::Core::Deprecations[:'rom-repository']
9+
810
private
911

10-
# @api private
12+
# @api public
1113
def prepare_relation(name, **)
1214
container
1315
.relations[name]
@@ -17,15 +19,21 @@ def prepare_relation(name, **)
1719
)
1820
end
1921

22+
# @api private
23+
def set_relation(name) # rubocop:disable Naming/AccessorMethodName
24+
prepare_relation(name)
25+
end
26+
deprecate :set_relation, :prepare_relation
27+
2028
# @api private
2129
def relation_reader(cache, ...)
2230
cache_key = relation_cache_key(...)
2331
cache.fetch_or_store(*cache_key) { prepare_relation(...) }
2432
end
2533

2634
# @api private
27-
def relation_cache_key(name, **)
28-
[name, auto_struct, struct_namespace]
35+
def relation_cache_key(name, **kwargs)
36+
[name, auto_struct, struct_namespace, kwargs]
2937
end
3038
end
3139

repository/lib/rom/repository/version.rb

+1-1
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,6 @@
22

33
module ROM
44
class Repository
5-
VERSION = '5.4.0'
5+
VERSION = '5.4.1'
66
end
77
end

repository/spec/integration/repository_spec.rb

+37
Original file line numberDiff line numberDiff line change
@@ -423,4 +423,41 @@ class Post < OpenStruct; end
423423

424424
expect(post).to be(post_from_user)
425425
end
426+
427+
context 'using #prepare_relation' do
428+
let(:repo_class) do
429+
Class.new(ROM::Repository[:users]) do
430+
def prepare_relation(name, custom: 'default')
431+
super.select_append { `'#{custom}'`.as(:extra_column) }
432+
end
433+
end
434+
end
435+
436+
it 'is uses modified relation' do
437+
expect(repo.users.to_a.map(&:extra_column)).to eql(%w[default default])
438+
expect(repo.users(custom: 'custom').to_a.map(&:extra_column)).to eql(%w[custom custom])
439+
end
440+
end
441+
442+
context 'using #set_relation' do
443+
let(:log_file) do
444+
Tempfile.new('dry_deprecations')
445+
end
446+
447+
before do
448+
Dry::Core::Deprecations.set_logger!(log_file)
449+
end
450+
451+
let(:repo_class) do
452+
Class.new(ROM::Repository[:users]) do
453+
def custom_users
454+
set_relation(:users).select_append { `'modified'`.as(:modified) }
455+
end
456+
end
457+
end
458+
459+
it "constructs a relation but it's deprecated" do
460+
expect(repo.custom_users.to_a.map(&:modified)).to eql(%w[modified modified])
461+
end
462+
end
426463
end

repository/spec/spec_helper.rb

+1
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
# frozen_string_literal: true
22

33
require 'pathname'
4+
require 'tempfile'
45

56
SPEC_ROOT = Pathname(__FILE__).dirname
67

spec/spec_helper.rb

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
# frozen_string_literal: true
22

3-
require 'pathname'
3+
require 'tempfile'
44

55
SPEC_ROOT = root = Pathname(__FILE__).dirname
66

0 commit comments

Comments
 (0)