Module: Vedeu::Repositories::Model

Overview

When included into a class, provides the mechanism to store the class in a repository for later retrieval.

Defined Under Namespace

Modules: ClassMethods

Instance Attribute Summary collapse

Class Method Summary collapse

Instance Method Summary collapse

Instance Attribute Details

#repositoryVedeu::Repositories::Repository



14
15
16
# File 'lib/vedeu/repositories/model.rb', line 14

def repository
  @repository
end

Class Method Details

.included(klass) ⇒ void

This method returns an undefined value.

When this module is included in a class, provide ClassMethods as class methods for the class.

Parameters:

  • klass (Class)


86
87
88
# File 'lib/vedeu/repositories/model.rb', line 86

def self.included(klass)
  klass.send(:extend, ClassMethods)
end

Instance Method Details

#absent?(variable) ⇒ Boolean Originally defined in module Common

This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.

Returns a boolean indicating whether a variable is nil or empty.

Parameters:

  • variable (String|Symbol|Array|Fixnum)

    The variable to check.

Returns:

  • (Boolean)

#demodulize(klass) ⇒ String Originally defined in module Common

This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.

Removes the module part from the expression in the string.

Examples:

demodulize('Vedeu::SomeModule::SomeClass') # => "SomeClass"

Parameters:

  • klass (Class|String)

Returns:

  • (String)

#present?(variable) ⇒ Boolean Originally defined in module Common

This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.

Returns a boolean indicating whether a variable has a useful value.

Parameters:

  • variable (String|Symbol|Array|Fixnum)

    The variable to check.

Returns:

  • (Boolean)

#snake_case(name) ⇒ String Originally defined in module Common

This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.

Converts a class name to a lowercase snake case string.

Examples:

snake_case(MyClassName) # => "my_class_name"
snake_case(NameSpaced::ClassName)
# => "name_spaced/class_name"

Parameters:

  • name (String)

Returns:

  • (String)

#storevoid

TODO:

Perhaps some validation could be added here?

Note:

If a block is given, store the model, return the model after yielding.

This method returns an undefined value.

Returns The model instance stored in the repository.



94
95
96
97
98
99
100
# File 'lib/vedeu/repositories/model.rb', line 94

def store
  new_model = repository.store(self)

  yield if block_given?

  new_model
end