Module: ROM::Repository::LoadingProxy::Wrap

Included in:
ROM::Repository::LoadingProxy
Defined in:
lib/rom/repository/loading_proxy/wrap.rb

Overview

Provides convenient methods for producing wrapped relations

Instance Method Summary collapse

Instance Method Details

#wrap(options) ⇒ LoadingProxy

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/loading_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)
  }

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

#wrap_parent(options) ⇒ LoadingProxy

Shortcut to wrap parents

Examples:

tasks.wrap_parent(owner: users)

Returns:



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

def wrap_parent(options)
  wrap(
    options.each_with_object({}) { |(name, parent), h|
      h[name] = [parent, combine_keys(parent, :children)]
    }
  )
end

#wrapped(name, keys) ⇒ LoadingProxy

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:



54
55
56
# File 'lib/rom/repository/loading_proxy/wrap.rb', line 54

def wrapped(name, keys)
  with(name: name, meta: { keys: keys, wrap: true })
end