Class: ROM::Repository::Root

Inherits:
ROM::Repository 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)

Instance Attribute Summary collapse

Class Method Summary collapse

Instance Method Summary collapse

Constructor Details

#initializeRoot

Returns a new instance of Root.

See Also:

  • ROM::Repository#initialize


61
62
63
64
# File 'repository/lib/rom/repository/root.rb', line 61

def initialize(*)
  super
  @root = set_relation(self.class.root)
end

Instance Attribute Details

#rootObject (readonly)



50
51
52
# File 'repository/lib/rom/repository/root.rb', line 50

def root
  @root
end

Class Method Details

.rootSymbol .root(identifier) ⇒ Symbol

Get or set repository root relation identifier

This method is automatically used when you define a class using MyRepo[:rel_identifier] shortcut

Overloads:

  • .rootSymbol

    Return root relation identifier

    Returns:

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

    Set root relation identifier

    Returns:

    • (Symbol)


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

defines :root