class Knowledge::Backupper

Description

Object used to backup configuration variables.

Usage

@example:

backupper = Knowledge::Backupper.new

backupper.register(name: :foo, value: 'bar')
backupper.register(name: :bar, value: 'baz')

backupper.backup!

Attributes

@attr_reader [Hash] configuration @attr_reader [String] path

Attributes

configuration[R]
path[R]

Backup file path

Public Class Methods

new(path:) click to toggle source

Just sets the basic configuration object.

Parameters

@param :path [String] Path to the YAML file where to backup the config

# File lib/knowledge/backupper.rb, line 47
def initialize(path:)
  @configuration = {}
  @path = path
end

Public Instance Methods

backup!() click to toggle source

Backups the configuration.

# File lib/knowledge/backupper.rb, line 57
def backup!
  f = File.new(path, 'w')

  f.write(configuration.to_yaml)

  f.close
end
register(name:, value:)
Alias for: set
set(name:, value:) click to toggle source

Sets the variable before backuping everything.

Parameters

@param :name [String | Symbol] @param :value [Any]

# File lib/knowledge/backupper.rb, line 73
def set(name:, value:)
  configuration[name.to_sym] = value
end
Also aliased as: register