Class: ROM::Repository::Root
- Inherits:
-
ROM::Repository
- Object
- ROM::Repository
- ROM::Repository::Root
- 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, opts = EMPTY_HASH) ⇒ Root
constructor
A new instance of Root.
Constructor Details
#initialize(container, opts = EMPTY_HASH) ⇒ Root
Returns a new instance of Root.
60 61 62 63 |
# File 'lib/rom/repository/root.rb', line 60 def initialize(container, opts = EMPTY_HASH) 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
54 55 56 57 |
# File 'lib/rom/repository/root.rb', line 54 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
45 |
# File 'lib/rom/repository/root.rb', line 45 defines :root |
Instance Method Details
#aggregate(*associations) ⇒ RelationProxy #aggregate(*associations, *assoc_opts) ⇒ RelationProxy #aggregate(options) ⇒ RelationProxy
Compose a relation aggregate from the root relation
99 100 101 102 103 104 105 |
# File 'lib/rom/repository/root.rb', line 99 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
148 149 150 151 152 153 154 155 156 157 |
# File 'lib/rom/repository/root.rb', line 148 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 |