Sha256: e7a7a8337dc45df61d684ccbf55036bfc75f206aa917725209ba905d12bd4854

Contents?: true

Size: 911 Bytes

Versions: 11

Compression:

Stored size: 911 Bytes

Contents

# frozen_string_literal: true

module Torque
  module PostgreSQL
    class TableName < Delegator
      def initialize(klass, table_name)
        @klass = klass
        @table_name = table_name
      end

      def schema
        return @schema if defined?(@schema)

        @schema = ([@klass] + @klass.module_parents[0..-2]).find do |klass|
          next unless klass.respond_to?(:schema) && !(value = klass.schema).nil?
          break value
        end
      end

      def to_s
        schema.nil? ? @table_name : "#{schema}.#{@table_name}"
      end

      alias __getobj__ to_s

      def ==(other)
        other.to_s =~ /("?#{schema | search_path_schemes.join('|')}"?\.)?"?#{@table_name}"?/
      end

      def __setobj__(value)
        @table_name = value
      end

      private

        def search_path_schemes
          klass.connection.schemas_search_path_sanitized
        end
    end
  end
end

Version data entries

11 entries across 11 versions & 1 rubygems

Version Path
torque-postgresql-3.4.1 lib/torque/postgresql/table_name.rb
torque-postgresql-2.4.5 lib/torque/postgresql/table_name.rb
torque-postgresql-3.4.0 lib/torque/postgresql/table_name.rb
torque-postgresql-3.3.3 lib/torque/postgresql/table_name.rb
torque-postgresql-2.4.4 lib/torque/postgresql/table_name.rb
torque-postgresql-3.3.2 lib/torque/postgresql/table_name.rb
torque-postgresql-2.4.3 lib/torque/postgresql/table_name.rb
torque-postgresql-3.3.1 lib/torque/postgresql/table_name.rb
torque-postgresql-3.3.0 lib/torque/postgresql/table_name.rb
torque-postgresql-3.2.2 lib/torque/postgresql/table_name.rb
torque-postgresql-2.4.2 lib/torque/postgresql/table_name.rb