Sha256: d7cb22aa90567723589bc740a16a26516ee8154de367b6edd668aaf5d0fe67f3
Contents?: true
Size: 1.82 KB
Versions: 10
Compression:
Stored size: 1.82 KB
Contents
module Outback class Configuration @loaded = [] class << self def add(configuration) raise ConfigurationError.new("duplicate configuration #{configuration.name}") if loaded.any?(&its.name == configuration.name) loaded << configuration end def loaded @loaded end def [](name) loaded.detect { |configuration| configuration.name == name.to_s } end def reset @loaded = [] end end attr_reader :name, :sources, :targets, :errors def initialize(name, &block) raise(ConfigurationError.new("configuration name can't be blank")) if name.blank? @name = name.to_s raise(ConfigurationError.new('configuration name may not contain underscores')) if @name.include?('_') @sources, @targets, @errors = [], [], [] if block_given? if block.arity == 1 then yield(self) else instance_eval(&block) end end self.class.add(self) end protected def source(type, *args, &block) "Outback::#{type.to_s.classify}Source".constantize.configure(*args, &block).tap { |instance| sources << instance } end def target(type, *args, &block) "Outback::#{type.to_s.classify}Target".constantize.configure(*args, &block).tap { |instance| targets << instance } end def valid? errors.clear return error('no targets specified') if targets.empty? moving_targets = targets.select { |t| t.is_a?(DirectoryTarget) && t.move } return error('cannot define more than one moving target') if moving_targets.size > 1 return error('moving target must be defined last') if moving_targets.first && moving_targets.first != targets.last true end def error(message) errors << ConfigurationError.new(message) false end end end
Version data entries
10 entries across 10 versions & 1 rubygems