Class: AssetCloud::BucketChain

Inherits:
Bucket
  • Object
show all
Defined in:
lib/asset_cloud/buckets/bucket_chain.rb

Instance Attribute Summary

Attributes inherited from Bucket

#cloud, #name

Class Method Summary collapse

Instance Method Summary collapse

Methods inherited from Bucket

#initialize, #versioned?

Constructor Details

This class inherits a constructor from AssetCloud::Bucket

Dynamic Method Handling

This class handles dynamic methods through the method_missing method

#method_missing(sym, *args) ⇒ Object



41
42
43
# File 'lib/asset_cloud/buckets/bucket_chain.rb', line 41

def method_missing(sym, *args)
  first_possible_bucket {|b| b.send(sym, *args)}
end

Class Method Details

.chain(*klasses) ⇒ Object

returns a new Bucket class which writes to each given Bucket but only uses the first one for reading



5
6
7
8
9
10
11
12
13
# File 'lib/asset_cloud/buckets/bucket_chain.rb', line 5

def self.chain(*klasses)
  Class.new(self) do
    attr_reader :chained_buckets
    define_method 'initialize' do |cloud, name|
      super(cloud, name)
      @chained_buckets = klasses.map {|klass| klass.new(cloud,name)}
    end
  end
end

Instance Method Details

#delete(key) ⇒ Object



34
35
36
# File 'lib/asset_cloud/buckets/bucket_chain.rb', line 34

def delete(key)
  every_bucket_with_transaction_on_key(key) {|b| b.delete(key)}
end

#ls(key = nil) ⇒ Object



15
16
17
# File 'lib/asset_cloud/buckets/bucket_chain.rb', line 15

def ls(key=nil)
  first_possible_bucket {|b| b.ls(key)}
end

#read(key) ⇒ Object



18
19
20
# File 'lib/asset_cloud/buckets/bucket_chain.rb', line 18

def read(key)
  first_possible_bucket {|b| b.read(key)}
end

#read_version(key, version) ⇒ Object



24
25
26
# File 'lib/asset_cloud/buckets/bucket_chain.rb', line 24

def read_version(key, version)
  first_possible_bucket {|b| b.read_version(key, version)}
end

#respond_to?(sym) ⇒ Boolean

Returns:

  • (Boolean)


38
39
40
# File 'lib/asset_cloud/buckets/bucket_chain.rb', line 38

def respond_to?(sym)
  @chained_buckets.any? {|b| b.respond_to?(sym)}
end

#stat(key = nil) ⇒ Object



21
22
23
# File 'lib/asset_cloud/buckets/bucket_chain.rb', line 21

def stat(key=nil)
  first_possible_bucket {|b| b.stat(key)}
end

#versions(key) ⇒ Object



27
28
29
# File 'lib/asset_cloud/buckets/bucket_chain.rb', line 27

def versions(key)
  first_possible_bucket {|b| b.versions(key)}
end

#write(key, data) ⇒ Object



31
32
33
# File 'lib/asset_cloud/buckets/bucket_chain.rb', line 31

def write(key, data)
  every_bucket_with_transaction_on_key(key) {|b| b.write(key, data)}
end