Class: Boxafe::Box
- Inherits:
-
Object
- Object
- Boxafe::Box
- 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
- #configure(options = {}, &block) ⇒ Object
- #description(verbose = false) ⇒ Object
- #encfs ⇒ Object
- #ensure_mount_point ⇒ Object
-
#initialize(options = {}) ⇒ Box
constructor
A new instance of Box.
- #mount ⇒ Object
- #mount_status ⇒ Object
- #name ⇒ Object
- #options ⇒ Object
- #unmount ⇒ Object
Constructor Details
Instance Method Details
#configure(options = {}, &block) ⇒ Object
84 85 86 87 88 |
# File 'lib/boxafe/box.rb', line 84 def configure = {}, &block @options.merge! DSL.new(@options).instance_eval &block if block self end |
#description(verbose = false) ⇒ Object
38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 |
# File 'lib/boxafe/box.rb', line 38 def description verbose = false opts = String.new.tap do |s| s << Paint["## #{name}", :cyan, :bold] s << "\nEncrypted Root: " s << if File.directory?(opts[:root]) Paint["#{opts[:root]}", :green] elsif File.exists?(opts[:root]) Paint["#{opts[:root]} (not a directory)", :red] else Paint["#{opts[:root]} (doesn't exist)", :red] end s << "\nMount Point: " s << case mount_status when :mounted Paint["#{opts[:mount]}", :green] when :invalid Paint["#{opts[:mount]} (not a directory)", :red] else Paint["#{opts[:mount]} (not mounted)", :yellow] end s << "\nVolume Name: #{opts[:volume]}" if opts[:password_file] s << "\nPassword File: #{opts[:password_file]}" elsif opts[:keychain] s << "\nKeychain Password: #{opts[:keychain]}" end s << "\nEncFS Config: #{opts[:encfs_config]}" if opts[:encfs_config] s << "\nCommand: #{Paint[encfs.command, :yellow]}" if verbose end end |
#ensure_mount_point ⇒ Object
34 35 36 |
# File 'lib/boxafe/box.rb', line 34 def ensure_mount_point FileUtils.mkdir_p [:mount] end |
#mount ⇒ Object
19 20 21 |
# File 'lib/boxafe/box.rb', line 19 def mount system encfs.command end |
#mount_status ⇒ Object
74 75 76 77 78 79 80 81 82 |
# File 'lib/boxafe/box.rb', line 74 def mount_status if File.directory? [:mount] :mounted elsif File.exists? [:mount] :invalid else :unmounted end end |
#name ⇒ Object
15 16 17 |
# File 'lib/boxafe/box.rb', line 15 def name @options[:name] end |
#options ⇒ Object
90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 |
# File 'lib/boxafe/box.rb', line 90 def @options.tap do |opts| opts[:root] = File. opts[:root] || "~/Dropbox/#{opts[:name]}" opts[:mount] = File. opts[:mount] || "/Volumes/#{opts[:name]}" opts[:encfs_config] = File. opts[:encfs_config] if opts[:encfs_config] opts[:volume] ||= opts[:name] if opts[:password_file] opts[:password_file] = File. opts[:password_file] opts.delete :keychain elsif opts[:keychain] == true opts[:keychain] = opts[:name] end end end |
#unmount ⇒ Object
23 24 25 26 27 28 |
# File 'lib/boxafe/box.rb', line 23 def unmount opts = result = system "#{opts[:umount]} #{opts[:mount]}" sleep opts[:umount_delay] if opts[:umount_delay] and opts[:umount_delay] > 0 result end |