module PgCtrl module Utils; end class RDBMSObject include Utils attr_reader :rdbms attr_reader :oid attr_reader :name attr_reader :owner def initialize(rdbms, oid, name, owner, opts = {}) @rdbms, @oid, @name, @owner = rdbms, oid, name, owner end def to_s() @name end end class User < RDBMSObject def superuser?() @is_superuser end def can_create_db?() @can_create_db end def can_create_role?() @can_create_role end def can_login?() @can_login end def initialize(rdbms, oid, name, opts = {}) super(rdbms, oid, name, self) set_opts(opts, :is_superuser, :can_create_db, :can_create_role, :can_login) end end class Database < RDBMSObject attr_reader :encoding attr_reader :lc_collate attr_reader :lc_ctype def template?() @is_template end def can_connect?() @can_connect end attr_reader :acl def initialize(rdbms, oid, name, owner, opts = {}) super(rdbms, oid, name, owner) set_opts(opts, :encoding, :lc_collate, :lc_ctype, :is_template, :can_connect, :acl) end end class RDBMS include Utils attr_reader :id attr_reader :connection def ip?() !host.nil? end def host() @connection.host end def port() @connection.port.to_i end # Users and databases indexed by name attr_reader :users attr_reader :databases # Current user and database attr_reader :user attr_reader :database # Arguments # initialize(PGconn args) # initialize(PGconn object) # def initialize(*args) if args.size == 1 && PGconn === args[0] @connection = args[0] else @connection = PGconn.new(args[0]) end @id = (!host || host == "127.0.0.1" ? "localhost" : host) load_data end def to_s() @id end end end