Skip to content

Commit

Permalink
Move ActiveRecord::FixtureSet.signed_global_id to this gem
Browse files Browse the repository at this point in the history
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.
  • Loading branch information
rafaelfranca committed Nov 24, 2021
1 parent e9d6ed9 commit b3ec8b9
Show file tree
Hide file tree
Showing 2 changed files with 18 additions and 0 deletions.
13 changes: 13 additions & 0 deletions lib/global_id/fixture_set.rb
Original file line number Diff line number Diff line change
@@ -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
5 changes: 5 additions & 0 deletions lib/global_id/railtie.rb
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down

0 comments on commit b3ec8b9

Please sign in to comment.