Module: Vedeu::Model::ClassMethods
- Defined in:
- lib/vedeu/repositories/model.rb
Overview
When Vedeu::Model is included in a class, the methods within this module are included as class methods on that class.
Instance Method Summary collapse
-
#build(attributes = {}, &block) ⇒ Object
Build models using a simple DSL when a block is given, otherwise returns a new instance of the class including this module.
-
#child(klass) ⇒ void
(also: #member, #collection)
Provide a convenient way to define the child or children of a model.
-
#defaults ⇒ Hash<Symbol => NilClass, String>
private
The default values for a new instance of this class.
- #repository(klass, as:) ⇒ void
Instance Method Details
#build(attributes = {}, &block) ⇒ Object
Build models using a simple DSL when a block is given, otherwise returns a new instance of the class including this module.
23 24 25 26 27 28 29 |
# File 'lib/vedeu/repositories/model.rb', line 23 def build(attributes = {}, &block) attributes = defaults.merge!(attributes) model = new(attributes) model.deputy(attributes[:client]).instance_eval(&block) if block_given? model end |
#child(klass) ⇒ void Also known as: member, collection
This method returns an undefined value.
Provide a convenient way to define the child or children of a model.
36 37 38 |
# File 'lib/vedeu/repositories/model.rb', line 36 def child(klass) send(:define_method, __callee__) { klass } end |
#defaults ⇒ Hash<Symbol => NilClass, String> (private)
The default values for a new instance of this class.
58 59 60 61 62 63 |
# File 'lib/vedeu/repositories/model.rb', line 58 def defaults { client: nil, name: '', } end |
#repository(klass, as:) ⇒ void
Note:
Not current used.
This method returns an undefined value.
48 49 50 51 |
# File 'lib/vedeu/repositories/model.rb', line 48 def repository(klass, as:) self.repository = as klass.register(as, self) end |