Class: Hanami::Mongoid::Repository
- Inherits:
-
Object
- Object
- Hanami::Mongoid::Repository
- Defined in:
- lib/hanami/mongoid/repository.rb
Instance Method Summary collapse
-
#create ⇒ Object
Forwards create method to accept a model instance.
-
#method ⇒ Object
Forwards common repository methods to the model’s collection.
-
#model_klass ⇒ Class
Model class.
Instance Method Details
#create ⇒ Object
Forwards create method to accept a model instance
24 25 26 27 28 29 30 |
# File 'lib/hanami/mongoid/repository.rb', line 24 define_method :create do |entity_instance| unless entity_instance.is_a? self.model_klass entity_instance = self.model_klass.new(entity_instance) end entity_instance.save(validate: false) entity_instance end |
#method ⇒ Object
Forwards common repository methods to the model’s collection
15 16 17 18 19 20 |
# File 'lib/hanami/mongoid/repository.rb', line 15 %i( find find_by where any_of all none first last destroy_all delete_all update_all ).each do |method| define_method method do |*args| self.model_klass.send method, *args end end |
#model_klass ⇒ Class
Model class
9 10 11 |
# File 'lib/hanami/mongoid/repository.rb', line 9 def model_klass Object.const_get self.class.name.gsub('Repository', '') end |