Module: Vedeu::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

Methods included from Common

#demodulize, #present?, #snake_case

Instance Attribute Details

#repositoryVedeu::Repository

Returns:



12
13
14
# File 'lib/vedeu/repositories/model.rb', line 12

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

#deputy(client = nil) ⇒ void

This method returns an undefined value.

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

Parameters:

  • client (Object|NilClass) (defaults to: nil)

    The client binding represents the client application object that is currently invoking a DSL method. It is required so that we can send messages to the client application object should we need to.



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.

Returns:

  • (String)


113
114
115
116
117
118
119
120
121
122
# File 'lib/vedeu/repositories/model.rb', line 113

def dsl_class
  case demodulize(self.class.name)
  when 'Border'   then 'Vedeu::Borders::DSL'
  when 'Buffer'   then 'Vedeu::Buffers::DSL'
  when 'Geometry' then 'Vedeu::Geometry::DSL'
  when 'Menu'     then 'Vedeu::Menus::DSL'
  else
    'Vedeu::DSL::' + demodulize(self.class.name)
  end
end

#storevoid

TODO:

Perhaps some validation could be added here?

This method returns an undefined value.

Returns The model instance stored in the repository.



104
105
106
# File 'lib/vedeu/repositories/model.rb', line 104

def store
  repository.store(self) # if valid?
end