Class: AssetCloud::ActiveRecordBucket

Inherits:
Bucket
  • Object
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?

Constructor Details

This class inherits a constructor from AssetCloud::Bucket

Instance Method Details

#delete(key) ⇒ Object



26
27
28
29
30
# File 'lib/asset_cloud/buckets/active_record_bucket.rb', line 26

def delete(key)
  if (record = find_record(key))
    record.destroy
  end
end

#ls(key = name) ⇒ Object



9
10
11
12
13
14
# File 'lib/asset_cloud/buckets/active_record_bucket.rb', line 9

def ls(key = name)
  col = records.connection.quote_column_name(key_attribute)
  records.all(conditions: ["#{col} LIKE ?", "#{key}%"]).map do |r|
    cloud[r.send(key_attribute)]
  end
end

#read(key) ⇒ Object



16
17
18
# File 'lib/asset_cloud/buckets/active_record_bucket.rb', line 16

def read(key)
  find_record!(key).send(value_attribute)
end

#stat(key) ⇒ Object



32
33
34
35
36
37
38
# File 'lib/asset_cloud/buckets/active_record_bucket.rb', line 32

def stat(key)
  if (record = find_record(key))
    AssetCloud::Metadata.new(true, record.send(value_attribute).size, record.created_at, record.updated_at)
  else
    AssetCloud::Metadata.new(false)
  end
end

#write(key, value) ⇒ Object



20
21
22
23
24
# File 'lib/asset_cloud/buckets/active_record_bucket.rb', line 20

def write(key, value)
  record = records.send("find_or_initialize_by_#{key_attribute}", key.to_s)
  record.send("#{value_attribute}=", value)
  record.save!
end