Sha256: c26d15eb79d3a98bf2c83d9282a98ab1a088106e14259c8d0ad021a7fab8ee6b
Contents?: true
Size: 1.87 KB
Versions: 1
Compression:
Stored size: 1.87 KB
Contents
# frozen_string_literal: true require "dry/core/class_attributes" module ROM class Repository # A specialized repository type dedicated to work with a root relation # # This repository type builds commands and aggregates for its root relation # # @example # class UserRepo < ROM::Repository[:users] # commands :create, update: :by_pk, delete: :by_pk # end # # rom = ROM.setup(: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) # # @api public class Root < Repository # @!method self.root # Get or set repository root relation identifier # # This method is automatically used when you define a class using # MyRepo[:rel_identifier] shortcut # # @overload root # Return root relation identifier # @return [Symbol] # # @overload root(identifier) # Set root relation identifier # @return [Symbol] defines :root # @!attribute [r] root # @return [Relation] The root relation attr_reader :root # Sets descendant root relation # # @api private def self.inherited(klass) super klass.root(root) end # @see Repository#initialize def initialize(*) super @root = set_relation(self.class.root) end ruby2_keywords(:initialize) if respond_to?(:ruby2_keywords, true) # @see ROM::Repository#transaction # # @api public def transaction(gateway: root.gateway, **opts, &block) super end end end end
Version data entries
1 entries across 1 versions & 1 rubygems
Version | Path |
---|---|
rom-6.0.0.alpha1 | lib/rom/repository/root.rb |