class Procrastinator::Config

Configuration object (State Pattern) used to coordinate settings across various components within Procrastinator.

It is immutable after init; use the config DSL in the configuration block to set its state.

@author Robin Miller

@!attribute [r] :queues

@return [Array] List of defined queues

@!attribute [r] :container

@return [Object] Container object that will be forwarded to tasks

@!attribute [r] :log_dir

@return [Pathname] Directory to write log files in

@!attribute [r] :log_level

@return [Integer] Logging level to use

@!attribute [r] :log_shift_age

@return [Integer] Number of previous files to keep (see Ruby Logger for details)

@!attribute [r] :log_shift_size

@return [Integer] Filesize before rotating to a new logfile (see Ruby Logger for details)

Constants

DEFAULT_LOG_DIRECTORY

Default directory to keep logs in.

DEFAULT_LOG_FORMATTER

Default log formatter @see Logger

DEFAULT_LOG_SHIFT_AGE

Default age to keep log files for. @see Logger

DEFAULT_LOG_SHIFT_SIZE

Default max size to keep log files under. @see Logger

Attributes

container[R]
log_dir[R]
log_level[R]
log_shift_age[R]
log_shift_size[R]
queues[R]

Public Class Methods

new() { |self| ... } click to toggle source
# File lib/procrastinator/config.rb, line 48
def initialize
   @queues         = []
   @container      = nil
   @log_dir        = DEFAULT_LOG_DIRECTORY
   @log_level      = Logger::INFO
   @log_shift_age  = DEFAULT_LOG_SHIFT_AGE
   @log_shift_size = DEFAULT_LOG_SHIFT_SIZE

   with_store(csv: TaskStore::SimpleCommaStore::DEFAULT_FILE) do
      if block_given?
         yield(self)
         raise SetupError, SetupError::ERR_NO_QUEUE if @queues.empty?
      end
   end

   @log_dir = @log_dir.expand_path

   @queues.freeze
   freeze
end

Public Instance Methods

queue(name: nil) click to toggle source
# File lib/procrastinator/config.rb, line 131
def queue(name: nil)
   queue = if name
              @queues.find do |q|
                 q.name == name
              end
           else
              if name.nil? && @queues.length > 1
                 raise ArgumentError,
                       "queue must be specified when more than one is defined. #{ known_queues }"
              end

              @queues.first
           end

   raise ArgumentError, "there is no :#{ name } queue registered. #{ known_queues }" unless queue

   queue
end

Private Instance Methods

interpret_store(store) click to toggle source
# File lib/procrastinator/config.rb, line 156
def interpret_store(store)
   raise(ArgumentError, 'task store cannot be nil') if store.nil?

   case store
   when Hash
      store_strategy = :csv
      unless store.key? store_strategy
         raise ArgumentError, "Must pass keyword :#{ store_strategy } if specifying a location for CSV file"
      end

      TaskStore::SimpleCommaStore.new(store[store_strategy])
   when String, Pathname
      TaskStore::SimpleCommaStore.new(store)
   else
      store
   end
end
known_queues() click to toggle source
# File lib/procrastinator/config.rb, line 152
def known_queues
   "Known queues are: #{ @queues.map { |queue| ":#{ queue.name }" }.join(', ') }"
end