Sha256: 649635d90df84a4a23c992fb9f5e118d2f560a99c00b9b0fed99e324c5f56b0e

Contents?: true

Size: 853 Bytes

Versions: 8

Compression:

Stored size: 853 Bytes

Contents

module Alf
  class Adapter
    class Connection
      class SchemaCached < Connection

        def self.empty_cache
          Hash.new{|h,k| h[k] = {}}
        end

        def initialize(connection, cache = nil)
          @connection = connection
          @cache      = cache || SchemaCached.empty_cache
        end

        Connection.instance_methods(false).each do |meth|
          define_method(meth) do |*args, &bl|
            @connection.send(meth, *args, &bl)
          end
        end

        [ :knows?, :heading, :keys ].each do |meth|
          define_method(meth) do |name|
            @cache[meth][name] ||= @connection.send(meth, name)
          end
        end

        def to_s
          "#{@connection.to_s} (with cache)"
        end

      end # class SchemaCached
    end # class Connection
  end # class Database
end # module Alf

Version data entries

8 entries across 8 versions & 1 rubygems

Version Path
alf-core-0.16.3 lib/alf/adapter/connection/schema_cached.rb
alf-core-0.16.2 lib/alf/adapter/connection/schema_cached.rb
alf-core-0.16.1 lib/alf/adapter/connection/schema_cached.rb
alf-core-0.16.0 lib/alf/adapter/connection/schema_cached.rb
alf-core-0.15.0 lib/alf/adapter/connection/schema_cached.rb
alf-core-0.14.0 lib/alf-adapter/alf/adapter/connection/schema_cached.rb
alf-core-0.13.1 lib/alf-adapter/alf/adapter/connection/schema_cached.rb
alf-core-0.13.0 lib/alf-adapter/alf/adapter/connection/schema_cached.rb