module MnoEnterprise::DatabaseExtendable::InstanceMethods

Public Instance Methods

extension() click to toggle source
# File lib/mno_enterprise/database_extendable.rb, line 22
def extension
  @extension ||= klass.where(foreign_key => self.uid).first_or_initialize
end
extension=(extension) click to toggle source
# File lib/mno_enterprise/database_extendable.rb, line 26
def extension=(extension)
  @extension = extension
end
foreign_key() click to toggle source
# File lib/mno_enterprise/database_extendable.rb, line 34
def foreign_key
  self.class.to_s.foreign_key.gsub(/_id/, '_uid')
end
klass() click to toggle source
# File lib/mno_enterprise/database_extendable.rb, line 30
def klass
  "#{self.class}Extension".constantize
end

Protected Instance Methods

delete_extension() click to toggle source
# File lib/mno_enterprise/database_extendable.rb, line 52
def delete_extension
  extension.destroy
end
save_extensions() click to toggle source
# File lib/mno_enterprise/database_extendable.rb, line 39
def save_extensions
  # Set extension foreign key
  if extension.send(foreign_key).blank?
    extension.send("#{foreign_key}=", self.uid)
  end
  # Save at all time to 'touch' to  expire the cache
  if extension.changed?
    extension.save
  else
    extension.touch
  end
end