Class: S3Light::Bucket

Inherits:
Struct
  • Object
show all
Defined in:
lib/s3-light/bucket.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(client, name, persisted = false) ⇒ Bucket

Returns a new instance of Bucket.



5
6
7
# File 'lib/s3-light/bucket.rb', line 5

def initialize(client, name, persisted = false)
  super(client, name, persisted)
end

Instance Attribute Details

#clientObject

Returns the value of attribute client

Returns:

  • (Object)

    the current value of client



4
5
6
# File 'lib/s3-light/bucket.rb', line 4

def client
  @client
end

#nameObject

Returns the value of attribute name

Returns:

  • (Object)

    the current value of name



4
5
6
# File 'lib/s3-light/bucket.rb', line 4

def name
  @name
end

#persistedObject

Returns the value of attribute persisted

Returns:

  • (Object)

    the current value of persisted



4
5
6
# File 'lib/s3-light/bucket.rb', line 4

def persisted
  @persisted
end

Instance Method Details

#__destroy!(connection) ⇒ Object



45
46
47
# File 'lib/s3-light/bucket.rb', line 45

def __destroy!(connection)
  connection.make_request(:delete, "/#{name}")
end

#__save!(connection) ⇒ Object



49
50
51
# File 'lib/s3-light/bucket.rb', line 49

def __save!(connection)
  connection.make_request(:put, "/#{name}")
end

#destroy!Object



26
27
28
29
30
31
32
33
34
35
36
37
38
39
# File 'lib/s3-light/bucket.rb', line 26

def destroy!
  unless persisted
    raise S3Light::Error, 'Bucket does not exist'
  end

  self.client.with_connection do |connection|
    __destroy!(connection)
  rescue S3Light::Connection::HttpError => e
    raise e unless e.code == 404
  end

  self.persisted = false
  true
end

#inspectObject



57
58
59
# File 'lib/s3-light/bucket.rb', line 57

def inspect
  "#<#{self.class.name} @name=#{name} @persisted=#{persisted}>"
end

#objectsObject



41
42
43
# File 'lib/s3-light/bucket.rb', line 41

def objects
  @objects ||= S3Light::Client::ObjectsList.new(client, self)
end

#persisted?Boolean

Returns:

  • (Boolean)


53
54
55
# File 'lib/s3-light/bucket.rb', line 53

def persisted?
  persisted
end

#save!Object



9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
# File 'lib/s3-light/bucket.rb', line 9

def save!
  if persisted
    raise S3Light::Error, 'Bucket already exists'
  end

  if name.nil? || name.empty?
    raise S3Light::Error, 'Bucket name is required'
  end

  self.client.with_connection do |connection|
    __save!(connection)
  end

  self.persisted = true
  self
end