If it were not for ActiveRecord
A test task with minimum functionality to demonstrate basic knowledge and understanding of the AR pattern.
- Records are stored directly in filesystem
- Storage CRUD functionality and search capabilities
- Minimalistic error handler
- SerDes
- Generator for creating models
- Simple associations
Version
0.0.3
Details
- Storage
- Common dataset schema is stored under
db/schema_IFWN4AR.yml
. Each first level key represents a model. The second level keys stand for attributes and their values are their types correspondingly. Convention has it that keys(table names) should be the singular of the entity that they store attributes of. - Each dataset is stored under
'db/DATASET_NAME_storage.csv'
(CSVs' must have a header) - id must be present in schema as the first attribute.
- Only integer and text types are supported.
- SerDes
- Object serializes in a string where attributes have tabulation symbol between. Be sure to not put tabulation in object attributes.
- Associations
- belongs_to, has_many associations supported. In order to use them you need to assign them in models as class instance variavles and restart server.
class User < IfItWerent4AR::Base
@has_many = [MobilePhone, Passport]
end
Installation
Add to your gemfile:
gem 'if_it_werent_4_AR', '>=0.0.6'
Add schema file db/schema_IFWN4AR.yml
user:
id: integer
name: text
mobile_phone:
id: integer
user_id: integer
book:
id: integer
author_id: integer
content: text
author:
id: integer
name: text
Run generator to create Model, storage if not exists with appropriate headers.
rails generate iitw4ar
TODOs
- Don't hardcode serialization delimiter
- Add tests
- Optimize storage solution
- Add validations
- Add ability to change primary/foreign keys
- Add id auto incrementation
- Add callbacks
- A lot
Features
- When a record is being deleted in the storage an empty string remains.
- Objects with the same attributes are considered equal(same object).
- When trying to get associations for a record (class instance) with an id existing in storage, associations will be fetched for that record in storage.
By
Azat Gataoulline
Source
[https://github.com/Gataniel/if_it_werent_4_AR.git]
License
MIT