Class: Epi::ConfigurationFile
- Inherits:
-
Object
- Object
- Epi::ConfigurationFile
- Extended by:
- Forwardable
- Includes:
- Exceptions
- Defined in:
- lib/epi/configuration_file.rb
Instance Attribute Summary collapse
-
#job_descriptions ⇒ Object
readonly
Returns the value of attribute job_descriptions.
-
#path ⇒ Object
readonly
Returns the value of attribute path.
Instance Method Summary collapse
- #changed? ⇒ Boolean
-
#initialize(path) ⇒ ConfigurationFile
constructor
A new instance of ConfigurationFile.
- #job(id_and_name, &block) ⇒ Object
- #logger ⇒ Object
- #read ⇒ Object
Constructor Details
#initialize(path) ⇒ ConfigurationFile
Returns a new instance of ConfigurationFile.
14 15 16 17 |
# File 'lib/epi/configuration_file.rb', line 14 def initialize(path) @job_descriptions = {} @path = Pathname path end |
Instance Attribute Details
#job_descriptions ⇒ Object (readonly)
Returns the value of attribute job_descriptions.
10 11 12 |
# File 'lib/epi/configuration_file.rb', line 10 def job_descriptions @job_descriptions end |
#path ⇒ Object (readonly)
Returns the value of attribute path.
10 11 12 |
# File 'lib/epi/configuration_file.rb', line 10 def path @path end |
Instance Method Details
#changed? ⇒ Boolean
35 36 37 |
# File 'lib/epi/configuration_file.rb', line 35 def changed? Digest::MD5.digest(binread) != @last_digest end |
#job(id_and_name, &block) ⇒ Object
39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 |
# 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 |
#read ⇒ Object
23 24 25 26 27 28 29 30 31 32 33 |
# 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 |