Module: Vedeu::Model::ClassMethods
- Defined in:
- lib/vedeu/models/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
private
The default values for a new instance of this class.
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.
22 23 24 25 26 27 28 |
# File 'lib/vedeu/models/model.rb', line 22 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.
35 36 37 |
# File 'lib/vedeu/models/model.rb', line 35 def child(klass) send(:define_method, __callee__) { klass } end |
#defaults ⇒ Hash (private)
The default values for a new instance of this class.
46 47 48 49 50 51 |
# File 'lib/vedeu/models/model.rb', line 46 def defaults { client: nil, name: '', } end |