Class: ROM::Repository::Root
- Inherits:
-
ROM::Repository
- Object
- ROM::Repository
- ROM::Repository::Root
- Extended by:
- Dry::Core::ClassAttributes
- Defined in:
- 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
Instance Attribute Summary collapse
- #root ⇒ Object readonly
Class Method Summary collapse
-
.inherited(klass) ⇒ Object
private
Sets descendant root relation.
-
.root ⇒ Object
Get or set repository root relation identifier.
Instance Method Summary collapse
-
#aggregate(*args) ⇒ RelationProxy
Compose a relation aggregate from the root relation.
- #changeset(*args) ⇒ Object
-
#initialize(container) ⇒ Root
constructor
A new instance of Root.
Constructor Details
#initialize(container) ⇒ Root
Returns a new instance of Root.
62 63 64 65 |
# File 'lib/rom/repository/root.rb', line 62 def initialize(container) super @root = relations[self.class.root] end |
Instance Attribute Details
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
56 57 58 59 |
# File 'lib/rom/repository/root.rb', line 56 def self.inherited(klass) super klass.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
47 |
# File 'lib/rom/repository/root.rb', line 47 defines :root |
Instance Method Details
#aggregate(*associations) ⇒ RelationProxy #aggregate(*associations, *assoc_opts) ⇒ RelationProxy #aggregate(options) ⇒ RelationProxy
Compose a relation aggregate from the root relation
101 102 103 104 105 106 107 |
# File 'lib/rom/repository/root.rb', line 101 def aggregate(*args) if args.all? { |arg| arg.is_a?(Symbol) } root.combine(*args) else args.reduce(root) { |a, e| a.combine(e) } end end |
#changeset(name, *args) ⇒ Object #changeset(data) ⇒ Changeset::Create #changeset(primary_key, data) ⇒ Changeset::Update #changeset(changeset_class) ⇒ Changeset
150 151 152 153 154 155 156 157 158 159 |
# File 'lib/rom/repository/root.rb', line 150 def changeset(*args) if args.first.is_a?(Symbol) && relations.key?(args.first) super elsif args.first.is_a?(Class) klass, *rest = args super(klass[self.class.root], *rest) else super(root.name, *args) end end |