Sha256: 3d97237901749c9a363ea64624dc6875332891947469a60e44581f3c625fdedf

Contents?: true

Size: 1.05 KB

Versions: 11

Compression:

Stored size: 1.05 KB

Contents

# frozen_string_literal: true

module FreshConnection
  module Extend
    module ArRelation
      def calculate(*args)
        manage_access { super }
      end

      def exists?(*args)
        manage_access { super }
      end

      def pluck(*args)
        manage_access { super }
      end

      def read_master
        spawn.read_master!
      end

      def read_master!
        self.read_master_value = true
        self
      end

      def read_master_value
        @values[:read_master]
      end

      def read_master_value=(value)
        raise ImmutableRelation if @loaded
        @values[:read_master] = value
      end

      def manage_access(replica_access: enable_replica_access, &block)
        FreshConnection::AccessControl.manage_access(
          model: @klass,
          replica_access: replica_access,
          &block
        )
      end

      private

      def exec_queries
        manage_access { super }
      end

      def enable_replica_access
        connection.open_transactions.zero? && !read_master_value
      end
    end
  end
end

Version data entries

11 entries across 11 versions & 1 rubygems

Version Path
fresh_connection-3.1.1 lib/fresh_connection/extend/ar_relation.rb
fresh_connection-3.1.1.rc1 lib/fresh_connection/extend/ar_relation.rb
fresh_connection-3.1.0 lib/fresh_connection/extend/ar_relation.rb
fresh_connection-3.0.3 lib/fresh_connection/extend/ar_relation.rb
fresh_connection-3.0.2 lib/fresh_connection/extend/ar_relation.rb
fresh_connection-3.0.2.rc1 lib/fresh_connection/extend/ar_relation.rb
fresh_connection-3.0.1 lib/fresh_connection/extend/ar_relation.rb
fresh_connection-3.0.1.rc2 lib/fresh_connection/extend/ar_relation.rb
fresh_connection-3.0.1.rc1 lib/fresh_connection/extend/ar_relation.rb
fresh_connection-3.0.0 lib/fresh_connection/extend/ar_relation.rb
fresh_connection-3.0.0.rc2 lib/fresh_connection/extend/ar_relation.rb