Class: Og::Entity

Inherits:
Object
  • Object
show all
Includes:
EntityMixin
Defined in:
lib/og/entity.rb

Overview

An Og Managed class. Also contains helper methods.

Class Method Summary collapse

Methods included from EntityMixin

#assign_attributes, #delete, #force_save!, included, #insert, #instance_attribute_set, #og_quote, #properties_to_hash, #reload, #save, #save_building_collections, #saved?, #set_attributes, #transaction, #update, #update_attributes, #update_by_sql

Class Method Details

.entity_from_string(str) ⇒ Object

Converts a string into it's corresponding class. Added to support STI. Ex: x = “Dave” becomes: (x.class.name == Dave) == true. Returns nil if there's no such class. – gmosx: investigate this patch! ++


727
728
729
730
731
732
733
734
735
736
# File 'lib/og/entity.rb', line 727

def entity_from_string(str)
  res = nil
  Og::Manager.managed_classes.each do |klass|
    if klass.name == str
      res = klass
      break
    end
  end
  res
end

.resolve_primary_key(klass) ⇒ Object


705
706
707
708
709
710
711
712
713
714
715
716
717
718
# File 'lib/og/entity.rb', line 705

def resolve_primary_key(klass)
  # Search the properties, try to find one annotated as primary_key.

  for a in klass.attributes
    anno = klass.ann(a)
    if anno.primary_key?
      return a
    end
  end

  # The default primary key is oid.

  return :oid
end