Class: RAWS::S3
- Inherits:
-
Object
show all
- Extended by:
- Enumerable
- Defined in:
- lib/raws/s3.rb
Defined Under Namespace
Modules: Model
Classes: ACL, Adapter, Metadata, Owner
Class Attribute Summary collapse
Instance Attribute Summary collapse
Class Method Summary
collapse
-
.[](bucket_name) ⇒ Object
Returns the instance of RAWS::S3.
-
.acl(bucket_name, key = nil) ⇒ Object
-
.all ⇒ Object
-
.buckets(&block) ⇒ Object
-
.copy ⇒ Object
-
.copy_object(src_bucket, src_key, dest_bucket, dest_key, header = {}) ⇒ Object
-
.create_bucket(bucket_name, location = nil, header = {}) ⇒ Object
Creates a new bucket and returns the instance of RAWS::S3.
-
.delete ⇒ Object
-
.delete_bucket(bucket_name, force = nil) ⇒ Object
-
.delete_object(bucket_name, key) ⇒ Object
-
.each(&block) ⇒ Object
-
.filter(bucket_name, query = {}) ⇒ Object
-
.get ⇒ Object
-
.get_object(bucket_name, key, header = {}, &block) ⇒ Object
-
.head ⇒ Object
-
.head_object(bucket_name, key) ⇒ Object
-
.list_buckets ⇒ Object
Returns an array of RAWS::S3 objects.
-
.location(bucket_name) ⇒ Object
-
.owner ⇒ Object
Returns the instance of RAWS::S3::Owner.
-
.put ⇒ Object
-
.put_object(bucket_name, key, header = {}, &block) ⇒ Object
Instance Method Summary
collapse
Constructor Details
#initialize(bucket_name) ⇒ S3
Returns a new instance of S3.
113
114
115
|
# File 'lib/raws/s3.rb', line 113
def initialize(bucket_name)
@bucket_name = bucket_name
end
|
Class Attribute Details
.http ⇒ Object
13
14
15
|
# File 'lib/raws/s3.rb', line 13
def http
@http ||= RAWS.http
end
|
Instance Attribute Details
#bucket_name ⇒ Object
Also known as:
name
Returns the value of attribute bucket_name.
110
111
112
|
# File 'lib/raws/s3.rb', line 110
def bucket_name
@bucket_name
end
|
Class Method Details
.[](bucket_name) ⇒ Object
Returns the instance of RAWS::S3.
65
66
67
|
# File 'lib/raws/s3.rb', line 65
def [](bucket_name)
self.new bucket_name
end
|
.acl(bucket_name, key = nil) ⇒ Object
74
75
76
|
# File 'lib/raws/s3.rb', line 74
def acl(bucket_name, key=nil)
ACL.new bucket_name, key
end
|
.all ⇒ Object
82
83
84
85
|
# File 'lib/raws/s3.rb', line 82
def filter(bucket_name, query={})
vals = Adapter.get_bucket(bucket_name, query).doc['ListBucketResult']
vals['Contents'] || []
end
|
.buckets(&block) ⇒ Object
52
53
54
55
56
57
58
|
# File 'lib/raws/s3.rb', line 52
def buckets(&block)
if block_given?
each(&block)
else
map
end
end
|
.copy ⇒ Object
92
93
94
|
# File 'lib/raws/s3.rb', line 92
def copy_object(src_bucket, src_key, dest_bucket, dest_key, ={})
Adapter.copy_object src_bucket, src_key, dest_bucket, dest_key,
end
|
.copy_object(src_bucket, src_key, dest_bucket, dest_key, header = {}) ⇒ Object
89
90
91
|
# File 'lib/raws/s3.rb', line 89
def copy_object(src_bucket, src_key, dest_bucket, dest_key, ={})
Adapter.copy_object src_bucket, src_key, dest_bucket, dest_key,
end
|
.create_bucket(bucket_name, location = nil, header = {}) ⇒ Object
Creates a new bucket and returns the instance of RAWS::S3.
18
19
20
21
|
# File 'lib/raws/s3.rb', line 18
def create_bucket(bucket_name, location=nil, ={})
Adapter.put_bucket bucket_name, location,
self[bucket_name]
end
|
.delete ⇒ Object
107
108
109
|
# File 'lib/raws/s3.rb', line 107
def delete_object(bucket_name, key)
Adapter.delete_object bucket_name, key
end
|
.delete_bucket(bucket_name, force = nil) ⇒ Object
24
25
26
27
28
29
30
31
32
33
|
# File 'lib/raws/s3.rb', line 24
def delete_bucket(bucket_name, force=nil)
begin
objects = filter(bucket_name)
objects.each do |val|
delete(bucket_name, val['Key'])
end
end until objects.empty? if force == :force
Adapter.delete_bucket(bucket_name)
end
|
.delete_object(bucket_name, key) ⇒ Object
104
105
106
|
# File 'lib/raws/s3.rb', line 104
def delete_object(bucket_name, key)
Adapter.delete_object bucket_name, key
end
|
.each(&block) ⇒ Object
60
61
62
|
# File 'lib/raws/s3.rb', line 60
def each(&block)
list_buckets.each(&block)
end
|
.filter(bucket_name, query = {}) ⇒ Object
78
79
80
81
|
# File 'lib/raws/s3.rb', line 78
def filter(bucket_name, query={})
vals = Adapter.get_bucket(bucket_name, query).doc['ListBucketResult']
vals['Contents'] || []
end
|
.get ⇒ Object
97
98
99
|
# File 'lib/raws/s3.rb', line 97
def get_object(bucket_name, key, ={}, &block)
Adapter.get_object bucket_name, key, , &block
end
|
.get_object(bucket_name, key, header = {}, &block) ⇒ Object
94
95
96
|
# File 'lib/raws/s3.rb', line 94
def get_object(bucket_name, key, ={}, &block)
Adapter.get_object bucket_name, key, , &block
end
|
.head ⇒ Object
102
103
104
|
# File 'lib/raws/s3.rb', line 102
def head_object(bucket_name, key)
Adapter.head_object bucket_name, key
end
|
.head_object(bucket_name, key) ⇒ Object
99
100
101
|
# File 'lib/raws/s3.rb', line 99
def head_object(bucket_name, key)
Adapter.head_object bucket_name, key
end
|
.list_buckets ⇒ Object
Returns an array of RAWS::S3 objects.
41
42
43
44
45
46
47
48
49
50
|
# File 'lib/raws/s3.rb', line 41
def list_buckets
doc = Adapter.get_service.doc['ListAllMyBucketsResult']['Buckets']
if doc
doc['Bucket'].map do |val|
self[val['Name']]
end
else
[]
end
end
|
.location(bucket_name) ⇒ Object
69
70
71
72
|
# File 'lib/raws/s3.rb', line 69
def location(bucket_name)
doc = Adapter.get_bucket_location(bucket_name).doc['LocationConstraint']
doc || 'US'
end
|
.owner ⇒ Object
Returns the instance of RAWS::S3::Owner.
.put ⇒ Object
87
88
89
|
# File 'lib/raws/s3.rb', line 87
def put_object(bucket_name, key, ={}, &block)
Adapter.put_object bucket_name, key, , &block
end
|
.put_object(bucket_name, key, header = {}, &block) ⇒ Object
84
85
86
|
# File 'lib/raws/s3.rb', line 84
def put_object(bucket_name, key, ={}, &block)
Adapter.put_object bucket_name, key, , &block
end
|
Instance Method Details
#<=>(a) ⇒ Object
167
168
169
|
# File 'lib/raws/s3.rb', line 167
def <=>(a)
bucket_name <=> a.bucket_name
end
|
#acl(key = nil) ⇒ Object
133
134
135
|
# File 'lib/raws/s3.rb', line 133
def acl(key=nil)
self.class.acl @bucket_name, key
end
|
#copy_object(key, dest_bucket, dest_key) ⇒ Object
Also known as:
copy
147
148
149
|
# File 'lib/raws/s3.rb', line 147
def copy_object(key, dest_bucket, dest_key)
self.class.copy_object @bucket_name, key, dest_bucket, dest_key
end
|
#create_bucket(location = nil) ⇒ Object
117
118
119
|
# File 'lib/raws/s3.rb', line 117
def create_bucket(location=nil)
self.class.create_bucket @bucket_name, location
end
|
#delete_bucket(force = nil) ⇒ Object
121
122
123
|
# File 'lib/raws/s3.rb', line 121
def delete_bucket(force=nil)
self.class.delete_bucket @bucket_name, force
end
|
#delete_object(key) ⇒ Object
Also known as:
delete
162
163
164
|
# File 'lib/raws/s3.rb', line 162
def delete_object(key)
self.class.delete_object @bucket_name, key
end
|
#filter(query = {}) ⇒ Object
Also known as:
all
137
138
139
|
# File 'lib/raws/s3.rb', line 137
def filter(query={})
self.class.filter @bucket_name, query
end
|
#get_object(key, header = {}, &block) ⇒ Object
Also known as:
get
152
153
154
|
# File 'lib/raws/s3.rb', line 152
def get_object(key, ={}, &block)
self.class.get_object @bucket_name, key, , &block
end
|
#head_object(key) ⇒ Object
Also known as:
head
157
158
159
|
# File 'lib/raws/s3.rb', line 157
def head_object(key)
self.class.head_object @bucket_name, key
end
|
#location ⇒ Object
129
130
131
|
# File 'lib/raws/s3.rb', line 129
def location
self.class.location @bucket_name
end
|
#owner ⇒ Object
125
126
127
|
# File 'lib/raws/s3.rb', line 125
def owner
self.class.owner
end
|
#put_object(key, header = {}, &block) ⇒ Object
Also known as:
put
142
143
144
|
# File 'lib/raws/s3.rb', line 142
def put_object(key, ={}, &block)
self.class.put_object @bucket_name, key, , &block
end
|