activegraph 10.0.0.pre.alpha.11 → 10.0.0.pre.beta.1
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/README.md +2 -2
- data/{neo4j.gemspec → activegraph.gemspec} +7 -9
- data/config/neo4j/config.yml +4 -4
- data/lib/active_graph.rb +120 -0
- data/lib/{neo4j → active_graph}/ansi.rb +1 -1
- data/lib/{neo4j → active_graph}/attribute_set.rb +3 -3
- data/lib/{neo4j/active_base.rb → active_graph/base.rb} +18 -12
- data/lib/{neo4j → active_graph}/class_arguments.rb +5 -5
- data/lib/{neo4j → active_graph}/config.rb +10 -10
- data/lib/active_graph/core.rb +14 -0
- data/lib/{neo4j → active_graph}/core/connection_failed_error.rb +1 -1
- data/lib/{neo4j → active_graph}/core/cypher_error.rb +1 -1
- data/lib/{neo4j → active_graph}/core/driver.rb +5 -5
- data/lib/{neo4j → active_graph}/core/has_uri.rb +1 -1
- data/lib/{neo4j → active_graph}/core/instrumentable.rb +4 -4
- data/lib/{neo4j → active_graph}/core/label.rb +13 -13
- data/lib/{neo4j → active_graph}/core/logging.rb +2 -2
- data/lib/{neo4j → active_graph}/core/node.rb +2 -2
- data/lib/{neo4j → active_graph}/core/querable.rb +7 -7
- data/lib/{neo4j → active_graph}/core/query.rb +16 -16
- data/lib/{neo4j → active_graph}/core/query_builder.rb +3 -3
- data/lib/{neo4j → active_graph}/core/query_clauses.rb +1 -1
- data/lib/{neo4j → active_graph}/core/query_ext.rb +5 -5
- data/lib/{neo4j → active_graph}/core/query_find_in_batches.rb +2 -2
- data/lib/{neo4j → active_graph}/core/relationship.rb +2 -2
- data/lib/{neo4j → active_graph}/core/responses.rb +3 -3
- data/lib/{neo4j → active_graph}/core/result.rb +1 -1
- data/lib/{neo4j → active_graph}/core/schema.rb +1 -1
- data/lib/{neo4j → active_graph}/core/schema_errors.rb +1 -1
- data/lib/{neo4j → active_graph}/core/wrappable.rb +1 -1
- data/lib/{neo4j → active_graph}/errors.rb +1 -1
- data/lib/{neo4j → active_graph}/lazy_attribute_hash.rb +1 -1
- data/lib/{neo4j → active_graph}/migration.rb +11 -11
- data/lib/{neo4j → active_graph}/migrations.rb +5 -5
- data/lib/{neo4j → active_graph}/migrations/base.rb +7 -7
- data/lib/{neo4j → active_graph}/migrations/check_pending.rb +3 -3
- data/lib/{neo4j → active_graph}/migrations/helpers.rb +4 -4
- data/lib/{neo4j → active_graph}/migrations/helpers/id_property.rb +3 -3
- data/lib/{neo4j → active_graph}/migrations/helpers/relationships.rb +1 -1
- data/lib/{neo4j → active_graph}/migrations/helpers/schema.rb +7 -7
- data/lib/{neo4j → active_graph}/migrations/migration_file.rb +1 -1
- data/lib/{neo4j → active_graph}/migrations/runner.rb +3 -3
- data/lib/{neo4j → active_graph}/migrations/schema.rb +1 -1
- data/lib/{neo4j → active_graph}/migrations/schema_migration.rb +2 -2
- data/lib/{neo4j → active_graph}/model_schema.rb +8 -8
- data/lib/{neo4j/active_node.rb → active_graph/node.rb} +32 -32
- data/lib/{neo4j/active_node → active_graph/node}/callbacks.rb +3 -3
- data/lib/{neo4j/active_node → active_graph/node}/dependent.rb +2 -2
- data/lib/{neo4j/active_node → active_graph/node}/dependent/association_methods.rb +2 -2
- data/lib/{neo4j/active_node → active_graph/node}/dependent/query_proxy_methods.rb +4 -4
- data/lib/{neo4j/active_node → active_graph/node}/dependent_callbacks.rb +4 -4
- data/lib/{neo4j/active_node → active_graph/node}/enum.rb +3 -3
- data/lib/{neo4j/active_node → active_graph/node}/has_n.rb +20 -20
- data/lib/{neo4j/active_node → active_graph/node}/has_n/association.rb +8 -8
- data/lib/{neo4j/active_node → active_graph/node}/has_n/association/rel_factory.rb +4 -4
- data/lib/{neo4j/active_node → active_graph/node}/has_n/association/rel_wrapper.rb +4 -4
- data/lib/{neo4j/active_node → active_graph/node}/has_n/association_cypher_methods.rb +2 -2
- data/lib/{neo4j/active_node → active_graph/node}/id_property.rb +7 -7
- data/lib/{neo4j/active_node → active_graph/node}/id_property/accessor.rb +1 -1
- data/lib/{neo4j/active_node → active_graph/node}/initialize.rb +3 -3
- data/lib/{neo4j/active_node → active_graph/node}/labels.rb +18 -18
- data/lib/{neo4j/active_node → active_graph/node}/labels/index.rb +6 -6
- data/lib/{neo4j/active_node → active_graph/node}/labels/reloading.rb +1 -1
- data/lib/{neo4j/active_node → active_graph/node}/node_list_formatter.rb +1 -1
- data/lib/{neo4j/active_node → active_graph/node}/node_wrapper.rb +5 -5
- data/lib/{neo4j/active_node → active_graph/node}/orm_adapter.rb +2 -2
- data/lib/{neo4j/active_node → active_graph/node}/persistence.rb +7 -7
- data/lib/{neo4j/active_node → active_graph/node}/property.rb +3 -3
- data/lib/{neo4j/active_node → active_graph/node}/query.rb +9 -9
- data/lib/{neo4j/active_node → active_graph/node}/query/query_proxy.rb +19 -19
- data/lib/{neo4j/active_node → active_graph/node}/query/query_proxy_eager_loading.rb +3 -3
- data/lib/{neo4j/active_node → active_graph/node}/query/query_proxy_eager_loading/association_tree.rb +2 -2
- data/lib/{neo4j/active_node → active_graph/node}/query/query_proxy_enumerable.rb +4 -4
- data/lib/{neo4j/active_node → active_graph/node}/query/query_proxy_find_in_batches.rb +2 -2
- data/lib/{neo4j/active_node → active_graph/node}/query/query_proxy_link.rb +3 -3
- data/lib/{neo4j/active_node → active_graph/node}/query/query_proxy_methods.rb +12 -12
- data/lib/{neo4j/active_node → active_graph/node}/query/query_proxy_methods_of_mass_updating.rb +4 -4
- data/lib/{neo4j/active_node → active_graph/node}/query_methods.rb +4 -4
- data/lib/{neo4j/active_node → active_graph/node}/reflection.rb +3 -3
- data/lib/{neo4j/active_node → active_graph/node}/rels.rb +1 -1
- data/lib/{neo4j/active_node → active_graph/node}/scope.rb +4 -4
- data/lib/{neo4j/active_node → active_graph/node}/unpersisted.rb +2 -2
- data/lib/{neo4j/active_node → active_graph/node}/validations.rb +3 -3
- data/lib/{neo4j → active_graph}/paginated.rb +1 -1
- data/lib/{neo4j → active_graph}/railtie.rb +18 -18
- data/lib/{neo4j/active_rel.rb → active_graph/relationship.rb} +19 -19
- data/lib/active_graph/relationship/callbacks.rb +21 -0
- data/lib/{neo4j/active_rel → active_graph/relationship}/initialize.rb +5 -5
- data/lib/{neo4j/active_rel → active_graph/relationship}/persistence.rb +6 -6
- data/lib/{neo4j/active_rel → active_graph/relationship}/persistence/query_factory.rb +7 -7
- data/lib/{neo4j/active_rel → active_graph/relationship}/property.rb +6 -6
- data/lib/{neo4j/active_rel → active_graph/relationship}/query.rb +7 -7
- data/lib/{neo4j/active_rel → active_graph/relationship}/rel_wrapper.rb +5 -5
- data/lib/{neo4j/active_rel → active_graph/relationship}/related_node.rb +7 -7
- data/lib/{neo4j/active_rel → active_graph/relationship}/types.rb +6 -6
- data/lib/active_graph/relationship/validations.rb +8 -0
- data/lib/{neo4j → active_graph}/schema/operation.rb +5 -5
- data/lib/{neo4j → active_graph}/shared.rb +7 -7
- data/lib/{neo4j → active_graph}/shared/attributes.rb +10 -10
- data/lib/{neo4j → active_graph}/shared/callbacks.rb +3 -3
- data/lib/{neo4j → active_graph}/shared/cypher.rb +1 -1
- data/lib/{neo4j → active_graph}/shared/declared_properties.rb +8 -8
- data/lib/{neo4j → active_graph}/shared/declared_property.rb +9 -9
- data/lib/{neo4j → active_graph}/shared/declared_property/index.rb +3 -3
- data/lib/{neo4j → active_graph}/shared/enum.rb +6 -6
- data/lib/{neo4j → active_graph}/shared/filtered_hash.rb +2 -2
- data/lib/{neo4j → active_graph}/shared/identity.rb +2 -2
- data/lib/{neo4j → active_graph}/shared/initialize.rb +3 -3
- data/lib/{neo4j → active_graph}/shared/marshal.rb +1 -1
- data/lib/{neo4j → active_graph}/shared/mass_assignment.rb +2 -2
- data/lib/{neo4j → active_graph}/shared/permitted_attributes.rb +1 -1
- data/lib/{neo4j → active_graph}/shared/persistence.rb +4 -4
- data/lib/{neo4j → active_graph}/shared/property.rb +10 -10
- data/lib/{neo4j → active_graph}/shared/query_factory.rb +5 -5
- data/lib/{neo4j → active_graph}/shared/rel_type_converters.rb +6 -6
- data/lib/{neo4j → active_graph}/shared/serialized_properties.rb +1 -1
- data/lib/{neo4j → active_graph}/shared/type_converters.rb +11 -13
- data/lib/{neo4j → active_graph}/shared/typecasted_attributes.rb +7 -7
- data/lib/{neo4j → active_graph}/shared/typecaster.rb +3 -3
- data/lib/{neo4j → active_graph}/shared/validations.rb +1 -1
- data/lib/{neo4j → active_graph}/tasks/migration.rake +25 -25
- data/lib/{neo4j → active_graph}/timestamps.rb +3 -3
- data/lib/{neo4j → active_graph}/timestamps/created.rb +1 -1
- data/lib/{neo4j → active_graph}/timestamps/updated.rb +1 -1
- data/lib/{neo4j → active_graph}/transaction.rb +9 -9
- data/lib/active_graph/transactions.rb +54 -0
- data/lib/{neo4j → active_graph}/type_converters.rb +2 -2
- data/lib/{neo4j → active_graph}/undeclared_properties.rb +1 -1
- data/lib/active_graph/version.rb +3 -0
- data/lib/{neo4j → active_graph}/wrapper.rb +1 -1
- data/lib/rails/generators/neo4j/migration/migration_generator.rb +4 -4
- data/lib/rails/generators/neo4j/migration/templates/migration.erb +2 -2
- data/lib/rails/generators/neo4j/model/model_generator.rb +4 -4
- data/lib/rails/generators/neo4j/model/templates/migration.erb +1 -1
- data/lib/rails/generators/neo4j/model/templates/model.erb +1 -1
- data/lib/rails/generators/neo4j/upgrade_v8/templates/migration.erb +1 -1
- data/lib/rails/generators/neo4j/upgrade_v8/upgrade_v8_generator.rb +6 -6
- data/lib/rails/generators/neo4j_generator.rb +4 -4
- metadata +134 -133
- data/lib/neo4j.rb +0 -119
- data/lib/neo4j/active_rel/callbacks.rb +0 -21
- data/lib/neo4j/active_rel/validations.rb +0 -8
- data/lib/neo4j/core.rb +0 -14
- data/lib/neo4j/version.rb +0 -3
@@ -1,18 +1,18 @@
|
|
1
|
-
require '
|
1
|
+
require 'active_graph/core/relationship'
|
2
2
|
|
3
3
|
wrapping_proc = proc do |relationship|
|
4
|
-
|
4
|
+
ActiveGraph::RelWrapping.wrapper(relationship)
|
5
5
|
end
|
6
6
|
Neo4j::Driver::Types::Relationship.wrapper_callback(wrapping_proc)
|
7
7
|
|
8
|
-
module
|
8
|
+
module ActiveGraph
|
9
9
|
module RelWrapping
|
10
10
|
class << self
|
11
11
|
def wrapper(rel)
|
12
12
|
rel.props.symbolize_keys!
|
13
13
|
begin
|
14
14
|
most_concrete_class = class_from_type(rel.rel_type).constantize
|
15
|
-
return rel unless most_concrete_class <
|
15
|
+
return rel unless most_concrete_class < ActiveGraph::Relationship
|
16
16
|
most_concrete_class.new
|
17
17
|
rescue NameError => e
|
18
18
|
raise e unless e.message =~ /(uninitialized|wrong) constant/
|
@@ -24,7 +24,7 @@ module Neo4j
|
|
24
24
|
end
|
25
25
|
|
26
26
|
def class_from_type(rel_type)
|
27
|
-
|
27
|
+
ActiveGraph::Relationship::Types::WRAPPED_CLASSES[rel_type] || ActiveGraph::Relationship::Types::WRAPPED_CLASSES[rel_type] = rel_type.to_s.downcase.camelize
|
28
28
|
end
|
29
29
|
end
|
30
30
|
end
|
@@ -1,18 +1,18 @@
|
|
1
|
-
module
|
2
|
-
# A container for
|
1
|
+
module ActiveGraph::Relationship
|
2
|
+
# A container for Relationship's :inbound and :outbound methods. It provides lazy loading of nodes.
|
3
3
|
# It's important (or maybe not really IMPORTANT, but at least worth mentioning) that calling method_missing
|
4
4
|
# will result in a query to load the node if the node is not already loaded.
|
5
5
|
class RelatedNode
|
6
|
-
class UnsetRelatedNodeError <
|
6
|
+
class UnsetRelatedNodeError < ActiveGraph::Error; end
|
7
7
|
|
8
|
-
#
|
8
|
+
# Relationship's related nodes can be initialized with nothing, an integer, or a fully wrapped node.
|
9
9
|
#
|
10
|
-
# Initialization with nothing happens when a new, non-persisted
|
10
|
+
# Initialization with nothing happens when a new, non-persisted Relationship object is first initialized.
|
11
11
|
#
|
12
12
|
# Initialization with an integer happens when a relationship is loaded from the database. It loads using the ID
|
13
13
|
# because that is provided by the Cypher response and does not require an extra query.
|
14
14
|
def initialize(node = nil)
|
15
|
-
@node = valid_node_param?(node) ? node : (fail
|
15
|
+
@node = valid_node_param?(node) ? node : (fail ActiveGraph::InvalidParameterError, 'RelatedNode must be initialized with either a node ID or node')
|
16
16
|
end
|
17
17
|
|
18
18
|
# Loads the node if needed, then conducts comparison.
|
@@ -32,7 +32,7 @@ module Neo4j::ActiveRel
|
|
32
32
|
@node = if @node.respond_to?(:neo_id)
|
33
33
|
@node
|
34
34
|
else
|
35
|
-
|
35
|
+
ActiveGraph::Base.new_query.match(:n).where(n: {neo_id: @node}).pluck(:n).first
|
36
36
|
end
|
37
37
|
end
|
38
38
|
|
@@ -1,10 +1,10 @@
|
|
1
|
-
module
|
2
|
-
module
|
1
|
+
module ActiveGraph
|
2
|
+
module Relationship
|
3
3
|
# provides mapping of type to model name
|
4
4
|
module Types
|
5
5
|
extend ActiveSupport::Concern
|
6
6
|
|
7
|
-
# WRAPPED_CLASSES maps relationship types to
|
7
|
+
# WRAPPED_CLASSES maps relationship types to Relationship models.
|
8
8
|
#
|
9
9
|
# Typically, it's a 1:1 relationship, with a type having a model of the same name. Sometimes, someone needs to be a precious
|
10
10
|
# snowflake and have a model name that doesn't match the rel type, so this comes in handy.
|
@@ -22,7 +22,7 @@ module Neo4j
|
|
22
22
|
end
|
23
23
|
|
24
24
|
module ClassMethods
|
25
|
-
include
|
25
|
+
include ActiveGraph::Shared::RelTypeConverters
|
26
26
|
|
27
27
|
def inherited(subclass)
|
28
28
|
subclass.type subclass.namespaced_model_name, true
|
@@ -46,11 +46,11 @@ module Neo4j
|
|
46
46
|
alias _type type # should be deprecated
|
47
47
|
|
48
48
|
def namespaced_model_name
|
49
|
-
case
|
49
|
+
case ActiveGraph::Config[:module_handling]
|
50
50
|
when :demodulize
|
51
51
|
self.name.demodulize
|
52
52
|
when Proc
|
53
|
-
|
53
|
+
ActiveGraph::Config[:module_handling].call(self.name)
|
54
54
|
else
|
55
55
|
self.name
|
56
56
|
end
|
@@ -1,13 +1,13 @@
|
|
1
|
-
module
|
1
|
+
module ActiveGraph
|
2
2
|
module Schema
|
3
3
|
class Operation
|
4
4
|
attr_reader :label, :property, :options
|
5
5
|
|
6
6
|
def initialize(label, property, options = default_options)
|
7
|
-
@label = if label.is_a?(
|
7
|
+
@label = if label.is_a?(ActiveGraph::Core::Label)
|
8
8
|
label
|
9
9
|
else
|
10
|
-
|
10
|
+
ActiveGraph::Core::Label.new(label)
|
11
11
|
end
|
12
12
|
|
13
13
|
@property = property.to_sym
|
@@ -62,7 +62,7 @@ module Neo4j
|
|
62
62
|
end
|
63
63
|
end
|
64
64
|
|
65
|
-
class ExactIndexOperation <
|
65
|
+
class ExactIndexOperation < ActiveGraph::Schema::Operation
|
66
66
|
def self.incompatible_operation_classes
|
67
67
|
[UniqueConstraintOperation]
|
68
68
|
end
|
@@ -76,7 +76,7 @@ module Neo4j
|
|
76
76
|
end
|
77
77
|
end
|
78
78
|
|
79
|
-
class UniqueConstraintOperation <
|
79
|
+
class UniqueConstraintOperation < ActiveGraph::Schema::Operation
|
80
80
|
def self.incompatible_operation_classes
|
81
81
|
[ExactIndexOperation]
|
82
82
|
end
|
@@ -1,4 +1,4 @@
|
|
1
|
-
module
|
1
|
+
module ActiveGraph
|
2
2
|
module Shared
|
3
3
|
extend ActiveSupport::Concern
|
4
4
|
extend ActiveModel::Naming
|
@@ -14,28 +14,28 @@ module Neo4j
|
|
14
14
|
|
15
15
|
# remove?
|
16
16
|
def neo4j_driver
|
17
|
-
|
17
|
+
ActiveGraph::Base.current_driver
|
18
18
|
end
|
19
19
|
|
20
20
|
# remove?
|
21
21
|
def current_transaction
|
22
|
-
|
22
|
+
ActiveGraph::Base.current_transaction
|
23
23
|
end
|
24
24
|
|
25
25
|
# This should be used everywhere. Should make it easy
|
26
26
|
# to support a driver-per-model system
|
27
27
|
def neo4j_query(*args)
|
28
|
-
|
28
|
+
ActiveGraph::Base.query(*args)
|
29
29
|
end
|
30
30
|
|
31
31
|
def new_query
|
32
|
-
|
32
|
+
ActiveGraph::Base.new_query
|
33
33
|
end
|
34
34
|
end
|
35
35
|
|
36
36
|
included do
|
37
|
-
self.include_root_in_json =
|
38
|
-
@_declared_properties ||=
|
37
|
+
self.include_root_in_json = ActiveGraph::Config.include_root_in_json
|
38
|
+
@_declared_properties ||= ActiveGraph::Shared::DeclaredProperties.new(self)
|
39
39
|
|
40
40
|
def self.i18n_scope
|
41
41
|
:neo4j
|
@@ -1,10 +1,10 @@
|
|
1
|
-
module
|
1
|
+
module ActiveGraph::Shared
|
2
2
|
# Attributes provides a set of class methods for defining an attributes
|
3
3
|
# schema and instance methods for reading and writing attributes.
|
4
4
|
#
|
5
5
|
# @example Usage
|
6
6
|
# class Person
|
7
|
-
# include
|
7
|
+
# include ActiveGraph::Shared::Attributes
|
8
8
|
# attribute :name
|
9
9
|
# end
|
10
10
|
#
|
@@ -61,14 +61,14 @@ module Neo4j::Shared
|
|
61
61
|
#
|
62
62
|
# @raise [UnknownAttributeError] if the attribute is unknown
|
63
63
|
def write_attribute(name, value)
|
64
|
-
fail
|
64
|
+
fail ActiveGraph::UnknownAttributeError, "unknown attribute: #{name}" if !respond_to? "#{name}="
|
65
65
|
|
66
66
|
send "#{name}=", value
|
67
67
|
end
|
68
68
|
alias []= write_attribute
|
69
69
|
|
70
70
|
def query_attribute(name)
|
71
|
-
fail
|
71
|
+
fail ActiveGraph::UnknownAttributeError, "unknown attribute: #{name}" if !respond_to? "#{name}?"
|
72
72
|
|
73
73
|
send "#{name}?"
|
74
74
|
end
|
@@ -77,13 +77,13 @@ module Neo4j::Shared
|
|
77
77
|
|
78
78
|
# Read an attribute from the attributes hash
|
79
79
|
def attribute(name)
|
80
|
-
@attributes ||=
|
80
|
+
@attributes ||= ActiveGraph::AttributeSet.new({}, self.class.attributes.keys)
|
81
81
|
@attributes.fetch_value(name.to_s)
|
82
82
|
end
|
83
83
|
|
84
84
|
# Write an attribute to the attributes hash
|
85
85
|
def attribute=(name, value)
|
86
|
-
@attributes ||=
|
86
|
+
@attributes ||= ActiveGraph::AttributeSet.new({}, self.class.attributes.keys)
|
87
87
|
@attributes.write_cast_value(name, value)
|
88
88
|
value
|
89
89
|
end
|
@@ -102,7 +102,7 @@ module Neo4j::Shared
|
|
102
102
|
end
|
103
103
|
|
104
104
|
def attribute?(name)
|
105
|
-
|
105
|
+
ActiveGraph::Shared::TypeConverters::BooleanConverter.to_ruby(read_attribute(name))
|
106
106
|
end
|
107
107
|
|
108
108
|
module ClassMethods
|
@@ -123,7 +123,7 @@ module Neo4j::Shared
|
|
123
123
|
#
|
124
124
|
# @return [AttributeDefinition] Attribute's definition
|
125
125
|
def attribute(name)
|
126
|
-
fail
|
126
|
+
fail ActiveGraph::DangerousAttributeError, %(an attribute method named "#{name}" would conflict with an existing method) if dangerous_attribute?(name)
|
127
127
|
|
128
128
|
attribute!(name)
|
129
129
|
end
|
@@ -143,7 +143,7 @@ module Neo4j::Shared
|
|
143
143
|
# @example Get attribute definitions
|
144
144
|
# Person.attributes
|
145
145
|
#
|
146
|
-
# @return [ActiveSupport::HashWithIndifferentAccess{String =>
|
146
|
+
# @return [ActiveSupport::HashWithIndifferentAccess{String => ActiveGraph::Shared::AttributeDefinition}]
|
147
147
|
# The Hash of AttributeDefinition instances
|
148
148
|
def attributes
|
149
149
|
@attributes ||= ActiveSupport::HashWithIndifferentAccess.new
|
@@ -189,7 +189,7 @@ module Neo4j::Shared
|
|
189
189
|
|
190
190
|
# Assign a set of attribute definitions, used when subclassing models
|
191
191
|
#
|
192
|
-
# @param [Array<
|
192
|
+
# @param [Array<ActiveGraph::Shared::DeclaredProperties>] The Array of
|
193
193
|
# AttributeDefinition instances
|
194
194
|
def attributes=(attributes)
|
195
195
|
@attributes = attributes
|
@@ -1,4 +1,4 @@
|
|
1
|
-
module
|
1
|
+
module ActiveGraph
|
2
2
|
module Shared
|
3
3
|
module Callbacks #:nodoc:
|
4
4
|
extend ActiveSupport::Concern
|
@@ -9,7 +9,7 @@ module Neo4j
|
|
9
9
|
|
10
10
|
included do
|
11
11
|
include ActiveModel::Validations::Callbacks
|
12
|
-
# after_find is triggered by the `find` method defined in lib/neo4j/
|
12
|
+
# after_find is triggered by the `find` method defined in lib/neo4j/node/id_property.rb
|
13
13
|
define_model_callbacks :initialize, :find, only: :after
|
14
14
|
define_model_callbacks :create_commit, :update_commit, :destroy_commit, only: :after
|
15
15
|
define_model_callbacks :save, :create, :update, :destroy, :touch
|
@@ -20,7 +20,7 @@ module Neo4j
|
|
20
20
|
end
|
21
21
|
|
22
22
|
def destroy #:nodoc:
|
23
|
-
tx =
|
23
|
+
tx = ActiveGraph::Base.new_transaction
|
24
24
|
tx.root.after_commit { run_callbacks(:destroy_commit) {} }
|
25
25
|
run_callbacks(:destroy) { super }
|
26
26
|
rescue
|
@@ -1,17 +1,17 @@
|
|
1
|
-
module
|
1
|
+
module ActiveGraph::Shared
|
2
2
|
# The DeclaredPropertyuManager holds details about objects created as a result of calling the #property
|
3
|
-
# class method on a class that includes
|
3
|
+
# class method on a class that includes ActiveGraph::Node or ActiveGraph::Relationship. There are many options
|
4
4
|
# that are referenced frequently, particularly during load and save, so this provides easy access and
|
5
5
|
# a way of separating behavior from the general Active{obj} modules.
|
6
6
|
#
|
7
|
-
# See
|
7
|
+
# See ActiveGraph::Shared::DeclaredProperty for definitions of the property objects themselves.
|
8
8
|
class DeclaredProperties
|
9
|
-
include
|
9
|
+
include ActiveGraph::Shared::TypeConverters
|
10
10
|
|
11
11
|
attr_reader :klass
|
12
12
|
delegate :each, :each_pair, :each_key, :each_value, to: :registered_properties
|
13
13
|
|
14
|
-
# Each class that includes
|
14
|
+
# Each class that includes ActiveGraph::Node or ActiveGraph::Relationship gets one instance of this class.
|
15
15
|
# @param [#declared_properties] klass An object that has the #declared_properties method.
|
16
16
|
def initialize(klass)
|
17
17
|
@klass = klass
|
@@ -25,8 +25,8 @@ module Neo4j::Shared
|
|
25
25
|
registered_properties.key?(key.to_sym)
|
26
26
|
end
|
27
27
|
|
28
|
-
# @param [
|
29
|
-
# #property on an
|
28
|
+
# @param [ActiveGraph::Shared::DeclaredProperty] property An instance of DeclaredProperty, created as the result of calling
|
29
|
+
# #property on an Node or Relationship class. The DeclaredProperty has specifics about the property, but registration
|
30
30
|
# makes the management object aware of it. This is necessary for type conversion, defaults, and inclusion in the nil and string hashes.
|
31
31
|
def register(property)
|
32
32
|
@_attributes_nil_hash = nil
|
@@ -48,7 +48,7 @@ module Neo4j::Shared
|
|
48
48
|
registered_properties[key].constraint!(type)
|
49
49
|
end
|
50
50
|
|
51
|
-
# The :default option in
|
51
|
+
# The :default option in ActiveGraph::Node#property class method allows for setting a default value instead of
|
52
52
|
# nil on declared properties. This holds those values.
|
53
53
|
def declared_property_defaults
|
54
54
|
@_default_property_values ||= {}
|
@@ -1,10 +1,10 @@
|
|
1
|
-
module
|
1
|
+
module ActiveGraph::Shared
|
2
2
|
# Contains methods related to the management
|
3
3
|
class DeclaredProperty
|
4
4
|
include Comparable
|
5
5
|
|
6
|
-
class IllegalPropertyError <
|
7
|
-
include
|
6
|
+
class IllegalPropertyError < ActiveGraph::Error; end
|
7
|
+
include ActiveGraph::Shared::DeclaredProperty::Index
|
8
8
|
|
9
9
|
ILLEGAL_PROPS = %w(from_node to_node start_node end_node)
|
10
10
|
attr_reader :name, :name_string, :name_sym, :options, :magic_typecaster, :type, :typecaster, :default_value
|
@@ -27,7 +27,7 @@ module Neo4j::Shared
|
|
27
27
|
# @example
|
28
28
|
# attribute_definition <=> other
|
29
29
|
#
|
30
|
-
# @param [
|
30
|
+
# @param [ActiveGraph::Shared::DeclaredProperty, Object] other The other
|
31
31
|
# attribute definition to compare with.
|
32
32
|
#
|
33
33
|
# @return [-1, 0, 1, nil]
|
@@ -62,7 +62,7 @@ module Neo4j::Shared
|
|
62
62
|
def fail_invalid_options!
|
63
63
|
case
|
64
64
|
when index?(:exact) && constraint?(:unique)
|
65
|
-
fail
|
65
|
+
fail ActiveGraph::InvalidPropertyOptionsError,
|
66
66
|
"#Uniqueness constraints also provide exact indexes, cannot set both options on property #{name}"
|
67
67
|
end
|
68
68
|
end
|
@@ -80,7 +80,7 @@ module Neo4j::Shared
|
|
80
80
|
|
81
81
|
# Tweaks properties
|
82
82
|
def register_magic_properties
|
83
|
-
@type ||=
|
83
|
+
@type ||= ActiveGraph::Config.timestamp_type if timestamp_prop?
|
84
84
|
|
85
85
|
register_magic_typecaster
|
86
86
|
register_type_converter
|
@@ -91,7 +91,7 @@ module Neo4j::Shared
|
|
91
91
|
end
|
92
92
|
|
93
93
|
def register_magic_typecaster
|
94
|
-
found_typecaster =
|
94
|
+
found_typecaster = ActiveGraph::Shared::TypeConverters.typecaster_for(type)
|
95
95
|
return unless found_typecaster && found_typecaster.respond_to?(:primitive_type)
|
96
96
|
@typecaster = found_typecaster
|
97
97
|
@magic_typecaster = type
|
@@ -102,8 +102,8 @@ module Neo4j::Shared
|
|
102
102
|
converter = options[:serializer]
|
103
103
|
return unless converter
|
104
104
|
@type = converter.convert_type
|
105
|
-
@typecaster =
|
106
|
-
|
105
|
+
@typecaster = ActiveGraph::Shared::TypeConverters::ObjectConverter
|
106
|
+
ActiveGraph::Shared::TypeConverters.register_converter(converter)
|
107
107
|
end
|
108
108
|
end
|
109
109
|
end
|
@@ -1,4 +1,4 @@
|
|
1
|
-
module
|
1
|
+
module ActiveGraph::Shared
|
2
2
|
class DeclaredProperty
|
3
3
|
# None of these methods interact with the database. They only keep track of property settings in models.
|
4
4
|
# It could (should?) handle the actual indexing/constraining, but that's TBD.
|
@@ -16,12 +16,12 @@ module Neo4j::Shared
|
|
16
16
|
end
|
17
17
|
|
18
18
|
def index!(type = :exact)
|
19
|
-
fail
|
19
|
+
fail ActiveGraph::InvalidPropertyOptionsError, "Can't set index on constrainted property #{name} (constraints get indexes automatically)" if constraint?(:unique)
|
20
20
|
options[:index] = type
|
21
21
|
end
|
22
22
|
|
23
23
|
def constraint!(type = :unique)
|
24
|
-
fail
|
24
|
+
fail ActiveGraph::InvalidPropertyOptionsError, "Can't set constraint on indexed property #{name} (constraints get indexes automatically)" if index?(:exact)
|
25
25
|
options[:constraint] = type
|
26
26
|
end
|
27
27
|
|
@@ -1,9 +1,9 @@
|
|
1
|
-
module
|
1
|
+
module ActiveGraph::Shared
|
2
2
|
module Enum
|
3
3
|
extend ActiveSupport::Concern
|
4
4
|
|
5
|
-
class ConflictingEnumMethodError <
|
6
|
-
class InvalidEnumValueError <
|
5
|
+
class ConflictingEnumMethodError < ActiveGraph::Error; end
|
6
|
+
class InvalidEnumValueError < ActiveGraph::InvalidParameterError; end
|
7
7
|
|
8
8
|
module ClassMethods
|
9
9
|
attr_reader :neo4j_enum_data
|
@@ -13,7 +13,7 @@ module Neo4j::Shared
|
|
13
13
|
#
|
14
14
|
# @example Base example
|
15
15
|
# class Media
|
16
|
-
# include
|
16
|
+
# include ActiveGraph::Node
|
17
17
|
# enum type: [:image, :video, :unknown]
|
18
18
|
# end
|
19
19
|
# Media.types # => { :images => 0, :video => 1, :unknown => 2 }
|
@@ -55,7 +55,7 @@ module Neo4j::Shared
|
|
55
55
|
protected
|
56
56
|
|
57
57
|
def normalize_key_list(enum_keys, options)
|
58
|
-
case_sensitive = options.fetch(:_case_sensitive,
|
58
|
+
case_sensitive = options.fetch(:_case_sensitive, ActiveGraph::Config.enums_case_sensitive)
|
59
59
|
|
60
60
|
case enum_keys
|
61
61
|
when Hash
|
@@ -92,7 +92,7 @@ module Neo4j::Shared
|
|
92
92
|
|
93
93
|
def define_property(property_name, enum_keys, options)
|
94
94
|
property property_name, build_property_options(enum_keys, options)
|
95
|
-
serialize property_name,
|
95
|
+
serialize property_name, ActiveGraph::Shared::TypeConverters::EnumConverter.new(enum_keys, build_enum_options(enum_keys, options))
|
96
96
|
|
97
97
|
# If class has already been inherited, make sure subclasses fully inherit enum
|
98
98
|
subclasses.each do |klass|
|