Sha256: 6395cec5c1c33039c7829ac4cc1cf736703a86c5ab475cb0f1304a1ef7dca12c

Contents?: true

Size: 1.44 KB

Versions: 5

Compression:

Stored size: 1.44 KB

Contents

module ActiveReplicas
  class Railtie < Rails::Railtie
    cattr_reader :connection_handler

    cattr_accessor :replica_delegated_methods
    cattr_accessor :primary_delegated_methods

    @@replica_delegated_methods = [
      :active?, :clear_query_cache, :column_name_for_operation, :columns,
      :disable_query_cache!, :disconnect!, :enable_query_cache!,
      :query_cache_enabled, :quote_column_name, :quote_table_name,
      :raw_connection, :reconnect!, :sanitize_limit, :schema_cache, :select,
      :select_all, :select_one, :select_rows, :select_value, :select_values,
      :substitute_at, :to_sql, :verify!
    ]

    @@primary_delegated_methods = [
      :insert, :next_sequence_value, :prefetch_primary_key?,
      :transaction, :transaction_state, :update
    ]

    def self.hijack_active_record(proxy_configuration, overrides: [])
      ProxyingConnection.generate_replica_delegations
      ProxyingConnection.generate_primary_delegations

      @@connection_handler =
        ConnectionHandler.new proxy_configuration: proxy_configuration,
                              delegate: ActiveRecord::Base.connection_handler,
                              overrides: overrides

      ActiveRecord::Base.class_eval do
        def self.connection_handler
          ActiveReplicas::Railtie.connection_handler
        end
      end

      # Take over logging duties now that we're the main connection handler.
      LogSubscriber.hijack_active_record
    end
  end
end

Version data entries

5 entries across 5 versions & 1 rubygems

Version Path
active_replicas-0.1.4 lib/active_replicas/railtie.rb
active_replicas-0.1.3 lib/active_replicas/railtie.rb
active_replicas-0.1.2 lib/active_replicas/railtie.rb
active_replicas-0.1.1 lib/active_replicas/railtie.rb
active_replicas-0.1.0 lib/active_replicas/railtie.rb