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 ]
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
80 81 82 83 84 |
# File 'lib/boxafe/box.rb', line 80 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 |
# 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]}" s << "\nKeychain Password: #{opts[:keychain]}" if opts[:keychain] 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
70 71 72 73 74 75 76 77 78 |
# File 'lib/boxafe/box.rb', line 70 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
86 87 88 89 90 91 92 93 94 |
# File 'lib/boxafe/box.rb', line 86 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] opts[:keychain] = opts[:name] if opts[:keychain] == true 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 |