Class: Trix51
- Inherits:
-
Object
- Object
- Trix51
- Defined in:
- lib/trix51db.rb
Overview
This class handles top level management of the database engine and contains various constants and information about active databases. It also provides a logger based interface to the internals of the other database objects.
Defined Under Namespace
Classes: ConstraintError, Database, DatabaseError, ExistsError, NotFoundError, ResultSet, Table, TableExistsError, Tuple, TupleSet, TypeError
Constant Summary collapse
- RECORD_PREFIX =
Record prefix
'@R@:'
- META_PREFIX =
Metadata Prefix - For table structure records
'@T@:'
- SEQ_PREFIX =
Sequence Prefix - For column sequences for autoincrement fields.
'@S@:'
- KEY_JOIN =
Used to join key values in a Record Key
':'
- @@databases =
[]
- @@class_to_database =
{}
- @@class_to_tablename =
{}
- @@table_to_database =
{}
- @@defer_classref =
false
- @@logger =
Logger.new('trix51.log')
Class Method Summary collapse
- .add_connection(database) ⇒ Object
- .add_helper(classname, database, table) ⇒ Object
-
.class_to_database(cn) ⇒ Object
Map a class name (String) to a Trix51::Database reference.
-
.class_to_table(cn) ⇒ Object
Map a class name (String) to a Trix51::Table reference.
-
.connections ⇒ Object
Return a list of active databases managed by the engine.
-
.create_helper_code(classname) ⇒ Object
Generate a helper class for a table.
-
.debug(msg) ⇒ Object
Log a debug message to the log.
-
.defer_classref ⇒ Object
Returns the value of the defer_classref flag.
-
.defer_classref=(toggle) ⇒ Object
Sets the defer_classref flag to true or false.
-
.error(msg) ⇒ Object
Log an error to the log.
-
.fatal(msg) ⇒ Object
Log a fatal message to the log and exit.
-
.info(msg) ⇒ Object
Log an info level message to the log.
-
.table_to_database(tbl) ⇒ Object
Map a tablename to its database.
-
.warn(msg) ⇒ Object
Log a warning message to the log.
Class Method Details
.add_connection(database) ⇒ Object
42 43 44 |
# File 'lib/trix51db.rb', line 42 def Trix51.add_connection( database ) @@databases.push( database ) end |
.add_helper(classname, database, table) ⇒ Object
46 47 48 49 50 51 |
# File 'lib/trix51db.rb', line 46 def Trix51.add_helper( classname, database, table ) @@class_to_database[ classname ] = database @@class_to_tablename[ classname ] = table @@table_to_database[ table.tablename.to_sym ] = database self.create_helper_code( classname ) end |
.class_to_database(cn) ⇒ Object
Map a class name (String) to a Trix51::Database reference.
64 65 66 |
# File 'lib/trix51db.rb', line 64 def Trix51.class_to_database( cn ) return @@class_to_database[ cn ] end |
.class_to_table(cn) ⇒ Object
Map a class name (String) to a Trix51::Table reference.
59 60 61 |
# File 'lib/trix51db.rb', line 59 def Trix51.class_to_table( cn ) return @@class_to_tablename[ cn ] end |
.connections ⇒ Object
Return a list of active databases managed by the engine
54 55 56 |
# File 'lib/trix51db.rb', line 54 def Trix51.connections return @@databases end |
.create_helper_code(classname) ⇒ Object
Generate a helper class for a table.
99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 |
# File 'lib/trix51db.rb', line 99 def Trix51.create_helper_code( classname ) return if (classname == 'Trix51::Tuple') or (@@defer_classref == true) code = <<TEMPLATE class #{classname} < Trix51::Tuple def #{classname}._table return Trix51.class_to_table( '#{classname}' ) end def #{classname}._db return Trix51.class_to_database( '#{classname}' ) end def #{classname}.find_or_create( *args ) return self._table.find_or_create( *args ) end def #{classname}.select( *args ) return self._table.select( *args ) end def #{classname}.delete( *args ) return select._table.delete( *args ) end def #{classname}.update( *args ) return self._table.update( *args ) end def #{classname}.first( *args ) return self._table.first( *args ) end def #{classname}.all return self._table.all end def #{classname}.dump self._table.dump end end TEMPLATE #puts code eval( code, BND ) end |
.debug(msg) ⇒ Object
Log a debug message to the log.
74 75 76 |
# File 'lib/trix51db.rb', line 74 def Trix51.debug( msg ) @@logger.debug( msg ) end |
.defer_classref ⇒ Object
Returns the value of the defer_classref flag
155 156 157 |
# File 'lib/trix51db.rb', line 155 def Trix51.defer_classref return @@defer_classref end |
.defer_classref=(toggle) ⇒ Object
Sets the defer_classref flag to true or false
150 151 152 |
# File 'lib/trix51db.rb', line 150 def Trix51.defer_classref=( toggle ) @@defer_classref = toggle end |
.error(msg) ⇒ Object
Log an error to the log.
89 90 91 |
# File 'lib/trix51db.rb', line 89 def Trix51.error( msg ) @@logger.error( msg ) end |
.fatal(msg) ⇒ Object
Log a fatal message to the log and exit.
94 95 96 |
# File 'lib/trix51db.rb', line 94 def Trix51.fatal( msg ) @@logger.debug( msg ) end |
.info(msg) ⇒ Object
Log an info level message to the log.
79 80 81 |
# File 'lib/trix51db.rb', line 79 def Trix51.info( msg ) @@logger.info( msg ) end |
.table_to_database(tbl) ⇒ Object
Map a tablename to its database.
69 70 71 |
# File 'lib/trix51db.rb', line 69 def Trix51.table_to_database( tbl ) return @@table_to_database[ tbl ] end |
.warn(msg) ⇒ Object
Log a warning message to the log.
84 85 86 |
# File 'lib/trix51db.rb', line 84 def Trix51.warn( msg ) @@logger.warn( msg ) end |