Class: Boxafe::Validator

Inherits:
Object
  • Object
show all
Defined in:
lib/boxafe/validator.rb

Instance Method Summary collapse

Constructor Details

#initialize(options = {}) ⇒ Validator

Returns a new instance of Validator.


6
7
8
# File 'lib/boxafe/validator.rb', line 6

def initialize options = {}
  @raise_first = options[:raise_first]
end

Instance Method Details

#validate(options = {}) ⇒ Object


10
11
12
# File 'lib/boxafe/validator.rb', line 10

def validate options = {}
  validate_global_options(options) + validate_mount_options(options)
end

#validate_global_options(options = {}) ⇒ Object


14
15
16
17
18
19
20
21
22
23
# File 'lib/boxafe/validator.rb', line 14

def validate_global_options options = {}
  
  errors = []
  encfs_bin, umount_bin = options[:encfs], options[:umount]

  add "could not find encfs binary '#{encfs_bin}'; is it in the PATH?", :encfs, errors unless Which.which encfs_bin
  add "could not find umount binary '#{umount_bin}'; is it in the PATH?", :umount, errors unless Which.which umount_bin

  errors
end

#validate_mount_options(options = {}) ⇒ Object


25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
# File 'lib/boxafe/validator.rb', line 25

def validate_mount_options options = {}

  errors = []

  validate_file :root, 'root directory', options[:root], errors, required: true
  validate_file :mount, 'mount directory', options[:mount], errors, required: true, presence: false
  validate_file :password_file, 'password file', options[:password_file], errors, file: true
  validate_file :config_file, 'config file', options[:config_file], errors, file: true

  if options[:password_file] and options[:keychain]
    add "cannot use both a password file and the keychain", :keychain, errors
  end

  errors
end