Module: Vedeu::Repositories::Registerable::SingletonMethods
- Defined in:
- lib/vedeu/repositories/registerable.rb
Overview
Provide additional behaviour as singleton methods to the including class or module.
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
(also: #borders, #buffers, #cursors, #documents, #events, #geometries, #groups, #interfaces, #keymaps, #menus)
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.
20 21 22 23 |
# File 'lib/vedeu/repositories/registerable.rb', line 20 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.
30 31 32 |
# File 'lib/vedeu/repositories/registerable.rb', line 30 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.
39 40 41 42 43 |
# File 'lib/vedeu/repositories/registerable.rb', line 39 def register(model = nil, storage = {}) new(model, storage).tap do |klass| Vedeu::Repositories.register(klass.repository) end end |
#repository ⇒ void Also known as: borders, buffers, cursors, documents, events, geometries, groups, interfaces, keymaps,
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.
53 54 55 |
# File 'lib/vedeu/repositories/registerable.rb', line 53 def repository @models ||= reset! end |
#reset! ⇒ void Also known as: reset
This method returns an undefined value.
Remove all stored models from the repository.
70 71 72 |
# File 'lib/vedeu/repositories/registerable.rb', line 70 def reset! @models = register end |