filestorage 0.0.2 → 0.0.3
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/Gemfile +2 -0
- data/lib/filestorage.rb +1 -0
- data/lib/filestorage/s3_filestorage.rb +50 -0
- data/lib/filestorage/version.rb +1 -1
- metadata +2 -1
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 127bdfaa77c8a4487a8d59390e2fefe8896cb929
|
4
|
+
data.tar.gz: 2baf8f28f227a1534575d128f89fc72fbdfe8cfa
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 6aed5c1d8f6ce34ae7effffa94cc810b46307119b196652be53d6f7f510372a07ff89e1a14ae7e909b15b7877730b596046c542f9dd938f753c201eea4e835e3
|
7
|
+
data.tar.gz: 73573b098183f4a74f1fdf9dff3c18abe7e883d759d7d44e5e242e40279a7243afb9d4ae8f26d867f0b40b05c46e757cf5930b2e5d9450e9f88277e431517eed
|
data/Gemfile
CHANGED
data/lib/filestorage.rb
CHANGED
@@ -0,0 +1,50 @@
|
|
1
|
+
# encoding: utf-8
|
2
|
+
|
3
|
+
require 'aws'
|
4
|
+
|
5
|
+
|
6
|
+
module Filestorage
|
7
|
+
|
8
|
+
class S3Filestorage
|
9
|
+
|
10
|
+
def initialize(bucket, access_key_id, secret_access_key)
|
11
|
+
@s3 = AWS::S3.new(:access_key_id => access_key_id,
|
12
|
+
:secret_access_key => secret_access_key)
|
13
|
+
@bucket = @s3.buckets[bucket]
|
14
|
+
end
|
15
|
+
|
16
|
+
def store(path, file)
|
17
|
+
obj = @bucket.objects[path]
|
18
|
+
raise AlreadyExist.new("Already exist #{path}") if obj.exists?
|
19
|
+
content = if file.instance_of?(Pathname)
|
20
|
+
File.open(file, "rb"){|f| f.read}
|
21
|
+
elsif file.instance_of?(File)
|
22
|
+
file.read
|
23
|
+
else
|
24
|
+
file
|
25
|
+
end
|
26
|
+
obj.write(content, :acl => :public_read)
|
27
|
+
path
|
28
|
+
end
|
29
|
+
|
30
|
+
def get(path)
|
31
|
+
obj = @bucket.objects[path]
|
32
|
+
raise NotExist.new("Not exist #{path}") unless obj.exists?
|
33
|
+
obj
|
34
|
+
end
|
35
|
+
|
36
|
+
def delete(path)
|
37
|
+
obj = @bucket.objects[path]
|
38
|
+
raise NotExist.new("Not exist #{path}") unless obj.exists?
|
39
|
+
obj.delete
|
40
|
+
path
|
41
|
+
end
|
42
|
+
|
43
|
+
def exist?(path)
|
44
|
+
obj = @bucket.objects[path]
|
45
|
+
obj.exists?
|
46
|
+
end
|
47
|
+
|
48
|
+
end # of class S3Filestorage
|
49
|
+
|
50
|
+
end # of module Filestorag
|
data/lib/filestorage/version.rb
CHANGED
metadata
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: filestorage
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.0.
|
4
|
+
version: 0.0.3
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- takatoh
|
@@ -53,6 +53,7 @@ files:
|
|
53
53
|
- filestorage.gemspec
|
54
54
|
- lib/filestorage.rb
|
55
55
|
- lib/filestorage/local_filestorage.rb
|
56
|
+
- lib/filestorage/s3_filestorage.rb
|
56
57
|
- lib/filestorage/version.rb
|
57
58
|
homepage: ''
|
58
59
|
licenses:
|