Class: ROM::Repository::Root

Inherits:
Repository
  • Object
show all
Defined in:
repository/lib/rom/repository/root.rb

Overview

A specialized repository type dedicated to work with a root relation

This repository type builds commands and aggregates for its root relation

Examples:

class UserRepo < ROM::Repository[:users]
  commands :create, update: :by_pk, delete: :by_pk
end

rom = ROM.container(:sql, 'sqlite::memory') do |conf|
  conf.default.create_table(:users) do
    primary_key :id
    column :name, String
  end
end

user_repo = UserRepo.new(rom)

user = user_repo.create(name: "Jane")

user_repo.update(user.id, name: "Jane Doe")

user_repo.delete(user.id)

Class Method Summary collapse

Class Method Details

.inherited(klass) ⇒ Object

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.

Sets descendant root relation



54
55
56
57
# File 'repository/lib/rom/repository/root.rb', line 54

def self.inherited(klass)
  super
  klass.root(root)
end

.new(*args, **kwargs) ⇒ Object



47
48
49
# File 'repository/lib/rom/repository/root.rb', line 47

def self.new(*args, **kwargs)
  super(*args, **kwargs, root: root)
end

.root ⇒ Symbol .root(identifier) ⇒ Symbol

Get or set repository root relation identifier

This method is automatically used when you define a class using MyRepo shortcut

Overloads:

  • .root ⇒ Symbol

    Return root relation identifier

    Returns:

    • (Symbol)
  • .root(identifier) ⇒ Symbol

    Set root relation identifier

    Returns:

    • (Symbol)


44
# File 'repository/lib/rom/repository/root.rb', line 44

defines :root