module ObjectidColumns::HasObjectidColumns
This module gets mixed into an ActiveRecord
class when you say +has_objectid_column(s)+ or has_objectid_primary_key
. It delegates everything it does to the ObjectidColumnsManager
; we do it this way so that we can define all kinds of helper methods on the ObjectidColumnsManager
without polluting the method namespace on the actual ActiveRecord
class.
Public Instance Methods
Called as a before_create
hook, if (and only if) this class has declared has_objectid_primary_key
– sets the primary key to a newly-generated ObjectId, unless it has one already.
# File lib/objectid_columns/has_objectid_columns.rb, line 27 def assign_objectid_primary_key self.class.objectid_columns_manager.assign_objectid_primary_key(self) end
Reads the current value of the given column_name
(which must be an ObjectId column) as an ObjectId object.
# File lib/objectid_columns/has_objectid_columns.rb, line 14 def read_objectid_column(column_name) self.class.objectid_columns_manager.read_objectid_column(self, column_name) end
Writes a new value to the given column_name
(which must be an ObjectId column), accepting a String (in either hex or binary formats) or an ObjectId object, and transforming it to whatever storage format is correct for that column.
# File lib/objectid_columns/has_objectid_columns.rb, line 21 def write_objectid_column(column_name, new_value) self.class.objectid_columns_manager.write_objectid_column(self, column_name, new_value) end