Class: NoopBackup::Configuration
- Inherits:
-
Object
- Object
- NoopBackup::Configuration
- Defined in:
- lib/noop_backup/configuration.rb
Constant Summary collapse
- DEFAULT_SENTINEL_HOST =
"https://boringbackup.com"
Instance Attribute Summary collapse
- #dump_command ⇒ Object
- #ignore_tables ⇒ Object
-
#min_size ⇒ Object
Returns the value of attribute min_size.
-
#pg_database ⇒ Object
Returns the value of attribute pg_database.
-
#pg_host ⇒ Object
Returns the value of attribute pg_host.
-
#pg_password ⇒ Object
Returns the value of attribute pg_password.
-
#pg_port ⇒ Object
Returns the value of attribute pg_port.
-
#pg_user ⇒ Object
Returns the value of attribute pg_user.
-
#prefix ⇒ Object
Returns the value of attribute prefix.
-
#report ⇒ Object
writeonly
Sets the attribute report.
- #sentinel_host ⇒ Object
-
#sentinel_key ⇒ Object
Returns the value of attribute sentinel_key.
-
#stores ⇒ Object
readonly
Returns the value of attribute stores.
Instance Method Summary collapse
- #db_config ⇒ Object
-
#initialize ⇒ Configuration
constructor
A new instance of Configuration.
- #notifier(type) ⇒ Object
- #notifiers ⇒ Object
- #pg_env ⇒ Object
- #register(store_type) {|store| ... } ⇒ Object
- #report? ⇒ Boolean
- #sentinel ⇒ Object
- #sentinel? ⇒ Boolean
Constructor Details
#initialize ⇒ Configuration
Returns a new instance of Configuration.
17 18 19 20 21 22 23 24 25 26 |
# File 'lib/noop_backup/configuration.rb', line 17 def initialize @prefix = ENV.fetch("NBU_PREFIX", "database") @stores = [] @min_size = ENV.fetch("NBU_MIN_SIZE", 2048).to_i @notifiers = [NoopBackup::Notifiers::Stdout.new] @report = true @ignore_tables = ENV.fetch("NBU_IGNORE_TABLES", "").split(",") @sentinel_key = ENV["NBU_SENTINEL_KEY"] @sentinel_host = ENV.fetch("NBU_SENTINEL_HOST", DEFAULT_SENTINEL_HOST) end |
Instance Attribute Details
#dump_command ⇒ Object
54 55 56 57 58 59 60 61 62 |
# File 'lib/noop_backup/configuration.rb', line 54 def dump_command @dump_command || [ pg_env, "pg_dump", "--format=custom", "--no-owner", *ignore_tables.map { |table| "--exclude-table-data=#{table}" } ] end |
#ignore_tables ⇒ Object
50 51 52 |
# File 'lib/noop_backup/configuration.rb', line 50 def ignore_tables Array(@ignore_tables).map { |table| table.to_s.strip }.reject(&:empty?).uniq end |
#min_size ⇒ Object
Returns the value of attribute min_size.
5 6 7 |
# File 'lib/noop_backup/configuration.rb', line 5 def min_size @min_size end |
#pg_database ⇒ Object
Returns the value of attribute pg_database.
5 6 7 |
# File 'lib/noop_backup/configuration.rb', line 5 def pg_database @pg_database end |
#pg_host ⇒ Object
Returns the value of attribute pg_host.
5 6 7 |
# File 'lib/noop_backup/configuration.rb', line 5 def pg_host @pg_host end |
#pg_password ⇒ Object
Returns the value of attribute pg_password.
5 6 7 |
# File 'lib/noop_backup/configuration.rb', line 5 def pg_password @pg_password end |
#pg_port ⇒ Object
Returns the value of attribute pg_port.
5 6 7 |
# File 'lib/noop_backup/configuration.rb', line 5 def pg_port @pg_port end |
#pg_user ⇒ Object
Returns the value of attribute pg_user.
5 6 7 |
# File 'lib/noop_backup/configuration.rb', line 5 def pg_user @pg_user end |
#prefix ⇒ Object
Returns the value of attribute prefix.
5 6 7 |
# File 'lib/noop_backup/configuration.rb', line 5 def prefix @prefix end |
#report=(value) ⇒ Object (writeonly)
Sets the attribute report
15 16 17 |
# File 'lib/noop_backup/configuration.rb', line 15 def report=(value) @report = value end |
#sentinel_host ⇒ Object
32 33 34 |
# File 'lib/noop_backup/configuration.rb', line 32 def sentinel_host @sentinel_host || DEFAULT_SENTINEL_HOST end |
#sentinel_key ⇒ Object
Returns the value of attribute sentinel_key.
5 6 7 |
# File 'lib/noop_backup/configuration.rb', line 5 def sentinel_key @sentinel_key end |
#stores ⇒ Object (readonly)
Returns the value of attribute stores.
14 15 16 |
# File 'lib/noop_backup/configuration.rb', line 14 def stores @stores end |
Instance Method Details
#db_config ⇒ Object
100 101 102 103 |
# File 'lib/noop_backup/configuration.rb', line 100 def db_config @db_config ||= defined?(::ActiveRecord) ? ::ActiveRecord::Base.connection_db_config.configuration_hash : {} end |
#notifier(type) ⇒ Object
78 79 80 81 82 83 84 85 86 87 88 |
# File 'lib/noop_backup/configuration.rb', line 78 def notifier(type) case type when :slack notifier = NoopBackup::Notifiers::Slack.new yield notifier @notifiers << notifier else raise "Unknown notifier: #{type}" end end |
#notifiers ⇒ Object
46 47 48 |
# File 'lib/noop_backup/configuration.rb', line 46 def notifiers [*@notifiers, sentinel].compact end |
#pg_env ⇒ Object
90 91 92 93 94 95 96 97 98 |
# File 'lib/noop_backup/configuration.rb', line 90 def pg_env { "PGHOST" => (pg_host || db_config[:host])&.to_s, "PGPORT" => (pg_port || db_config[:port])&.to_s, "PGUSER" => (pg_user || db_config[:username])&.to_s, "PGPASSWORD" => (pg_password || db_config[:password])&.to_s, "PGDATABASE" => (pg_database || db_config[:database])&.to_s }.compact end |
#register(store_type) {|store| ... } ⇒ Object
64 65 66 67 68 69 70 71 72 73 74 75 76 |
# File 'lib/noop_backup/configuration.rb', line 64 def register(store_type) raise NoopBackup::ConfigurationError, "`config.register` requires a block" unless block_given? store = case store_type.to_sym when :s3 then NoopBackup::Stores::S3.new else raise NoopBackup::ConfigurationError, "unknown store type: #{store_type}" end @stores << store yield store end |
#report? ⇒ Boolean
28 29 30 |
# File 'lib/noop_backup/configuration.rb', line 28 def report? @report end |
#sentinel ⇒ Object
40 41 42 43 44 |
# File 'lib/noop_backup/configuration.rb', line 40 def sentinel return unless sentinel? @sentinel ||= NoopBackup::Notifiers::Sentinel.new(key: sentinel_key, host: sentinel_host) end |
#sentinel? ⇒ Boolean
36 37 38 |
# File 'lib/noop_backup/configuration.rb', line 36 def sentinel? !sentinel_key.to_s.empty? end |