Class: ActiveGraph::Shared::QueryFactory
- Inherits:
-
Object
- Object
- ActiveGraph::Shared::QueryFactory
show all
- Defined in:
- lib/active_graph/shared/query_factory.rb
Overview
Acts as a bridge between the node and rel models and ActiveGraph::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.
Instance Attribute Summary collapse
Class Method Summary
collapse
Instance Method Summary
collapse
Constructor Details
#initialize(graph_object, identifier) ⇒ QueryFactory
Returns a new instance of QueryFactory.
8
9
10
11
|
# File 'lib/active_graph/shared/query_factory.rb', line 8
def initialize(graph_object, identifier)
@graph_object = graph_object
@identifier = identifier.to_sym
end
|
Instance Attribute Details
#graph_object ⇒ Object
Returns the value of attribute graph_object.
6
7
8
|
# File 'lib/active_graph/shared/query_factory.rb', line 6
def graph_object
@graph_object
end
|
#identifier ⇒ Object
Returns the value of attribute identifier.
6
7
8
|
# File 'lib/active_graph/shared/query_factory.rb', line 6
def identifier
@identifier
end
|
Class Method Details
.create(graph_object, identifier) ⇒ Object
13
14
15
|
# File 'lib/active_graph/shared/query_factory.rb', line 13
def self.create(graph_object, identifier)
factory_for(graph_object).new(graph_object, identifier)
end
|
.factory_for(graph_obj) ⇒ Object
17
18
19
20
21
22
23
24
25
26
|
# File 'lib/active_graph/shared/query_factory.rb', line 17
def self.factory_for(graph_obj)
case
when graph_obj.respond_to?(:labels_for_create)
NodeQueryFactory
when graph_obj.respond_to?(:type)
RelQueryFactory
else
fail "Unable to find factory for #{graph_obj}"
end
end
|
Instance Method Details
#base_query ⇒ Object
38
39
40
|
# File 'lib/active_graph/shared/query_factory.rb', line 38
def base_query
@base_query || ActiveGraph::Base.new_query
end
|
#base_query=(query) ⇒ Object
33
34
35
36
|
# File 'lib/active_graph/shared/query_factory.rb', line 33
def base_query=(query)
return if query.blank?
@base_query = query
end
|
#query ⇒ Object
28
29
30
|
# File 'lib/active_graph/shared/query_factory.rb', line 28
def query
graph_object.persisted? ? match_query : create_query
end
|