Sha256: d4e6bc6eb23b3f7560a7877f27b66354d767ba448a4cf45e28cf80096519b2f2

Contents?: true

Size: 881 Bytes

Versions: 4

Compression:

Stored size: 881 Bytes

Contents

module PgHero
  module Methods
    module Databases
      def databases
        @databases ||= begin
          Hash[
            config["databases"].map do |id, c|
              [id, PgHero::Database.new(id, c)]
            end
          ]
        end
      end

      def primary_database
        databases.keys.first
      end

      def current_database
        Thread.current[:pghero_current_database] ||= primary_database
      end

      def current_database=(database)
        raise "Database not found" unless databases[database]
        Thread.current[:pghero_current_database] = database.to_s
        database
      end

      def with(database)
        previous_database = current_database
        begin
          self.current_database = database
          yield
        ensure
          self.current_database = previous_database
        end
      end
    end
  end
end

Version data entries

4 entries across 4 versions & 1 rubygems

Version Path
pghero-1.3.1 lib/pghero/methods/databases.rb
pghero-1.3.0 lib/pghero/methods/databases.rb
pghero-1.2.4 lib/pghero/methods/databases.rb
pghero-1.2.3 lib/pghero/methods/databases.rb