lib/vedeu/repositories/model.rb in vedeu-0.7.4 vs lib/vedeu/repositories/model.rb in vedeu-0.8.0

- old
+ new

@@ -31,33 +31,21 @@ # @param attributes [Hash] A collection of attributes specific # to the model. # @param block [Proc] The block passed to the build method. # @return [Object] An instance of the model. def build(attributes = {}, &block) - attributes = defaults.merge!(attributes) - model = new(attributes) - if block_given? - model.deputy(attributes[:client]).instance_eval(&block) - end + Vedeu.log(type: :debug, + message: "DSL building: '#{model.class.name}' for " \ + "'#{model.name}'".freeze) + model.deputy.instance_eval(&block) if block_given? + model end - # Provide a convenient way to define the child or children of - # a model. - # - # @param klass [Class] The member (singular) or collection - # (multiple) class name for the respective model. - # @return [void] - def child(klass) - send(:define_method, __callee__) { klass } - end - alias_method :member, :child - alias_method :collection, :child - # Allow models to specify their repository using a class # method. # # @param klass [void] # @return [void] @@ -71,39 +59,21 @@ # to the model. # @param block [Proc] A block of code to be executing whilst # storing. # @return [Object] An instance of the model. def store(attributes = {}, &block) - if block_given? - new(attributes).store(&block) - - else - new(attributes).store - - end + new(attributes).store(&block) end - private - - # The default values for a new instance of this class. - # - # @return [Hash<Symbol => NilClass, String>] - def defaults - { - client: nil, - name: '', - } - end - end # ClassMethods # When this module is included in a class, provide ClassMethods # as class methods for the class. # # @param klass [Class] # @return [void] def self.included(klass) - klass.send(:extend, ClassMethods) + klass.extend(Vedeu::Repositories::Model::ClassMethods) end # @note If a block is given, store the model, return the model # after yielding. # @todo Perhaps some validation could be added here?