sync_fog 0.1.0 → 0.2.0

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: 328082eeedeead682bb41bf3774bba91a31bb1a8
4
- data.tar.gz: 89c9d199d90cf2259fffbb16715ee3a455eb06f5
3
+ metadata.gz: 783b32b57d819b428dd5a48899a950f88ebaf812
4
+ data.tar.gz: a44c051d4c264649208d2c7a9b8cd55dc684ee6e
5
5
  SHA512:
6
- metadata.gz: 92043f10bae790ff50bbe6616657e256b4512fa77345d7a6395b221cadd25f2f38235ef86d535aaf495508e0be2a0b1935891cc79b4c17fbfb6c3e55632761a8
7
- data.tar.gz: 824c5e6d28f6d87b4daab0a8952a8982ea08d9ca2ee243f029fae711a162b9aa3553466850b0a31d614435465885e6bb10cd5d6ec1684ad89fc6027a9b643400
6
+ metadata.gz: 4690c38f7203a4588ba90eb1cf21bac061ccf3b8756bd888983af1a420bc849f1d00f0225f6d221bf8cf1ea95326bf58880f43731427ce0524fe2cf698ad0d33
7
+ data.tar.gz: c43219c2fe44abd925280078a9465aeaebc30b6e27be9283a278b75d1c1f4ce010e23b31d03bea3144d6d4c289ec4c9075341b7bb0a96db7527a9b32777d0bca
data/README.md CHANGED
@@ -1,3 +1,6 @@
1
+ [![Gem Version](https://badge.fury.io/rb/sync_fog.svg)](https://badge.fury.io/rb/sync_fog)
2
+ [![Code Climate](https://codeclimate.com/github/ben-ole/sync_fog/badges/gpa.svg)](https://codeclimate.com/github/ben-ole/sync_fog)
3
+
1
4
  # SyncFog
2
5
 
3
6
  SyncFog is a super simple way to upload precompiled (static) assets on a file storage like S3, Rackspace or OpenStack. This is specifically useful if you are deploying to cloud containers like Heroku as you don't want your application containers being responsible for serving static files.
@@ -10,6 +13,7 @@ This gem is an alternative to [asset_sync](https://github.com/AssetSync/asset_sy
10
13
  - SyncFog can be used with any storage supported by the famous [fog gem](https://github.com/fog/fog).
11
14
  - SyncFog is easy to configure (using almost the same attributes as carrierwave!)
12
15
  - SyncFog hooks in automatically on assets:precompile
16
+ - tested with Rails 4.2 and OpenStack, but should work with Rails 3+
13
17
 
14
18
  ## Installation
15
19
 
@@ -57,4 +57,10 @@ SyncFog.configure do |config|
57
57
  # #
58
58
  # config.hook_enabled = true
59
59
 
60
+ # ##
61
+ # # Enable/Disable upload only gzip variants and set correct headers.
62
+ # # Default is true
63
+ # #
64
+ # config.use_gzip = true
65
+
60
66
  end
@@ -54,6 +54,12 @@ module SyncFog
54
54
  #
55
55
  attr_accessor :hook_enabled
56
56
 
57
+ ##
58
+ # Enable/Disable upload only gzip variants and set correct headers.
59
+ # Default is true
60
+ #
61
+ attr_accessor :use_gzip
62
+
57
63
 
58
64
  def initialize #:nodoc:
59
65
  @fog_credentials = { }
@@ -69,6 +75,8 @@ module SyncFog
69
75
  @num_threads = 5
70
76
 
71
77
  @hook_enabled = true
78
+
79
+ @use_gzip = true
72
80
  end
73
81
  end
74
82
 
@@ -20,7 +20,26 @@ module SyncFog
20
20
  files << path.relative_path_from(root_path) unless %w(. ..).include?(file)
21
21
  end
22
22
 
23
- files
23
+ SyncFog.configuration.use_gzip ? filter_zip(files) : files
24
+ end
25
+
26
+
27
+ ## Helper
28
+ def filter_zip(files)
29
+ files_copy = files
30
+ files_strings = files.map{|f| f.to_s}
31
+
32
+ Parallel.map(files, in_threads: @num_threads) do |file|
33
+
34
+ # remove files which have an gz equivalent
35
+ unless File.extname(file) != ".gz" &&
36
+ files_strings.include?( "#{file.to_s}.gz" )
37
+
38
+ files_copy << file
39
+ end
40
+ end
41
+
42
+ files_copy
24
43
  end
25
44
 
26
45
  end
@@ -5,6 +5,7 @@
5
5
 
6
6
  require 'fog'
7
7
  require 'parallel'
8
+ require 'multi_mime'
8
9
 
9
10
  module SyncFog
10
11
  class SyncFogUpload
@@ -13,9 +14,10 @@ module SyncFog
13
14
 
14
15
  @fog_service = Fog::Storage.new(config)
15
16
  @container = @fog_service.directories.get(container)
16
- @skip = SyncFog.configuration.skip_existing
17
+ @skip = SyncFog.configuration.skip_existing
17
18
  @num_threads = SyncFog.configuration.num_threads
18
19
  @meta = SyncFog.configuration.fog_attributes
20
+ @check_zip = SyncFog.configuration.use_gzip
19
21
  end
20
22
 
21
23
  ## uploading files
@@ -23,25 +25,33 @@ module SyncFog
23
25
 
24
26
  Parallel.map(files,in_threads: @num_threads) do |source_file|
25
27
  upload_file(source_file,dir)
26
- end
28
+ end
27
29
  end
28
30
 
29
31
  def upload_file(source_file,dir)
30
32
  path = dir + source_file
31
- name = source_file.to_s
33
+ name = source_file.to_s
34
+ meta = @meta
32
35
 
33
36
  return if File.directory?(path)
37
+
38
+ if @check_zip && File.extname(path) == ".gz"
39
+ meta = {'Content-Encoding' => 'gzip'}.merge(meta)
40
+ name = name.gsub('.gz','')
41
+ end
42
+
34
43
  return if @skip && @container.files.head(name)
35
44
 
45
+ content_type = MultiMime.type_for_path( name )
46
+
36
47
  File.open(path) do |data|
37
- @container.files.create(key: name, body: data, metadata: @meta)
38
- @meta
48
+ @container.files.create(key: name, body: data, metadata: meta, content_type: content_type)
39
49
  end
40
50
  end
41
51
 
42
52
  ## Removing files
43
53
  def clean_remote(keep_files)
44
- keep_files_string = keep_files.map{|f| f.to_s}
54
+ keep_files_string = keep_files.map{|f| f.to_s}
45
55
 
46
56
  Parallel.map(@container.files,in_threads: @num_threads) do |file|
47
57
  remove_file(file,keep_files_string)
@@ -49,9 +59,10 @@ module SyncFog
49
59
  end
50
60
 
51
61
  def remove_file(file,keep_files_string)
52
- unless keep_files_string.include?(file.key)
62
+ unless keep_files_string.include?(file.key) ||
63
+ keep_files_string.include?("#{file.key}.gz")
53
64
  p "SyncFog: -> removing #{file.key}"
54
- file.destroy
65
+ file.destroy
55
66
  end
56
67
  end
57
68
 
@@ -4,5 +4,5 @@
4
4
  # 2015
5
5
 
6
6
  module SyncFog
7
- VERSION = "0.1.0"
7
+ VERSION = "0.2.0"
8
8
  end
data/sync_fog.gemspec CHANGED
@@ -25,4 +25,5 @@ Gem::Specification.new do |spec|
25
25
 
26
26
  spec.add_runtime_dependency 'fog', '~> 1.35'
27
27
  spec.add_runtime_dependency 'parallel', '~> 1.6'
28
+ spec.add_runtime_dependency 'multi_mime', '~> 1.0'
28
29
  end
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: sync_fog
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.1.0
4
+ version: 0.2.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - Benjamin Müller
8
8
  autorequire:
9
9
  bindir: exe
10
10
  cert_chain: []
11
- date: 2015-11-01 00:00:00.000000000 Z
11
+ date: 2015-11-03 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: bundler
@@ -98,6 +98,20 @@ dependencies:
98
98
  - - ~>
99
99
  - !ruby/object:Gem::Version
100
100
  version: '1.6'
101
+ - !ruby/object:Gem::Dependency
102
+ name: multi_mime
103
+ requirement: !ruby/object:Gem::Requirement
104
+ requirements:
105
+ - - ~>
106
+ - !ruby/object:Gem::Version
107
+ version: '1.0'
108
+ type: :runtime
109
+ prerelease: false
110
+ version_requirements: !ruby/object:Gem::Requirement
111
+ requirements:
112
+ - - ~>
113
+ - !ruby/object:Gem::Version
114
+ version: '1.0'
101
115
  description: Uploads the precompiled assets in public/assets to any fog storage.
102
116
  email:
103
117
  - elchbenny@googlemail.com