Class: NoopBackup::Configuration
- Inherits:
-
Object
- Object
- NoopBackup::Configuration
- Defined in:
- lib/noop_backup/configuration.rb
Instance Attribute Summary collapse
- #dump_command ⇒ Object
-
#min_size ⇒ Object
Returns the value of attribute min_size.
-
#notifiers ⇒ Object
readonly
Returns the value of attribute notifiers.
-
#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.
-
#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
- #pg_env ⇒ Object
- #register(store_type) {|store| ... } ⇒ Object
- #report? ⇒ Boolean
Constructor Details
#initialize ⇒ Configuration
Returns a new instance of Configuration.
14 15 16 17 18 19 20 |
# File 'lib/noop_backup/configuration.rb', line 14 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 end |
Instance Attribute Details
#dump_command ⇒ Object
26 27 28 |
# File 'lib/noop_backup/configuration.rb', line 26 def dump_command @dump_command || [pg_env, "pg_dump", "--format=custom", "--no-owner"] end |
#min_size ⇒ Object
Returns the value of attribute min_size.
3 4 5 |
# File 'lib/noop_backup/configuration.rb', line 3 def min_size @min_size end |
#notifiers ⇒ Object (readonly)
Returns the value of attribute notifiers.
11 12 13 |
# File 'lib/noop_backup/configuration.rb', line 11 def notifiers @notifiers end |
#pg_database ⇒ Object
Returns the value of attribute pg_database.
3 4 5 |
# File 'lib/noop_backup/configuration.rb', line 3 def pg_database @pg_database end |
#pg_host ⇒ Object
Returns the value of attribute pg_host.
3 4 5 |
# File 'lib/noop_backup/configuration.rb', line 3 def pg_host @pg_host end |
#pg_password ⇒ Object
Returns the value of attribute pg_password.
3 4 5 |
# File 'lib/noop_backup/configuration.rb', line 3 def pg_password @pg_password end |
#pg_port ⇒ Object
Returns the value of attribute pg_port.
3 4 5 |
# File 'lib/noop_backup/configuration.rb', line 3 def pg_port @pg_port end |
#pg_user ⇒ Object
Returns the value of attribute pg_user.
3 4 5 |
# File 'lib/noop_backup/configuration.rb', line 3 def pg_user @pg_user end |
#prefix ⇒ Object
Returns the value of attribute prefix.
3 4 5 |
# File 'lib/noop_backup/configuration.rb', line 3 def prefix @prefix end |
#report=(value) ⇒ Object (writeonly)
Sets the attribute report
12 13 14 |
# File 'lib/noop_backup/configuration.rb', line 12 def report=(value) @report = value end |
#stores ⇒ Object (readonly)
Returns the value of attribute stores.
11 12 13 |
# File 'lib/noop_backup/configuration.rb', line 11 def stores @stores end |
Instance Method Details
#db_config ⇒ Object
66 67 68 69 |
# File 'lib/noop_backup/configuration.rb', line 66 def db_config @db_config ||= defined?(::ActiveRecord) ? ::ActiveRecord::Base.connection_db_config.configuration_hash : {} end |
#notifier(type) ⇒ Object
44 45 46 47 48 49 50 51 52 53 54 |
# File 'lib/noop_backup/configuration.rb', line 44 def notifier(type) case type when :slack notifier = NoopBackup::Notifiers::Slack.new yield notifier @notifiers << notifier else raise "Unknown notifier: #{type}" end end |
#pg_env ⇒ Object
56 57 58 59 60 61 62 63 64 |
# File 'lib/noop_backup/configuration.rb', line 56 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
30 31 32 33 34 35 36 37 38 39 40 41 42 |
# File 'lib/noop_backup/configuration.rb', line 30 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
22 23 24 |
# File 'lib/noop_backup/configuration.rb', line 22 def report? @report end |