class Neo4j::ActiveNode::Query::QueryProxy::Link
Attributes
clause[R]
Public Class Methods
converted_key(model, key)
click to toggle source
# File lib/neo4j/active_node/query/query_proxy_link.rb 123 def converted_key(model, key) 124 if key.to_sym == :id 125 model ? model.id_property_name : :uuid 126 else 127 key 128 end 129 end
converted_keys(model, arg)
click to toggle source
# File lib/neo4j/active_node/query/query_proxy_link.rb 119 def converted_keys(model, arg) 120 arg.is_a?(Hash) ? Hash[arg.map { |key, value| [converted_key(model, key), value] }] : arg 121 end
converted_value(model, key, value)
click to toggle source
# File lib/neo4j/active_node/query/query_proxy_link.rb 131 def converted_value(model, key, value) 132 model.declared_properties.value_for_where(key, value) 133 end
for_arg(model, clause, arg, *args)
click to toggle source
# File lib/neo4j/active_node/query/query_proxy_link.rb 111 def for_arg(model, clause, arg, *args) 112 default = [Link.new(clause, arg, *args)] 113 114 Link.for_clause(clause, arg, model, *args) || default 115 rescue NoMethodError 116 default 117 end
for_args(model, clause, args, association = nil)
click to toggle source
# File lib/neo4j/active_node/query/query_proxy_link.rb 101 def for_args(model, clause, args, association = nil) 102 if [:where, :where_not].include?(clause) && args[0].is_a?(String) # Better way? 103 [for_arg(model, clause, args[0], *args[1..-1])] 104 elsif [:rel_where, :rel_where_not].include?(clause) 105 args.map { |arg| for_arg(model, clause, arg, association) } 106 else 107 args.map { |arg| for_arg(model, clause, arg) } 108 end 109 end
for_association(name, value, n_string, model)
click to toggle source
# File lib/neo4j/active_node/query/query_proxy_link.rb 68 def for_association(name, value, n_string, model) 69 neo_id = value.try(:neo_id) || value 70 fail ArgumentError, "Invalid value for '#{name}' condition" if not neo_id.is_a?(Integer) 71 72 [ 73 new(:match, ->(v, _) { "(#{v})#{model.associations[name].arrow_cypher}(#{n_string})" }), 74 new(:where, ->(_, _) { {"ID(#{n_string})" => neo_id.to_i} }) 75 ] 76 end
for_clause(clause, arg, model, *args)
click to toggle source
# File lib/neo4j/active_node/query/query_proxy_link.rb 23 def for_clause(clause, arg, model, *args) 24 method_to_call = "for_#{clause}_clause" 25 26 send(method_to_call, arg, model, *args) 27 end
for_order_clause(arg, model)
click to toggle source
# File lib/neo4j/active_node/query/query_proxy_link.rb 97 def for_order_clause(arg, model) 98 [new(:order, ->(v, _) { arg.is_a?(String) ? arg : {v => converted_keys(model, arg)} })] 99 end
for_rel_order_clause(arg, _)
click to toggle source
# File lib/neo4j/active_node/query/query_proxy_link.rb 93 def for_rel_order_clause(arg, _) 94 [new(:order, ->(_, v) { arg.is_a?(String) ? arg : {v => arg} })] 95 end
for_rel_where_clause(arg, _, association)
click to toggle source
We don't accept strings here. If you want to use a string, just use where.
# File lib/neo4j/active_node/query/query_proxy_link.rb 79 def for_rel_where_clause(arg, _, association) 80 arg.each_with_object([]) do |(key, value), result| 81 rel_class = association.relationship_class if association.relationship_class 82 val = rel_class ? converted_value(rel_class, key, value) : value 83 result << new(:where, ->(_, rel_var) { {rel_var => {key => val}} }) 84 end 85 end
for_rel_where_not_clause(*args)
click to toggle source
# File lib/neo4j/active_node/query/query_proxy_link.rb 87 def for_rel_where_not_clause(*args) 88 for_rel_where_clause(*args).each do |link| 89 link.instance_variable_set('@clause', :where_not) 90 end 91 end
for_where_clause(arg, model, *args)
click to toggle source
# File lib/neo4j/active_node/query/query_proxy_link.rb 29 def for_where_clause(arg, model, *args) 30 node_num = 1 31 result = [] 32 if arg.is_a?(Hash) 33 arg.each do |key, value| 34 if model && model.association?(key) 35 result += for_association(key, value, "n#{node_num}", model) 36 node_num += 1 37 else 38 result << new_for_key_and_value(model, key, value) 39 end 40 end 41 elsif arg.is_a?(String) 42 result << new(:where, arg, args) 43 end 44 result 45 end
Also aliased as: for_node_where_clause
for_where_not_clause(*args)
click to toggle source
# File lib/neo4j/active_node/query/query_proxy_link.rb 48 def for_where_not_clause(*args) 49 for_where_clause(*args).each do |link| 50 link.instance_variable_set('@clause', :where_not) 51 end 52 end
new(clause, arg, args = [])
click to toggle source
# File lib/neo4j/active_node/query/query_proxy_link.rb 8 def initialize(clause, arg, args = []) 9 @clause = clause 10 @arg = arg 11 @args = args 12 end
new_for_key_and_value(model, key, value)
click to toggle source
# File lib/neo4j/active_node/query/query_proxy_link.rb 54 def new_for_key_and_value(model, key, value) 55 key = converted_key(model, key) 56 57 val = if !model 58 value 59 elsif key == model.id_property_name && value.is_a?(Neo4j::ActiveNode) 60 value.id 61 else 62 converted_value(model, key, value) 63 end 64 65 new(:where, ->(v, _) { {v => {key => val}} }) 66 end
Public Instance Methods
args(var, rel_var)
click to toggle source
# File lib/neo4j/active_node/query/query_proxy_link.rb 14 def args(var, rel_var) 15 if @arg.respond_to?(:call) 16 @arg.call(var, rel_var) 17 else 18 [@arg] + @args 19 end 20 end