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 +4 -4
- data/CHANGELOG.md +5 -1
- data/README.md +4 -2
- data/jackal-assets.gemspec +1 -0
- data/lib/jackal-assets/store.rb +69 -2
- data/lib/jackal-assets/version.rb +1 -1
- metadata +16 -2
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 36e961c75794a2675f8614633df07b0a36296bb0
|
4
|
+
data.tar.gz: 53b634197b5337c6d11e4804e26faeb066f36f40
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 717a32e002651c49e00a96c04c44c1691697374392a845e5b26b6fc1abf8ca709a230c5b0554d79a45ce2ac1829aa6ca3f08a1bc9de29902e76143589266f30e
|
7
|
+
data.tar.gz: 8d9816ce192fa881118c0a80d370ae71fb6ea4a359ab01b7f527ea68da9aa3a84737fff46014d0536e41ee144edb7b823154cec61e4a33dbfb89bbf39e8772e8
|
data/CHANGELOG.md
CHANGED
data/README.md
CHANGED
data/jackal-assets.gemspec
CHANGED
data/lib/jackal-assets/store.rb
CHANGED
@@ -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.
|
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
|
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.
|
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-
|
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: []
|