Sha256: 5c08733917ee6e08440c0c40b067224599eb2e2d4f8bb187091d2e732441e513

Contents?: true

Size: 1.67 KB

Versions: 17

Compression:

Stored size: 1.67 KB

Contents

module Scenic
  module Adapters
    class Postgres
      # Decorates an ActiveRecord connection with methods that help determine
      # the connections capabilities.
      #
      # Every attempt is made to use the versions of these methods defined by
      # Rails where they are available and public before falling back to our own
      # implementations for older Rails versions.
      #
      # @api private
      class Connection < SimpleDelegator
        # True if the connection supports materialized views.
        #
        # Delegates to the method of the same name if it is already defined on
        # the connection. This is the case for Rails 4.2 or higher.
        #
        # @return [Boolean]
        def supports_materialized_views?
          if undecorated_connection.respond_to?(:supports_materialized_views?)
            super
          else
            postgresql_version >= 90300
          end
        end

        # True if the connection supports concurrent refreshes of materialized
        # views.
        #
        # @return [Boolean]
        def supports_concurrent_refreshes?
          postgresql_version >= 90400
        end

        # An integer representing the version of Postgres we're connected to.
        #
        # postgresql_version is public in Rails 5, but protected in earlier
        # versions.
        #
        # @return [Integer]
        def postgresql_version
          if undecorated_connection.respond_to?(:postgresql_version)
            super
          else
            undecorated_connection.send(:postgresql_version)
          end
        end

        private

        def undecorated_connection
          __getobj__
        end
      end
    end
  end
end

Version data entries

17 entries across 17 versions & 2 rubygems

Version Path
scenic-1.8.0 lib/scenic/adapters/postgres/connection.rb
scenic-1.7.0 lib/scenic/adapters/postgres/connection.rb
scenic-1.6.0 lib/scenic/adapters/postgres/connection.rb
scenic-1.5.5 lib/scenic/adapters/postgres/connection.rb
scenic-jets-1.5.5 lib/scenic/adapters/postgres/connection.rb
scenic-jets-1.5.4 lib/scenic/adapters/postgres/connection.rb
scenic-1.5.4 lib/scenic/adapters/postgres/connection.rb
scenic-1.5.3 lib/scenic/adapters/postgres/connection.rb
scenic-1.5.2 lib/scenic/adapters/postgres/connection.rb
scenic-1.5.1 lib/scenic/adapters/postgres/connection.rb
scenic-1.5.0 lib/scenic/adapters/postgres/connection.rb
scenic-1.4.1 lib/scenic/adapters/postgres/connection.rb
scenic-1.4.0 lib/scenic/adapters/postgres/connection.rb
scenic-1.3.0 lib/scenic/adapters/postgres/connection.rb
scenic-1.2.0 lib/scenic/adapters/postgres/connection.rb
scenic-1.1.1 lib/scenic/adapters/postgres/connection.rb
scenic-1.1.0 lib/scenic/adapters/postgres/connection.rb