Skip to content

Commit 03b4abd

Browse files
♻️ Eliminate unnecessary hash state
Because of Identification.global_id_column, we can keep this internal API much cleaner and avoid mucking with hash state to pass around this column
1 parent cff0ef8 commit 03b4abd

File tree

3 files changed

+2
-8
lines changed

3 files changed

+2
-8
lines changed

lib/global_id/global_id.rb

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,6 @@ class << self
1111
def create(model, options = {})
1212
if app = options.fetch(:app) { GlobalID.app }
1313
params = options.except(:app, :verifier, :for)
14-
params[:global_id_column] ||= model.global_id_column
1514
new URI::GID.create(app, model, params), options
1615
else
1716
raise ArgumentError, 'An app is required to create a GlobalID. ' \

lib/global_id/uri/gid.rb

Lines changed: 1 addition & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -72,12 +72,7 @@ def parse(uri)
7272
#
7373
# URI::GID.create('bcx', Person.find(5), database: 'superhumans')
7474
def create(app, model, params = nil)
75-
global_id_column = params&.delete(:global_id_column)
76-
model_id_method = if model.id.is_a?(Array)
77-
:id
78-
else
79-
global_id_column
80-
end || :id
75+
model_id_method = model.id.is_a?(Array) ? :id : model.global_id_column
8176

8277
build app: app, model_name: model.class.name, model_id: model.send(model_id_method), params: params
8378
end

test/cases/uri_gid_test.rb

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -46,7 +46,7 @@ class URI::GIDTest < ActiveSupport::TestCase
4646

4747
test 'create from a configurable key model' do
4848
model = ConfigurableKeyModel.new(id: 'id-value', external_id: 'external-id-123')
49-
assert_equal @ckm_gid_string, URI::GID.create('bcx', model, global_id_column: :external_id).to_s
49+
assert_equal @ckm_gid_string, URI::GID.create('bcx', model).to_s
5050
end
5151

5252
test 'build' do

0 commit comments

Comments
 (0)