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! ++



704
705
706
707
708
709
710
711
712
713
# File 'lib/og/entity.rb', line 704

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



682
683
684
685
686
687
688
689
690
691
692
693
694
695
# File 'lib/og/entity.rb', line 682

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