asset_sync 0.2.3 → 0.2.4
Sign up to get free protection for your applications and to get access to all the features.
- data/asset_sync.gemspec +1 -1
- data/lib/asset_sync/config.rb +3 -3
- data/lib/asset_sync/storage.rb +7 -7
- data/lib/asset_sync/version.rb +1 -1
- data/spec/asset_sync_spec.rb +111 -123
- data/spec/rackspace_spec.rb +67 -68
- data/spec/spec_helper.rb +22 -11
- metadata +2 -2
data/asset_sync.gemspec
CHANGED
@@ -6,7 +6,7 @@ require "asset_sync/version"
|
|
6
6
|
Gem::Specification.new do |s|
|
7
7
|
s.name = "asset_sync"
|
8
8
|
s.version = AssetSync::VERSION
|
9
|
-
s.date = "
|
9
|
+
s.date = "2012-01-06"
|
10
10
|
s.platform = Gem::Platform::RUBY
|
11
11
|
s.authors = ["Simon Hamilton", "David Rice", "Phil McClure"]
|
12
12
|
s.email = ["shamilton@rumblelabs.com", "me@davidjrice.co.uk", "pmcclure@rumblelabs.com"]
|
data/lib/asset_sync/config.rb
CHANGED
@@ -41,7 +41,7 @@ module AssetSync
|
|
41
41
|
end
|
42
42
|
|
43
43
|
def manifest_path
|
44
|
-
default = File.join(Rails.root, 'public',
|
44
|
+
default = File.join(Rails.root, 'public', Rails.application.config.assets.prefix, 'manifest.yml')
|
45
45
|
Rails.application.config.assets.manifest || default
|
46
46
|
end
|
47
47
|
|
@@ -56,7 +56,7 @@ module AssetSync
|
|
56
56
|
def aws?
|
57
57
|
fog_provider == 'AWS'
|
58
58
|
end
|
59
|
-
|
59
|
+
|
60
60
|
def fail_silently?
|
61
61
|
fail_silently == true
|
62
62
|
end
|
@@ -90,7 +90,7 @@ module AssetSync
|
|
90
90
|
self.gzip_compression = yml["gzip_compression"] if yml.has_key?("gzip_compression")
|
91
91
|
self.manifest = yml["manifest"] if yml.has_key?("manifest")
|
92
92
|
self.fail_silently = yml["fail_silently"] if yml.has_key?("fail_silently")
|
93
|
-
|
93
|
+
|
94
94
|
# TODO deprecate the other old style config settings. FML.
|
95
95
|
self.aws_access_key_id = yml["aws_access_key"] if yml.has_key?("aws_access_key")
|
96
96
|
self.aws_secret_access_key = yml["aws_access_secret"] if yml.has_key?("aws_access_secret")
|
data/lib/asset_sync/storage.rb
CHANGED
@@ -15,7 +15,7 @@ module AssetSync
|
|
15
15
|
|
16
16
|
def bucket
|
17
17
|
# fixes: https://github.com/rumblelabs/asset_sync/issues/18
|
18
|
-
@bucket ||= connection.directories.get(self.config.fog_directory, :prefix =>
|
18
|
+
@bucket ||= connection.directories.get(self.config.fog_directory, :prefix => Rails.application.config.assets.prefix)
|
19
19
|
end
|
20
20
|
|
21
21
|
def keep_existing_remote_files?
|
@@ -27,7 +27,7 @@ module AssetSync
|
|
27
27
|
end
|
28
28
|
|
29
29
|
def local_files
|
30
|
-
@local_files ||= get_local_files
|
30
|
+
@local_files ||= get_local_files
|
31
31
|
end
|
32
32
|
|
33
33
|
def get_local_files
|
@@ -35,14 +35,14 @@ module AssetSync
|
|
35
35
|
if File.exists?(self.config.manifest_path)
|
36
36
|
yml = YAML.load(IO.read(self.config.manifest_path))
|
37
37
|
STDERR.puts "Using: Manifest #{self.config.manifest_path}"
|
38
|
-
return yml.values.map { |f| File.join(
|
38
|
+
return yml.values.map { |f| File.join(Rails.application.config.assets.prefix, f) }
|
39
39
|
else
|
40
40
|
STDERR.puts "Warning: manifest.yml not found at #{self.config.manifest_path}"
|
41
41
|
end
|
42
42
|
end
|
43
|
-
STDERR.puts "Using: Directory Search of #{path}
|
44
|
-
Dir["#{path}
|
45
|
-
end
|
43
|
+
STDERR.puts "Using: Directory Search of #{path}/#{Rails.application.config.assets.prefix}"
|
44
|
+
Dir["#{path}/#{Rails.application.config.assets.prefix}/**/**"].map { |f| f[path.length+1,f.length-path.length] }
|
45
|
+
end
|
46
46
|
|
47
47
|
def get_remote_files
|
48
48
|
raise BucketNotFound.new("#{self.config.fog_provider} Bucket: #{self.config.fog_directory} not found.") unless bucket
|
@@ -65,7 +65,7 @@ module AssetSync
|
|
65
65
|
remote_files = get_remote_files
|
66
66
|
# fixes: https://github.com/rumblelabs/asset_sync/issues/19
|
67
67
|
from_remote_files_to_delete = remote_files - local_files
|
68
|
-
|
68
|
+
|
69
69
|
STDERR.puts "Flagging #{from_remote_files_to_delete.size} file(s) for deletion"
|
70
70
|
# Delete unneeded remote files
|
71
71
|
bucket.files.each do |f|
|
data/lib/asset_sync/version.rb
CHANGED
data/spec/asset_sync_spec.rb
CHANGED
@@ -1,162 +1,150 @@
|
|
1
1
|
require File.dirname(__FILE__) + '/spec_helper'
|
2
2
|
|
3
|
-
|
4
|
-
|
5
|
-
|
6
|
-
|
7
|
-
|
8
|
-
|
9
|
-
|
10
|
-
|
11
|
-
|
12
|
-
|
13
|
-
|
14
|
-
|
15
|
-
|
3
|
+
describe AssetSync do
|
4
|
+
include_context "mock Rails without_yml"
|
5
|
+
|
6
|
+
describe 'with initializer' do
|
7
|
+
before(:each) do
|
8
|
+
AssetSync.config = AssetSync::Config.new
|
9
|
+
AssetSync.configure do |config|
|
10
|
+
config.fog_provider = 'AWS'
|
11
|
+
config.aws_access_key_id = 'aaaa'
|
12
|
+
config.aws_secret_access_key = 'bbbb'
|
13
|
+
config.fog_directory = 'mybucket'
|
14
|
+
config.fog_region = 'eu-west-1'
|
15
|
+
config.existing_remote_files = "keep"
|
16
|
+
end
|
16
17
|
end
|
17
|
-
end
|
18
18
|
|
19
|
-
|
20
|
-
|
21
|
-
|
22
|
-
|
19
|
+
it "should configure provider as AWS" do
|
20
|
+
AssetSync.config.fog_provider.should == 'AWS'
|
21
|
+
AssetSync.config.should be_aws
|
22
|
+
end
|
23
23
|
|
24
|
-
|
25
|
-
|
26
|
-
|
24
|
+
it "should should keep existing remote files" do
|
25
|
+
AssetSync.config.existing_remote_files?.should == true
|
26
|
+
end
|
27
27
|
|
28
|
-
|
29
|
-
|
30
|
-
|
28
|
+
it "should configure aws_access_key" do
|
29
|
+
AssetSync.config.aws_access_key_id.should == "aaaa"
|
30
|
+
end
|
31
31
|
|
32
|
-
|
33
|
-
|
34
|
-
|
32
|
+
it "should configure aws_access_key" do
|
33
|
+
AssetSync.config.aws_secret_access_key.should == "bbbb"
|
34
|
+
end
|
35
35
|
|
36
|
-
|
37
|
-
|
38
|
-
|
36
|
+
it "should configure aws_access_key" do
|
37
|
+
AssetSync.config.fog_directory.should == "mybucket"
|
38
|
+
end
|
39
39
|
|
40
|
-
|
41
|
-
|
42
|
-
|
40
|
+
it "should configure aws_access_key" do
|
41
|
+
AssetSync.config.fog_region.should == "eu-west-1"
|
42
|
+
end
|
43
43
|
|
44
|
-
|
45
|
-
|
46
|
-
|
44
|
+
it "should configure aws_access_key" do
|
45
|
+
AssetSync.config.existing_remote_files.should == "keep"
|
46
|
+
end
|
47
47
|
|
48
|
-
|
49
|
-
|
50
|
-
|
48
|
+
it "should default gzip_compression to false" do
|
49
|
+
AssetSync.config.gzip_compression.should be_false
|
50
|
+
end
|
51
51
|
|
52
|
-
|
53
|
-
|
52
|
+
it "should default manifest to false" do
|
53
|
+
AssetSync.config.manifest.should be_false
|
54
|
+
end
|
54
55
|
end
|
55
56
|
|
56
|
-
|
57
|
-
|
58
|
-
|
59
|
-
|
60
|
-
|
61
|
-
before(:all) do
|
62
|
-
Rails.root = 'aws_with_yml'
|
63
|
-
AssetSync.config = AssetSync::Config.new
|
64
|
-
end
|
57
|
+
describe 'from yml' do
|
58
|
+
before(:each) do
|
59
|
+
set_rails_root('aws_with_yml')
|
60
|
+
AssetSync.config = AssetSync::Config.new
|
61
|
+
end
|
65
62
|
|
66
|
-
|
67
|
-
|
68
|
-
|
63
|
+
it "should configure aws_access_key_id" do
|
64
|
+
AssetSync.config.aws_access_key_id.should == "xxxx"
|
65
|
+
end
|
69
66
|
|
70
|
-
|
71
|
-
|
72
|
-
|
67
|
+
it "should configure aws_secret_access_key" do
|
68
|
+
AssetSync.config.aws_secret_access_key.should == "zzzz"
|
69
|
+
end
|
73
70
|
|
74
|
-
|
75
|
-
|
76
|
-
|
71
|
+
it "should configure aws_access_key" do
|
72
|
+
AssetSync.config.fog_directory.should == "rails_app_test"
|
73
|
+
end
|
77
74
|
|
78
|
-
|
79
|
-
|
80
|
-
|
75
|
+
it "should configure aws_access_key" do
|
76
|
+
AssetSync.config.fog_region.should == "eu-west-1"
|
77
|
+
end
|
81
78
|
|
82
|
-
|
83
|
-
|
84
|
-
|
79
|
+
it "should configure aws_access_key" do
|
80
|
+
AssetSync.config.existing_remote_files.should == "keep"
|
81
|
+
end
|
85
82
|
|
86
|
-
|
87
|
-
|
88
|
-
|
83
|
+
it "should default gzip_compression to false" do
|
84
|
+
AssetSync.config.gzip_compression.should be_false
|
85
|
+
end
|
89
86
|
|
90
|
-
|
91
|
-
|
87
|
+
it "should default manifest to false" do
|
88
|
+
AssetSync.config.manifest.should be_false
|
89
|
+
end
|
92
90
|
end
|
93
|
-
|
94
|
-
end
|
95
91
|
|
96
|
-
describe
|
97
|
-
|
98
|
-
|
99
|
-
|
100
|
-
AssetSync.config = AssetSync::Config.new
|
101
|
-
end
|
92
|
+
describe 'with no configuration' do
|
93
|
+
before(:each) do
|
94
|
+
AssetSync.config = AssetSync::Config.new
|
95
|
+
end
|
102
96
|
|
103
|
-
|
104
|
-
|
97
|
+
it "should be invalid" do
|
98
|
+
lambda{ AssetSync.sync }.should raise_error(AssetSync::Config::Invalid)
|
99
|
+
end
|
105
100
|
end
|
106
101
|
|
107
|
-
|
108
|
-
|
109
|
-
|
110
|
-
|
111
|
-
|
112
|
-
|
113
|
-
AssetSync.config = AssetSync::Config.new
|
114
|
-
AssetSync.configure do |config|
|
115
|
-
config.fail_silently = true
|
102
|
+
describe 'with fail_silent configuration' do
|
103
|
+
before(:each) do
|
104
|
+
AssetSync.config = AssetSync::Config.new
|
105
|
+
AssetSync.configure do |config|
|
106
|
+
config.fail_silently = true
|
107
|
+
end
|
116
108
|
end
|
117
|
-
end
|
118
109
|
|
119
|
-
|
120
|
-
|
110
|
+
it "should not raise an invalid exception" do
|
111
|
+
lambda{ AssetSync.sync }.should_not raise_error(AssetSync::Config::Invalid)
|
112
|
+
end
|
121
113
|
end
|
122
114
|
|
123
|
-
|
124
|
-
|
125
|
-
|
126
|
-
|
127
|
-
|
128
|
-
Rails.root = 'without_yml'
|
129
|
-
AssetSync.config = AssetSync::Config.new
|
130
|
-
AssetSync.config.gzip_compression = true
|
131
|
-
end
|
115
|
+
describe 'with gzip_compression enabled' do
|
116
|
+
before(:each) do
|
117
|
+
AssetSync.config = AssetSync::Config.new
|
118
|
+
AssetSync.config.gzip_compression = true
|
119
|
+
end
|
132
120
|
|
133
|
-
|
134
|
-
|
121
|
+
it "config.gzip? should be true" do
|
122
|
+
AssetSync.config.gzip?.should be_true
|
123
|
+
end
|
135
124
|
end
|
136
125
|
|
137
|
-
|
138
|
-
|
139
|
-
|
126
|
+
describe 'with manifest enabled' do
|
127
|
+
before(:each) do
|
128
|
+
AssetSync.config = AssetSync::Config.new
|
129
|
+
AssetSync.config.manifest = true
|
130
|
+
end
|
140
131
|
|
141
|
-
|
142
|
-
|
143
|
-
|
144
|
-
AssetSync.config.manifest = true
|
145
|
-
end
|
132
|
+
it "config.manifest should be true" do
|
133
|
+
AssetSync.config.manifest.should be_true
|
134
|
+
end
|
146
135
|
|
147
|
-
|
148
|
-
|
149
|
-
|
136
|
+
it "config.manifest_path should default to public/assets.." do
|
137
|
+
AssetSync.config.manifest_path.should =~ /public\/assets\/manifest.yml/
|
138
|
+
end
|
150
139
|
|
151
|
-
|
152
|
-
|
153
|
-
|
154
|
-
|
140
|
+
it "config.manifest_path should default to public/assets.." do
|
141
|
+
Rails.application.config.assets.manifest = "/var/assets/manifest.yml"
|
142
|
+
AssetSync.config.manifest_path.should == "/var/assets/manifest.yml"
|
143
|
+
end
|
155
144
|
|
156
|
-
|
157
|
-
|
158
|
-
|
159
|
-
|
145
|
+
it "config.manifest_path should default to public/custom_assets.." do
|
146
|
+
Rails.application.config.assets.prefix = 'custom_assets'
|
147
|
+
AssetSync.config.manifest_path.should =~ /public\/custom_assets\/manifest.yml/
|
148
|
+
end
|
160
149
|
end
|
161
|
-
|
162
150
|
end
|
data/spec/rackspace_spec.rb
CHANGED
@@ -1,91 +1,90 @@
|
|
1
1
|
require File.dirname(__FILE__) + '/spec_helper'
|
2
2
|
|
3
|
+
describe AssetSync do
|
4
|
+
include_context "mock Rails"
|
5
|
+
|
6
|
+
describe 'using Rackspace with initializer' do
|
7
|
+
before(:each) do
|
8
|
+
set_rails_root('without_yml')
|
9
|
+
AssetSync.config = AssetSync::Config.new
|
10
|
+
AssetSync.configure do |config|
|
11
|
+
config.fog_provider = 'Rackspace'
|
12
|
+
config.fog_directory = 'mybucket'
|
13
|
+
config.fog_region = 'dunno'
|
14
|
+
config.rackspace_username = 'aaaa'
|
15
|
+
config.rackspace_api_key = 'bbbb'
|
16
|
+
config.existing_remote_files = 'keep'
|
17
|
+
end
|
18
|
+
end
|
3
19
|
|
4
|
-
|
5
|
-
|
6
|
-
|
7
|
-
Rails.root = 'without_yml'
|
8
|
-
AssetSync.config = AssetSync::Config.new
|
9
|
-
AssetSync.configure do |config|
|
10
|
-
config.fog_provider = 'Rackspace'
|
11
|
-
config.fog_directory = 'mybucket'
|
12
|
-
config.fog_region = 'dunno'
|
13
|
-
config.rackspace_username = 'aaaa'
|
14
|
-
config.rackspace_api_key = 'bbbb'
|
15
|
-
config.existing_remote_files = 'keep'
|
20
|
+
it "should configure provider as Rackspace" do
|
21
|
+
AssetSync.config.fog_provider.should == 'Rackspace'
|
22
|
+
AssetSync.config.should be_rackspace
|
16
23
|
end
|
17
|
-
end
|
18
24
|
|
19
|
-
|
20
|
-
|
21
|
-
|
22
|
-
end
|
25
|
+
it "should keep existing remote files" do
|
26
|
+
AssetSync.config.existing_remote_files?.should == true
|
27
|
+
end
|
23
28
|
|
24
|
-
|
25
|
-
|
26
|
-
|
29
|
+
it "should configure rackspace_username" do
|
30
|
+
AssetSync.config.rackspace_username.should == "aaaa"
|
31
|
+
end
|
27
32
|
|
28
|
-
|
29
|
-
|
30
|
-
|
33
|
+
it "should configure rackspace_api_key" do
|
34
|
+
AssetSync.config.rackspace_api_key.should == "bbbb"
|
35
|
+
end
|
31
36
|
|
32
|
-
|
33
|
-
|
34
|
-
|
37
|
+
it "should configure fog_directory" do
|
38
|
+
AssetSync.config.fog_directory.should == "mybucket"
|
39
|
+
end
|
35
40
|
|
36
|
-
|
37
|
-
|
38
|
-
|
41
|
+
it "should configure fog_region" do
|
42
|
+
AssetSync.config.fog_region.should == "dunno"
|
43
|
+
end
|
39
44
|
|
40
|
-
|
41
|
-
|
42
|
-
|
45
|
+
it "should configure existing_remote_files" do
|
46
|
+
AssetSync.config.existing_remote_files.should == "keep"
|
47
|
+
end
|
43
48
|
|
44
|
-
|
45
|
-
|
46
|
-
|
49
|
+
it "should configure existing_remote_files" do
|
50
|
+
AssetSync.config.existing_remote_files.should == "keep"
|
51
|
+
end
|
47
52
|
|
48
|
-
|
49
|
-
|
50
|
-
|
53
|
+
it "should default rackspace_auth_url to false" do
|
54
|
+
AssetSync.config.rackspace_auth_url.should be_false
|
55
|
+
end
|
51
56
|
|
52
|
-
it "should default rackspace_auth_url to false" do
|
53
|
-
AssetSync.config.rackspace_auth_url.should be_false
|
54
57
|
end
|
55
58
|
|
56
|
-
|
57
|
-
|
58
|
-
|
59
|
-
describe AssetSync, 'using Rackspace from yml' do
|
59
|
+
describe 'using Rackspace from yml' do
|
60
60
|
|
61
|
-
|
62
|
-
|
63
|
-
|
64
|
-
|
61
|
+
before(:each) do
|
62
|
+
set_rails_root('rackspace_with_yml')
|
63
|
+
AssetSync.config = AssetSync::Config.new
|
64
|
+
end
|
65
65
|
|
66
|
-
|
67
|
-
|
68
|
-
|
66
|
+
it "should keep existing remote files" do
|
67
|
+
AssetSync.config.existing_remote_files?.should == true
|
68
|
+
end
|
69
69
|
|
70
|
-
|
71
|
-
|
72
|
-
|
70
|
+
it "should configure rackspace_username" do
|
71
|
+
AssetSync.config.rackspace_username.should == "xxxx"
|
72
|
+
end
|
73
73
|
|
74
|
-
|
75
|
-
|
76
|
-
|
74
|
+
it "should configure rackspace_api_key" do
|
75
|
+
AssetSync.config.rackspace_api_key.should == "zzzz"
|
76
|
+
end
|
77
77
|
|
78
|
-
|
79
|
-
|
80
|
-
|
78
|
+
it "should configure fog_directory" do
|
79
|
+
AssetSync.config.fog_directory.should == "rails_app_test"
|
80
|
+
end
|
81
81
|
|
82
|
-
|
83
|
-
|
84
|
-
|
82
|
+
it "should configure fog_region" do
|
83
|
+
AssetSync.config.fog_region.should == "eu-west-1"
|
84
|
+
end
|
85
85
|
|
86
|
-
|
87
|
-
|
86
|
+
it "should configure existing_remote_files" do
|
87
|
+
AssetSync.config.existing_remote_files.should == "keep"
|
88
|
+
end
|
88
89
|
end
|
89
|
-
|
90
|
-
|
91
|
-
end
|
90
|
+
end
|
data/spec/spec_helper.rb
CHANGED
@@ -12,20 +12,31 @@ $LOAD_PATH.unshift(File.join(File.dirname(__FILE__), '..', 'lib'))
|
|
12
12
|
$LOAD_PATH.unshift(File.dirname(__FILE__))
|
13
13
|
require 'asset_sync'
|
14
14
|
|
15
|
-
|
16
|
-
|
17
|
-
|
15
|
+
RSpec.configure do |config|
|
16
|
+
config.mock_framework = :rspec
|
17
|
+
end
|
18
18
|
|
19
|
-
|
20
|
-
|
19
|
+
shared_context "mock Rails" do
|
20
|
+
before(:each) do
|
21
|
+
unless defined? Rails
|
22
|
+
Rails = mock 'Rails'
|
23
|
+
end
|
24
|
+
Rails.stub(:env).and_return('test')
|
25
|
+
Rails.stub :application => mock('application')
|
26
|
+
Rails.application.stub :config => mock('config')
|
27
|
+
Rails.application.config.stub :assets => ActiveSupport::OrderedOptions.new
|
28
|
+
Rails.application.config.assets.prefix = '/assets'
|
21
29
|
end
|
30
|
+
end
|
22
31
|
|
23
|
-
|
24
|
-
|
25
|
-
end
|
32
|
+
shared_context "mock Rails without_yml" do
|
33
|
+
include_context "mock Rails"
|
26
34
|
|
27
|
-
|
28
|
-
|
35
|
+
before(:each) do
|
36
|
+
set_rails_root('without_yml')
|
29
37
|
end
|
38
|
+
end
|
30
39
|
|
31
|
-
|
40
|
+
def set_rails_root(path)
|
41
|
+
Rails.stub(:root).and_return(File.join(File.dirname(__FILE__), path))
|
42
|
+
end
|
metadata
CHANGED
@@ -2,7 +2,7 @@
|
|
2
2
|
name: asset_sync
|
3
3
|
version: !ruby/object:Gem::Version
|
4
4
|
prerelease:
|
5
|
-
version: 0.2.
|
5
|
+
version: 0.2.4
|
6
6
|
platform: ruby
|
7
7
|
authors:
|
8
8
|
- Simon Hamilton
|
@@ -12,7 +12,7 @@ autorequire:
|
|
12
12
|
bindir: bin
|
13
13
|
cert_chain: []
|
14
14
|
|
15
|
-
date:
|
15
|
+
date: 2012-01-06 00:00:00 Z
|
16
16
|
dependencies:
|
17
17
|
- !ruby/object:Gem::Dependency
|
18
18
|
name: fog
|