lib/sitefuel/Configuration.rb in sitefuel-0.0.0b vs lib/sitefuel/Configuration.rb in sitefuel-0.1.0a
- old
+ new
@@ -1,35 +1,71 @@
#
# File:: configuration.rb
# Author:: wkm
-# Copyright:: 2009
-# License:: GPL
+# Copyright:: 2009, Zanoccio LLC.
+# License:: GPL version 2.0 (see LICENSE.rb)
#
# Load and process SiteFuel YAML configuration files
#
module SiteFuel
+ require 'sitefuel/SiteFuelLogger'
require 'yaml'
+ # exception which represents that a configuration could not be found
class Configuration
- # exception which represents that a configuration could not be found
- class NotFound < StandardError
- end
+ include SiteFuel::Logging
+ DEFAULT_CONFIGURATION_FILE = 'deployment.yml'
+
# given a directory path will attempt to location a configuration file
- # and load it, returning a SiteFuel::Configuration class
- def self.load(path)
- unless File.exist?(path)
- throw NotFound, path
+ def self.find_configuration(path, filename = DEFAULT_CONFIGURATION_FILE)
+ files = Dir["**/"+filename]
+
+ if files.length < 0
+ return nil
+ elsif files.length > 1
+ warn("Multiple possible configuration files found: #{files.join(', ')}; using #{files.first}")
+ return files.first
+ else
+ return files.first
end
+ end
- yamlconfig = YAML::load_file(configfile)
-
- Configuration.new(yamlconfig)
+
+ # given a directory path will attempt to find and load a
+ # configuration file
+ def self.load_configuration(runtime, path, filename = DEFAULT_CONFIGURATION_FILE)
+ configuration_file = find_configuration(path, filename)
+
+ if configuration_file == nil
+ warn('No deployment configuration file found. Using defaults.')
+ return Configuration.new(runtime, nil)
+ else
+ yaml = YAML::load_file(configuration_file)
+ return Configuration.new(runtime, yaml)
+ end
end
+
# builds a sitefuel configuration from a parsed YAML file
- def initialize(yamlconfig)
+ def initialize(runtime, yaml_config)
+ @processor_configurations = Hash.new([])
+ @runtime = runtime
+
+ load_yaml_config(yaml_config)
+ end
+
+
+ # loads a yaml configuration
+ def load_yaml_config(yaml_config)
+
+ end
+
+
+ # gives an array of configuration options for the processor
+ def processor_configuration(processor)
+ @processor_configurations[processor]
end
end
end
\ No newline at end of file