Sha256: a50c61d62f41336b1549e41500ca1a2385042941c4a175b7eb020ee6fcb6b334

Contents?: true

Size: 1.22 KB

Versions: 1

Compression:

Stored size: 1.22 KB

Contents

require 'logger'
require 'ns-options'
require 'inbox-sync/config/imap_config'
require 'inbox-sync/config/smtp_config'
require 'inbox-sync/config/filter'

module InboxSync

  class Config
    include NsOptions::Proxy

    opt :source, IMAPConfig, :required => true, :default => {}
    opt :dest,   IMAPConfig, :required => true, :default => {}
    opt :notify, SMTPConfig, :required => true, :default => {}

    opt :archive_folder, :default => 'Archived'
    opt :logger, Logger, :required => true, :default => STDOUT
    opt :filters, :default => [], :required => true
    opt :num_workers, :default => 1, :required => true

    def filter(*args, &block)
      filters << Filter.new(*args, &block)
    end

    def validate!
      if !required_set?
        raise ArgumentError, "some required configs are missing"
      end

      source.validate!
      dest.validate!
      notify.validate!
    end

    protected

    def contains(value);    /.*#{value}.*/; end
    def starts_with(value); /\A#{value}.*/; end
    def ends_with(value);   /.*#{value}\Z/; end

    alias_method :like, :contains
    alias_method :includes, :contains
    alias_method :inc, :includes
    alias_method :sw,  :starts_with
    alias_method :ew,  :ends_with

  end

end

Version data entries

1 entries across 1 versions & 1 rubygems

Version Path
inbox-sync-0.4.1 lib/inbox-sync/config.rb