Class: Buckets::BucketMetaObject

Inherits:
Utils
  • Object
show all
Defined in:
lib/buckets.rb

Overview

BucketMetaObject Contains information about an object

Instance Attribute Summary collapse

Instance Method Summary collapse

Methods inherited from Utils

#connection

Constructor Details

#initialize(*args) ⇒ BucketMetaObject

Returns a new instance of BucketMetaObject.



136
137
138
139
140
141
142
143
144
145
146
# File 'lib/buckets.rb', line 136

def initialize(*args)
  @properties         = args.first
  @bucket_name        = @properties[:bucket_name]
  @key                = @properties[:key]
  @last_modified      = @properties[:last_modified]
  @e_tag              = @properties[:e_tag]
  @size               = @properties[:size]
  @storage_class      = @properties[:storage_class]
  @owner_id           = @properties[:owner_id]
  @owner_display_name = @properties[:owner_display_name]
end

Instance Attribute Details

#bucket_nameObject

Returns the value of attribute bucket_name.



131
132
133
# File 'lib/buckets.rb', line 131

def bucket_name
  @bucket_name
end

#e_tagObject

Returns the value of attribute e_tag.



131
132
133
# File 'lib/buckets.rb', line 131

def e_tag
  @e_tag
end

#keyObject

Returns the value of attribute key.



131
132
133
# File 'lib/buckets.rb', line 131

def key
  @key
end

#last_modifiedObject

Returns the value of attribute last_modified.



131
132
133
# File 'lib/buckets.rb', line 131

def last_modified
  @last_modified
end

#owner_display_nameObject

Returns the value of attribute owner_display_name.



131
132
133
# File 'lib/buckets.rb', line 131

def owner_display_name
  @owner_display_name
end

#owner_idObject

Returns the value of attribute owner_id.



131
132
133
# File 'lib/buckets.rb', line 131

def owner_id
  @owner_id
end

#propertiesObject

Returns the value of attribute properties.



131
132
133
# File 'lib/buckets.rb', line 131

def properties
  @properties
end

#sizeObject

Returns the value of attribute size.



131
132
133
# File 'lib/buckets.rb', line 131

def size
  @size
end

#storage_classObject

Returns the value of attribute storage_class.



131
132
133
# File 'lib/buckets.rb', line 131

def storage_class
  @storage_class
end

Instance Method Details

#copy_to(bucket_name, path = nil) ⇒ Object



165
166
167
168
# File 'lib/buckets.rb', line 165

def copy_to(bucket_name, path=nil)
  path = "/#{path.nil? ? URI.escape(@key) : URI.escape(path)}"
  connection.put(path, bucket_name, nil, {'x-goog-copy-source' => "#{@bucket_name}/#{URI.escape(@key)}"})
end

#deleteObject

Deletes the object from the bucket.



161
162
163
# File 'lib/buckets.rb', line 161

def delete
  connection.delete("/#{URI.escape(@key)}", @bucket_name)
end

#objectObject

When called, returns the previously set data of the object. If the object data hasn’t been set, it will go fetch it from Google Storage and set it as an instance variable to be returned next time.



151
152
153
# File 'lib/buckets.rb', line 151

def object
  @object ||= object!
end

#object!Object

Forces retrieval of the object data from Google Storage.



156
157
158
# File 'lib/buckets.rb', line 156

def object!
  connection.get("/#{URI.escape(@key)}", @bucket_name)
end