Module: PgEasyReplicate::Helper

Included in:
PgEasyReplicate, Group, Orchestrate, Query, Stats
Defined in:
lib/pg_easy_replicate/helper.rb

Instance Method Summary collapse

Instance Method Details

#abort_with(msg) ⇒ Object



63
64
65
66
# File 'lib/pg_easy_replicate/helper.rb', line 63

def abort_with(msg)
  raise(msg) if test_env?
  abort(msg)
end

#connection_info(conn_string) ⇒ Object



50
51
52
53
54
55
56
57
# File 'lib/pg_easy_replicate/helper.rb', line 50

def connection_info(conn_string)
  PG::Connection
    .conninfo_parse(conn_string)
    .each_with_object({}) do |obj, hash|
      hash[obj[:keyword].to_sym] = obj[:val]
    end
    .compact
end

#db_user(url) ⇒ Object



59
60
61
# File 'lib/pg_easy_replicate/helper.rb', line 59

def db_user(url)
  connection_info(url)[:user]
end

#internal_schema_nameObject



21
22
23
# File 'lib/pg_easy_replicate/helper.rb', line 21

def internal_schema_name
  "pger"
end

#internal_user_nameObject



25
26
27
# File 'lib/pg_easy_replicate/helper.rb', line 25

def internal_user_name
  "pger_su_h1a4fb"
end

#loggerObject



17
18
19
# File 'lib/pg_easy_replicate/helper.rb', line 17

def logger
  PgEasyReplicate.logger
end

#publication_name(group_name) ⇒ Object



29
30
31
# File 'lib/pg_easy_replicate/helper.rb', line 29

def publication_name(group_name)
  "pger_publication_#{underscore(group_name)}"
end

#secondary_source_db_urlObject



9
10
11
# File 'lib/pg_easy_replicate/helper.rb', line 9

def secondary_source_db_url
  ENV.fetch("SECONDARY_SOURCE_DB_URL", nil)
end

#source_db_urlObject



5
6
7
# File 'lib/pg_easy_replicate/helper.rb', line 5

def source_db_url
  ENV.fetch("SOURCE_DB_URL", nil)
end

#subscription_name(group_name) ⇒ Object



33
34
35
# File 'lib/pg_easy_replicate/helper.rb', line 33

def subscription_name(group_name)
  "pger_subscription_#{underscore(group_name)}"
end

#target_db_urlObject



13
14
15
# File 'lib/pg_easy_replicate/helper.rb', line 13

def target_db_url
  ENV.fetch("TARGET_DB_URL", nil)
end

#test_env?Boolean

Returns:

  • (Boolean)


46
47
48
# File 'lib/pg_easy_replicate/helper.rb', line 46

def test_env?
  ENV.fetch("RACK_ENV", nil) == "test"
end

#underscore(str) ⇒ Object



37
38
39
40
41
42
43
44
# File 'lib/pg_easy_replicate/helper.rb', line 37

def underscore(str)
  str
    .gsub(/::/, "/")
    .gsub(/([A-Z]+)([A-Z][a-z])/, '\1_\2')
    .gsub(/([a-z\d])([A-Z])/, '\1_\2')
    .tr("-", "_")
    .downcase
end