Module: Bcdatabase

Defined in:
lib/bcdatabase.rb,
lib/bcdatabase/cli.rb,
lib/bcdatabase/version.rb

Defined Under Namespace

Modules: Commands Classes: CLI, DatabaseConfigurations, Error

Constant Summary collapse

DEFAULT_BASE_PATH =
File.join('/', 'etc', 'nubic', 'db')
DEFAULT_PASS_FILE =
File.join('/', 'var', 'lib', 'nubic', 'db.pass')
CIPHER =
'aes-256-ecb'
VERSION =
'1.2.4'

Class Method Summary collapse

Class Method Details

.decrypt(s) ⇒ Object



61
62
63
# File 'lib/bcdatabase.rb', line 61

def decrypt(s)
  encipher(:decrypt, Base64.decode64(s))
end

.encrypt(s) ⇒ Object



50
51
52
53
54
55
56
57
# File 'lib/bcdatabase.rb', line 50

def encrypt(s)
  bits = encipher(:encrypt, s)
  if Base64.respond_to?(:strict_encode64)
    Base64.strict_encode64(bits).strip
  else
    Base64.encode64(bits).gsub("\n", '').strip
  end
end

.load(options = {}) ⇒ DatabaseConfigurations .load(path = nil, options = {}) ⇒ DatabaseConfigurations

The main entry point for Bcdatabase.

Overloads:

  • .load(options = {}) ⇒ DatabaseConfigurations

    (See other alternative for option definitions.)

    Returns:

  • .load(path = nil, options = {}) ⇒ DatabaseConfigurations

    Returns a new instance reflecting the selected path.

    Parameters:

    • path (String, nil) (defaults to: nil)

      the directory to load from. If nil, will use the value in the environment variable ‘BCDATABASE_PATH`. If that’s nil, too, it will use the default path.

    • options (Hash, nil) (defaults to: {})

      additional options affecting the load behavior.

    Options Hash (options):

    • :transforms (Array<Symbol, #call>) — default: []

      Custom transforms. This can either be a symbol naming a built-in transform or a callable which is the transform itself. A transform is a function that takes three arguments (the entry itself, the entry name, and the group name) and returns a new copy, modified as desired. It may also return nil to indicate that it doesn’t wish to make any changes.

    Returns:



41
42
43
44
45
46
# File 'lib/bcdatabase.rb', line 41

def load(*args)
  options = extract_options(args)
  path ||= (args.first || base_path)
  files = Dir.glob(File.join(path, "*.yml")) + Dir.glob(File.join(path, "*.yaml"))
  DatabaseConfigurations.new(files, options[:transforms] || [])
end

.pass_fileObject



65
66
67
# File 'lib/bcdatabase.rb', line 65

def pass_file
  Pathname.new(ENV["BCDATABASE_PASS"] || DEFAULT_PASS_FILE)
end