Module: ObjectidColumns::HasObjectidColumns

Extended by:
ActiveSupport::Concern
Defined in:
lib/objectid_columns/has_objectid_columns.rb

Overview

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.

Defined Under Namespace

Modules: ClassMethods

Instance Method Summary collapse

Instance Method Details

#assign_objectid_primary_keyObject

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.



27
28
29
# 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

#read_objectid_column(column_name) ⇒ Object

Reads the current value of the given column_name (which must be an ObjectId column) as an ObjectId object.



14
15
16
# 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

#write_objectid_column(column_name, new_value) ⇒ Object

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.



21
22
23
# 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