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.



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

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

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

Removes the module part from the expression in the string.

Examples:

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

#deputy(client = nil) ⇒ void

This method returns an undefined value.

Returns a DSL instance responsible for defining the DSL methods of this model.



98
99
100
# File 'lib/vedeu/repositories/model.rb', line 98

def deputy(client = nil)
  Object.const_get(dsl_class).new(self, client)
end

#dsl_classString (private)

Returns the DSL class name responsible for this model.



119
120
121
122
123
124
125
126
127
128
129
130
131
132
# File 'lib/vedeu/repositories/model.rb', line 119

def dsl_class
  case demodulize(self.class.name)
  when 'Border'.freeze    then 'Vedeu::Borders::DSL'.freeze
  when 'Buffer'.freeze    then 'Vedeu::Buffers::DSL'.freeze
  when 'Geometry'.freeze  then 'Vedeu::Geometry::DSL'.freeze
  when 'Group'.freeze     then 'Vedeu::Groups::DSL'.freeze
  when 'Interface'.freeze then 'Vedeu::Interfaces::DSL'.freeze
  when 'Keymap'.freeze    then 'Vedeu::Input::DSL'.freeze
  when 'Menu'.freeze      then 'Vedeu::Menus::DSL'.freeze
  # when 'ModelTestClass' then 'Vedeu::Repositories::ModelTestClass::DSL'
  else
    'Vedeu::DSL::'.freeze + demodulize(self.class.name)
  end
end

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

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

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

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"

#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.



106
107
108
109
110
111
112
# File 'lib/vedeu/repositories/model.rb', line 106

def store
  new_model = repository.store(self)

  yield if block_given?

  new_model
end