Class: FeideeUtils::Record
- Inherits:
-
Object
- Object
- FeideeUtils::Record
- Defined in:
- lib/feidee_utils/record.rb,
lib/feidee_utils/record/utils.rb,
lib/feidee_utils/record/accessors.rb,
lib/feidee_utils/record/namespaced.rb,
lib/feidee_utils/record/persistent.rb,
lib/feidee_utils/record/modified_record.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, Namespaced, Persistent, Utils Classes: ModifiedRecord
Instance Attribute Summary collapse
-
#field ⇒ Object
readonly
Returns the value of attribute field.
-
#field_type ⇒ Object
readonly
Returns the value of attribute field_type.
Attributes included from Namespaced::ClassMethods
Class Method Summary collapse
Instance Method Summary collapse
-
#initialize(columns, types, raw_row) ⇒ Record
constructor
A new instance of Record.
- #validate_integrity ⇒ Object
Methods included from Accessors::ClassMethods
Methods included from Namespaced::ClassMethods
collect_subclass, generate_namespaced_record_classes
Methods included from Persistent::ClassMethods
all, find, find_by_id, genereate_names
Methods included from Accessors
Constructor Details
#initialize(columns, types, raw_row) ⇒ Record
Returns a new instance of Record.
25 26 27 28 29 30 |
# File 'lib/feidee_utils/record.rb', line 25 def initialize(columns, types, raw_row) @field = Hash[ columns.zip(raw_row) ] @field_type = Hash[ columns.zip(types) ] validate_integrity end |
Instance Attribute Details
#field ⇒ Object (readonly)
Returns the value of attribute field.
22 23 24 |
# File 'lib/feidee_utils/record.rb', line 22 def field @field end |
#field_type ⇒ Object (readonly)
Returns the value of attribute field_type.
22 23 24 |
# File 'lib/feidee_utils/record.rb', line 22 def field_type @field_type end |
Class Method Details
.validate_integrity_globally ⇒ Object
36 37 38 |
# File 'lib/feidee_utils/record.rb', line 36 def self.validate_integrity_globally # 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 |