Class: NoopBackup::Configuration

Inherits:
Object
  • Object
show all
Defined in:
lib/noop_backup/configuration.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initializeConfiguration

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_commandObject



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_sizeObject

Returns the value of attribute min_size.



3
4
5
# File 'lib/noop_backup/configuration.rb', line 3

def min_size
  @min_size
end

#notifiersObject (readonly)

Returns the value of attribute notifiers.



11
12
13
# File 'lib/noop_backup/configuration.rb', line 11

def notifiers
  @notifiers
end

#pg_databaseObject

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_hostObject

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_passwordObject

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_portObject

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_userObject

Returns the value of attribute pg_user.



3
4
5
# File 'lib/noop_backup/configuration.rb', line 3

def pg_user
  @pg_user
end

#prefixObject

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

Parameters:

  • value

    the value to set the attribute report to.



12
13
14
# File 'lib/noop_backup/configuration.rb', line 12

def report=(value)
  @report = value
end

#storesObject (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_configObject



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_envObject



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

Yields:

  • (store)

Raises:



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

Returns:

  • (Boolean)


22
23
24
# File 'lib/noop_backup/configuration.rb', line 22

def report?
  @report
end