Module: ActiveGraphExtensions::Node::Query::QueryProxyEagerLoading::ScopeEagerLoading
- Defined in:
- lib/active_graph_extensions/node/query/query_proxy_eager_loading/scope_eager_loading.rb
Overview
Used to append auth scopes to query proxy eagerloading
Instance Method Summary collapse
- #assign_config_chain(conf, auth_proxy, rel_length) ⇒ Object
- #authorized_rel(path, var) ⇒ Object
- #authorized_scope(rel_model, path) ⇒ Object
- #properties_for(rel_model) ⇒ Object
- #proxy_rel_parts(auth_proxy, conf) ⇒ Object
- #relationship_model(path) ⇒ Object
Instance Method Details
#assign_config_chain(conf, auth_proxy, rel_length) ⇒ Object
40 41 42 43 |
# File 'lib/active_graph_extensions/node/query/query_proxy_eager_loading/scope_eager_loading.rb', line 40 def assign_config_chain(conf, auth_proxy, rel_length) return unless (auth_chain = auth_proxy.instance_variable_get(:@chain)) conf[:chain][[auth_proxy.identity, rel_length ? "#{auth_proxy.identity}_rel" : nil]] = auth_chain end |
#authorized_rel(path, var) ⇒ Object
9 10 11 12 13 14 15 16 17 |
# File 'lib/active_graph_extensions/node/query/query_proxy_eager_loading/scope_eager_loading.rb', line 9 def (path, var) rel_model = relationship_model(path) return {} if @opts.blank? || !(auth_scope = (rel_model, path)) conf = { rels: [], chain: {} } proxy = auth_scope.call(var, "#{var}_rel", @opts.merge(properties: properties_for(rel_model), rel_length: path.last.rel_length)) proxy_rel_parts(proxy.instance_variable_get(:@break_proxy) || proxy, conf) conf end |
#authorized_scope(rel_model, path) ⇒ Object
28 29 30 |
# File 'lib/active_graph_extensions/node/query/query_proxy_eager_loading/scope_eager_loading.rb', line 28 def (rel_model, path) rel_model.scopes["authorized_#{path.last.association.name}".to_sym] end |
#properties_for(rel_model) ⇒ Object
19 20 21 22 |
# File 'lib/active_graph_extensions/node/query/query_proxy_eager_loading/scope_eager_loading.rb', line 19 def properties_for(rel_model) return [] unless @opts[:properties] @opts[:properties].select { |prop| prop.model.name == rel_model.name }.map(&:name) end |
#proxy_rel_parts(auth_proxy, conf) ⇒ Object
32 33 34 35 36 37 38 |
# File 'lib/active_graph_extensions/node/query/query_proxy_eager_loading/scope_eager_loading.rb', line 32 def proxy_rel_parts(auth_proxy, conf) return unless auth_proxy&.association rel_length = auth_proxy.instance_variable_get(:@rel_length) conf[:rels] << relationship_part(auth_proxy.association, auth_proxy.identity, rel_length) assign_config_chain(conf, auth_proxy, rel_length) proxy_rel_parts(auth_proxy.query_proxy, conf) end |
#relationship_model(path) ⇒ Object
24 25 26 |
# File 'lib/active_graph_extensions/node/query/query_proxy_eager_loading/scope_eager_loading.rb', line 24 def relationship_model(path) path[0..-2].inject(model) { |mod, rel| mod.send(rel.name).model } end |