Sha256: 73ab8d4d3f8922bfb08266423b968678329e5b074c93388e2178d2a202631eb0

Contents?: true

Size: 1.21 KB

Versions: 17

Compression:

Stored size: 1.21 KB

Contents

module Gorynich
  module Head
    module ActiveRecord
      extend ActiveSupport::Concern

      included do
        module ::GlobalID::Locator
          class << self
            def original_locate(gid, options = {})
              if (gid = GlobalID.parse(gid)) && find_allowed?(gid.model_class, options[:only])
                locator_for(gid).locate gid
              end
            end

            def locate(gid, options = {})
              gid = GlobalID.parse(gid)
              return original_locate(gid, options) unless gid

              tenant = gid.params['tenant']
              if tenant && tenant != Gorynich::Current.tenant
                Gorynich.with(tenant) do
                  original_locate(gid, options)
                end
              else
                original_locate(gid, options)
              end
            end
          end
        end

        connects_to database: Gorynich.instance.connects_to_config

        def cache_key(*args)
          "#{Gorynich::Current.tenant}:#{super}"
        end

        def to_global_id(options = {})
          options[:tenant] ||= Gorynich::Current.tenant
          super
        end

        alias_method :to_gid, :to_global_id
      end
    end
  end
end

Version data entries

17 entries across 17 versions & 1 rubygems

Version Path
gorynich-1.3.4.273062 lib/gorynich/head/active_record.rb
gorynich-1.3.3.231946 lib/gorynich/head/active_record.rb
gorynich-1.3.2.231715 lib/gorynich/head/active_record.rb
gorynich-1.3.1.213701 lib/gorynich/head/active_record.rb
gorynich-1.3.0.213297 lib/gorynich/head/active_record.rb
gorynich-1.2.3.198656 lib/gorynich/head/active_record.rb
gorynich-1.2.2.198643 lib/gorynich/head/active_record.rb
gorynich-1.2.1.184916 lib/gorynich/head/active_record.rb
gorynich-1.2.0.180668 lib/gorynich/head/active_record.rb
gorynich-1.1.1.148381 lib/gorynich/head/active_record.rb
gorynich-1.1.0.142168 lib/gorynich/head/active_record.rb
gorynich-1.1.0.142154 lib/gorynich/head/active_record.rb
gorynich-1.1.0.142147 lib/gorynich/head/active_record.rb
gorynich-1.1.0.142142 lib/gorynich/head/active_record.rb
gorynich-1.1.0.142139 lib/gorynich/head/active_record.rb
gorynich-1.1.0.142136 lib/gorynich/head/active_record.rb
gorynich-1.1.0.142046 lib/gorynich/head/active_record.rb