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

Instance Method Details

#wrap(options) ⇒ RelationProxy

Wrap other relations

Examples:

tasks.wrap(owner: [users, user_id: :id])

Parameters:

  • options (Hash)

Returns:



18
19
20
21
22
23
24
25
26
27
28
# File 'lib/rom/repository/relation_proxy/wrap.rb', line 18

def wrap(options)
  wraps = options.map { |(name, (relation, keys))|
    relation.wrapped(name, keys)
  }

  relation = wraps.reduce(self) { |a, e|
    a.relation.for_wrap(e.meta.fetch(:keys), e.base_name.relation)
  }

  __new__(relation, meta: { wraps: wraps })
end

#wrap_parent(options) ⇒ RelationProxy

Shortcut to wrap parents

Examples:

tasks.wrap_parent(owner: users)

Returns:



38
39
40
41
42
43
44
45
# File 'lib/rom/repository/relation_proxy/wrap.rb', line 38

def wrap_parent(options)
  wrap(
    options.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

Returns:



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