Class: Posgra::Client
- Inherits:
-
Object
- Object
- Posgra::Client
- Defined in:
- lib/posgra/client.rb
Constant Summary collapse
- DEFAULT_EXCLUDE_SCHEMA =
/\A(?:pg_.*|information_schema)\z/
- DEFAULT_EXCLUDE_ROLE =
/\A\z/
Instance Method Summary collapse
- #apply_grants(file, options = {}) ⇒ Object
- #apply_roles(file, options = {}) ⇒ Object
- #close ⇒ Object
- #export_grants(options = {}) ⇒ Object
- #export_roles(options = {}) ⇒ Object
-
#initialize(options = {}) ⇒ Client
constructor
A new instance of Client.
Constructor Details
#initialize(options = {}) ⇒ Client
Returns a new instance of Client.
5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 |
# File 'lib/posgra/client.rb', line 5 def initialize( = {}) if [:exclude_schema] [:exclude_schema] = Regexp.union( [:exclude_schema], DEFAULT_EXCLUDE_SCHEMA ) else [:exclude_schema] = DEFAULT_EXCLUDE_SCHEMA end if [:exclude_role] [:exclude_role] = Regexp.union( [:exclude_role], DEFAULT_EXCLUDE_SCHEMA ) else [:exclude_role] = DEFAULT_EXCLUDE_ROLE end @options = @client = connect() @driver = Posgra::Driver.new(@client, ) end |
Instance Method Details
#apply_grants(file, options = {}) ⇒ Object
59 60 61 62 |
# File 'lib/posgra/client.rb', line 59 def apply_grants(file, = {}) = @options.merge() walk_for_grants(file, ) end |
#apply_roles(file, options = {}) ⇒ Object
54 55 56 57 |
# File 'lib/posgra/client.rb', line 54 def apply_roles(file, = {}) = @options.merge() walk_for_roles(file, ) end |
#close ⇒ Object
64 65 66 |
# File 'lib/posgra/client.rb', line 64 def close @client.close end |
#export_grants(options = {}) ⇒ Object
35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 |
# File 'lib/posgra/client.rb', line 35 def export_grants( = {}) = @options.merge() exported = Posgra::Exporter.export_grants(@driver, ) if [:split] dsl_h = Hash.new {|hash, key| hash[key] = {} } exported.each do |role, schemas| dsl = Posgra::DSL.convert_grants({role => schemas}, ) dsl_h[role] = dsl end dsl_h else Posgra::DSL.convert_grants(exported, ) end end |
#export_roles(options = {}) ⇒ Object
29 30 31 32 33 |
# File 'lib/posgra/client.rb', line 29 def export_roles( = {}) = @options.merge() exported = Posgra::Exporter.export_roles(@driver, ) Posgra::DSL.convert_roles(exported, ) end |