Module: Lotus::Repository
- Defined in:
- lib/lotus/repository.rb
Overview
Mediates between the entities and the persistence layer, by offering an API to query and execute commands on a database.
By default, a repository is named after an entity, by appending the ‘Repository` suffix to the entity class name.
Repository for an entity can be configured by setting # the ‘#repository` on the mapper.
A repository is storage independent. All the queries and commands are delegated to the current adapter.
This architecture has several advantages:
* Applications depend on an abstract API, instead of low level details
(Dependency Inversion principle)
* Applications depend on a stable API, that doesn't change if the
storage changes
* Developers can postpone storage decisions
* Isolates the persistence logic at a low level
Lotus::Model is shipped with two adapters:
* SqlAdapter
* MemoryAdapter
All the queries and commands are private. This decision forces developers to define intention revealing API, instead leak storage API details outside of a repository.
Defined Under Namespace
Modules: ClassMethods
Class Method Summary collapse
-
.included(base) ⇒ Object
Inject the public API into the hosting class.
Class Method Details
.included(base) ⇒ Object
Inject the public API into the hosting class.
132 133 134 135 136 137 138 139 140 |
# File 'lib/lotus/repository.rb', line 132 def self.included(base) base.class_eval do extend ClassMethods include Lotus::Utils::ClassAttribute class_attribute :collection self.adapter = Lotus::Model::Adapters::NullAdapter.new end end |