Class: FeideeUtils::Record
- Inherits:
-
Object
- Object
- FeideeUtils::Record
- Extended by:
- Accessors::ClassMethods, Computed::ClassMethods, Namespaced::ClassMethods, Persistent::ClassMethods
- Defined in:
- lib/feidee_utils/record.rb,
lib/feidee_utils/record/utils.rb,
lib/feidee_utils/record/computed.rb,
lib/feidee_utils/record/accessors.rb,
lib/feidee_utils/record/namespaced.rb,
lib/feidee_utils/record/persistent.rb
Overview
The implementation here is wired. The goal is to create a class hierachy similar to ActiveRecord, where every table is represented by a subclass of ActiveRecord::Base. Class methods, attribute accessors and almost all other functionalities are provided by ActiveRecord::Base. For example, Base.all(), Base.find_by_id() are tied to a specific table in a specific database. The problem we are solving here is not the same as ActiveRecord. In ActiveRecord, the databases are static, i.e. they won’t be changed at runtime. Meanwhile, in our case, new databases can be created at runtime, when a new KBF backup file is uploaded. Furthermore, multiple instances of different databases can co-exist at the same time. To provide the same syntax as ActiveRecord, a standalone “Base” class has to be created for each database. In our implementation, when a new database is created, a subclass of Record is created in a new namepsace. For each subclass of Record, a new subclass is copied to the new namespace, with it’s database method overloaded.
Direct Known Subclasses
Defined Under Namespace
Modules: Accessors, Computed, Namespaced, Persistent, Utils
Constant Summary
Constants included from Utils
Instance Attribute Summary
Attributes included from Namespaced::ClassMethods
Class Method Summary collapse
Instance Method Summary collapse
-
#initialize(row) ⇒ Record
constructor
A new instance of Record.
- #validate_integrity ⇒ Object
Methods included from Computed::ClassMethods
Methods included from Persistent::ClassMethods
all, column_names, columns, find, find_by_id
Methods included from Accessors
Constructor Details
#initialize(row) ⇒ Record
Returns a new instance of Record.
26 27 28 29 30 |
# File 'lib/feidee_utils/record.rb', line 26 def initialize(row) @row = row.freeze validate_integrity end |
Class Method Details
.generate_subclasses(db) ⇒ Object
40 41 42 43 44 45 46 |
# File 'lib/feidee_utils/record.rb', line 40 def self.generate_subclasses db env = generate_namespaced_record_classes db env.contained_classes.each do |klass| klass.define_indexed_accessors end env end |
.validate_global_integrity ⇒ Object
36 37 38 |
# File 'lib/feidee_utils/record.rb', line 36 def self.validate_global_integrity # Do nothing. end |
Instance Method Details
#validate_integrity ⇒ Object
32 33 34 |
# File 'lib/feidee_utils/record.rb', line 32 def validate_integrity # Do nothing. end |