Skip to content

Commit

Permalink
moved default location constraint logic from config_loader.rb to endp…
Browse files Browse the repository at this point in the history
…oint.rb
  • Loading branch information
adelevie committed Apr 8, 2013
1 parent ef19f16 commit da35da4
Show file tree
Hide file tree
Showing 4 changed files with 14 additions and 7 deletions.
1 change: 0 additions & 1 deletion lib/jekyll-s3/config_loader.rb
Expand Up @@ -24,7 +24,6 @@ def self.check_s3_configuration(site_dir)
# Raise MalformedConfigurationFileError if the configuration file does not contain the keys we expect # Raise MalformedConfigurationFileError if the configuration file does not contain the keys we expect
def self.load_configuration(site_dir) def self.load_configuration(site_dir)
config = load_yaml_file_and_validate site_dir config = load_yaml_file_and_validate site_dir
config['s3_endpoint'] = config['s3_endpoint'] || 'us-east-1'
return config return config
end end


Expand Down
4 changes: 3 additions & 1 deletion lib/jekyll-s3/endpoint.rb
@@ -1,9 +1,11 @@
module Jekyll module Jekyll
module S3 module S3
class Endpoint class Endpoint
DEFAULT_LOCATION_CONSTRAINT = 'us-east-1'
attr_reader :region, :location_constraint, :hostname, :website_hostname attr_reader :region, :location_constraint, :hostname, :website_hostname


def initialize(location_constraint) def initialize(location_constraint=nil)
location_constraint = DEFAULT_LOCATION_CONSTRAINT if location_constraint.nil?
raise "Invalid S3 location constraint #{location_constraint}" unless raise "Invalid S3 location constraint #{location_constraint}" unless
location_constraints.has_key?location_constraint location_constraints.has_key?location_constraint
@region = location_constraints.fetch(location_constraint)[:region] @region = location_constraints.fetch(location_constraint)[:region]
Expand Down
5 changes: 0 additions & 5 deletions spec/lib/config_loader_spec.rb
Expand Up @@ -8,11 +8,6 @@
config['s3_bucket'].should eq('galaxy') config['s3_bucket'].should eq('galaxy')
end end


it 'uses the "us-east-1" as the default endpoint' do
config = Jekyll::S3::ConfigLoader.load_configuration('spec/sample_files/hyde_site/_site')
config['s3_endpoint'].should eq('us-east-1')
end

it 'reads the S3 endpoint setting from _jekyll_s3.yml' do it 'reads the S3 endpoint setting from _jekyll_s3.yml' do
config = Jekyll::S3::ConfigLoader.load_configuration('spec/sample_files/tokyo_site/_site') config = Jekyll::S3::ConfigLoader.load_configuration('spec/sample_files/tokyo_site/_site')
config['s3_endpoint'].should eq('ap-northeast-1') config['s3_endpoint'].should eq('ap-northeast-1')
Expand Down
11 changes: 11 additions & 0 deletions spec/lib/endpoint_spec.rb
@@ -0,0 +1,11 @@
require 'spec_helper'
require 'pp'

describe Jekyll::S3::Endpoint do

it 'uses the "us-east-1" as the default location' do
endpoint = Jekyll::S3::Endpoint.new
endpoint.location_constraint.should eq(Jekyll::S3::Endpoint::DEFAULT_LOCATION_CONSTRAINT)
end

end

0 comments on commit da35da4

Please sign in to comment.