Class: AssetCloud::ActiveRecordBucket
- Inherits:
-
Bucket
- Object
- Bucket
- AssetCloud::ActiveRecordBucket
show all
- Defined in:
- lib/asset_cloud/buckets/active_record_bucket.rb
Instance Attribute Summary
Attributes inherited from Bucket
#cloud, #name
Instance Method Summary
collapse
Methods inherited from Bucket
#initialize, #versioned?
Instance Method Details
#delete(key) ⇒ Object
24
25
26
27
28
|
# File 'lib/asset_cloud/buckets/active_record_bucket.rb', line 24
def delete(key)
if record = find_record(key)
record.destroy
end
end
|
#ls(key = name) ⇒ Object
7
8
9
10
11
12
|
# File 'lib/asset_cloud/buckets/active_record_bucket.rb', line 7
def ls(key=name)
col = records.connection.quote_column_name(self.key_attribute)
records.all(:conditions => ["#{col} LIKE ?", "#{key}%"]).map do |r|
cloud[r.send(self.key_attribute)]
end
end
|
#read(key) ⇒ Object
14
15
16
|
# File 'lib/asset_cloud/buckets/active_record_bucket.rb', line 14
def read(key)
find_record!(key).send(self.value_attribute)
end
|
#stat(key) ⇒ Object
30
31
32
33
34
35
36
|
# File 'lib/asset_cloud/buckets/active_record_bucket.rb', line 30
def stat(key)
if record = find_record(key)
AssetCloud::Metadata.new(true, record.send(self.value_attribute).size, record.created_at, record.updated_at)
else
AssetCloud::Metadata.new(false)
end
end
|
#write(key, value) ⇒ Object
18
19
20
21
22
|
# File 'lib/asset_cloud/buckets/active_record_bucket.rb', line 18
def write(key, value)
record = records.send("find_or_initialize_by_#{self.key_attribute}", key.to_s)
record.send("#{self.value_attribute}=", value)
record.save!
end
|