Module: PgBouncerHero

Defined in:
lib/pgbouncerhero.rb,
lib/pgbouncerhero/group.rb,
lib/pgbouncerhero/engine.rb,
lib/pgbouncerhero/version.rb,
lib/pgbouncerhero/database.rb,
lib/pgbouncerhero/connection.rb,
lib/pgbouncerhero/methods/basics.rb,
lib/generators/pgbouncerhero/config_generator.rb,
app/helpers/pg_bouncer_hero/application_helper.rb,
app/controllers/pg_bouncer_hero/home_controller.rb,
app/controllers/pg_bouncer_hero/database_controller.rb,
app/controllers/pg_bouncer_hero/application_controller.rb

Defined Under Namespace

Modules: ApplicationHelper, Generators, Methods Classes: ApplicationController, ConfigurationError, Connection, Database, DatabaseController, Engine, Group, HomeController

Constant Summary collapse

ADMIN_COMMAND_EVENT =
"admin_command.pgbouncerhero"
VERSION =
"3.2.0"

Class Attribute Summary collapse

Class Method Summary collapse

Class Attribute Details

.envObject

Returns the value of attribute env.



43
44
45
# File 'lib/pgbouncerhero.rb', line 43

def env
  @env
end

Class Method Details

.configObject



71
72
73
# File 'lib/pgbouncerhero.rb', line 71

def config
  STATE_MONITOR.synchronize { @config ||= selected_config(load_config) }
end

.config_pathObject



60
61
62
# File 'lib/pgbouncerhero.rb', line 60

def config_path
  STATE_MONITOR.synchronize { @config_path || default_config_path }
end

.config_path=(path) ⇒ Object



64
65
66
67
68
69
# File 'lib/pgbouncerhero.rb', line 64

def config_path=(path)
  STATE_MONITOR.synchronize do
    @config_path = path && Pathname(path)
    reset!
  end
end

.disconnect!Object



101
102
103
104
105
106
107
# File 'lib/pgbouncerhero.rb', line 101

def disconnect!
  STATE_MONITOR.synchronize do
    @groups&.each_value do |group|
      group.databases.each(&:disconnect!)
    end
  end
end

.groupsObject



75
76
77
78
79
80
81
# File 'lib/pgbouncerhero.rb', line 75

def groups
  STATE_MONITOR.synchronize do
    @groups ||= config.fetch("pgbouncers").to_h do |group_id, _databases|
      [ group_id.parameterize, PgBouncerHero::Group.new(group_id, config.fetch("pgbouncers")) ]
    end
  end
end

.parse_read_only(value) ⇒ Object



95
96
97
98
99
# File 'lib/pgbouncerhero.rb', line 95

def parse_read_only(value)
  BOOLEAN_SETTINGS.fetch(value.is_a?(String) ? value.downcase : value)
rescue KeyError
  raise ConfigurationError, "read_only must be a boolean"
end

.read_only?Boolean

Returns:

  • (Boolean)


83
84
85
86
# File 'lib/pgbouncerhero.rb', line 83

def read_only?
  value = ENV.fetch("PGBOUNCERHERO_READ_ONLY") { config.fetch("read_only", false) }
  parse_read_only(value)
end

.read_only_for?(database) ⇒ Boolean

Returns:

  • (Boolean)


88
89
90
91
92
93
# File 'lib/pgbouncerhero.rb', line 88

def read_only_for?(database)
  value = ENV.fetch("PGBOUNCERHERO_READ_ONLY") do
    database.config.fetch("read_only") { config.fetch("read_only", false) }
  end
  parse_read_only(value)
end

.reset!Object



109
110
111
112
113
114
115
# File 'lib/pgbouncerhero.rb', line 109

def reset!
  STATE_MONITOR.synchronize do
    disconnect!
    @config = nil
    @groups = nil
  end
end

.time_zoneObject



49
50
51
# File 'lib/pgbouncerhero.rb', line 49

def time_zone
  @time_zone || Time.zone
end

.time_zone=(time_zone) ⇒ Object



45
46
47
# File 'lib/pgbouncerhero.rb', line 45

def time_zone=(time_zone)
  @time_zone = time_zone.is_a?(ActiveSupport::TimeZone) ? time_zone : ActiveSupport::TimeZone[time_zone.to_s]
end