module PgRls
PostgreSQL Row Level Security
Constants
- DELEGATORS_METHODS
- READER_METHODS
- SECURE_USERNAME
- VERSION
- WRITER_METHODS
Public Class Methods
admin_execute(query = nil) { || ... }
click to toggle source
# File lib/pg_rls.rb, line 56 def admin_execute(query = nil) self.establish_default_connection = true establish_new_connection return yield if block_given? execute(query) ensure self.establish_default_connection = false establish_new_connection end
all_tenants() { |tenant| ... }
click to toggle source
# File lib/pg_rls.rb, line 80 def all_tenants main_model.all.each do |tenant| allowed_search_fields = search_methods.map(&:to_s).intersection(main_model.column_names) Tenant.switch tenant.send(allowed_search_fields.first) yield(tenant) if block_given? end end
connection_class()
click to toggle source
# File lib/pg_rls.rb, line 46 def connection_class @connection_class ||= ActiveRecord::Base end
current_connection_username()
click to toggle source
# File lib/pg_rls.rb, line 89 def current_connection_username connection_class.connection_db_config.configuration_hash[:username] end
database_configuration()
click to toggle source
# File lib/pg_rls.rb, line 97 def database_configuration database_connection_file[Rails.env].tap do |config| config['username'] = PgRls::SECURE_USERNAME unless default_connection? end end
database_connection_file()
click to toggle source
# File lib/pg_rls.rb, line 40 def database_connection_file file = File.read(Rails.root.join('config', 'database.yml')) YAML.safe_load(ERB.new(file).result, aliases: true) end
default_connection?()
click to toggle source
# File lib/pg_rls.rb, line 72 def default_connection? @default_connection end
establish_default_connection=(value)
click to toggle source
# File lib/pg_rls.rb, line 67 def establish_default_connection=(value) ENV['AS_DB_ADMIN'] = value.to_s @default_connection = value end
establish_new_connection()
click to toggle source
# File lib/pg_rls.rb, line 50 def establish_new_connection connection_class.establish_connection( **database_configuration ) end
execute(query)
click to toggle source
# File lib/pg_rls.rb, line 93 def execute(query) ActiveRecord::Migration.execute(query) end
main_model()
click to toggle source
# File lib/pg_rls.rb, line 76 def main_model class_name.to_s.camelize.constantize end
setup() { |self| ... }
click to toggle source
Your code goes hereā¦
# File lib/pg_rls.rb, line 36 def setup yield self end