Class: Atmos::Object

Inherits:
Object
  • Object
show all
Defined in:
lib/atmos/object.rb

Overview

Object

This class represents an object in an Atmos store.

Object Data

When an object is instantiated, it’s data is not loaded due to memory considerations. You can access an object’s data as a ruby String or as a progressive download via a block.

all at once

obj.data

progressive download

obj.data_as_stream do |chunk|
   datafile.write(chunk)
end

partial data

obj.data_as_stream(0...59) do |chunk|
   readin.concat(chunk)
end

System Metadata

Each object has some information about it stored by the system. This information is read only, and available as a hash on the object:

obj. => Hash

obj..each do |key,value|
  puts "#{key}=#{value}"
end

See Atmos::Metadata for more detailed information.

User Metadata

There are two kinds of user metadata, listable and non-listable. Each of these is available as a hash on the object class. These can both be modified.

obj. => Hash

obj..each do |key,value|
  puts "#{key}=#{value}"
end

obj. => Hash

obj..each do |key,value|
  puts "#{key}=#{value}"
end

See Atmos::Metadata for more detailed information.

Access Control Lists (ACLs)

There are two hashes for access control available as properties on the object: user_acl and group_acl.

The keys are the Atmos usernames and the values are one of :none, :read, :write, :full.

puts obj.user_acl.inspect => {user => :full}
puts obj.group_acl.inspect => {other => :none}

See Atmos::ACL for more detailed information.

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(store, action, options = {}) ⇒ Object

This constructor is only meant for internal use. Get or create an object with an Atmos::Store object:

obj = store.create
obj = store.get(:id => obj_id)
obj = store.get(:namespace => obj_id)


95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
# File 'lib/atmos/object.rb', line 95

def initialize(store, action, options = {})
   Atmos::LOG.debug("obj.new options: #{options.inspect}")   
   validate_options(options)

   @deleted    = false
   @aoid       = aoid
   @store      = store
   @request    = Atmos::Request.new(:store => @store)
   @user       = @store.user

   if (action == :create)
      
         if (options[:id])
            raise Atmos::Exceptions::ArgumentException, "You can't specify an id on object creation."
         end
      
         Atmos::LOG.debug("Object.new: creating new object")
         response = @request.do(:create_object, options)
         @aoid = response.id
      
   elsif (action == :get)
      
         Atmos::LOG.debug("Retrieving object: id: #{options[:id]}; namespace: #{options[:namespace]}")
         response = @request.do(:get_object_info, options)
         @aoid = Atmos::Parser::response_get_string(response.http_response, '//xmlns:objectId')            
         Atmos::LOG.debug("Retrieved object id for namespace: #{@aoid}")
   end

end

Instance Attribute Details

#aoidObject (readonly)

:nodoc:



76
77
78
# File 'lib/atmos/object.rb', line 76

def aoid
  @aoid
end

#requestObject (readonly)

:nodoc:



76
77
78
# File 'lib/atmos/object.rb', line 76

def request
  @request
end

#userObject (readonly)

:nodoc:



76
77
78
# File 'lib/atmos/object.rb', line 76

def user
  @user
end

Instance Method Details

#copyObject

:nodoc:



264
265
266
# File 'lib/atmos/object.rb', line 264

def copy #:nodoc:
   do_delete_check
end

#data(range = nil) ⇒ Object

Returns all the object data in a single string. Be judicious about use of this method, since it can load the entire blob into memory.

Optional:

  • :range - range of bytes to retrieve (e.g. 0…10000)



215
216
217
218
219
# File 'lib/atmos/object.rb', line 215

def data(range = nil)
   do_delete_check
   response = @request.do(:read_object, :id => @aoid, 'Range' => range)
   response.http_response.body
end

#data_as_stream(range = nil, &block) ⇒ Object

Allows progressive download of the object’s data. Takes a block:

obj.data_as_stream do |chunk|
   datafile.write(chunk)
end

Optional:

  • :range - range of bytes to retrieve (e.g. 0…10000)



232
233
234
235
236
237
238
239
# File 'lib/atmos/object.rb', line 232

def data_as_stream(range = nil, &block)
   do_delete_check
   @request.do(:read_object, :id => @aoid, 'Range' => range) do |response|
      response.read_body do |chunk| 
         block.call(chunk)
      end
   end
end

#deleteObject

Deletes the object from Atmos and invalidates the object.

obj = store.create
obj.delete


201
202
203
204
205
# File 'lib/atmos/object.rb', line 201

def delete
   do_delete_check
   response = @request.do(:delete_object, :id => @aoid)
   @deleted = true
end

#exists?Boolean

Checks to see if the represented object exists on Atmos by requesting it’s system metadata.

Returns boolean true or false.

Returns:

  • (Boolean)


253
254
255
256
257
258
259
260
261
# File 'lib/atmos/object.rb', line 253

def exists?
   rv = true
   begin
      @request.do(:list_system_metadata, :id => @aoid)
   rescue Atmos::Exceptions::NoSuchObjectException
      rv = false
   end
   rv
end

#group_aclObject

Lazy evaluation of hash-like object containing group access control properties of the object.



142
143
144
145
146
147
148
# File 'lib/atmos/object.rb', line 142

def group_acl
   if (@group_acl.nil?)
      @group_acl = Atmos::ACL.new(self, Atmos::ACL::GROUP)
   end
   
   @group_acl
end

#headersObject

:nodoc:



269
270
271
272
273
274
275
276
277
278
# File 'lib/atmos/object.rb', line 269

def headers #:nodoc:
   do_delete_check
   headers = {}
   [@user_acl, @group_acl, @tags, @listable_tags, @metadata, @listable_metadata].each do |attr|
      val = attr.header_value
      next if (val.nil? || val.empty?)
      headers[attr.header_name] = attr.header_value
   end
   headers
end

#listable_metadataObject

Lazy evaluation of hash-like object containing listable metadata properties of the object.



166
167
168
169
170
171
172
# File 'lib/atmos/object.rb', line 166

def 
   if (@listable_metadata.nil?)
      @listable_metadata = Atmos::Metadata.new(self, Atmos::Metadata::LISTABLE)
   end
   
   @listable_metadata
end

#metadataObject

Lazy evaluation of hash-like object containing non-listable properties of the object.



154
155
156
157
158
159
160
# File 'lib/atmos/object.rb', line 154

def 
   if (@metadata.nil?)
      @metadata = Atmos::Metadata.new(self, Atmos::Metadata::NON_LISTABLE)
   end
   
   @metadata
end

#system_metadataObject

Lazy evaluation of Hash-like object containing read-only system metadata associated with the object.



178
179
180
181
182
183
184
# File 'lib/atmos/object.rb', line 178

def 
   if (@system_metadata.nil?)
      @system_metadata = Atmos::Metadata.new(self, Atmos::Metadata::SYSTEM)
   end
   
   @system_metadata
end

#truncateObject

Truncates the object to size 0 without changing any of the Metadata or ACLs.



190
191
192
193
# File 'lib/atmos/object.rb', line 190

def truncate
   do_delete_check
   response = @request.do(:trunc_object, :id => @aoid, :data => nil, :length => 0)
end

#update(data, range = nil) ⇒ Object



242
243
244
# File 'lib/atmos/object.rb', line 242

def update(data, range=nil)    
   response = @request.do(:update_object, :id => @aoid, :data => data, 'Range' => range)
end

#user_aclObject

Lazy evaluation of hash-like object containing user access control properties of the object.



128
129
130
131
132
133
134
135
136
# File 'lib/atmos/object.rb', line 128

def user_acl
   #Atmos::LOG.warn("user_acl: #{@user_acl.inspect}")   
   if (@user_acl.nil?)
      @user_acl = Atmos::ACL.new(self, Atmos::ACL::USER)
      #Atmos::LOG.warn("user_acl: #{@user_acl.inspect}")   
   end
   
   @user_acl
end