Class: Outback::Configuration

Inherits:
Object
  • Object
show all
Defined in:
lib/outback/configuration.rb

Instance Attribute Summary collapse

Class Method Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(name, &block) ⇒ Configuration

Returns a new instance of Configuration.

Raises:



27
28
29
30
31
32
33
34
35
36
# File 'lib/outback/configuration.rb', line 27

def initialize(name, &block)
  name = name.to_s
  raise ConfigurationError, "Illegal configuration name #{name.inspect}" unless name.match(/\A[a-z][a-z0-9_\-.]+\z/)
  @name = name
  @sources, @processors, @targets, @errors = [], [], [], []
  if block_given?
    if block.arity == 1 then yield(self) else instance_eval(&block) end
  end
  self.class.add(self)
end

Instance Attribute Details

#errorsObject (readonly)

Returns the value of attribute errors.



25
26
27
# File 'lib/outback/configuration.rb', line 25

def errors
  @errors
end

#nameObject (readonly)

Returns the value of attribute name.



25
26
27
# File 'lib/outback/configuration.rb', line 25

def name
  @name
end

#processorsObject (readonly)

Returns the value of attribute processors.



25
26
27
# File 'lib/outback/configuration.rb', line 25

def processors
  @processors
end

#sourcesObject (readonly)

Returns the value of attribute sources.



25
26
27
# File 'lib/outback/configuration.rb', line 25

def sources
  @sources
end

#targetsObject (readonly)

Returns the value of attribute targets.



25
26
27
# File 'lib/outback/configuration.rb', line 25

def targets
  @targets
end

Class Method Details

.[](name) ⇒ Object



16
17
18
# File 'lib/outback/configuration.rb', line 16

def [](name)
  loaded.detect { |configuration| configuration.name == name.to_s }
end

.add(configuration) ⇒ Object

Raises:



7
8
9
10
# File 'lib/outback/configuration.rb', line 7

def add(configuration)
  raise ConfigurationError, "duplicate configuration #{configuration.name}" if loaded.any?(&its.name == configuration.name)
  loaded << configuration
end

.loadedObject



12
13
14
# File 'lib/outback/configuration.rb', line 12

def loaded
  @loaded
end

.resetObject



20
21
22
# File 'lib/outback/configuration.rb', line 20

def reset
  @loaded = []
end

Instance Method Details

#tmpdir(*args) ⇒ Object



47
48
49
50
51
52
53
54
55
56
57
# File 'lib/outback/configuration.rb', line 47

def tmpdir(*args)
  if args.empty?
    @tmpdir
  elsif args.size == 1
    dir = Pathname.new(args.first).realpath
    raise ConfigurationError, "tmpdir #{dir} is not a directory" unless dir.directory?
    @tmpdir = dir
  else
    raise ConfigurationError, "tmpdir: wrong number of arguments(#{args.size} for 1)"
  end
end

#valid?Boolean



38
39
40
41
42
43
44
45
# File 'lib/outback/configuration.rb', line 38

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