Class: WAZ::Blobs::Container

Inherits:
Object
  • Object
show all
Defined in:
lib/waz/blobs/container.rb

Instance Attribute Summary collapse

Class Method Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(name, metadata = nil) ⇒ Container

Returns a new instance of Container.



33
34
35
36
# File 'lib/waz/blobs/container.rb', line 33

def initialize(name,  = nil)
  self.name = name
  self.properties = 
end

Instance Attribute Details

#nameObject

Returns the value of attribute name.



31
32
33
# File 'lib/waz/blobs/container.rb', line 31

def name
  @name
end

#propertiesObject

Returns the value of attribute properties.



31
32
33
# File 'lib/waz/blobs/container.rb', line 31

def properties
  @properties
end

#public_accessObject

Returns the value of attribute public_access.



31
32
33
# File 'lib/waz/blobs/container.rb', line 31

def public_access
  @public_access
end

Class Method Details

.create(name) ⇒ Object



6
7
8
9
# File 'lib/waz/blobs/container.rb', line 6

def create(name)
  service_instance.create_container(name)
  return Container.new(name)
end

.find(name) ⇒ Object



11
12
13
14
15
16
17
18
# File 'lib/waz/blobs/container.rb', line 11

def find(name)
  begin 
    properties = service_instance.get_container_properties(name)
    return Container.new(name, properties)
  rescue RestClient::ResourceNotFound
    return nil
  end
end

.list(options = {}) ⇒ Object



20
21
22
# File 'lib/waz/blobs/container.rb', line 20

def list(options = {})
  service_instance.list_containers(options).map { |c| Container.new(c[:name]) }
end

Instance Method Details

#[](blob_name) ⇒ Object



71
72
73
74
75
76
77
78
79
80
# File 'lib/waz/blobs/container.rb', line 71

def [](blob_name)
  begin
    properties = service_instance.get_blob_properties("#{self.name}/#{blob_name}")
    return BlobObject.new(blob_name, 
                          service_instance.generate_request_uri(nil, "#{self.name}/#{blob_name}"),
                          properties[:content_type])
  rescue RestClient::ResourceNotFound
    return nil
  end
end

#blobsObject



60
61
62
# File 'lib/waz/blobs/container.rb', line 60

def blobs
  service_instance.list_blobs(name).map { |blob| WAZ::Blobs::BlobObject.new(blob[:name], blob[:url], blob[:content_type]) }
end

#destroy!Object



47
48
49
# File 'lib/waz/blobs/container.rb', line 47

def destroy!
  service_instance.delete_container(self.name)
end

#metadataObject



38
39
40
# File 'lib/waz/blobs/container.rb', line 38

def 
  self.properties ||= service_instance.get_container_properties(self.name)
end

#public_access?Boolean

Returns:

  • (Boolean)


51
52
53
# File 'lib/waz/blobs/container.rb', line 51

def public_access?
  public_access ||= service_instance.get_container_acl(self.name)
end

#put_properties(properties = {}) ⇒ Object



42
43
44
45
# File 'lib/waz/blobs/container.rb', line 42

def put_properties(properties = {})
  service_instance.set_container_properties(self.name, properties)
  self.properties = .merge!(properties)
end

#store(blob_name, payload, content_type, options = {}) ⇒ Object



64
65
66
67
68
69
# File 'lib/waz/blobs/container.rb', line 64

def store(blob_name, payload, content_type, options = {})
  service_instance.put_blob("#{self.name}/#{blob_name}", payload, content_type, options)
  return BlobObject.new(blob_name, 
                        service_instance.generate_request_uri(nil, "#{self.name}/#{blob_name}"),
                        content_type)
end