Class: Og::Entity
Overview
An Og Managed class. Also contains helper methods.
Class Method Summary collapse
-
.entity_from_string(str) ⇒ Object
Converts a string into it’s corresponding class.
- .resolve_primary_key(klass) ⇒ Object
Methods included from EntityMixin
#assign_properties, #delete, #insert, #og_quote, #reload, #save, #saved?, #transaction, #update, #update_by_sql, #update_properties
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! ++
420 421 422 423 424 425 426 427 428 429 |
# File 'lib/og/entity.rb', line 420 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
393 394 395 396 397 398 399 400 401 402 403 404 405 406 407 408 409 410 411 |
# File 'lib/og/entity.rb', line 393 def resolve_primary_key(klass) # Is the class annotated with a primary key? if pk = klass.ann.self[:primary_key] return pk end # Search the properties, try to find one annotated as primary_key. for p in klass.properties.values if p.primary_key return Property.new(:symbol => p.symbol, :klass => p.klass) end end # The default primary key is oid. return Property.new(:symbol => :oid, :klass => Fixnum) end |