| Class | TaliaCore::DataTypes::DataRecord |
| In: |
lib/talia_core/data_types/data_record.rb
|
| Parent: | ActiveRecord::Base |
Base class for all data records in Talia. This only contains a basic interface, without much functionality. All data-related methods will return a NotImplementedError
The DataRecord provides an interface to access a generic array/buffer of bytes, with the base class not making any assumptions on how these bytes are stored.
Subclasses should usually provide the inferface of this class, which is more or less like the standard file interface.
Each data record has a "location" field, which is roughly equivalent to the file name, and a MIME type. The default behaviour is that, if not set manually, the MIME type is automatically set before saving. It will be determined by the "file extension" of the location field.
Each data record must belong to an ActiveSource. For more information on how to handle records with files, see the FileRecord class
| temp_path | [RW] |
# File lib/talia_core/data_types/data_record.rb, line 93
93: def find_by_type_and_location!(source_data_type, location)
94: # TODO: Should it directly instantiate the STI sub-class?
95: # In this case we should use the following line instead.
96: #
97: # source_data = source_data_type.classify.constantize.find_by_location(location, :limit => 1)
98: #
99: data_type = "TaliaCore::DataTypes::#{source_data_type.camelize}"
100: source_data = self.find(:first, :conditions => ["type = ? AND location = ?", data_type, location])
101:
102: raise ActiveRecord::RecordNotFound if source_data.nil?
103: source_data
104: end
Find all data records about a specified source
# File lib/talia_core/data_types/data_record.rb, line 89
89: def find_data_records(id)
90: find(:all, :conditions => { :source_id => id })
91: end
returns all bytes in the object as an array of unsigned integers
# File lib/talia_core/data_types/data_record.rb, line 39
39: def all_bytes
40: raise NotImplementedError
41: end
# File lib/talia_core/data_types/data_record.rb, line 72
72: def extract_mime_type(location)
73: # Lookup the mime type for the extension (removing the dot
74: # in front of the file extension) Works only for the file
75: # types supported by Rails' Mime class.
76: Mime::Type.lookup_by_extension((File.extname(location).downcase)[1..-1]).to_s
77: end
returns the next byte from the object, or nil at EOS
# File lib/talia_core/data_types/data_record.rb, line 49
49: def get_byte(close_after_single_read=false)
50: raise NotImplementedError
51: end