jackal-assets 0.1.0 → 0.1.2

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: 442d2cbf6b9fd0b6efa1123a1331a87d42814180
4
- data.tar.gz: 3cd7bb3f70a8b8ff56cd1576d1f327353a41ddd7
3
+ metadata.gz: 36e961c75794a2675f8614633df07b0a36296bb0
4
+ data.tar.gz: 53b634197b5337c6d11e4804e26faeb066f36f40
5
5
  SHA512:
6
- metadata.gz: 6a5a1521f5a4be2df8b8953982fac97188fb137b6451dd94d605b47af47e694b9ea39b024be32e6f878c3ea6b671cc62753b0bcea69f5f6ba68ce7d780231529
7
- data.tar.gz: 2ab1b4eacc496ba34bf3f93d74d86880088f47760112126d7ce8b9ed8777e03ade358b650f61e08b722b322427a5fa58987f6787ff21d5a388f2f0ef753df193
6
+ metadata.gz: 717a32e002651c49e00a96c04c44c1691697374392a845e5b26b6fc1abf8ca709a230c5b0554d79a45ce2ac1829aa6ca3f08a1bc9de29902e76143589266f30e
7
+ data.tar.gz: 8d9816ce192fa881118c0a80d370ae71fb6ea4a359ab01b7f527ea68da9aa3a84737fff46014d0536e41ee144edb7b823154cec61e4a33dbfb89bbf39e8772e8
@@ -1,2 +1,6 @@
1
- ## v0.1.0
1
+ # v0.1.2
2
+ * Include support for packing and unpacking assets
3
+ * Return proper IO-ish object from #get
4
+
5
+ # v0.1.0
2
6
  * Initial release
data/README.md CHANGED
@@ -27,8 +27,10 @@ Configure
27
27
  {
28
28
  "jackal": {
29
29
  "assets": {
30
- "provider": "aws",
31
- "credentials": {
30
+ "connection": {
31
+ "provider": "aws",
32
+ "credentials": {
33
+ }
32
34
  },
33
35
  "bucket": "BUCKET_NAME"
34
36
  }
@@ -13,5 +13,6 @@ Gem::Specification.new do |s|
13
13
  s.add_dependency 'jackal'
14
14
  s.add_dependency 'miasma'
15
15
  s.add_dependency 'miasma-local'
16
+ s.add_dependency 'rubyzip'
16
17
  s.files = Dir['{lib}/**/**/*'] + %w(jackal-assets.gemspec README.md CHANGELOG.md)
17
18
  end
@@ -1,4 +1,5 @@
1
1
  require 'jackal-assets'
2
+ require 'zip'
2
3
 
3
4
  module Jackal
4
5
  module Assets
@@ -47,7 +48,10 @@ module Jackal
47
48
  )
48
49
  )
49
50
  )
50
- @bucket = @connection.buckets.build(:name => bucket_name).save
51
+ @bucket = @connection.buckets.get(bucket_name)
52
+ unless(@bucket)
53
+ @bucket = @connection.buckets.build(:name => bucket_name).save
54
+ end
51
55
  end
52
56
 
53
57
  # Fetch object
@@ -57,7 +61,7 @@ module Jackal
57
61
  def get(key)
58
62
  remote_file = bucket.files.reload.get(key)
59
63
  if(remote_file)
60
- remote_file.body
64
+ remote_file.body.io
61
65
  else
62
66
  raise Error::NotFound.new "Remote file does not exist! (<#{bucket}>:#{key})"
63
67
  end
@@ -104,6 +108,69 @@ module Jackal
104
108
  end
105
109
  end
106
110
 
111
+ # Pack directory into compressed file
112
+ #
113
+ # @param directory [String]
114
+ # @param name [String] tmp file base name
115
+ # @return [File]
116
+ def pack(directory, name=nil)
117
+ tmp_file = Tempfile.new(name || File.basename(directory))
118
+ file_path = "#{tmp_file.path}.zip"
119
+ tmp_file.delete
120
+ entries = Hash[
121
+ Dir.glob(File.join(directory, '**', '{*,.*}')).map do |path|
122
+ next if path.end_with?('.')
123
+ [path.sub(%r{#{Regexp.escape(directory)}/?}, ''), path]
124
+ end
125
+ ]
126
+ Zip::File.open(file_path, Zip::File::CREATE) do |zipfile|
127
+ entries.keys.sort.each do |entry|
128
+ path = entries[entry]
129
+ if(File.directory?(path))
130
+ zipfile.mkdir(entry.dup)
131
+ else
132
+ zipfile.add(entry, path)
133
+ end
134
+ end
135
+ end
136
+ file = File.open(file_path, 'rb')
137
+ file
138
+ end
139
+
140
+ # Unpack object
141
+ #
142
+ # @param object [File]
143
+ # @param destination [String]
144
+ # @param args [Symbol] argument list (:disable_overwrite)
145
+ # @return [String] destination
146
+ def unpack(object, destination, *args)
147
+ if(File.exists?(destination) && args.include?(:disable_overwrite))
148
+ destination
149
+ else
150
+ unless(File.directory?(destination))
151
+ FileUtils.mkdir_p(destination)
152
+ end
153
+ if(object.respond_to?(:path))
154
+ to_unpack = object.path
155
+ elsif(object.respond_to?(:io))
156
+ to_unpack = object.io
157
+ else
158
+ to_unpack = object
159
+ end
160
+ zfile = Zip::File.new(to_unpack)
161
+ zfile.restore_permissions = true
162
+ zfile.each do |entry|
163
+ new_dest = File.join(destination, entry.name)
164
+ if(File.exists?(new_dest))
165
+ FileUtils.rm_rf(new_dest)
166
+ end
167
+ entry.restore_permissions = true
168
+ entry.extract(new_dest)
169
+ end
170
+ destination
171
+ end
172
+ end
173
+
107
174
  end
108
175
  end
109
176
  end
@@ -1,6 +1,6 @@
1
1
  module Jackal
2
2
  module Assets
3
3
  # Current library version
4
- VERSION = Gem::Version.new('0.1.0')
4
+ VERSION = Gem::Version.new('0.1.2')
5
5
  end
6
6
  end
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: jackal-assets
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.1.0
4
+ version: 0.1.2
5
5
  platform: ruby
6
6
  authors:
7
7
  - Chris Roberts
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2015-01-18 00:00:00.000000000 Z
11
+ date: 2015-03-04 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: jackal
@@ -52,6 +52,20 @@ dependencies:
52
52
  - - ">="
53
53
  - !ruby/object:Gem::Version
54
54
  version: '0'
55
+ - !ruby/object:Gem::Dependency
56
+ name: rubyzip
57
+ requirement: !ruby/object:Gem::Requirement
58
+ requirements:
59
+ - - ">="
60
+ - !ruby/object:Gem::Version
61
+ version: '0'
62
+ type: :runtime
63
+ prerelease: false
64
+ version_requirements: !ruby/object:Gem::Requirement
65
+ requirements:
66
+ - - ">="
67
+ - !ruby/object:Gem::Version
68
+ version: '0'
55
69
  description: Jackal Assets
56
70
  email: code@chrisroberts.org
57
71
  executables: []