From b3ec8b9314555dede5b865ea7ad30c421bddbaea Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Rafael=20Mendon=C3=A7a=20Fran=C3=A7a?= Date: Wed, 24 Nov 2021 22:13:56 +0000 Subject: [PATCH] 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. --- lib/global_id/fixture_set.rb | 13 +++++++++++++ lib/global_id/railtie.rb | 5 +++++ 2 files changed, 18 insertions(+) create mode 100644 lib/global_id/fixture_set.rb diff --git a/lib/global_id/fixture_set.rb b/lib/global_id/fixture_set.rb new file mode 100644 index 0000000..44f01af --- /dev/null +++ b/lib/global_id/fixture_set.rb @@ -0,0 +1,13 @@ +# frozen_string_literal: true + +class GlobalID + module FixtureSet + def signed_global_id(fixture_set_name, label, column_type: :integer, **options) + identifier = identify(label, column_type) + model_name = default_fixture_model_name(fixture_set_name) + uri = URI::GID.build([GlobalID.app, model_name, identifier, {}]) + + SignedGlobalID.new(uri, **options) + end + end +end diff --git a/lib/global_id/railtie.rb b/lib/global_id/railtie.rb index 8db99a0..1860950 100644 --- a/lib/global_id/railtie.rb +++ b/lib/global_id/railtie.rb @@ -37,6 +37,11 @@ class Railtie < Rails::Railtie # :nodoc: require 'global_id/identification' send :include, GlobalID::Identification end + + ActiveSupport.on_load(:active_record_fixture_set) do + require 'global_id/fixture_set' + send :extend, GlobalID::FixtureSet + end end end end