lib/posgra/driver.rb in posgra-0.1.2 vs lib/posgra/driver.rb in posgra-0.1.3
- old
+ new
@@ -227,13 +227,19 @@
WHERE
pg_namespace.nspname = #{@client.escape_literal(schema)}
AND pg_class.relkind NOT IN ('i')
SQL
- rs.map do |row|
- row.fetch('relname')
+ objects = []
+
+ rs.each do |row|
+ relname = row.fetch('relname')
+ next unless matched?(relname, @options[:include_object], @options[:exclude_object])
+ objects << relname
end
+
+ objects
end
def describe_users
rs = @client.exec('SELECT * FROM pg_user')
@@ -291,10 +297,11 @@
relname = row.fetch('relname')
nspname = row.fetch('nspname')
relacl = row.fetch('relacl')
usename = row.fetch('usename')
+ next unless matched?(relname, @options[:include_object], @options[:exclude_object])
next unless matched?(nspname, @options[:include_schema], @options[:exclude_schema])
parse_aclitems(relacl, usename).each do |aclitem|
role = aclitem.fetch('grantee')
privs = aclitem.fetch('privileges')
@@ -306,23 +313,10 @@
end
grants_by_role
end
- def describe_schemas
- rs = @client.exec <<-SQL
- SELECT
- nspname
- FROM
- pg_namespace
- SQL
-
- rs.map do |row|
- row.fetch('nspname')
- end
- end
-
private
def parse_aclitems(aclitems, owner)
aclitems ||= DEFAULT_ACL % [owner, owner]
aclitems = aclitems[1..-2].split(',')
@@ -339,10 +333,10 @@
end
end
def expand_privileges(privileges)
options_by_privilege = {}
-p
+
privileges.scan(/([a-z])(\*)?/i).each do |privilege_type_char,is_grantable|
privilege_type = PRIVILEGE_TYPES[privilege_type_char]
unless privilege_type
log(:warn, "Unknown privilege type: #{privilege_type_char}", :color => :yellow)