Skip to content

Loading…

Add possibility to ignore files #63

Closed
wants to merge 1 commit into from

2 participants

@manuelmeurer

I added a config value that lets you define a regex to ignore files that should not be uploaded to the remote server.

@davidjrice

Looks good, how about a test for this?

@manuelmeurer

Good point. :) Will try to work on some test this or next week.

@davidjrice

If you want to rebase your commit and have a look at some of the tests added from this recent pull.
#70

@manuelmeurer

New pull request with specs: #71

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Commits on Apr 8, 2012
  1. @manuelmeurer
Showing with 19 additions and 2 deletions.
  1. +2 −0 lib/asset_sync/config.rb
  2. +17 −2 lib/asset_sync/storage.rb
View
2 lib/asset_sync/config.rb
@@ -9,6 +9,7 @@ class Invalid < StandardError; end
attr_accessor :gzip_compression
attr_accessor :manifest
attr_accessor :fail_silently
+ attr_accessor :ignored_files
# FOG configuration
attr_accessor :fog_provider # Currently Supported ['AWS', 'Rackspace']
@@ -37,6 +38,7 @@ def initialize
self.gzip_compression = false
self.manifest = false
self.fail_silently = false
+ self.ignored_files = []
load_yml! if yml_exists?
end
View
19 lib/asset_sync/storage.rb
@@ -30,6 +30,21 @@ def path
"#{Rails.root.to_s}/public"
end
+ def ignored_files
+ files = []
+ Array(self.config.ignored_files).each do |ignore|
+ case ignore
+ when Regexp
+ files += self.local_files.select do |file|
+ file =~ ignore
+ end
+ else
+ log "Error: please define ignored_files as regular expressions. #{ignore} (#{ignore.class}) ignored."
+ end
+ end
+ files.uniq
+ end
+
def local_files
@local_files ||= get_local_files
end
@@ -68,7 +83,7 @@ def delete_extra_remote_files
log "Fetching files to flag for delete"
remote_files = get_remote_files
# fixes: https://github.com/rumblelabs/asset_sync/issues/19
- from_remote_files_to_delete = remote_files - local_files
+ from_remote_files_to_delete = remote_files - local_files - ignored_files
log "Flagging #{from_remote_files_to_delete.size} file(s) for deletion"
# Delete unneeded remote files
@@ -125,7 +140,7 @@ def upload_files
# get a fresh list of remote files
remote_files = get_remote_files
# fixes: https://github.com/rumblelabs/asset_sync/issues/19
- local_files_to_upload = local_files - remote_files
+ local_files_to_upload = local_files - ignored_files - remote_files
# Upload new files
local_files_to_upload.each do |f|
Something went wrong with that request. Please try again.