configure-s3-website 1.2.0 → 1.3.0

Sign up to get free protection for your applications and to get access to all the features.
@@ -1,3 +1,3 @@
1
1
  module ConfigureS3Website
2
- VERSION = '1.2.0'
2
+ VERSION = '1.3.0'
3
3
  end
@@ -0,0 +1,15 @@
1
+ module ConfigureS3Website
2
+ class XmlHelper
3
+ def self.hash_to_api_xml(hash={}, indent=0)
4
+ "".tap do |body|
5
+ hash.each do |key, value|
6
+ key_name = key.sub(/^[a-z\d]*/) { $&.capitalize }.gsub(/(?:_|(\/))([a-z\d]*)/) { $2.capitalize }
7
+ value = value.is_a?(Hash) ? self.hash_to_api_xml(value, indent+1) : value
8
+ body << "\n"
9
+ body << " " * indent * 2 # 2-space indentation formatting for xml
10
+ body << "<#{key_name}>#{value}</#{key_name}>"
11
+ end
12
+ end
13
+ end
14
+ end
15
+ end
@@ -0,0 +1,22 @@
1
+ require 'rspec'
2
+ require 'configure-s3-website'
3
+
4
+ describe ConfigureS3Website::FileConfigSource do
5
+ let(:yaml_file_path) {
6
+ 'spec/sample_files/_config_file_with_eruby.yml'
7
+ }
8
+
9
+ let(:config_source) {
10
+ ConfigureS3Website::FileConfigSource.new(yaml_file_path)
11
+ }
12
+
13
+ it 'can parse files that contain eRuby code' do
14
+ config_source.s3_access_key_id.should eq('hello world')
15
+ config_source.s3_secret_access_key.should eq('secret world')
16
+ config_source.s3_bucket_name.should eq('my-bucket')
17
+ end
18
+
19
+ it 'returns the yaml file path as description' do
20
+ config_source.description.should eq(yaml_file_path)
21
+ end
22
+ end
@@ -23,7 +23,7 @@ describe ConfigureS3Website::S3Client do
23
23
  }
24
24
 
25
25
  it 'calls the S3 api without request body' do
26
- ConfigureS3Website::S3Client.should_receive(:call_s3_api).
26
+ ConfigureS3Website::HttpHelper.should_receive(:call_s3_api).
27
27
  with(anything(), anything(), '', anything())
28
28
  ConfigureS3Website::S3Client.send(:create_bucket,
29
29
  config_source)
@@ -38,7 +38,7 @@ describe ConfigureS3Website::S3Client do
38
38
  }
39
39
 
40
40
  it 'calls the S3 api with location constraint XML' do
41
- ConfigureS3Website::S3Client.should_receive(:call_s3_api).
41
+ ConfigureS3Website::HttpHelper.should_receive(:call_s3_api).
42
42
  with(anything(), anything(),
43
43
  %|
44
44
  <CreateBucketConfiguration xmlns="http://s3.amazonaws.com/doc/2006-03-01/">
@@ -0,0 +1,39 @@
1
+ require 'rspec'
2
+ require 'configure-s3-website'
3
+
4
+ describe ConfigureS3Website::XmlHelper do
5
+ context '#hash_to_api_xml' do
6
+ it 'returns an empty string, if the hash is empty' do
7
+ str = ConfigureS3Website::XmlHelper.send(:hash_to_api_xml,
8
+ { })
9
+ str.should eq('')
10
+ end
11
+
12
+ it 'capitalises hash keys but not values' do
13
+ str = ConfigureS3Website::XmlHelper.send(:hash_to_api_xml,
14
+ { 'key' => 'value' })
15
+ str.should eq("\n<Key>value</Key>")
16
+ end
17
+
18
+ it 'removes underscores and capitalises the following letter' do
19
+ str = ConfigureS3Website::XmlHelper.send(:hash_to_api_xml,
20
+ { 'hello_key' => 'value' })
21
+ str.should eq("\n<HelloKey>value</HelloKey>")
22
+ end
23
+
24
+ it 'can handle hash values as well' do
25
+ str = ConfigureS3Website::XmlHelper.send(:hash_to_api_xml,
26
+ { 'key' => { 'subkey' => 'subvalue' } })
27
+ str.should eq("\n<Key>\n <Subkey>subvalue</Subkey></Key>")
28
+ end
29
+
30
+ it 'indents' do
31
+ str = ConfigureS3Website::XmlHelper.send(
32
+ :hash_to_api_xml,
33
+ { 'key' => { 'subkey' => 'subvalue' } },
34
+ indent = 1
35
+ )
36
+ str.should eq("\n <Key>\n <Subkey>subvalue</Subkey></Key>")
37
+ end
38
+ end
39
+ end
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: configure-s3-website
3
3
  version: !ruby/object:Gem::Version
4
- version: 1.2.0
4
+ version: 1.3.0
5
5
  prerelease:
6
6
  platform: ruby
7
7
  authors:
@@ -9,7 +9,7 @@ authors:
9
9
  autorequire:
10
10
  bindir: bin
11
11
  cert_chain: []
12
- date: 2013-05-05 00:00:00.000000000 Z
12
+ date: 2013-05-20 00:00:00.000000000 Z
13
13
  dependencies:
14
14
  - !ruby/object:Gem::Dependency
15
15
  name: rspec
@@ -142,26 +142,36 @@ files:
142
142
  - features/cassettes/cucumber_tags/bucket-does-not-exist-in-tokyo.yml
143
143
  - features/cassettes/cucumber_tags/bucket-does-not-exist.yml
144
144
  - features/cassettes/cucumber_tags/bucket-exists.yml
145
+ - features/cassettes/cucumber_tags/create-cf-dist.yml
145
146
  - features/cassettes/cucumber_tags/redirects.yml
146
147
  - features/config_file.feature
147
148
  - features/configure_bucket.feature
149
+ - features/create_cloudfront_dist.feature
148
150
  - features/step_definitions/steps.rb
149
151
  - features/support/env.rb
152
+ - features/support/sample_config_files/config_with_cloudfront_distribution_id.yml
153
+ - features/support/sample_config_files/create_cf_dist.yml
150
154
  - features/support/sample_config_files/endpoint_tokyo.yml
151
155
  - features/support/sample_config_files/redirects.yml
152
156
  - features/support/sample_config_files/s3_config_with_existing_bucket.yml
153
157
  - features/support/sample_config_files/s3_config_with_non-existing_bucket.yml
154
158
  - features/support/vcr.rb
155
159
  - lib/configure-s3-website.rb
160
+ - lib/configure-s3-website/cli.rb
161
+ - lib/configure-s3-website/cloudfront_client.rb
156
162
  - lib/configure-s3-website/config_source/config_source.rb
157
163
  - lib/configure-s3-website/config_source/file_config_source.rb
164
+ - lib/configure-s3-website/http_helper.rb
165
+ - lib/configure-s3-website/runner.rb
158
166
  - lib/configure-s3-website/s3_client.rb
159
167
  - lib/configure-s3-website/version.rb
160
- - spec/config_extractor/file_config_extractor_spec.rb
168
+ - lib/configure-s3-website/xml_helper.rb
169
+ - spec/config_source/file_config_source_spec.rb
161
170
  - spec/s3_client_spec.rb
162
171
  - spec/sample_files/_config_file.yml
163
172
  - spec/sample_files/_config_file_oregon.yml
164
173
  - spec/sample_files/_config_file_with_eruby.yml
174
+ - spec/xml_helper_spec.rb
165
175
  homepage: https://github.com/laurilehmijoki/configure-s3-website
166
176
  licenses: []
167
177
  post_install_message:
@@ -176,7 +186,7 @@ required_ruby_version: !ruby/object:Gem::Requirement
176
186
  version: '0'
177
187
  segments:
178
188
  - 0
179
- hash: -1020516680573187683
189
+ hash: -2014890720503017169
180
190
  required_rubygems_version: !ruby/object:Gem::Requirement
181
191
  none: false
182
192
  requirements:
@@ -185,7 +195,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
185
195
  version: '0'
186
196
  segments:
187
197
  - 0
188
- hash: -1020516680573187683
198
+ hash: -2014890720503017169
189
199
  requirements: []
190
200
  rubyforge_project:
191
201
  rubygems_version: 1.8.25
@@ -196,18 +206,23 @@ test_files:
196
206
  - features/cassettes/cucumber_tags/bucket-does-not-exist-in-tokyo.yml
197
207
  - features/cassettes/cucumber_tags/bucket-does-not-exist.yml
198
208
  - features/cassettes/cucumber_tags/bucket-exists.yml
209
+ - features/cassettes/cucumber_tags/create-cf-dist.yml
199
210
  - features/cassettes/cucumber_tags/redirects.yml
200
211
  - features/config_file.feature
201
212
  - features/configure_bucket.feature
213
+ - features/create_cloudfront_dist.feature
202
214
  - features/step_definitions/steps.rb
203
215
  - features/support/env.rb
216
+ - features/support/sample_config_files/config_with_cloudfront_distribution_id.yml
217
+ - features/support/sample_config_files/create_cf_dist.yml
204
218
  - features/support/sample_config_files/endpoint_tokyo.yml
205
219
  - features/support/sample_config_files/redirects.yml
206
220
  - features/support/sample_config_files/s3_config_with_existing_bucket.yml
207
221
  - features/support/sample_config_files/s3_config_with_non-existing_bucket.yml
208
222
  - features/support/vcr.rb
209
- - spec/config_extractor/file_config_extractor_spec.rb
223
+ - spec/config_source/file_config_source_spec.rb
210
224
  - spec/s3_client_spec.rb
211
225
  - spec/sample_files/_config_file.yml
212
226
  - spec/sample_files/_config_file_oregon.yml
213
227
  - spec/sample_files/_config_file_with_eruby.yml
228
+ - spec/xml_helper_spec.rb
@@ -1,11 +0,0 @@
1
- require 'rspec'
2
- require 'configure-s3-website'
3
-
4
- describe ConfigureS3Website::FileConfigSource do
5
- it 'can parse files that contain eRuby code' do
6
- extractor = ConfigureS3Website::FileConfigSource.new('spec/sample_files/_config_file_with_eruby.yml')
7
- extractor.s3_access_key_id.should eq('hello world')
8
- extractor.s3_secret_access_key.should eq('secret world')
9
- extractor.s3_bucket_name.should eq('my-bucket')
10
- end
11
- end