Class: Posgra::Client
- Inherits:
-
Object
- Object
- Posgra::Client
- Includes:
- Utils::Helper
- Defined in:
- lib/posgra/client.rb
Constant Summary collapse
- DEFAULT_EXCLUDE_SCHEMA =
/\A(?:pg_.*|information_schema)\z/
- DEFAULT_EXCLUDE_ROLE =
/\A\z/
- DEFAULT_EXCLUDE_DATABASE =
/\A(?:template\d+|postgres)\z/
Instance Method Summary collapse
- #apply_databases(file, options = {}) ⇒ Object
- #apply_grants(file, options = {}) ⇒ Object
- #apply_roles(file, options = {}) ⇒ Object
- #close ⇒ Object
- #export_databases(options = {}) ⇒ Object
- #export_grants(options = {}) ⇒ Object
- #export_roles(options = {}) ⇒ Object
-
#initialize(options = {}) ⇒ Client
constructor
A new instance of Client.
Methods included from Utils::Helper
Constructor Details
#initialize(options = {}) ⇒ Client
Returns a new instance of Client.
8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 |
# File 'lib/posgra/client.rb', line 8 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_ROLE ) else [:exclude_role] = DEFAULT_EXCLUDE_ROLE end if [:exclude_database] [:exclude_database] = Regexp.union( [:exclude_database], DEFAULT_EXCLUDE_DATABASE ) else [:exclude_database] = DEFAULT_EXCLUDE_DATABASE end @options = @client = connect() @driver = Posgra::Driver.new(@client, ) end |
Instance Method Details
#apply_databases(file, options = {}) ⇒ Object
93 94 95 96 |
# File 'lib/posgra/client.rb', line 93 def apply_databases(file, = {}) = @options.merge() walk_for_database_grants(file, ) end |
#apply_grants(file, options = {}) ⇒ Object
88 89 90 91 |
# File 'lib/posgra/client.rb', line 88 def apply_grants(file, = {}) = @options.merge() walk_for_grants(file, ) end |
#apply_roles(file, options = {}) ⇒ Object
83 84 85 86 |
# File 'lib/posgra/client.rb', line 83 def apply_roles(file, = {}) = @options.merge() walk_for_roles(file, ) end |
#close ⇒ Object
98 99 100 |
# File 'lib/posgra/client.rb', line 98 def close @client.close end |
#export_databases(options = {}) ⇒ Object
65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 |
# File 'lib/posgra/client.rb', line 65 def export_databases( = {}) = @options.merge() exported = Posgra::Exporter.export_databases(@driver, ) if [:split] dsl_h = Hash.new {|hash, key| hash[key] = {} } exported.each do |role, databases| dsl = Posgra::DSL.convert_databases({role => databases}, ) dsl_h[role] = dsl end dsl_h else Posgra::DSL.convert_databases(exported, ) end end |
#export_grants(options = {}) ⇒ Object
47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 |
# File 'lib/posgra/client.rb', line 47 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
41 42 43 44 45 |
# File 'lib/posgra/client.rb', line 41 def export_roles( = {}) = @options.merge() exported = Posgra::Exporter.export_roles(@driver, ) Posgra::DSL.convert_roles(exported, ) end |