Class: Graphiti::ActiveGraph::Adapters::ActiveGraph
- Inherits:
-
Graphiti::Adapters::Abstract
- Object
- Graphiti::Adapters::Abstract
- Graphiti::ActiveGraph::Adapters::ActiveGraph
show all
- Defined in:
- lib/graphiti/active_graph/adapters/active_graph.rb
Defined Under Namespace
Modules: Sideload
Classes: HasManySideload, HasOneSideload, PolymorphicBelongsTo
Class Method Summary
collapse
Instance Method Summary
collapse
-
#assign_attributes(model_instance, attributes) ⇒ Object
-
#associate(parent, child, association_name, type) ⇒ Object
-
#base_scope(model) ⇒ Object
-
#clear_active_connections! ⇒ Object
-
#count(scope, _attr) ⇒ Object
-
#destroy(model_instance) ⇒ Object
-
#disassociate(parent, child, association_name, type) ⇒ Object
-
#filter_eq(scope, attribute, value) ⇒ Object
(also: #filter_integer_eq, #filter_float_eq, #filter_big_decimal_eq, #filter_date_eq, #filter_boolean_eq, #filter_uuid_eq, #filter_enum_eq)
-
#filter_not_eq(scope, attribute, value) ⇒ Object
(also: #filter_integer_not_eq, #filter_float_not_eq, #filter_big_decimal_not_eq, #filter_date_not_eq, #filter_boolean_not_eq, #filter_uuid_not_eq, #filter_enum_not_eq)
-
#order(scope, attribute, direction, extra_field = false) ⇒ Object
-
#paginate(scope, current_page, per_page, offset) ⇒ Object
-
#persistence_attributes(persistence, attributes) ⇒ Object
-
#process_belongs_to(persistence, attributes) ⇒ Object
def associate_all(parent, children, association_name, association_type) if association_type == :has_many if !parent.send(:“#association_name”).present? parent.send(:“#association_name=”, children) else parent.send(:“#association_name”) << children end else parent.send(:“#association_name=”, children) end end.
-
#process_has_many(persistence, caller_model) ⇒ Object
-
#resolve(scope, resolve_to_rel = false) ⇒ Object
-
#save(model_instance) ⇒ Object
-
#transaction(_model_class) ⇒ Object
Class Method Details
.sideloading_classes ⇒ Object
Instance Method Details
#assign_attributes(model_instance, attributes) ⇒ Object
17
18
19
20
21
22
23
24
25
26
|
# File 'lib/graphiti/active_graph/adapters/active_graph.rb', line 17
def assign_attributes(model_instance, attributes)
model_instance.before_assign_resource_attr if model_instance.respond_to?(:before_assign_resource_attr)
model_instance.update(attributes)
end
|
#associate(parent, child, association_name, type) ⇒ Object
96
97
|
# File 'lib/graphiti/active_graph/adapters/active_graph.rb', line 96
def associate(parent, child, association_name, type)
end
|
#base_scope(model) ⇒ Object
13
14
15
|
# File 'lib/graphiti/active_graph/adapters/active_graph.rb', line 13
def base_scope(model)
model
end
|
#clear_active_connections! ⇒ Object
103
104
|
# File 'lib/graphiti/active_graph/adapters/active_graph.rb', line 103
def clear_active_connections!
end
|
#count(scope, _attr) ⇒ Object
47
48
49
|
# File 'lib/graphiti/active_graph/adapters/active_graph.rb', line 47
def count(scope, _attr)
scope.skip(0).limit(nil).count
end
|
#destroy(model_instance) ⇒ Object
56
57
58
59
|
# File 'lib/graphiti/active_graph/adapters/active_graph.rb', line 56
def destroy(model_instance)
model_instance.destroy
model_instance
end
|
#disassociate(parent, child, association_name, type) ⇒ Object
99
100
101
|
# File 'lib/graphiti/active_graph/adapters/active_graph.rb', line 99
def disassociate(parent, child, association_name, type)
parent.send(:"#{association_name}=", nil)
end
|
#filter_eq(scope, attribute, value) ⇒ Object
Also known as:
filter_integer_eq, filter_float_eq, filter_big_decimal_eq, filter_date_eq, filter_boolean_eq, filter_uuid_eq, filter_enum_eq
106
107
108
|
# File 'lib/graphiti/active_graph/adapters/active_graph.rb', line 106
def filter_eq(scope, attribute, value)
scope.where(attribute => value)
end
|
#filter_not_eq(scope, attribute, value) ⇒ Object
Also known as:
filter_integer_not_eq, filter_float_not_eq, filter_big_decimal_not_eq, filter_date_not_eq, filter_boolean_not_eq, filter_uuid_not_eq, filter_enum_not_eq
117
118
119
|
# File 'lib/graphiti/active_graph/adapters/active_graph.rb', line 117
def filter_not_eq(scope, attribute, value)
scope.where_not(attribute => value)
end
|
#order(scope, attribute, direction, extra_field = false) ⇒ Object
39
40
41
42
43
44
45
|
# File 'lib/graphiti/active_graph/adapters/active_graph.rb', line 39
def order(scope, attribute, direction, = false)
if
scope.query.order("#{attribute} #{direction}").proxy_as(scope.model, scope.identity)
else
scope.send(resource.relation_resource? ? :rel_order : :order, attribute => direction)
end
end
|
#paginate(scope, current_page, per_page, offset) ⇒ Object
28
29
30
31
|
# File 'lib/graphiti/active_graph/adapters/active_graph.rb', line 28
def paginate(scope, current_page, per_page, offset)
offset ||= (current_page - 1) * per_page
scope.skip(offset).limit(per_page)
end
|
#persistence_attributes(persistence, attributes) ⇒ Object
85
86
87
88
89
90
91
92
93
94
|
# File 'lib/graphiti/active_graph/adapters/active_graph.rb', line 85
def persistence_attributes(persistence, attributes)
rel_attrs = {}
@persistence = persistence
del_empty_rels(rel_attrs) unless resource.relation_resource?
attributes_for_has_one(rel_attrs)
attributes_for_has_many(rel_attrs)
attributes.merge rel_attrs
end
|
#process_belongs_to(persistence, attributes) ⇒ Object
def associate_all(parent, children, association_name, association_type)
if association_type == :has_many
if !parent.send(:"#{association_name}").present?
parent.send(:"#{association_name}=", children)
else
parent.send(:"#{association_name}") << children
end
else
parent.send(:"#{association_name}=", children)
end
end
77
78
79
|
# File 'lib/graphiti/active_graph/adapters/active_graph.rb', line 77
def process_belongs_to(persistence, attributes)
[]
end
|
#process_has_many(persistence, caller_model) ⇒ Object
81
82
83
|
# File 'lib/graphiti/active_graph/adapters/active_graph.rb', line 81
def process_has_many(persistence, caller_model)
[]
end
|
#resolve(scope, resolve_to_rel = false) ⇒ Object
61
62
63
|
# File 'lib/graphiti/active_graph/adapters/active_graph.rb', line 61
def resolve(scope, resolve_to_rel = false)
resolve_to_rel ? scope.to_a(false, true) : scope.to_a
end
|
#save(model_instance) ⇒ Object
51
52
53
54
|
# File 'lib/graphiti/active_graph/adapters/active_graph.rb', line 51
def save(model_instance)
model_instance.save if model_instance.changed?
model_instance
end
|
#transaction(_model_class) ⇒ Object
33
34
35
36
37
|
# File 'lib/graphiti/active_graph/adapters/active_graph.rb', line 33
def transaction(_model_class)
::ActiveGraph::Base.transaction do
yield
end
end
|