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(*names, **options) ⇒ RelationProxy
Wrap other relations.
-
#wrap_parent(options) ⇒ RelationProxy
Shortcut to wrap parents.
-
#wrapped(name, keys, wrap_from_assoc = false) ⇒ RelationProxy
private
Return a wrapped representation of a loading-proxy relation.
- #wraps_from_names(names) ⇒ Object private
- #wraps_from_options(options) ⇒ Object private
Instance Method Details
#wrap(*names, **options) ⇒ RelationProxy
Wrap other relations
18 19 20 21 22 23 24 25 26 27 |
# File 'lib/rom/repository/relation_proxy/wrap.rb', line 18 def wrap(*names, **) new_wraps = wraps_from_names(names) + () relation = new_wraps.reduce(self) { |a, e| name = e.[:wrap_from_assoc] ? e.[:combine_name] : e.base_name.relation a.relation.for_wrap(e..fetch(:keys), name) } __new__(relation, meta: { wraps: wraps + new_wraps }) end |
#wrap_parent(options) ⇒ RelationProxy
Shortcut to wrap parents
37 38 39 40 41 42 43 44 |
# File 'lib/rom/repository/relation_proxy/wrap.rb', line 37 def wrap_parent() wrap( .each_with_object({}) { |(name, parent), h| keys = combine_keys(parent, relation, :children) h[name] = [parent, keys] } ) end |
#wrapped(name, keys, wrap_from_assoc = false) ⇒ 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
54 55 56 57 58 59 60 61 |
# File 'lib/rom/repository/relation_proxy/wrap.rb', line 54 def wrapped(name, keys, wrap_from_assoc = false) with( name: name, meta: { keys: keys, wrap_from_assoc: wrap_from_assoc, wrap: true, combine_name: name } ) end |
#wraps_from_names(names) ⇒ 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.
69 70 71 72 73 74 |
# File 'lib/rom/repository/relation_proxy/wrap.rb', line 69 def wraps_from_names(names) names.map { |name| assoc = associations[name] registry[assoc.target.relation].wrapped(name, assoc.combine_keys(__registry__), true) } end |
#wraps_from_options(options) ⇒ 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.
64 65 66 |
# File 'lib/rom/repository/relation_proxy/wrap.rb', line 64 def () .map { |(name, (relation, keys))| relation.wrapped(name, keys) } end |