class Neo4j::Shared::QueryFactory
Acts as a bridge between the node and rel models and Neo4j::Core::Query
. If the object is persisted, it returns a query matching; otherwise, it returns a query creating it. This class does not execute queries, so it keeps no record of what identifiers have been set or what has happened in previous factories.
Attributes
graph_object[R]
identifier[R]
Public Class Methods
create(graph_object, identifier)
click to toggle source
# File lib/neo4j/shared/query_factory.rb 13 def self.create(graph_object, identifier) 14 factory_for(graph_object).new(graph_object, identifier) 15 end
factory_for(graph_obj)
click to toggle source
# File lib/neo4j/shared/query_factory.rb 17 def self.factory_for(graph_obj) 18 case 19 when graph_obj.respond_to?(:labels_for_create) 20 NodeQueryFactory 21 when graph_obj.respond_to?(:rel_type) 22 RelQueryFactory 23 else 24 fail "Unable to find factory for #{graph_obj}" 25 end 26 end
new(graph_object, identifier)
click to toggle source
# File lib/neo4j/shared/query_factory.rb 8 def initialize(graph_object, identifier) 9 @graph_object = graph_object 10 @identifier = identifier.to_sym 11 end
Public Instance Methods
base_query()
click to toggle source
# File lib/neo4j/shared/query_factory.rb 38 def base_query 39 @base_query || Neo4j::ActiveBase.new_query 40 end
base_query=(query)
click to toggle source
@param [Neo4j::Core::Query] query An instance of Neo4j::Core::Query
upon which methods will be chained.
# File lib/neo4j/shared/query_factory.rb 33 def base_query=(query) 34 return if query.blank? 35 @base_query = query 36 end
query()
click to toggle source
# File lib/neo4j/shared/query_factory.rb 28 def query 29 graph_object.persisted? ? match_query : create_query 30 end
Protected Instance Methods
create_query()
click to toggle source
# File lib/neo4j/shared/query_factory.rb 44 def create_query 45 fail 'Abstract class, not implemented' 46 end
identifier_id()
click to toggle source
# File lib/neo4j/shared/query_factory.rb 54 def identifier_id 55 @identifier_id ||= "#{identifier}_id" 56 end
identifier_params()
click to toggle source
# File lib/neo4j/shared/query_factory.rb 58 def identifier_params 59 @identifier_params ||= "#{identifier}_params" 60 end
match_query()
click to toggle source
# File lib/neo4j/shared/query_factory.rb 48 def match_query 49 base_query 50 .match(match_string).where("ID(#{identifier}) = {#{identifier_id}}") 51 .params(identifier_id.to_sym => graph_object.neo_id) 52 end