Sha256: e6072e42ae42d95789caaf7a22d64b3054ec315b2841cfa8143ebdc23510b6d9

Contents?: true

Size: 1.02 KB

Versions: 4

Compression:

Stored size: 1.02 KB

Contents

# encoding: UTF-8
class Boxafe::Config

  # TODO: document unmount_delay
  OPTION_KEYS = [ :encfs, :umount, :umount_delay ]

  attr_reader :boxes, :options

  def initialize options = {}
    @boxes = []
    @options = { encfs: 'encfs', umount: 'umount', umount_delay: 0.5 }.merge options
  end

  def configure file = nil, &block
    DSL.new(self).tap do |dsl|
      dsl.instance_eval File.read(file), file if file
      dsl.instance_eval &block if block
    end
    self
  end

  def load
    configure file
  end

  def file
    File.expand_path [ @options[:config], ENV['BOXAFE_CONFIG'], "~/.boxafe.rb" ].compact.first
  end

  class DSL

    def initialize config
      @config = config
    end

    def box options = {}, &block
      Boxafe::Box.new(@config.options.merge(options)).tap do |box|
        @config.boxes << box.configure(&block)
      end
    end

    def env *args
      Mutaconf.env *args
    end

    OPTION_KEYS.each do |name|
      define_method(name){ |value| @config.options[name.to_sym] = value }
    end
  end
end

Version data entries

4 entries across 4 versions & 1 rubygems

Version Path
boxafe-0.1.3 lib/boxafe/config.rb
boxafe-0.1.2 lib/boxafe/config.rb
boxafe-0.1.1 lib/boxafe/config.rb
boxafe-0.1.0 lib/boxafe/config.rb