Class: ROM::Repository::Base

Inherits:
Object
  • Object
show all
Includes:
Options
Defined in:
lib/rom/repository/base.rb

Overview

Abstract repository class to inherit from

TODO: rename this to Repository once deprecated Repository from rom core is gone

Class Method Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(env, options = {}) ⇒ Base

This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.

Returns a new instance of Base.



45
46
47
48
49
50
51
52
53
# File 'lib/rom/repository/base.rb', line 45

def initialize(env, options = {})
  super
  self.class.relations.each do |name|
    proxy = LoadingProxy.new(
      env.relation(name), name: name, mapper_builder: mapper_builder
    )
    instance_variable_set("@#{name}", proxy)
  end
end

Class Method Details

.relations(*names) ⇒ Array<Symbol>

Define which relations your repository is going to use

Examples:

class MyRepo < ROM::Repository::Base
  relations :users, :tasks
end

my_repo = MyRepo.new(rom_env)

my_repo.users
my_repo.tasks

Returns:

  • (Array<Symbol>)


35
36
37
38
39
40
41
42
# File 'lib/rom/repository/base.rb', line 35

def self.relations(*names)
  if names.any?
    attr_reader(*names)
    @relations = names
  else
    @relations
  end
end