Module: ROM::Repository::RelationProxy::Wrap
- Included in:
- ROM::Repository::RelationProxy
- Defined in:
- lib/rom/repository/relation_proxy/wrap.rb
Overview
Provides convenient methods for producing wrapped relations
Instance Method Summary collapse
-
#wrap(options) ⇒ RelationProxy
Wrap other relations.
-
#wrap_parent(options) ⇒ RelationProxy
Shortcut to wrap parents.
-
#wrapped(name, keys) ⇒ RelationProxy
private
Return a wrapped representation of a loading-proxy relation.
Instance Method Details
#wrap(options) ⇒ RelationProxy
Wrap other relations
18 19 20 21 22 23 24 25 26 27 28 |
# File 'lib/rom/repository/relation_proxy/wrap.rb', line 18 def wrap() wraps = .map { |(name, (relation, keys))| relation.wrapped(name, keys) } relation = wraps.reduce(self) { |a, e| a.relation.for_wrap(e..fetch(:keys), e.base_name.relation) } __new__(relation, meta: { wraps: wraps }) end |
#wrap_parent(options) ⇒ RelationProxy
Shortcut to wrap parents
38 39 40 41 42 43 44 45 |
# File 'lib/rom/repository/relation_proxy/wrap.rb', line 38 def wrap_parent() wrap( .each_with_object({}) { |(name, parent), h| keys = combine_keys(parent, relation, :children) h[name] = [parent, keys] } ) end |
#wrapped(name, keys) ⇒ RelationProxy
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.
Return a wrapped representation of a loading-proxy relation
This will carry meta info used to produce a correct AST from a relation so that correct mapper can be generated
55 56 57 |
# File 'lib/rom/repository/relation_proxy/wrap.rb', line 55 def wrapped(name, keys) with(name: name, meta: { keys: keys, wrap: true, combine_name: name }) end |