Class: TableNameToClass

Inherits:
Object
  • Object
show all
Defined in:
lib/table-name-to-class.rb

Constant Summary collapse

@@conversion_hash =
nil

Class Method Summary collapse

Class Method Details

.convert(name, force_update = nil) ⇒ Object

Convert a table name into a class constant (or nil if no constant for that table)


Expects:

name (object like string):: Name of database table, this can be anything
                            that returns a valid table name when hit with
                            to_s
force_update (boolean):: Should the table/class correspondence be updated?
                         Any none-nil value triggers a reload.

Returns:

nil if the lookup fails, the constant for the class associated with the
table otherwise.


18
19
20
21
# File 'lib/table-name-to-class.rb', line 18

def self.convert(name, force_update = nil)
  init_hash unless @@conversion_hash || force_update
  @@conversion_hash[name.to_s]
end

.debugObject

Debug helper


Returns the hash of table name and class constant pairs



27
28
29
# File 'lib/table-name-to-class.rb', line 27

def self.debug
  return @@conversion_hash
end