asset_sync 1.1.0 → 2.0.0

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: 629deff4029487b164c47ee0a479cf5111461a15
4
- data.tar.gz: 06e62f086d0a574def1741993066f42cf11b96da
3
+ metadata.gz: 5201ed972f382f2871c2a1ac0b9a6815c09d405b
4
+ data.tar.gz: 623dd4f586d82eb6603b2b536a322679d16015d4
5
5
  SHA512:
6
- metadata.gz: d37ddb643b78c91cdb24f1c8cf0fe3fb25162ace2c934eb6488ef8baf9eba8d080d892cdf85846eb0892677d58b2aea7b7a7baf3b35717de2082710d06ee8f75
7
- data.tar.gz: fcb7bfb3c0a9b67fb341fb4eb8c4ca18e16e106e8eea852c150186685f59d75e97765246c90c2779feb4b4a1ebd707df9edc457a0db3fcf973e9994d0efce2e5
6
+ metadata.gz: 94a34b39843e11ea819de2df23a48b71ee985edd709c77eb28a085e9c0be5d8c4307e4331ca77b2fa03cef8d3ba7136c700498719f06419383cc287c67f774b6
7
+ data.tar.gz: 667284efc400775f931a7164d251f087b6b61fdd8dbe2284eb8b50059ce3dd2593cf02c01ef714bd0bb4fb57f05203b25158476cfe49e00b163f6d36844bd459
data/.travis.yml CHANGED
@@ -36,6 +36,7 @@ matrix:
36
36
  - rvm: 2.1.2
37
37
  gemfile: gemfiles/rails_4.1.gemfile
38
38
  allow_failures:
39
+ - rvm: 1.9.2
39
40
  - rvm: rbx-2
40
41
  - rvm: ruby-head
41
42
  - rvm: jruby-head
data/CHANGELOG.md CHANGED
@@ -1,4 +1,64 @@
1
- # RELEASE HISTORY
1
+ # Change Log
2
+ All notable changes to this project will be documented in this file.
3
+ This project adheres to [Semantic Versioning](http://semver.org/).
4
+
5
+
6
+ ## [Unreleased]
7
+
8
+ ### Added
9
+
10
+ - Nothing
11
+
12
+ ### Changed
13
+
14
+ - Nothing
15
+
16
+ ### Fixed
17
+
18
+ - Nothing
19
+
20
+
21
+ ## [2.0.0] - 2016-12-21
22
+
23
+ ### Changed
24
+
25
+ - [BREAKING] require “fog-core” instead of “fog” as runtime requirement
26
+
27
+
28
+ ## [1.3.0] - 2016-11-30
29
+
30
+ ### Changed
31
+
32
+ - Add regex support to always_upload (https://github.com/AssetSync/asset_sync/pull/333)
33
+ - Stop failing sliently when YAML file does not contain key for rails environment (https://github.com/AssetSync/asset_sync/pull/270)
34
+ - Stop failing sliently when YAML file cannot be parsed due to syntax error
35
+
36
+
37
+ ## [1.2.1] - 2016-08-19
38
+
39
+ ### Fixed
40
+
41
+ - Respect value of option `log_silently` even when `ENV['RAILS_GROUPS'] == 'assets'`
42
+
43
+
44
+ ## [1.2.0] - 2016-08-17
45
+
46
+ ### Added
47
+
48
+ - Support for `fog_path_style` config option (AWS only) (https://github.com/AssetSync/asset_sync/pull/302)
49
+
50
+ ### Changed
51
+
52
+ - Set Expires and Cache-Control headers for .gz files (https://github.com/AssetSync/asset_sync/pull/329)
53
+
54
+ ### Fixed
55
+
56
+ - Add missing runtime dependency declaration for `mime-types` to gemspec (https://github.com/AssetSync/asset_sync/pull/328)
57
+ - Update outdated error message for unknown AssetSync provider (https://github.com/AssetSync/asset_sync/pull/298)
58
+ - Allow hash digest in file name with over 32 chars (for sprockets 3+) (https://github.com/AssetSync/asset_sync/pull/315)
59
+ - Fix `config.log_silently?` (https://github.com/AssetSync/asset_sync/pull/324)
60
+ - Stop using deprecated Ruby API (https://github.com/AssetSync/asset_sync/pull/276)
61
+
2
62
 
3
63
  ## v1.1.0 / 2014-08-13
4
64
 
@@ -736,3 +796,9 @@ Changes:
736
796
  * Improve documentation on ignored_files config option
737
797
  * Merge branch 'sinatra'
738
798
 
799
+
800
+ [Unreleased]: https://github.com/AssetSync/asset_sync/compare/v2.0.0...HEAD
801
+ [2.0.0]: https://github.com/AssetSync/asset_sync/compare/v1.3.0...v2.0.0
802
+ [1.3.0]: https://github.com/AssetSync/asset_sync/compare/v1.2.1...v1.3.0
803
+ [1.2.1]: https://github.com/AssetSync/asset_sync/compare/v1.2.0...v1.2.1
804
+ [1.2.0]: https://github.com/AssetSync/asset_sync/compare/v1.1.0...v1.2.0
data/Gemfile CHANGED
@@ -3,3 +3,4 @@ gemspec
3
3
  gem 'rcov', :platforms => :mri_18, :group => [:development, :test]
4
4
  gem 'simplecov', :platforms => [:jruby, :mri_19, :ruby_19, :mri_20, :rbx], :group => [:development, :test], :require => false
5
5
  gem 'jruby-openssl', :platform => :jruby
6
+ gem 'rails', '4.1.5'
data/README.md CHANGED
@@ -1,5 +1,5 @@
1
1
  [![Build Status](https://secure.travis-ci.org/rumblelabs/asset_sync.png)](http://travis-ci.org/rumblelabs/asset_sync)
2
- [![Code Climate](https://codeclimate.com/badge.png)](https://codeclimate.com/github/rumblelabs/asset_sync)
2
+ [![Code Climate](https://codeclimate.com/github/rumblelabs/asset_sync/badges/gpa.svg)](https://codeclimate.com/github/rumblelabs/asset_sync)
3
3
 
4
4
  # Asset Sync
5
5
 
@@ -12,55 +12,20 @@ This was initially built and is intended to work on [Heroku](http://heroku.com)
12
12
 
13
13
  ## Upgrading?
14
14
 
15
- If you are upgrading from a version of asset_sync **< 0.2.0** (i.e. 0.1.x). All of the references to config variables have changed to reference those used in **Fog**. Ensure to backup your `asset_sync.rb` or `asset_sync.yml` files and re-run the generator. You may also then need to update your ENV configuration variables (or you can change the ones that are referenced).
16
-
17
- ## Heroku Labs (BETA)
18
-
19
- Previously there were [several issues](http://github.com/rumblelabs/asset_sync/blob/master/docs/heroku.md) with using asset_sync on Heroku as described in our [Heroku dev center article](http://devcenter.heroku.com/articles/cdn-asset-host-rails31).
20
-
21
- Now to get everything working smoothly with using **ENV** variables to configure `asset_sync` we just need to enable the [user-env-compile](http://devcenter.heroku.com/articles/labs-user-env-compile) functionality. In short:
22
-
23
- heroku labs:enable user-env-compile -a myapp
24
-
25
- Hopefully this will make it's way into the platform as standard.
15
+ Upgraded from 1.x? Read `UPGRADING.md`
26
16
 
27
17
  ## Installation
28
18
 
29
- Add the gem to your Gemfile
30
-
31
- ``` ruby
32
- gem 'asset_sync'
33
- ```
34
-
35
- If you want, you can put it within your **:assets** group in your Gemfile.
36
-
37
- ``` ruby
38
- group :assets do
39
- gem 'sass-rails', '~> 3.2.3'
40
- gem 'coffee-rails', '~> 3.2.1'
41
- gem 'uglifier', '>= 1.0.3'
42
- gem 'asset_sync'
43
- end
44
- ```
45
-
46
- This is good practice when pre-compiling your assets as it will reduce load time and server memory in production. The only caveat being, you may not be able to use a custom initializer, without perhaps wrapping it with.
47
-
48
- ``` ruby
49
- if defined?(AssetSync)
50
- ...
51
- end
52
- ```
53
-
54
- ### Optimized Fog loading
19
+ Since 2.x, Asset Sync depends on gem `fog-core` instead of `fog`.
20
+ This is due to `fog` is including many unused storage provider gems as its dependencies.
55
21
 
56
- Since AssetSync doesn't know which parts of Fog you intend to use, it will just load the entire library.
57
- If you prefer to load fewer classes into your application, which will reduce load time and memory use,
58
- you need to load those parts of Fog yourself *before* loading AssetSync:
22
+ Asset Sync has no idea about what provider will be used,
23
+ so you are responsible for bundling the right gem for the provider to be used.
59
24
 
60
25
  In your Gemfile:
61
26
  ```ruby
62
- gem "fog", "~>1.20", require "fog/aws/storage"
63
27
  gem "asset_sync"
28
+ gem "fog-aws"
64
29
  ```
65
30
 
66
31
  ### Extended Installation (Faster sync with turbosprockets)
@@ -141,7 +106,8 @@ If you need more control over configuration you will want to use a **custom rail
141
106
 
142
107
  Configuration using a **YAML** file (a common strategy for Capistrano deployments) is also supported.
143
108
 
144
- The recommend way to configure **asset_sync** is by using **environment variables** however it's up to you, it will work fine if you hard code them too. The main reason is that then your access keys are not checked into version control.
109
+ The recommend way to configure **asset_sync** is by using **environment variables** however it's up to you, it will work fine if you hard code them too. The main reason why using environment variables is recommended is so your access keys are not checked into version control.
110
+
145
111
 
146
112
  ### Built-in Initializer (Environment Variables)
147
113
 
@@ -221,6 +187,10 @@ AssetSync.configure do |config|
221
187
  #
222
188
  # Fail silently. Useful for environments such as Heroku
223
189
  # config.fail_silently = true
190
+ #
191
+ # Log silently. Default is `true`. But you can set it to false if more logging message are preferred.
192
+ # Logging messages are sent to `STDOUT` when `log_silently` is falsy
193
+ # config.log_silently = true
224
194
  end
225
195
  ```
226
196
 
@@ -253,7 +223,7 @@ defaults: &defaults
253
223
  # Always upload. Useful if you want to overwrite specific remote assets regardless of their existence
254
224
  # eg: Static files in public often reference non-fingerprinted application.css
255
225
  # note: You will still need to expire them from the CDN's edge cache locations
256
- # always_upload: ['application.js', 'application.css']
226
+ # always_upload: ['application.js', 'application.css', !ruby/regexp '/application-/\d{32}\.css/']
257
227
  # Ignored files. Useful if there are some files that are created dynamically on the server and you don't want to upload on deploy.
258
228
  # ignored_files: ['ignore_me.js', !ruby/regexp '/ignore_some/\d{32}\.css/']
259
229
 
@@ -296,7 +266,8 @@ AssetSync.config.gzip_compression == ENV['ASSET_SYNC_GZIP_COMPRESSION']
296
266
 
297
267
  #### Fog (Optional)
298
268
 
299
- * **fog\_region**: the region your storage bucket is in e.g. *eu-west-1*
269
+ * **fog\_region**: the region your storage bucket is in e.g. *eu-west-1* (AWS), *ord* (Rackspace)
270
+ * **fog\_path\_style**: To use buckets with dot in names, check https://github.com/fog/fog/issues/2381#issuecomment-28088524
300
271
 
301
272
  #### AWS
302
273
 
@@ -341,6 +312,44 @@ production:
341
312
  fog_region: 'eu-west-1'
342
313
  ```
343
314
 
315
+ ### Amazon (AWS) IAM Users
316
+
317
+ Amazon has switched to the more secure IAM User security policy model. When generating a user & policy for asset_sync you will need to ensure the policy has the following permissions.
318
+ You __must__ give the user permission to **s3:ListAllMyBuckets** as well as give permission to both the bucket, as well as the bucket's contents (/*). If not given all these permissions you'll see the error ```Expected(200) <=> Actual(403 Forbidden) ```
319
+
320
+ IAM User Policy Example (replace "bucket_name" with your bucket):
321
+ ``` json
322
+ {
323
+ "Statement": [
324
+ {
325
+ "Action": [
326
+ "s3:ListAllMyBuckets"
327
+ ],
328
+ "Effect": "Allow",
329
+ "Resource": "arn:aws:s3:::*"
330
+ },
331
+ {
332
+ "Action": "s3:*",
333
+ "Effect": "Allow",
334
+ "Resource": "arn:aws:s3:::bucket_name"
335
+ },
336
+ {
337
+ "Action": "s3:*",
338
+ "Effect": "Allow",
339
+ "Resource": "arn:aws:s3:::bucket_name/*"
340
+ }
341
+ ]
342
+ }
343
+ ```
344
+
345
+ If you want to use IAM roles you must set ```config.aws_iam_roles = true``` in your initializers.
346
+ ```
347
+ AssetSync.configure do |config|
348
+ # ...
349
+ config.aws_iam_roles = true
350
+ end
351
+ ```
352
+
344
353
 
345
354
  ## Automatic gzip compression
346
355
 
@@ -428,6 +437,18 @@ namespace :assets do
428
437
  end
429
438
  ```
430
439
 
440
+ ## Running the specs
441
+
442
+ Make sure you have a .env file with these details:-
443
+
444
+ AWS_ACCESS_KEY_ID=<yourkeyid>
445
+ AWS_SECRET_ACCESS_KEY=<yoursecretkey>
446
+ FOG_DIRECTORY=<yourbucket>
447
+
448
+ Make sure the bucket has read/write permissions. Then to run the tests:-
449
+
450
+ foreman run rake
451
+
431
452
  ## Todo
432
453
 
433
454
  1. Add some before and after filters for deleting and uploading
data/UPGRADING.md ADDED
@@ -0,0 +1,25 @@
1
+ # Guide to upgrading from AssetSync 1.x to 2.x
2
+
3
+ Make sure that you're running the latest AssetSync 1.x release.
4
+
5
+ This upgrading guide touches on:
6
+ - Changed dependencies
7
+
8
+
9
+ ## Changed dependencies
10
+ Asset Sync now depends on gem `fog-core` instead of `fog`.
11
+ This is due to `fog` is including many unused storage provider gems as its dependencies.
12
+
13
+ Asset Sync has no idea about what provider will be used,
14
+ so you are responsible for bundling the right gem for the provider to be used.
15
+
16
+ For example, when using AWS as fog provider:
17
+ ```ruby
18
+ # Gemfile
19
+ gem "asset_sync"
20
+ gem "fog-aws"
21
+ ```
22
+
23
+ If you don't install the required gem,
24
+ Fog will complain (by exception) about it when provider is set by Asset Sync.
25
+
data/asset_sync.gemspec CHANGED
@@ -14,16 +14,21 @@ Gem::Specification.new do |s|
14
14
  s.summary = %q{Synchronises Assets in a Rails 3 application and Amazon S3/Cloudfront and Rackspace Cloudfiles}
15
15
  s.description = %q{After you run assets:precompile your compiled assets will be synchronised with your S3 bucket.}
16
16
 
17
+ s.license = 'MIT'
18
+
17
19
  s.rubyforge_project = "asset_sync"
18
20
 
19
- s.add_dependency('fog', ">= 1.8.0")
21
+ s.add_dependency("fog-core")
20
22
  s.add_dependency('unf')
21
23
  s.add_dependency('activemodel')
24
+ s.add_dependency('mime-types')
22
25
 
23
26
  s.add_development_dependency "rspec"
24
27
  s.add_development_dependency "bundler"
25
28
  s.add_development_dependency "jeweler"
26
29
 
30
+ s.add_development_dependency "fog-aws"
31
+
27
32
  s.add_development_dependency "uglifier"
28
33
  s.add_development_dependency "appraisal"
29
34
 
@@ -57,7 +57,7 @@ module AssetSync
57
57
  end
58
58
 
59
59
  def log(msg)
60
- stdout.puts msg if config.log_silently?
60
+ stdout.puts msg unless config.log_silently?
61
61
  end
62
62
 
63
63
  def enabled?
@@ -1,3 +1,7 @@
1
+ require "active_model"
2
+ require "erb"
3
+ require "yaml"
4
+
1
5
  module AssetSync
2
6
  class Config
3
7
  include ActiveModel::Validations
@@ -24,6 +28,7 @@ module AssetSync
24
28
  attr_accessor :fog_provider # Currently Supported ['AWS', 'Rackspace']
25
29
  attr_accessor :fog_directory # e.g. 'the-bucket-name'
26
30
  attr_accessor :fog_region # e.g. 'eu-west-1'
31
+ attr_accessor :fog_path_style # e.g true
27
32
 
28
33
  # Amazon AWS
29
34
  attr_accessor :aws_access_key_id, :aws_secret_access_key, :aws_reduced_redundancy, :aws_iam_roles
@@ -60,12 +65,12 @@ module AssetSync
60
65
  self.run_on_precompile = true
61
66
  self.cdn_distribution_id = nil
62
67
  self.invalidate = []
63
- load_yml! if defined?(Rails) && yml_exists?
68
+ load_yml! if defined?(::Rails) && yml_exists?
64
69
  end
65
70
 
66
71
  def manifest_path
67
72
  directory =
68
- Rails.application.config.assets.manifest || default_manifest_directory
73
+ ::Rails.application.config.assets.manifest || default_manifest_directory
69
74
  File.join(directory, "manifest.yml")
70
75
  end
71
76
 
@@ -78,7 +83,7 @@ module AssetSync
78
83
  end
79
84
 
80
85
  def aws?
81
- fog_provider == 'AWS'
86
+ fog_provider =~ /aws/i
82
87
  end
83
88
 
84
89
  def aws_rrs?
@@ -94,7 +99,7 @@ module AssetSync
94
99
  end
95
100
 
96
101
  def log_silently?
97
- ENV['RAILS_GROUPS'] == 'assets' || self.log_silently == false
102
+ !!self.log_silently
98
103
  end
99
104
 
100
105
  def enabled?
@@ -102,36 +107,32 @@ module AssetSync
102
107
  end
103
108
 
104
109
  def rackspace?
105
- fog_provider == 'Rackspace'
110
+ fog_provider =~ /rackspace/i
106
111
  end
107
112
 
108
113
  def google?
109
- fog_provider == 'Google'
114
+ fog_provider =~ /google/i
110
115
  end
111
116
 
112
117
  def yml_exists?
113
- defined?(Rails.root) ? File.exists?(self.yml_path) : false
118
+ defined?(::Rails.root) ? File.exist?(self.yml_path) : false
114
119
  end
115
120
 
116
121
  def yml
117
- begin
118
- @yml ||= YAML.load(ERB.new(IO.read(yml_path)).result)[Rails.env] rescue nil || {}
119
- rescue Psych::SyntaxError
120
- @yml = {}
121
- end
122
+ @yml ||= ::YAML.load(::ERB.new(IO.read(yml_path)).result)[::Rails.env] || {}
122
123
  end
123
124
 
124
125
  def yml_path
125
- Rails.root.join("config", "asset_sync.yml").to_s
126
+ ::Rails.root.join("config", "asset_sync.yml").to_s
126
127
  end
127
128
 
128
129
  def assets_prefix
129
130
  # Fix for Issue #38 when Rails.config.assets.prefix starts with a slash
130
- self.prefix || Rails.application.config.assets.prefix.sub(/^\//, '')
131
+ self.prefix || ::Rails.application.config.assets.prefix.sub(/^\//, '')
131
132
  end
132
133
 
133
134
  def public_path
134
- @public_path || Rails.public_path
135
+ @public_path || ::Rails.public_path
135
136
  end
136
137
 
137
138
  def load_yml!
@@ -139,6 +140,7 @@ module AssetSync
139
140
  self.fog_provider = yml["fog_provider"]
140
141
  self.fog_directory = yml["fog_directory"]
141
142
  self.fog_region = yml["fog_region"]
143
+ self.fog_path_style = yml["fog_path_style"]
142
144
  self.aws_access_key_id = yml["aws_access_key_id"]
143
145
  self.aws_secret_access_key = yml["aws_secret_access_key"]
144
146
  self.aws_reduced_redundancy = yml["aws_reduced_redundancy"]
@@ -203,17 +205,18 @@ module AssetSync
203
205
  :google_storage_access_key_id => google_storage_access_key_id
204
206
  })
205
207
  else
206
- raise ArgumentError, "AssetSync Unknown provider: #{fog_provider} only AWS and Rackspace are supported currently."
208
+ raise ArgumentError, "AssetSync Unknown provider: #{fog_provider} only AWS, Rackspace and Google are supported currently."
207
209
  end
208
210
 
209
211
  options.merge!({:region => fog_region}) if fog_region && !rackspace?
212
+ options.merge!({:path_style => fog_path_style}) if fog_path_style && aws?
210
213
  return options
211
214
  end
212
215
 
213
216
  private
214
217
 
215
218
  def default_manifest_directory
216
- File.join(Rails.public_path, assets_prefix)
219
+ File.join(::Rails.public_path, assets_prefix)
217
220
  end
218
221
  end
219
222
  end
@@ -7,10 +7,10 @@ module AssetSync
7
7
  app_initializer = Rails.root.join('config', 'initializers', 'asset_sync.rb').to_s
8
8
  app_yaml = Rails.root.join('config', 'asset_sync.yml').to_s
9
9
 
10
- if File.exists?( app_initializer )
10
+ if File.exist?( app_initializer )
11
11
  AssetSync.log "AssetSync: using #{app_initializer}"
12
12
  load app_initializer
13
- elsif !File.exists?( app_initializer ) && !File.exists?( app_yaml )
13
+ elsif !File.exist?( app_initializer ) && !File.exist?( app_yaml )
14
14
  AssetSync.log "AssetSync: using default configuration from built-in initializer"
15
15
  AssetSync.configure do |config|
16
16
  config.fog_provider = ENV['FOG_PROVIDER'] if ENV.has_key?('FOG_PROVIDER')
@@ -44,7 +44,7 @@ module AssetSync
44
44
 
45
45
  end
46
46
 
47
- if File.exists?( app_yaml )
47
+ if File.exist?( app_yaml )
48
48
  AssetSync.log "AssetSync: YAML file found #{app_yaml} settings will be merged into the configuration"
49
49
  end
50
50
  end
@@ -1,3 +1,5 @@
1
+ require "fog/core"
2
+
1
3
  module AssetSync
2
4
  class Storage
3
5
  REGEXP_FINGERPRINTED_FILES = /^(.*)\/([^-]+)-[^\.]+\.([^\.]+)$/
@@ -33,22 +35,7 @@ module AssetSync
33
35
  end
34
36
 
35
37
  def ignored_files
36
- files = []
37
- Array(self.config.ignored_files).each do |ignore|
38
- case ignore
39
- when Regexp
40
- files += self.local_files.select do |file|
41
- file =~ ignore
42
- end
43
- when String
44
- files += self.local_files.select do |file|
45
- file.split('/').last == ignore
46
- end
47
- else
48
- log "Error: please define ignored_files as string or regular expression. #{ignore} (#{ignore.class}) ignored."
49
- end
50
- end
51
- files.uniq
38
+ expand_file_names(self.config.ignored_files)
52
39
  end
53
40
 
54
41
  def local_files
@@ -56,7 +43,7 @@ module AssetSync
56
43
  end
57
44
 
58
45
  def always_upload_files
59
- self.config.always_upload.map { |f| File.join(self.config.assets_prefix, f) }
46
+ expand_file_names(self.config.always_upload)
60
47
  end
61
48
 
62
49
  def files_with_custom_headers
@@ -73,10 +60,10 @@ module AssetSync
73
60
  log "Using: Rails 4.0 manifest access"
74
61
  manifest = Sprockets::Manifest.new(ActionView::Base.assets_manifest.environment, ActionView::Base.assets_manifest.dir)
75
62
  return manifest.assets.values.map { |f| File.join(self.config.assets_prefix, f) }
76
- elsif File.exists?(self.config.manifest_path)
63
+ elsif File.exist?(self.config.manifest_path)
77
64
  log "Using: Manifest #{self.config.manifest_path}"
78
65
  yml = YAML.load(IO.read(self.config.manifest_path))
79
-
66
+
80
67
  return yml.map do |original, compiled|
81
68
  # Upload font originals and compiled
82
69
  if original =~ /^.+(eot|svg|ttf|woff)$/
@@ -91,7 +78,8 @@ module AssetSync
91
78
  end
92
79
  log "Using: Directory Search of #{path}/#{self.config.assets_prefix}"
93
80
  Dir.chdir(path) do
94
- Dir["#{self.config.assets_prefix}/**/**"]
81
+ to_load = self.config.assets_prefix.present? ? "#{self.config.assets_prefix}/**/**" : '**/**'
82
+ Dir[to_load]
95
83
  end
96
84
  end
97
85
 
@@ -136,7 +124,9 @@ module AssetSync
136
124
  :content_type => mime
137
125
  }
138
126
 
139
- if /-[0-9a-fA-F]{32}$/.match(File.basename(f,File.extname(f)))
127
+ uncompressed_filename = f.sub(/\.gz\z/, '')
128
+ basename = File.basename(uncompressed_filename, File.extname(uncompressed_filename))
129
+ if /-[0-9a-fA-F]{32,}$/.match(basename)
140
130
  file.merge!({
141
131
  :cache_control => "public, max-age=#{one_year}",
142
132
  :expires => CGI.rfc1123_date(Time.now + one_year)
@@ -150,8 +140,8 @@ module AssetSync
150
140
  log "Overwriting #{f} with custom headers #{files_with_custom_headers[f].to_s}"
151
141
  elsif key = self.config.custom_headers.keys.detect {|k| f.match(Regexp.new(k))}
152
142
  headers = {}
153
- self.config.custom_headers[key].each do |key, value|
154
- headers[key.to_sym] = value
143
+ self.config.custom_headers[key].each do |k, value|
144
+ headers[k.to_sym] = value
155
145
  end
156
146
  file.merge! headers
157
147
  log "Overwriting matching file #{f} with custom headers #{headers.to_s}"
@@ -166,7 +156,7 @@ module AssetSync
166
156
  # as we will overwrite file.css with file.css.gz if it exists.
167
157
  log "Ignoring: #{f}"
168
158
  ignore = true
169
- elsif config.gzip? && File.exists?(gzipped)
159
+ elsif config.gzip? && File.exist?(gzipped)
170
160
  original_size = File.size("#{path}/#{f}")
171
161
  gzipped_size = File.size(gzipped)
172
162
 
@@ -248,5 +238,24 @@ module AssetSync
248
238
  end.compact
249
239
  end
250
240
 
241
+ def expand_file_names(names)
242
+ files = []
243
+ Array(names).each do |name|
244
+ case name
245
+ when Regexp
246
+ files += self.local_files.select do |file|
247
+ file =~ name
248
+ end
249
+ when String
250
+ files += self.local_files.select do |file|
251
+ file.split('/').last == name
252
+ end
253
+ else
254
+ log "Error: please define file names as string or regular expression. #{name} (#{name.class}) ignored."
255
+ end
256
+ end
257
+ files.uniq
258
+ end
259
+
251
260
  end
252
261
  end
@@ -1,3 +1,3 @@
1
1
  module AssetSync
2
- VERSION = "1.1.0"
2
+ VERSION = "2.0.0"
3
3
  end
data/lib/asset_sync.rb CHANGED
@@ -1,6 +1,3 @@
1
- require 'fog' unless defined?(::Fog)
2
- require 'active_model'
3
- require 'erb'
4
1
  require "asset_sync/asset_sync"
5
2
  require 'asset_sync/config'
6
3
  require 'asset_sync/storage'
@@ -38,4 +38,8 @@ AssetSync.configure do |config|
38
38
  #
39
39
  # Fail silently. Useful for environments such as Heroku
40
40
  # config.fail_silently = true
41
+ #
42
+ # Log silently. Default is `true`. But you can set it to false if more logging message are preferred.
43
+ # Logging messages are sent to `STDOUT` when `log_silently` is falsy
44
+ # config.log_silently = true
41
45
  end
@@ -3,7 +3,7 @@ require 'rubygems'
3
3
  ENV['RAILS_ROOT'] = File.dirname(__FILE__)
4
4
  # Set up gems listed in the Gemfile.
5
5
  ENV['BUNDLE_GEMFILE'] ||= File.expand_path('../../Gemfile', __FILE__)
6
- require 'bundler/setup' if File.exists?(ENV['BUNDLE_GEMFILE'])
6
+ require 'bundler/setup' if File.exist?(ENV['BUNDLE_GEMFILE'])
7
7
  # require 'rails/all'
8
8
  require "action_controller/railtie"
9
9
  require "sprockets/railtie"
@@ -4,6 +4,7 @@ defaults: &defaults
4
4
  aws_secret_access_key: "zzzz"
5
5
  region: "eu-west-1"
6
6
  run_on_precompile: false
7
+ fog_path_style: true
7
8
 
8
9
  development:
9
10
  <<: *defaults
@@ -1,4 +1,5 @@
1
1
  require File.dirname(__FILE__) + '/../spec_helper'
2
+ require "fog/aws"
2
3
 
3
4
  def bucket(name)
4
5
  options = {
@@ -23,12 +24,12 @@ describe "AssetSync" do
23
24
  @prefix = SecureRandom.hex(6)
24
25
  end
25
26
 
26
- let(:app_js_regex){
27
- /#{@prefix}\/application-[a-zA-Z0-9]*.js$/
27
+ let(:app_js_regex){
28
+ /#{@prefix}\/application-[a-zA-Z0-9]*.js$/
28
29
  }
29
30
 
30
- let(:app_js_gz_regex){
31
- /#{@prefix}\/application-[a-zA-Z0-9]*.js.gz$/
31
+ let(:app_js_gz_regex){
32
+ /#{@prefix}\/application-[a-zA-Z0-9]*.js.gz$/
32
33
  }
33
34
 
34
35
  let(:files){ bucket(@prefix).files }
@@ -12,6 +12,7 @@ describe AssetSync do
12
12
  config.aws_secret_access_key = 'bbbb'
13
13
  config.fog_directory = 'mybucket'
14
14
  config.fog_region = 'eu-west-1'
15
+ config.fog_path_style = 'true'
15
16
  config.existing_remote_files = "keep"
16
17
  end
17
18
  end
@@ -50,6 +51,10 @@ describe AssetSync do
50
51
  expect(AssetSync.config.fog_region).to eq("eu-west-1")
51
52
  end
52
53
 
54
+ it "should configure path_style" do
55
+ expect(AssetSync.config.fog_path_style).to be_truthy
56
+ end
57
+
53
58
  it "should configure existing_remote_files" do
54
59
  expect(AssetSync.config.existing_remote_files).to eq("keep")
55
60
  end
@@ -66,6 +71,18 @@ describe AssetSync do
66
71
  expect(AssetSync.config.log_silently).to be_truthy
67
72
  end
68
73
 
74
+ it "log_silently? should reflect the configuration" do
75
+ AssetSync.config.log_silently = false
76
+ expect(AssetSync.config.log_silently?).to eq(false)
77
+ end
78
+
79
+ it "log_silently? should always be true if ENV['RAILS_GROUPS'] == 'assets'" do
80
+ AssetSync.config.log_silently = false
81
+ allow(ENV).to receive(:[]).with('RAILS_GROUPS').and_return('assets')
82
+
83
+ expect(AssetSync.config.log_silently?).to eq(false)
84
+ end
85
+
69
86
  it "should default cdn_distribution_id to nil" do
70
87
  expect(AssetSync.config.cdn_distribution_id).to be_nil
71
88
  end
@@ -106,6 +123,10 @@ describe AssetSync do
106
123
  expect(AssetSync.config.fog_region).to eq("eu-west-1")
107
124
  end
108
125
 
126
+ it "should configure path_style" do
127
+ expect(AssetSync.config.fog_path_style).to be_truthy
128
+ end
129
+
109
130
  it "should configure existing_remote_files" do
110
131
  expect(AssetSync.config.existing_remote_files).to eq("keep")
111
132
  end
@@ -127,7 +148,7 @@ describe AssetSync do
127
148
  end
128
149
 
129
150
  it "should be disabled" do
130
- expect{ AssetSync.sync }.not_to raise_error()
151
+ expect{ AssetSync.sync }.not_to raise_error
131
152
  end
132
153
 
133
154
  after(:each) do
@@ -141,7 +162,7 @@ describe AssetSync do
141
162
  end
142
163
 
143
164
  it "should be invalid" do
144
- expect{ AssetSync.sync }.to raise_error()
165
+ expect{ AssetSync.sync }.to raise_error(::AssetSync::Config::Invalid)
145
166
  end
146
167
  end
147
168
 
@@ -154,7 +175,7 @@ describe AssetSync do
154
175
  end
155
176
 
156
177
  it "should do nothing, without complaining" do
157
- expect{ AssetSync.sync }.not_to raise_error()
178
+ expect{ AssetSync.sync }.not_to raise_error
158
179
  end
159
180
  end
160
181
 
@@ -168,7 +189,7 @@ describe AssetSync do
168
189
  end
169
190
 
170
191
  it "should not raise an invalid exception" do
171
- expect{ AssetSync.sync }.not_to raise_error()
192
+ expect{ AssetSync.sync }.not_to raise_error
172
193
  end
173
194
 
174
195
  it "should output a warning to stderr" do
@@ -187,7 +208,7 @@ describe AssetSync do
187
208
  end
188
209
 
189
210
  it "should not raise an invalid exception" do
190
- expect{ AssetSync.sync }.not_to raise_error()
211
+ expect{ AssetSync.sync }.not_to raise_error
191
212
  end
192
213
  end
193
214
 
@@ -228,18 +249,12 @@ describe AssetSync do
228
249
  end
229
250
 
230
251
  describe 'with invalid yml' do
231
-
232
252
  before(:each) do
233
253
  set_rails_root('with_invalid_yml')
234
- AssetSync.config = AssetSync::Config.new
235
- end
236
-
237
- it "config should be invalid" do
238
- expect(AssetSync.config.valid?).to be_falsey
239
254
  end
240
255
 
241
- it "should raise a config invalid error" do
242
- expect{ AssetSync.sync }.to raise_error()
256
+ it "an error" do
257
+ expect{ AssetSync::Config.new }.to raise_error(Psych::SyntaxError)
243
258
  end
244
259
  end
245
260
  end
@@ -86,7 +86,7 @@ describe AssetSync do
86
86
  end
87
87
 
88
88
  it "should be invalid" do
89
- expect{ AssetSync.sync }.to raise_error()
89
+ expect{ AssetSync.sync }.to raise_error(::AssetSync::Config::Invalid)
90
90
  end
91
91
  end
92
92
 
@@ -100,7 +100,7 @@ describe AssetSync do
100
100
  end
101
101
 
102
102
  it "should not raise an invalid exception" do
103
- expect{ AssetSync.sync }.not_to raise_error()
103
+ expect{ AssetSync.sync }.not_to raise_error
104
104
  end
105
105
  end
106
106
 
@@ -6,7 +6,7 @@ describe AssetSync::Storage do
6
6
  describe '#upload_files' do
7
7
  before(:each) do
8
8
  @local_files = ["local_image2.jpg", "local_image1.jpg", "local_stylesheet1.css", "local_stylesheet2.css"]
9
- @remote_files = ["local_image.jpg", "local_stylesheet1.css"]
9
+ @remote_files = ["local_image.jpg", "local_image3.svg", "local_image4.svg", "local_stylesheet1.css"]
10
10
  @config = AssetSync::Config.new
11
11
  end
12
12
 
@@ -23,7 +23,7 @@ describe AssetSync::Storage do
23
23
  end
24
24
 
25
25
  it 'should allow force overwriting of specific files' do
26
- @config.always_upload = ['local_image.jpg']
26
+ @config.always_upload = ['local_image.jpg', /local_image\d\.svg/]
27
27
 
28
28
  storage = AssetSync::Storage.new(@config)
29
29
  allow(storage).to receive(:local_files).and_return(@local_files)
@@ -84,8 +84,20 @@ describe AssetSync::Storage do
84
84
 
85
85
 
86
86
  it 'should correctly set expire date' do
87
- local_files = ['file1.jpg', 'file1-1234567890abcdef1234567890abcdef.jpg']
88
- local_files += ['dir1/dir2/file2.jpg', 'dir1/dir2/file2-1234567890abcdef1234567890abcdef.jpg']
87
+ local_files = [
88
+ 'file1.jpg',
89
+ 'file1-1234567890abcdef1234567890abcdef.jpg',
90
+ 'file1-1234567890abcdef1234567890abcdef.jpg.gz',
91
+ 'file1-1234567890abcdef1234567890abcdef1234567890abcdef1234567890abcdef.jpg',
92
+ 'file1-1234567890abcdef1234567890abcdef1234567890abcdef1234567890abcdef.jpg.gz'
93
+ ]
94
+ local_files += [
95
+ 'dir1/dir2/file2.jpg',
96
+ 'dir1/dir2/file2-1234567890abcdef1234567890abcdef.jpg',
97
+ 'dir1/dir2/file2-1234567890abcdef1234567890abcdef.jpg.gz',
98
+ 'dir1/dir2/file2-1234567890abcdef1234567890abcdef1234567890abcdef1234567890abcdef.jpg',
99
+ 'dir1/dir2/file2-1234567890abcdef1234567890abcdef1234567890abcdef1234567890abcdef.jpg.gz'
100
+ ]
89
101
  remote_files = []
90
102
  storage = AssetSync::Storage.new(@config)
91
103
  allow(storage).to receive(:local_files).and_return(local_files)
@@ -99,7 +111,13 @@ describe AssetSync::Storage do
99
111
  when 'dir1/dir2/file2.jpg'
100
112
  !expect(file).not_to include(:cache_control, :expires)
101
113
  when 'file1-1234567890abcdef1234567890abcdef.jpg'
114
+ when 'file1-1234567890abcdef1234567890abcdef.jpg.gz'
115
+ when 'file1-1234567890abcdef1234567890abcdef1234567890abcdef1234567890abcdef.jpg'
116
+ when 'file1-1234567890abcdef1234567890abcdef1234567890abcdef1234567890abcdef.jpg.gz'
102
117
  when 'dir1/dir2/file2-1234567890abcdef1234567890abcdef.jpg'
118
+ when 'dir1/dir2/file2-1234567890abcdef1234567890abcdef.jpg.gz'
119
+ when 'dir1/dir2/file2-1234567890abcdef1234567890abcdef1234567890abcdef1234567890abcdef.jpg'
120
+ when 'dir1/dir2/file2-1234567890abcdef1234567890abcdef1234567890abcdef1234567890abcdef.jpg.gz'
103
121
  expect(file).to include(:cache_control, :expires)
104
122
  else
105
123
  fail
@@ -114,7 +132,7 @@ describe AssetSync::Storage do
114
132
  storage.upload_files
115
133
  end
116
134
 
117
- it "shoud invalidate files" do
135
+ it "should invalidate files" do
118
136
  @config.cdn_distribution_id = "1234"
119
137
  @config.invalidate = ['local_image1.jpg']
120
138
  @config.fog_provider = 'AWS'
@@ -136,7 +154,12 @@ describe AssetSync::Storage do
136
154
  before(:each) do
137
155
  # Object#remove_const does not remove the loaded
138
156
  # file from the $" variable
139
- #Object.send(:remove_const, :MIME) if defined?(MIME)
157
+ #
158
+ # So we need do both
159
+ #
160
+ # 1. Remove constant(s) to avoid warning messages
161
+ # 2. Remove loaded file(s)
162
+ Object.send(:remove_const, :MIME) if defined?(MIME)
140
163
  mime_types = $".grep(/mime\/types/).first
141
164
  $".delete(mime_types)
142
165
  require 'mime/types'
@@ -186,9 +209,5 @@ describe AssetSync::Storage do
186
209
  end
187
210
  storage.upload_file('assets/some_longer_path/local_image2.jpg')
188
211
  end
189
-
190
- after(:each) do
191
- #Object.send(:remove_const, :MIME) if defined?(MIME)
192
- end
193
212
  end
194
213
  end
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: asset_sync
3
3
  version: !ruby/object:Gem::Version
4
- version: 1.1.0
4
+ version: 2.0.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - Simon Hamilton
@@ -14,19 +14,19 @@ cert_chain: []
14
14
  date: 2013-08-26 00:00:00.000000000 Z
15
15
  dependencies:
16
16
  - !ruby/object:Gem::Dependency
17
- name: fog
17
+ name: fog-core
18
18
  requirement: !ruby/object:Gem::Requirement
19
19
  requirements:
20
20
  - - ">="
21
21
  - !ruby/object:Gem::Version
22
- version: 1.8.0
22
+ version: '0'
23
23
  type: :runtime
24
24
  prerelease: false
25
25
  version_requirements: !ruby/object:Gem::Requirement
26
26
  requirements:
27
27
  - - ">="
28
28
  - !ruby/object:Gem::Version
29
- version: 1.8.0
29
+ version: '0'
30
30
  - !ruby/object:Gem::Dependency
31
31
  name: unf
32
32
  requirement: !ruby/object:Gem::Requirement
@@ -55,6 +55,20 @@ dependencies:
55
55
  - - ">="
56
56
  - !ruby/object:Gem::Version
57
57
  version: '0'
58
+ - !ruby/object:Gem::Dependency
59
+ name: mime-types
60
+ requirement: !ruby/object:Gem::Requirement
61
+ requirements:
62
+ - - ">="
63
+ - !ruby/object:Gem::Version
64
+ version: '0'
65
+ type: :runtime
66
+ prerelease: false
67
+ version_requirements: !ruby/object:Gem::Requirement
68
+ requirements:
69
+ - - ">="
70
+ - !ruby/object:Gem::Version
71
+ version: '0'
58
72
  - !ruby/object:Gem::Dependency
59
73
  name: rspec
60
74
  requirement: !ruby/object:Gem::Requirement
@@ -97,6 +111,20 @@ dependencies:
97
111
  - - ">="
98
112
  - !ruby/object:Gem::Version
99
113
  version: '0'
114
+ - !ruby/object:Gem::Dependency
115
+ name: fog-aws
116
+ requirement: !ruby/object:Gem::Requirement
117
+ requirements:
118
+ - - ">="
119
+ - !ruby/object:Gem::Version
120
+ version: '0'
121
+ type: :development
122
+ prerelease: false
123
+ version_requirements: !ruby/object:Gem::Requirement
124
+ requirements:
125
+ - - ">="
126
+ - !ruby/object:Gem::Version
127
+ version: '0'
100
128
  - !ruby/object:Gem::Dependency
101
129
  name: uglifier
102
130
  requirement: !ruby/object:Gem::Requirement
@@ -143,6 +171,7 @@ files:
143
171
  - Gemfile
144
172
  - README.md
145
173
  - Rakefile
174
+ - UPGRADING.md
146
175
  - asset_sync.gemspec
147
176
  - docs/heroku.md
148
177
  - gemfiles/rails_3.1.gemfile
@@ -176,7 +205,8 @@ files:
176
205
  - spec/unit/railsless_spec.rb
177
206
  - spec/unit/storage_spec.rb
178
207
  homepage: https://github.com/rumblelabs/asset_sync
179
- licenses: []
208
+ licenses:
209
+ - MIT
180
210
  metadata: {}
181
211
  post_install_message:
182
212
  rdoc_options: []
@@ -194,7 +224,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
194
224
  version: '0'
195
225
  requirements: []
196
226
  rubyforge_project: asset_sync
197
- rubygems_version: 2.2.2
227
+ rubygems_version: 2.5.2
198
228
  signing_key:
199
229
  specification_version: 4
200
230
  summary: Synchronises Assets in a Rails 3 application and Amazon S3/Cloudfront and