Class: Outback::Configuration
Instance Attribute Summary collapse
-
#errors ⇒ Object
readonly
Returns the value of attribute errors.
-
#name ⇒ Object
readonly
Returns the value of attribute name.
-
#processors ⇒ Object
readonly
Returns the value of attribute processors.
-
#sources ⇒ Object
readonly
Returns the value of attribute sources.
-
#targets ⇒ Object
readonly
Returns the value of attribute targets.
Class Method Summary collapse
Instance Method Summary collapse
-
#initialize(name, &block) ⇒ Configuration
constructor
A new instance of Configuration.
- #tmpdir(*args) ⇒ Object
- #valid? ⇒ Boolean
Constructor Details
#initialize(name, &block) ⇒ Configuration
Returns a new instance of Configuration.
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
#errors ⇒ Object (readonly)
Returns the value of attribute errors.
25 26 27 |
# File 'lib/outback/configuration.rb', line 25 def errors @errors end |
#name ⇒ Object (readonly)
Returns the value of attribute name.
25 26 27 |
# File 'lib/outback/configuration.rb', line 25 def name @name end |
#processors ⇒ Object (readonly)
Returns the value of attribute processors.
25 26 27 |
# File 'lib/outback/configuration.rb', line 25 def processors @processors end |
#sources ⇒ Object (readonly)
Returns the value of attribute sources.
25 26 27 |
# File 'lib/outback/configuration.rb', line 25 def sources @sources end |
#targets ⇒ Object (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
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 |
.loaded ⇒ Object
12 13 14 |
# File 'lib/outback/configuration.rb', line 12 def loaded @loaded end |
.reset ⇒ Object
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 |