middleman-s3_sync 3.0.30 → 3.0.31

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: 9eec69a71b3cb5ba6681a2ea6a08e72cc79abfb1
4
- data.tar.gz: 364925a716f0eb16908f79757d6802ed45e1bcf2
3
+ metadata.gz: 5f431194b1a96375b88da5f61aae633e9281bd3b
4
+ data.tar.gz: 1ee6ebd0ff9c2c793917db1caa3f44fc3d00e3bd
5
5
  SHA512:
6
- metadata.gz: 8648165f7f064c871eacd58d08d255f139628d462b93a0de525583586d991f993f1d0529c3d20da9475c114c64ea2ea42f0a1c90d98addb2cd70fd4510d4a77f
7
- data.tar.gz: a47176aa6031d12cafbaf911bfb1e50bfcd1efa6594f2a0cfda60df6dd4d5d5e163e55717e8b14d144bab0ad60acb085ea9f40813e1039187b0de484061d5a88
6
+ metadata.gz: 37ec664a5db9d9225ab9634a1a481f0e248926ee247a0c5f0a1b653737edd1b900865de2830c2f0db1356d8d9763022663b38574b8d4f2514ec81c4a833c698d
7
+ data.tar.gz: f6088910de0c27cd4b60ea18579709bbe0c56c45d75be7fb701e2f67d4da80246c077605c2afa74faf88b79097de1064a1c16004584bcc1b85d4ad016040782c
@@ -4,14 +4,18 @@ require 'map'
4
4
  module Middleman
5
5
  module S3Sync
6
6
  class << self
7
+ attr_accessor :options
8
+
7
9
  def registered(app, options_hash = {}, &block)
8
10
  options = Options.new
9
11
  yield options if block_given?
10
12
 
11
- @@options = options
13
+ @options = options
12
14
 
13
15
  app.send :include, Helpers
14
16
 
17
+ app.define_hook :after_s3_sync
18
+
15
19
  app.after_configuration do |config|
16
20
 
17
21
  # Define the after_build step after during configuration so
@@ -26,7 +30,7 @@ module Middleman
26
30
  alias :included :registered
27
31
 
28
32
  def s3_sync_options
29
- @@options
33
+ @options
30
34
  end
31
35
 
32
36
  module Helpers
@@ -15,6 +15,8 @@ module Middleman
15
15
  include Status
16
16
 
17
17
  def sync
18
+ @app = ::Middleman::Application.server.inst
19
+
18
20
  unless work_to_be_done?
19
21
  say_status "\nAll S3 files are up to date."
20
22
  return
@@ -28,6 +30,11 @@ module Middleman
28
30
  create_resources
29
31
  update_resources
30
32
  delete_resources
33
+
34
+ @app.run_hook :after_s3_sync, ignored: files_to_ignore.map(&:path),
35
+ created: files_to_create.map(&:path),
36
+ updated: files_to_update.map(&:path),
37
+ deleted: files_to_delete.map(&:path)
31
38
  end
32
39
 
33
40
  def bucket
@@ -1,7 +1,7 @@
1
1
  module Middleman
2
2
  module S3Sync
3
3
  class Options
4
- attr_accessor \
4
+ OPTIONS = [
5
5
  :prefix,
6
6
  :acl,
7
7
  :bucket,
@@ -19,6 +19,8 @@ module Middleman
19
19
  :path_style,
20
20
  :version_bucket,
21
21
  :verbose
22
+ ]
23
+ attr_accessor *OPTIONS
22
24
 
23
25
  def initialize
24
26
  # read config from .s3_sync on initialization
@@ -105,10 +107,11 @@ module Middleman
105
107
  io = File.open(config_file_path, "r")
106
108
  end
107
109
 
108
- config = YAML.load(io)
110
+ config = YAML.load(io).symbolize_keys
109
111
 
110
- self.aws_access_key_id = config["aws_access_key_id"] if config["aws_access_key_id"]
111
- self.aws_secret_access_key = config["aws_secret_access_key"] if config["aws_secret_access_key"]
112
+ OPTIONS.each do |config_option|
113
+ self.send("#{config_option}=".to_sym, config[config_option]) if config[config_option]
114
+ end
112
115
  end
113
116
 
114
117
  protected
@@ -1,24 +1,24 @@
1
1
  module Middleman
2
2
  module S3Sync
3
3
  class Resource
4
- attr_accessor :path, :partial_s3_resource, :content_type, :gzipped
4
+ attr_accessor :path, :partial_s3_resource, :full_s3_resource, :content_type, :gzipped, :options
5
5
 
6
6
  CONTENT_MD5_KEY = 'x-amz-meta-content-md5'
7
7
 
8
8
  include Status
9
9
 
10
+ def initialize(path, partial_s3_resource)
11
+ @path = path
12
+ @partial_s3_resource = partial_s3_resource
13
+ end
14
+
10
15
  def s3_resource
11
16
  @full_s3_resource || @partial_s3_resource
12
17
  end
13
18
 
14
19
  # S3 resource as returned by a HEAD request
15
20
  def full_s3_resource
16
- @full_s3_resource ||= bucket.files.head("#{options.prefix}#{path}")
17
- end
18
-
19
- def initialize(path, partial_s3_resource)
20
- @path = path
21
- @partial_s3_resource = partial_s3_resource
21
+ @full_s3_resource ||= bucket.files.head(remote_path)
22
22
  end
23
23
 
24
24
  def remote_path
@@ -122,10 +122,10 @@ module Middleman
122
122
  :redirect
123
123
  elsif directory?
124
124
  :directory
125
- elsif alternate_encoding?
126
- 'alternate encoding'
127
125
  end
128
- say_status "Ignoring".yellow + " #{remote_path} #{ reason ? "(#{reason})".white : "" }"
126
+ unless alternate_encoding?
127
+ say_status "Ignoring".yellow + " #{remote_path} #{ reason ? "(#{reason})".white : "" }"
128
+ end
129
129
  end
130
130
 
131
131
  def to_delete?
@@ -196,7 +196,7 @@ module Middleman
196
196
  end
197
197
 
198
198
  def remote?
199
- s3_resource
199
+ !!s3_resource
200
200
  end
201
201
 
202
202
  def redirect?
@@ -253,7 +253,7 @@ module Middleman
253
253
  end
254
254
 
255
255
  def options
256
- Middleman::S3Sync.s3_sync_options
256
+ @options || Middleman::S3Sync.s3_sync_options
257
257
  end
258
258
  end
259
259
  end
@@ -1,5 +1,5 @@
1
1
  module Middleman
2
2
  module S3Sync
3
- VERSION = "3.0.30"
3
+ VERSION = "3.0.31"
4
4
  end
5
5
  end
data/spec/options_spec.rb CHANGED
@@ -105,7 +105,8 @@ describe Middleman::S3Sync::Options do
105
105
  context "#read_config" do
106
106
  let(:aws_access_key_id) { "foo" }
107
107
  let(:aws_secret_access_key) { "bar" }
108
- let(:config) { { "aws_access_key_id" => aws_access_key_id, "aws_secret_access_key" => aws_secret_access_key } }
108
+ let(:bucket) { "baz" }
109
+ let(:config) { { "aws_access_key_id" => aws_access_key_id, "aws_secret_access_key" => aws_secret_access_key, "bucket" => bucket } }
109
110
  let(:file) { StringIO.new(YAML.dump(config)) }
110
111
 
111
112
  before do
@@ -114,5 +115,6 @@ describe Middleman::S3Sync::Options do
114
115
 
115
116
  its(:aws_access_key_id) { should eq(aws_access_key_id) }
116
117
  its(:aws_secret_access_key) { should eq(aws_secret_access_key) }
118
+ its(:bucket) { should eq(bucket) }
117
119
  end
118
120
  end
@@ -2,4 +2,148 @@ require 'spec_helper'
2
2
 
3
3
  describe Middleman::S3Sync::Resource do
4
4
 
5
+ let(:options) {
6
+ Middleman::S3Sync::Options.new
7
+ }
8
+
9
+ before do
10
+ Middleman::S3Sync.options = options
11
+ options.build_dir = "build"
12
+ options.prefer_gzip = false
13
+ end
14
+
15
+ context "a new resource" do
16
+ subject(:resource) { Middleman::S3Sync::Resource.new('path/to/resource.html', nil) }
17
+
18
+ context "without a prefix" do
19
+ before do
20
+ allow(File).to receive(:exist?).with('build/path/to/resource.html').and_return(true)
21
+ end
22
+
23
+ its(:status) { should eq :new }
24
+
25
+ it "does not have a remote equivalend" do
26
+ expect(resource).not_to be_remote
27
+ end
28
+
29
+ it "exits locally" do
30
+ expect(resource).to be_local
31
+ end
32
+
33
+ its(:path) { should eq 'path/to/resource.html'}
34
+ its(:local_path) { should eq 'build/path/to/resource.html' }
35
+ its(:remote_path) { should eq 'path/to/resource.html' }
36
+ end
37
+
38
+ context "with a prefix set" do
39
+ before do
40
+ allow(File).to receive(:exist?).with('build/path/to/resource.html').and_return(true)
41
+ options.prefix = "bob"
42
+ end
43
+
44
+ it "does not have a remote equivalent" do
45
+ expect(resource).not_to be_remote
46
+ end
47
+
48
+ it "exists locally" do
49
+ expect(resource).to be_local
50
+ end
51
+
52
+ its(:path) { should eq 'path/to/resource.html' }
53
+ its(:local_path) { should eq 'build/path/to/resource.html' }
54
+ its(:remote_path) { should eq 'bob/path/to/resource.html' }
55
+ end
56
+
57
+ context "gzipped" do
58
+ before do
59
+ allow(File).to receive(:exist?).with('build/path/to/resource.html.gz').and_return(true)
60
+ options.prefer_gzip = true
61
+ end
62
+
63
+ it "does not have a remote equivalent" do
64
+ expect(resource).not_to be_remote
65
+ end
66
+
67
+ it "exists locally" do
68
+ expect(resource).to be_local
69
+ end
70
+
71
+ its(:path) { should eq 'path/to/resource.html' }
72
+ its(:local_path) { should eq 'build/path/to/resource.html.gz' }
73
+ its(:remote_path) { should eq 'path/to/resource.html' }
74
+ end
75
+ end
76
+
77
+ context "the file does not exist locally" do
78
+ subject(:resource) { Middleman::S3Sync::Resource.new('path/to/resource.html', remote) }
79
+
80
+ let(:remote) { double("remote") }
81
+
82
+ before do
83
+ allow(remote).to receive(:key).and_return('path/to/resource.html')
84
+ allow(remote).to receive(:metadata).and_return({})
85
+ resource.full_s3_resource = remote
86
+ end
87
+
88
+ context "without a prefix" do
89
+ before do
90
+ allow(File).to receive(:exist?).with('build/path/to/resource.html').and_return(false)
91
+ end
92
+
93
+ its(:status) { should eq :deleted }
94
+ it "does not have a remote equivalent" do
95
+ expect(resource).to be_remote
96
+ end
97
+
98
+ it "exits locally" do
99
+ expect(resource).not_to be_local
100
+ end
101
+
102
+ its(:path) { should eq 'path/to/resource.html'}
103
+ its(:local_path) { should eq 'build/path/to/resource.html' }
104
+ its(:remote_path) { should eq 'path/to/resource.html' }
105
+ end
106
+
107
+ context "with a prefix set" do
108
+ before do
109
+ allow(File).to receive(:exist?).with('build/path/to/resource.html').and_return(false)
110
+ allow(remote).to receive(:key).and_return('bob/path/to/resource.html')
111
+ options.prefix = "bob"
112
+ end
113
+
114
+ its(:status) { should eq :deleted }
115
+ it "does not have a remote equivalent" do
116
+ expect(resource).to be_remote
117
+ end
118
+
119
+ it "exists locally" do
120
+ expect(resource).not_to be_local
121
+ end
122
+
123
+ its(:path) { should eq 'path/to/resource.html' }
124
+ its(:local_path) { should eq 'build/path/to/resource.html' }
125
+ its(:remote_path) { should eq 'bob/path/to/resource.html' }
126
+ end
127
+
128
+ context "gzipped" do
129
+ before do
130
+ allow(File).to receive(:exist?).with('build/path/to/resource.html.gz').and_return(false)
131
+ allow(File).to receive(:exist?).with('build/path/to/resource.html').and_return(false)
132
+ options.prefer_gzip = true
133
+ end
134
+
135
+ its(:status) { should eq :deleted }
136
+ it "does not have a remote equivalent" do
137
+ expect(resource).to be_remote
138
+ end
139
+
140
+ it "exists locally" do
141
+ expect(resource).not_to be_local
142
+ end
143
+
144
+ its(:path) { should eq 'path/to/resource.html' }
145
+ its(:local_path) { should eq 'build/path/to/resource.html' }
146
+ its(:remote_path) { should eq 'path/to/resource.html' }
147
+ end
148
+ end
5
149
  end
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: middleman-s3_sync
3
3
  version: !ruby/object:Gem::Version
4
- version: 3.0.30
4
+ version: 3.0.31
5
5
  platform: ruby
6
6
  authors:
7
7
  - Frederic Jean
@@ -9,7 +9,7 @@ authors:
9
9
  autorequire:
10
10
  bindir: bin
11
11
  cert_chain: []
12
- date: 2014-06-20 00:00:00.000000000 Z
12
+ date: 2014-07-30 00:00:00.000000000 Z
13
13
  dependencies:
14
14
  - !ruby/object:Gem::Dependency
15
15
  name: middleman-core