Class: Boxafe::Box

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

Defined Under Namespace

Classes: DSL

Constant Summary collapse

OPTION_KEYS =
[ :name, :root, :mount, :volume, :encfs_config, :keychain, :password_file ]

Instance Method Summary collapse

Constructor Details

#initialize(options = {}) ⇒ Box

Returns a new instance of Box.

Raises:



9
10
11
12
13
# File 'lib/boxafe/box.rb', line 9

def initialize options = {}
  raise OptionError.new("The :name option is required", :name) unless options[:name]
  @options = options
  @validator = Validator.new raise_first: true
end

Instance Method Details

#commandObject



19
20
21
# File 'lib/boxafe/box.rb', line 19

def command
  encfs.command
end

#configure(options = {}, &block) ⇒ Object



47
48
49
50
51
# File 'lib/boxafe/box.rb', line 47

def configure options = {}, &block
  @options.merge! options
  DSL.new(@options).instance_eval &block if block
  self
end

#mountObject



23
24
25
26
27
# File 'lib/boxafe/box.rb', line 23

def mount
  @validator.validate mount_options
  ensure_mount_point
  system command
end

#mount_optionsObject



41
42
43
44
45
# File 'lib/boxafe/box.rb', line 41

def mount_options
  default_mount_options.merge(@options).tap do |options|
    options[:keychain] = @options[:name] if options[:keychain] == true
  end
end

#mounted?Boolean

Returns:

  • (Boolean)


36
37
38
39
# File 'lib/boxafe/box.rb', line 36

def mounted?
  # TODO: check if it's possible to differentiate between an empty mounted directory and an unmounted directory
  File.directory?(mount_options[:mount]) && !Dir.entries(mount_options[:mount]).reject{ |e| e.match(/^\.{1,2}$/) }.empty?
end

#nameObject



15
16
17
# File 'lib/boxafe/box.rb', line 15

def name
  @options[:name]
end

#unmountObject



29
30
31
32
33
34
# File 'lib/boxafe/box.rb', line 29

def unmount
  options = mount_options
  result = system "#{options[:umount]} #{options[:mount]}"
  sleep options[:umount_delay] if options[:umount_delay] and options[:umount_delay] > 0
  result
end