Module: Vedeu::Repositories::Registerable::ClassMethods
- Defined in:
- lib/vedeu/repositories/registerable.rb
Overview
These class methods are mixed into the repository.
Instance Method Summary collapse
-
#null(klass, attributes = {}) ⇒ Symbol
The null model is used when the repository cannot be found.
-
#real(klass) ⇒ Symbol
The real model is the usual model to use for a given repository.
-
#register(model = nil, storage = {}) ⇒ Vedeu::Repositories::Repository
Register a repository for storing models.
-
#repository ⇒ void
Returns the repositories registered.
-
#reset! ⇒ void
(also: #reset)
Remove all stored models from the repository.
Instance Method Details
#null(klass, attributes = {}) ⇒ Symbol
The null model is used when the repository cannot be found.
18 19 20 21 |
# File 'lib/vedeu/repositories/registerable.rb', line 18 def null(klass, attributes = {}) define_method(:null_model) { klass } define_method(:null_attributes) { attributes } end |
#real(klass) ⇒ Symbol
The real model is the usual model to use for a given repository.
28 29 30 |
# File 'lib/vedeu/repositories/registerable.rb', line 28 def real(klass) define_method(:model) { instance_variable_set('@model', klass) } end |
#register(model = nil, storage = {}) ⇒ Vedeu::Repositories::Repository
Register a repository for storing models.
37 38 39 40 41 |
# File 'lib/vedeu/repositories/registerable.rb', line 37 def register(model = nil, storage = {}) new(model, storage).tap do |klass| Vedeu::Repositories.register(klass.repository) end end |
#repository ⇒ void
If the repository is ‘Geometries’, for example, then @models will be either an empty Geometries repository or the collection of stored models.
This method returns an undefined value.
Returns the repositories registered.
51 52 53 |
# File 'lib/vedeu/repositories/registerable.rb', line 51 def repository @models ||= reset! end |
#reset! ⇒ void Also known as: reset
This method returns an undefined value.
Remove all stored models from the repository.
58 59 60 |
# File 'lib/vedeu/repositories/registerable.rb', line 58 def reset! @models = register end |