Module: Vedeu::Repositories::Model
- Includes:
- Common
- Included in:
- Borders::Border, Buffers::Buffer, Cursors::Cursor, Editor::Document, Events::Event, Geometry::Geometry, Groups::Group, Input::Keymap, Interfaces::Interface, Menus::Menu, Views::Composition, Views::Line, Views::Stream, Views::View
- Defined in:
- lib/vedeu/repositories/model.rb
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
-
.included(klass) ⇒ void
When this module is included in a class, provide ClassMethods as class methods for the class.
Instance Method Summary collapse
-
#absent?(variable) ⇒ Boolean
included
from Common
Returns a boolean indicating whether a variable is nil or empty.
-
#demodulize(klass) ⇒ String
included
from Common
Removes the module part from the expression in the string.
-
#deputy(client = nil) ⇒ void
Returns a DSL instance responsible for defining the DSL methods of this model.
-
#dsl_class ⇒ String
private
Returns the DSL class name responsible for this model.
-
#present?(variable) ⇒ Boolean
included
from Common
Returns a boolean indicating whether a variable has a useful value.
-
#snake_case(name) ⇒ String
included
from Common
Converts a class name to a lowercase snake case string.
-
#store ⇒ void
The model instance stored in the repository.
Instance Attribute Details
#repository ⇒ Vedeu::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.
#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_class ⇒ String (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.
#store ⇒ void
Perhaps some validation could be added here?
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 |