Skip to content

Commit b3ec8b9

Browse files
committed
Move ActiveRecord::FixtureSet.signed_global_id to this gem
Active Record doesn't depend on GlobalID so this code should not be defined there. Instead, we should use the `active_record_fixture_set` `on_load` hook to define the GlobalID specific method using the GlobalID railtie.
1 parent e9d6ed9 commit b3ec8b9

File tree

2 files changed

+18
-0
lines changed

2 files changed

+18
-0
lines changed

lib/global_id/fixture_set.rb

+13
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
1+
# frozen_string_literal: true
2+
3+
class GlobalID
4+
module FixtureSet
5+
def signed_global_id(fixture_set_name, label, column_type: :integer, **options)
6+
identifier = identify(label, column_type)
7+
model_name = default_fixture_model_name(fixture_set_name)
8+
uri = URI::GID.build([GlobalID.app, model_name, identifier, {}])
9+
10+
SignedGlobalID.new(uri, **options)
11+
end
12+
end
13+
end

lib/global_id/railtie.rb

+5
Original file line numberDiff line numberDiff line change
@@ -37,6 +37,11 @@ class Railtie < Rails::Railtie # :nodoc:
3737
require 'global_id/identification'
3838
send :include, GlobalID::Identification
3939
end
40+
41+
ActiveSupport.on_load(:active_record_fixture_set) do
42+
require 'global_id/fixture_set'
43+
send :extend, GlobalID::FixtureSet
44+
end
4045
end
4146
end
4247
end

0 commit comments

Comments
 (0)