class Epi::ConfigurationFile

Attributes

job_descriptions[R]
path[R]

Public Class Methods

new(path) click to toggle source
# File lib/epi/configuration_file.rb, line 14
def initialize(path)
  @job_descriptions = {}
  @path = Pathname path
end

Public Instance Methods

changed?() click to toggle source
# File lib/epi/configuration_file.rb, line 35
def changed?
  Digest::MD5.digest(binread) != @last_digest
end
job(id_and_name, &block) click to toggle source
# File lib/epi/configuration_file.rb, line 39
def job(id_and_name, &block)
  raise InvalidConfigurationFile, 'Improper use of "job"' unless
      Hash === id_and_name &&
      id_and_name.count == 1 &&
      Symbol === id_and_name.keys.first &&
      String === id_and_name.values.first &&
      block.respond_to?(:call) &&
      block.respond_to?(:arity) &&
      block.arity >= 1
  id, name = id_and_name.first
  id = id.to_s
  job_description = @job_descriptions[id] ||= JobDescription.new(id)
  job_description.name = name
  job_description.reconfigure &block
end
logger() click to toggle source
# File lib/epi/configuration_file.rb, line 19
def logger
  Epi.logger
end
read() click to toggle source
# File lib/epi/configuration_file.rb, line 23
def read
  return unless exist? && changed?
  logger.info "Reading configuration file #{path}"
  data = binread
  begin
    instance_eval data, path.to_s
    @last_digest = Digest::MD5.digest(data)
  rescue => error
    raise InvalidConfigurationFile.new("Unhandled exception of type #{error.class.name}", error)
  end
end