Class: Lafcadio::ObjectType
- Inherits:
-
Object
- Object
- Lafcadio::ObjectType
- Defined in:
- lib/lafcadio/domain/ObjectType.rb
Overview
A utility class that handles a few details for the DomainObject class. All the methods here are usually called as methods of DomainObject, and then delegated to this class.
Constant Summary collapse
- @@instances =
{}
Class Method Summary collapse
-
.flush ⇒ Object
:nodoc:.
-
.getObjectType(aClass) ⇒ Object
:nodoc:.
Instance Method Summary collapse
-
#getClassFields ⇒ Object
Returns an Array of ObjectField instances for this domain class, parsing them from XML if necessary.
-
#initialize(objectType) ⇒ ObjectType
constructor
:nodoc:.
-
#sqlPrimaryKeyName ⇒ Object
Returns the name of the primary key in the database, retrieving it from the class definition XML if necessary.
-
#tableName ⇒ Object
Returns the table name, which is assumed to be the domain class name pluralized, and with the first letter lowercase.
Constructor Details
#initialize(objectType) ⇒ ObjectType
:nodoc:
26 27 28 29 30 31 32 33 34 35 36 37 38 39 |
# File 'lib/lafcadio/domain/ObjectType.rb', line 26 def initialize(objectType) #:nodoc: @objectType = objectType ( @classFields, @xmlParser ) = [ nil, nil ] dirName = LafcadioConfig.new['classDefinitionDir'] xmlFileName = @objectType. + '.xml' xmlPath = File.join( dirName, xmlFileName ) xml = '' begin File.open( xmlPath ) { |file| xml = file.readlines.join } @xmlParser = ClassDefinitionXmlParser.new( @objectType, xml ) rescue Errno::ENOENT # no xml file, so no @xmlParser end end |
Class Method Details
.flush ⇒ Object
:nodoc:
11 12 13 |
# File 'lib/lafcadio/domain/ObjectType.rb', line 11 def self.flush #:nodoc: @@instances = {} end |
.getObjectType(aClass) ⇒ Object
:nodoc:
15 16 17 18 19 20 21 22 |
# File 'lib/lafcadio/domain/ObjectType.rb', line 15 def self.getObjectType( aClass ) #:nodoc: instance = @@instances[aClass] if instance.nil? @@instances[aClass] = new( aClass ) instance = @@instances[aClass] end instance end |
Instance Method Details
#getClassFields ⇒ Object
Returns an Array of ObjectField instances for this domain class, parsing them from XML if necessary.
43 44 45 46 47 48 49 50 51 52 53 54 |
# File 'lib/lafcadio/domain/ObjectType.rb', line 43 def getClassFields unless @classFields if @xmlParser @classFields = @xmlParser.getClassFields else error_msg = "Couldn't find either an XML class description file " + "or getClassFields method for " + @objectType.name raise MissingError, error_msg, caller end end @classFields end |
#sqlPrimaryKeyName ⇒ Object
Returns the name of the primary key in the database, retrieving it from the class definition XML if necessary.
58 59 60 61 62 63 64 |
# File 'lib/lafcadio/domain/ObjectType.rb', line 58 def sqlPrimaryKeyName if !@xmlParser.nil? && ( spkn = @xmlParser.sqlPrimaryKeyName ) spkn else 'pkId' end end |
#tableName ⇒ Object
Returns the table name, which is assumed to be the domain class name pluralized, and with the first letter lowercase. A User class is assumed to be stored in a “users” table, while a ProductCategory class is assumed to be stored in a “productCategories” table.
70 71 72 73 74 75 76 77 78 |
# File 'lib/lafcadio/domain/ObjectType.rb', line 70 def tableName if (!@xmlParser.nil? && tableName = @xmlParser.tableName) tableName else tableName = @objectType. tableName[0] = tableName[0..0].downcase English.plural tableName end end |