Class: Hanami::Mongoid::Repository

Inherits:
Object
  • Object
show all
Defined in:
lib/hanami/mongoid/repository.rb

Class Method Summary collapse

Instance Method Summary collapse

Class Method Details

.model_klassClass

Model class

Returns:

  • (Class)

    the model class



9
10
11
# File 'lib/hanami/mongoid/repository.rb', line 9

def self.model_klass
  Object.const_get self.name.gsub('Repository', '')
end

Instance Method Details

#methodObject

Forwards common repository methods to the model’s collection



15
16
17
18
19
20
21
# File 'lib/hanami/mongoid/repository.rb', line 15

%i( find where any_of all first last
    new create update_all destroy_all delete_all ).each do |method|
  define_singleton_method method do |*args|
    puts self.inspect
    self.model_klass.send method, *args
  end
end