Sha256: 8971e1ca67986a7bda6014e876178905648496bbcf0dd59ca167f4edc2b56a20
Contents?: true
Size: 1.71 KB
Versions: 2
Compression:
Stored size: 1.71 KB
Contents
module S3Website class ConfigLoader CONFIGURATION_FILE = 's3_website.yml' CONFIGURATION_FILE_TEMPLATE = <<-EOF s3_id: YOUR_AWS_S3_ACCESS_KEY_ID s3_secret: YOUR_AWS_S3_SECRET_ACCESS_KEY s3_bucket: your.blog.bucket.com EOF def self.check_project(site_dir) raise NotAJekyllProjectError unless File.directory?(site_dir) end # Raise NoConfigurationFileError if the configuration file does not exists def self.check_s3_configuration(dir) config_file = dir + '/' + CONFIGURATION_FILE unless File.exists?(config_file) create_template_configuration_file config_file raise NoConfigurationFileError end end def self.get_configuration_file(site_dir) "#{site_dir}/../#{CONFIGURATION_FILE}" end private # Load configuration from s3_website.yml # Raise MalformedConfigurationFileError if the configuration file does not contain the keys we expect def self.load_configuration(site_dir) config = load_yaml_file_and_validate site_dir return config end def self.create_template_configuration_file(file) File.open(file, 'w') { |f| f.write(CONFIGURATION_FILE_TEMPLATE) } end def self.load_yaml_file_and_validate(site_dir) begin config = YAML.load(Erubis::Eruby.new(File.read(get_configuration_file(site_dir))).result) rescue Exception raise MalformedConfigurationFileError end raise MalformedConfigurationFileError unless config raise MalformedConfigurationFileError if ['s3_bucket'].any? { |key| mandatory_config_value = config[key] mandatory_config_value.nil? || mandatory_config_value == '' } config end end end
Version data entries
2 entries across 2 versions & 1 rubygems
Version | Path |
---|---|
s3_website-0.2.1 | lib/s3_website/config_loader.rb |
s3_website-0.2.0 | lib/s3_website/config_loader.rb |