Sha256: 41f86caa74c9df4f821f1566085d2672d15a9456379c77f707b78b03f9e3fe56

Contents?: true

Size: 1.69 KB

Versions: 58

Compression:

Stored size: 1.69 KB

Contents

module S3Website
  class ConfigLoader
    CONFIGURATION_FILE = 's3_website.yml'

    def self.check_project(site_dir)
      raise NoWebsiteDirectoryFound 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.read_configuration_file_template
      path = File.dirname(__FILE__) + '/../../resources/configuration_file_template.yml'
      cfg_template = File.open(path).read
    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(config_file_dir)
      config = load_yaml_file_and_validate config_file_dir
      return config
    end

    def self.create_template_configuration_file(file)
      File.open(file, 'w') { |f|
        f.write(read_configuration_file_template)
      }
    end

    def self.load_yaml_file_and_validate(config_file_dir)
      begin
        config = YAML.load(Erubis::Eruby.new(
          File.read(config_file_dir + '/' + CONFIGURATION_FILE)
        ).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

58 entries across 58 versions & 2 rubygems

Version Path
s3_website-1.8.2 lib/s3_website/config_loader.rb
s3_website-1.8.1 lib/s3_website/config_loader.rb
s3_website-1.8.0 lib/s3_website/config_loader.rb
s3_website_monadic-0.0.15 lib/s3_website/config_loader.rb
s3_website_monadic-0.0.14 lib/s3_website/config_loader.rb
s3_website_monadic-0.0.13 lib/s3_website/config_loader.rb
s3_website_monadic-0.0.12 lib/s3_website/config_loader.rb
s3_website_monadic-0.0.11 lib/s3_website/config_loader.rb
s3_website_monadic-0.0.9 lib/s3_website/config_loader.rb
s3_website_monadic-0.0.8 lib/s3_website/config_loader.rb
s3_website_monadic-0.0.7 lib/s3_website/config_loader.rb
s3_website_monadic-0.0.6 lib/s3_website/config_loader.rb
s3_website_monadic-0.0.5 lib/s3_website/config_loader.rb
s3_website-1.7.6 lib/s3_website/config_loader.rb
s3_website_monadic-0.0.4 lib/s3_website/config_loader.rb
s3_website_monadic-0.0.3 lib/s3_website/config_loader.rb
s3_website-1.7.5 lib/s3_website/config_loader.rb
s3_website_monadic-0.0.2 lib/s3_website/config_loader.rb
s3_website_monadic-0.0.1 lib/s3_website/config_loader.rb
s3_website-1.7.4 lib/s3_website/config_loader.rb