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

Instance Method Details

#null(klass, attributes = {}) ⇒ Symbol

The null model is used when the repository cannot be found.

Parameters:

  • klass (Class)
  • attributes (Hash) (defaults to: {})

Returns:

  • (Symbol)


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.

Parameters:

  • klass (Class)

Returns:

  • (Symbol)


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.

Parameters:

  • model (Class) (defaults to: nil)
  • storage (Class|Hash) (defaults to: {})

Returns:



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

#repositoryvoid Also known as: borders, buffers, cursors, documents, events, geometries, groups, interfaces, keymaps, menus

Note:

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