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,6 +1,6 @@
|
|
1
|
-
module
|
1
|
+
module ActiveGraph::Shared
|
2
2
|
class FilteredHash
|
3
|
-
class InvalidHashFilterType <
|
3
|
+
class InvalidHashFilterType < ActiveGraph::Error; end
|
4
4
|
VALID_SYMBOL_INSTRUCTIONS = [:all, :none]
|
5
5
|
VALID_HASH_INSTRUCTIONS = [:on]
|
6
6
|
VALID_INSTRUCTIONS_TYPES = [Hash, Symbol]
|
@@ -1,4 +1,4 @@
|
|
1
|
-
module
|
1
|
+
module ActiveGraph
|
2
2
|
module Shared
|
3
3
|
module Identity
|
4
4
|
def ==(other)
|
@@ -21,7 +21,7 @@ module Neo4j
|
|
21
21
|
if self.class.id_property_name
|
22
22
|
send(self.class.id_property_name)
|
23
23
|
else
|
24
|
-
#
|
24
|
+
# Relationship
|
25
25
|
neo_id
|
26
26
|
end
|
27
27
|
end
|
@@ -1,8 +1,8 @@
|
|
1
|
-
module
|
1
|
+
module ActiveGraph::Shared
|
2
2
|
module Initialize
|
3
3
|
extend ActiveSupport::Concern
|
4
4
|
|
5
|
-
# Implements the
|
5
|
+
# Implements the ActiveGraph::Node#wrapper and ActiveGraph::Relationship#wrapper method
|
6
6
|
# so that we don't have to care if the node is wrapped or not.
|
7
7
|
# @return self
|
8
8
|
def wrapper
|
@@ -12,7 +12,7 @@ module Neo4j::Shared
|
|
12
12
|
private
|
13
13
|
|
14
14
|
def convert_and_assign_attributes(properties)
|
15
|
-
@attributes ||=
|
15
|
+
@attributes ||= ActiveGraph::AttributeSet.new(self.class.attributes_nil_hash, self.class.attributes.keys)
|
16
16
|
stringify_attributes!(@attributes, properties)
|
17
17
|
self.default_properties = properties if respond_to?(:default_properties=)
|
18
18
|
self.class.declared_properties.convert_properties_to(self, :ruby, @attributes)
|
@@ -1,4 +1,4 @@
|
|
1
|
-
module
|
1
|
+
module ActiveGraph::Shared
|
2
2
|
# MassAssignment allows you to bulk set and update attributes
|
3
3
|
#
|
4
4
|
# Including MassAssignment into your model gives it a set of mass assignment
|
@@ -6,7 +6,7 @@ module Neo4j::Shared
|
|
6
6
|
#
|
7
7
|
# @example Usage
|
8
8
|
# class Person
|
9
|
-
# include
|
9
|
+
# include ActiveGraph::Shared::MassAssignment
|
10
10
|
# end
|
11
11
|
#
|
12
12
|
# Originally part of ActiveAttr, https://github.com/cgriego/active_attr
|
@@ -1,4 +1,4 @@
|
|
1
|
-
module
|
1
|
+
module ActiveGraph::Shared
|
2
2
|
# rubocop:disable Metrics/ModuleLength
|
3
3
|
module Persistence
|
4
4
|
# rubocop:enable Metrics/ModuleLength
|
@@ -89,7 +89,7 @@ module Neo4j::Shared
|
|
89
89
|
@_create_or_updating = true
|
90
90
|
apply_default_values
|
91
91
|
result = _persisted_obj ? update_model : create_model
|
92
|
-
current_transaction =
|
92
|
+
current_transaction = ActiveGraph::Base.current_transaction
|
93
93
|
|
94
94
|
current_transaction.mark_failed if result == false && current_transaction
|
95
95
|
|
@@ -196,7 +196,7 @@ module Neo4j::Shared
|
|
196
196
|
alias update_column update_db_property
|
197
197
|
|
198
198
|
def update_db_properties(hash)
|
199
|
-
fail ::
|
199
|
+
fail ::ActiveGraph::Error, 'can not update on a new record object' unless persisted?
|
200
200
|
self.class.run_transaction do
|
201
201
|
db_values = props_for_db(hash)
|
202
202
|
neo4j_query(query_as(:n).set(n: db_values))
|
@@ -229,7 +229,7 @@ module Neo4j::Shared
|
|
229
229
|
|
230
230
|
module ClassMethods
|
231
231
|
def run_transaction(run_in_tx = true)
|
232
|
-
|
232
|
+
ActiveGraph::Base.run_transaction(run_in_tx) { |tx| yield tx }
|
233
233
|
end
|
234
234
|
end
|
235
235
|
|
@@ -1,13 +1,13 @@
|
|
1
|
-
module
|
1
|
+
module ActiveGraph::Shared
|
2
2
|
module Property
|
3
3
|
extend ActiveSupport::Concern
|
4
4
|
|
5
|
-
include
|
6
|
-
include
|
5
|
+
include ActiveGraph::Shared::MassAssignment
|
6
|
+
include ActiveGraph::Shared::TypecastedAttributes
|
7
7
|
include ActiveModel::Dirty
|
8
8
|
|
9
|
-
class UndefinedPropertyError <
|
10
|
-
class MultiparameterAssignmentError <
|
9
|
+
class UndefinedPropertyError < ActiveGraph::Error; end
|
10
|
+
class MultiparameterAssignmentError < ActiveGraph::Error; end
|
11
11
|
|
12
12
|
attr_reader :_persisted_obj
|
13
13
|
|
@@ -24,15 +24,15 @@ module Neo4j::Shared
|
|
24
24
|
|
25
25
|
def inspect
|
26
26
|
attribute_descriptions = inspect_attributes.map do |key, value|
|
27
|
-
"#{
|
27
|
+
"#{ActiveGraph::ANSI::CYAN}#{key}: #{ActiveGraph::ANSI::CLEAR}#{value.inspect}"
|
28
28
|
end.join(', ')
|
29
29
|
|
30
30
|
separator = ' ' unless attribute_descriptions.empty?
|
31
|
-
"#<#{
|
31
|
+
"#<#{ActiveGraph::ANSI::YELLOW}#{self.class.name}#{ActiveGraph::ANSI::CLEAR}#{separator}#{attribute_descriptions}>"
|
32
32
|
end
|
33
33
|
|
34
34
|
def initialize(attributes = nil)
|
35
|
-
@attributes ||=
|
35
|
+
@attributes ||= ActiveGraph::AttributeSet.new({}, self.class.attributes.keys)
|
36
36
|
attributes = process_attributes(attributes)
|
37
37
|
modded_attributes = inject_defaults!(attributes)
|
38
38
|
validate_attributes!(modded_attributes)
|
@@ -79,7 +79,7 @@ module Neo4j::Shared
|
|
79
79
|
def extract_writer_methods!(attributes)
|
80
80
|
return attributes if attributes.blank?
|
81
81
|
{}.tap do |writer_method_props|
|
82
|
-
attributes.
|
82
|
+
attributes.keys.each do |key|
|
83
83
|
writer_method_props[key] = attributes.delete(key) if self.respond_to?("#{key}=")
|
84
84
|
end
|
85
85
|
end
|
@@ -166,7 +166,7 @@ module Neo4j::Shared
|
|
166
166
|
end
|
167
167
|
|
168
168
|
# @param [Symbol] name The property name
|
169
|
-
# @param [
|
169
|
+
# @param [ActiveGraph::Shared::AttributeDefinition] attr_def A cloned AttributeDefinition to reuse
|
170
170
|
# @param [Hash] options An options hash to use in the new property definition
|
171
171
|
def inherit_property(name, attr_def, options = {})
|
172
172
|
build_property(name, options) do |prop_name|
|
@@ -1,5 +1,5 @@
|
|
1
|
-
module
|
2
|
-
# Acts as a bridge between the node and rel models and
|
1
|
+
module ActiveGraph::Shared
|
2
|
+
# Acts as a bridge between the node and rel models and ActiveGraph::Core::Query.
|
3
3
|
# If the object is persisted, it returns a query matching; otherwise, it returns a query creating it.
|
4
4
|
# This class does not execute queries, so it keeps no record of what identifiers have been set or what has happened in previous factories.
|
5
5
|
class QueryFactory
|
@@ -29,14 +29,14 @@ module Neo4j::Shared
|
|
29
29
|
graph_object.persisted? ? match_query : create_query
|
30
30
|
end
|
31
31
|
|
32
|
-
# @param [
|
32
|
+
# @param [ActiveGraph::Core::Query] query An instance of ActiveGraph::Core::Query upon which methods will be chained.
|
33
33
|
def base_query=(query)
|
34
34
|
return if query.blank?
|
35
35
|
@base_query = query
|
36
36
|
end
|
37
37
|
|
38
38
|
def base_query
|
39
|
-
@base_query ||
|
39
|
+
@base_query || ActiveGraph::Base.new_query
|
40
40
|
end
|
41
41
|
|
42
42
|
protected
|
@@ -92,7 +92,7 @@ module Neo4j::Shared
|
|
92
92
|
private
|
93
93
|
|
94
94
|
def filtered_props
|
95
|
-
|
95
|
+
ActiveGraph::Shared::FilteredHash.new(graph_object.props_for_create, graph_object.creates_unique_option).filtered_base
|
96
96
|
end
|
97
97
|
|
98
98
|
def query_string(create_props)
|
@@ -1,14 +1,14 @@
|
|
1
|
-
module
|
2
|
-
# This module controls changes to relationship type based on
|
3
|
-
# It's used whenever a rel type is automatically determined based on
|
1
|
+
module ActiveGraph::Shared
|
2
|
+
# This module controls changes to relationship type based on ActiveGraph::Config.transform_rel_type.
|
3
|
+
# It's used whenever a rel type is automatically determined based on Relationship model name or
|
4
4
|
# association type.
|
5
5
|
module RelTypeConverters
|
6
6
|
def decorated_rel_type(type)
|
7
|
-
@decorated_rel_type ||=
|
7
|
+
@decorated_rel_type ||= ActiveGraph::Shared::RelTypeConverters.decorated_rel_type(type)
|
8
8
|
end
|
9
9
|
|
10
10
|
class << self
|
11
|
-
# Determines how relationship types should look when inferred based on association or
|
11
|
+
# Determines how relationship types should look when inferred based on association or Relationship model name.
|
12
12
|
# With the exception of `:none`, all options will call `underscore`, so `ThisClass` becomes `this_class`, with capitalization
|
13
13
|
# determined by the specific option passed.
|
14
14
|
# Valid options:
|
@@ -17,7 +17,7 @@ module Neo4j::Shared
|
|
17
17
|
# * :legacy - downcases and prepends `#`, so ThisClass becomes `#this_class`
|
18
18
|
# * :none - uses the string version of whatever is passed with no modifications
|
19
19
|
def rel_transformer
|
20
|
-
@rel_transformer ||=
|
20
|
+
@rel_transformer ||= ActiveGraph::Config[:transform_rel_type].nil? ? :upcase : ActiveGraph::Config[:transform_rel_type]
|
21
21
|
end
|
22
22
|
|
23
23
|
# @param [String,Symbol] type The raw string or symbol to be used as the basis of the relationship type
|
@@ -1,4 +1,4 @@
|
|
1
|
-
module
|
1
|
+
module ActiveGraph::Shared
|
2
2
|
# This module adds the `serialize` class method. It lets you store hashes and arrays in Neo4j properties.
|
3
3
|
# Be aware that you won't be able to search within serialized properties and stuff use indexes. If you do a regex search for portion of a string
|
4
4
|
# property, the search happens in Cypher and you may take a performance hit.
|
@@ -4,7 +4,7 @@ require 'bigdecimal/util'
|
|
4
4
|
require 'active_support/core_ext/big_decimal/conversions'
|
5
5
|
require 'active_support/core_ext/string/conversions'
|
6
6
|
|
7
|
-
module
|
7
|
+
module ActiveGraph::Shared
|
8
8
|
class Boolean; end
|
9
9
|
|
10
10
|
module TypeConverters
|
@@ -100,8 +100,6 @@ module Neo4j::Shared
|
|
100
100
|
|
101
101
|
def to_ruby(value)
|
102
102
|
value.respond_to?(:to_date) ? value.to_date : Time.at(value).utc.to_date
|
103
|
-
rescue Exception => e
|
104
|
-
raise e
|
105
103
|
end
|
106
104
|
|
107
105
|
alias to_db to_ruby
|
@@ -179,7 +177,7 @@ module Neo4j::Shared
|
|
179
177
|
end
|
180
178
|
|
181
179
|
def db_type
|
182
|
-
|
180
|
+
ActiveGraph::Shared::Boolean
|
183
181
|
end
|
184
182
|
|
185
183
|
alias convert_type db_type
|
@@ -253,7 +251,7 @@ module Neo4j::Shared
|
|
253
251
|
|
254
252
|
return unless @options[:case_sensitive].nil?
|
255
253
|
|
256
|
-
@options[:case_sensitive] =
|
254
|
+
@options[:case_sensitive] = ActiveGraph::Config.enums_case_sensitive
|
257
255
|
end
|
258
256
|
|
259
257
|
def converted?(value)
|
@@ -283,10 +281,10 @@ module Neo4j::Shared
|
|
283
281
|
value.map(&method(:to_db))
|
284
282
|
elsif @options[:case_sensitive]
|
285
283
|
@enum_keys[value.to_s.to_sym] ||
|
286
|
-
fail(
|
284
|
+
fail(ActiveGraph::Shared::Enum::InvalidEnumValueError, 'Value passed to an enum property must match one of the enum keys')
|
287
285
|
else
|
288
286
|
@enum_keys[value.to_s.downcase.to_sym] ||
|
289
|
-
fail(
|
287
|
+
fail(ActiveGraph::Shared::Enum::InvalidEnumValueError, 'Case-insensitive (downcased) value passed to an enum property must match one of the enum keys')
|
290
288
|
end
|
291
289
|
end
|
292
290
|
end
|
@@ -304,7 +302,7 @@ module Neo4j::Shared
|
|
304
302
|
end
|
305
303
|
|
306
304
|
# Modifies a hash's values to be of types acceptable to Neo4j or matching what the user defined using `type` in property definitions.
|
307
|
-
# @param [
|
305
|
+
# @param [ActiveGraph::Shared::Property] obj A node or rel that mixes in the Property module
|
308
306
|
# @param [Symbol] medium Indicates the type of conversion to perform.
|
309
307
|
# @param [Hash] properties A hash of symbol-keyed properties for conversion.
|
310
308
|
def convert_properties_to(obj, medium, properties)
|
@@ -313,7 +311,7 @@ module Neo4j::Shared
|
|
313
311
|
next if skip_conversion?(obj, key, value)
|
314
312
|
|
315
313
|
converted_value = convert_property(key, value, direction)
|
316
|
-
if properties.is_a?(
|
314
|
+
if properties.is_a?(ActiveGraph::AttributeSet)
|
317
315
|
properties.write_cast_value(key, converted_value)
|
318
316
|
else
|
319
317
|
properties[key] = converted_value
|
@@ -335,11 +333,11 @@ module Neo4j::Shared
|
|
335
333
|
end
|
336
334
|
|
337
335
|
def typecaster_for(value)
|
338
|
-
|
336
|
+
ActiveGraph::Shared::TypeConverters.typecaster_for(value)
|
339
337
|
end
|
340
338
|
|
341
339
|
def typecast_attribute(typecaster, value)
|
342
|
-
|
340
|
+
ActiveGraph::Shared::TypeConverters.typecast_attribute(typecaster, value)
|
343
341
|
end
|
344
342
|
|
345
343
|
private
|
@@ -368,8 +366,8 @@ module Neo4j::Shared
|
|
368
366
|
|
369
367
|
class << self
|
370
368
|
def included(_)
|
371
|
-
|
372
|
-
constant =
|
369
|
+
ActiveGraph::Shared::TypeConverters.constants.each do |constant_name|
|
370
|
+
constant = ActiveGraph::Shared::TypeConverters.const_get(constant_name)
|
373
371
|
register_converter(constant) if constant.respond_to?(:convert_type)
|
374
372
|
end
|
375
373
|
end
|
@@ -1,4 +1,4 @@
|
|
1
|
-
module
|
1
|
+
module ActiveGraph::Shared
|
2
2
|
# TypecastedAttributes allows types to be declared for your attributes
|
3
3
|
#
|
4
4
|
# Types are declared by passing the :type option to the attribute class
|
@@ -11,7 +11,7 @@ module Neo4j::Shared
|
|
11
11
|
#
|
12
12
|
# @example Usage
|
13
13
|
# class Person
|
14
|
-
# include
|
14
|
+
# include ActiveGraph::Shared::TypecastedAttributes
|
15
15
|
# attribute :age, :type => Integer
|
16
16
|
# end
|
17
17
|
#
|
@@ -23,7 +23,7 @@ module Neo4j::Shared
|
|
23
23
|
# Originally part of ActiveAttr, https://github.com/cgriego/active_attr
|
24
24
|
module TypecastedAttributes
|
25
25
|
extend ActiveSupport::Concern
|
26
|
-
include
|
26
|
+
include ActiveGraph::Shared::Attributes
|
27
27
|
|
28
28
|
included do
|
29
29
|
attribute_method_suffix '_before_type_cast'
|
@@ -39,7 +39,7 @@ module Neo4j::Shared
|
|
39
39
|
#
|
40
40
|
# @return [Object, nil] The attribute value before typecasting
|
41
41
|
def attribute_before_type_cast(name)
|
42
|
-
@attributes ||=
|
42
|
+
@attributes ||= ActiveGraph::AttributeSet.new({}, self.class.attributes.keys)
|
43
43
|
@attributes.fetch_value(name.to_s)
|
44
44
|
end
|
45
45
|
|
@@ -67,8 +67,8 @@ module Neo4j::Shared
|
|
67
67
|
def _attribute_typecaster(attribute_name)
|
68
68
|
type = _attribute_type(attribute_name)
|
69
69
|
default_typecaster = self.class.attributes[attribute_name].typecaster
|
70
|
-
caster = default_typecaster ||
|
71
|
-
caster || fail(
|
70
|
+
caster = default_typecaster || ActiveGraph::Shared::TypeConverters.typecaster_for(type)
|
71
|
+
caster || fail(ActiveGraph::UnknownTypeConverterError, "Unable to cast to type #{type}")
|
72
72
|
end
|
73
73
|
|
74
74
|
module ClassMethods
|
@@ -92,7 +92,7 @@ module Neo4j::Shared
|
|
92
92
|
end
|
93
93
|
|
94
94
|
def typecast_attribute(typecaster, value)
|
95
|
-
|
95
|
+
ActiveGraph::Shared::TypeConverters.typecast_attribute(typecaster, value)
|
96
96
|
end
|
97
97
|
end
|
98
98
|
end
|
@@ -1,4 +1,4 @@
|
|
1
|
-
module
|
1
|
+
module ActiveGraph
|
2
2
|
module Shared
|
3
3
|
# This module provides a convenient way of registering a custom Typecasting class. Custom Typecasters all follow a simple pattern.
|
4
4
|
#
|
@@ -27,7 +27,7 @@ module Neo4j
|
|
27
27
|
# alias_method :call, :to_ruby
|
28
28
|
# end
|
29
29
|
#
|
30
|
-
# include
|
30
|
+
# include ActiveGraph::Shared::Typecaster
|
31
31
|
# end
|
32
32
|
#
|
33
33
|
# This would allow you to use `property :my_prop, type: Range` in a model.
|
@@ -46,7 +46,7 @@ module Neo4j
|
|
46
46
|
|
47
47
|
module Typecaster
|
48
48
|
def self.included(other)
|
49
|
-
|
49
|
+
ActiveGraph::Shared::TypeConverters.register_converter(other)
|
50
50
|
end
|
51
51
|
end
|
52
52
|
end
|
@@ -1,23 +1,23 @@
|
|
1
1
|
require 'rake'
|
2
2
|
require 'active_support/concern'
|
3
|
-
require '
|
3
|
+
require 'active_graph/migration'
|
4
4
|
|
5
5
|
if !defined?(Rails) && !Rake::Task.task_defined?('environment')
|
6
6
|
desc 'Run a script against the database to perform system-wide changes'
|
7
7
|
task :environment do
|
8
|
-
require '
|
8
|
+
require 'active_graph/session_manager'
|
9
9
|
require 'ostruct'
|
10
10
|
neo4j_url = ENV['NEO4J_URL'] || 'http://localhost:7474'
|
11
11
|
$LOAD_PATH.unshift File.dirname('./')
|
12
|
-
|
13
|
-
|
12
|
+
ActiveGraph::Base.on_establish_session do
|
13
|
+
ActiveGraph::Base.new_driver(neo4j_url)
|
14
14
|
end
|
15
15
|
end
|
16
16
|
end
|
17
17
|
|
18
18
|
namespace :neo4j do
|
19
19
|
task :allow_migrations do
|
20
|
-
|
20
|
+
ActiveGraph::Migrations.currently_running_migrations = true
|
21
21
|
end
|
22
22
|
desc 'Run a script against the database to perform system-wide changes'
|
23
23
|
task :legacy_migrate, [:task_name, :subtask] => :environment do |_, args|
|
@@ -25,7 +25,7 @@ namespace :neo4j do
|
|
25
25
|
migration_task = args[:task_name]
|
26
26
|
task_name_constant = migration_task.split('_').map(&:capitalize).join('')
|
27
27
|
begin
|
28
|
-
migration_class = "
|
28
|
+
migration_class = "ActiveGraph::Migration::#{task_name_constant}".constantize
|
29
29
|
rescue NameError
|
30
30
|
load File.join(path, 'db', 'neo4j-migrate', "#{migration_task}.rb")
|
31
31
|
migration_class = task_name_constant.to_s.constantize
|
@@ -50,7 +50,7 @@ namespace :neo4j do
|
|
50
50
|
SCHEMA_YAML_PATH = 'db/neo4j/schema.yml'
|
51
51
|
SCHEMA_YAML_COMMENT = <<COMMENT
|
52
52
|
# This file is auto-generated from the current state of the database. Instead
|
53
|
-
# of editing this file, please use the migrations feature of
|
53
|
+
# of editing this file, please use the migrations feature of Node to
|
54
54
|
# incrementally modify your database, and then regenerate this schema definition.
|
55
55
|
#
|
56
56
|
# Note that this schema.yml definition is the authoritative source for your
|
@@ -64,7 +64,7 @@ namespace :neo4j do
|
|
64
64
|
COMMENT
|
65
65
|
|
66
66
|
def check_neo4j_version_3
|
67
|
-
if
|
67
|
+
if ActiveGraph::Base.transaction.version > '3.0.0'
|
68
68
|
yield
|
69
69
|
else
|
70
70
|
puts 'WARNING: This task does not work for versions of Neo4j before 3.0.0'
|
@@ -74,11 +74,11 @@ COMMENT
|
|
74
74
|
desc 'Creates a db/neo4j/schema.yml file which represents the indexes / constraints in the Neo4j DB'
|
75
75
|
task dump: :environment do
|
76
76
|
check_neo4j_version_3 do
|
77
|
-
require '
|
77
|
+
require 'active_graph/migrations/schema'
|
78
78
|
|
79
|
-
schema_data =
|
79
|
+
schema_data = ActiveGraph::Migrations::Schema.fetch_schema_data(ActiveGraph::Base.transaction)
|
80
80
|
|
81
|
-
runner =
|
81
|
+
runner = ActiveGraph::Migrations::Runner.new
|
82
82
|
schema_data[:versions] = runner.complete_migration_versions.sort
|
83
83
|
|
84
84
|
FileUtils.mkdir_p(File.dirname(SCHEMA_YAML_PATH))
|
@@ -91,20 +91,20 @@ COMMENT
|
|
91
91
|
desc "Loads a db/neo4j/schema.yml file into the database\nOptionally removes schema elements which aren't in the schema.yml file (defaults to false)"
|
92
92
|
task :load, [:remove_missing] => :environment do |_t, args|
|
93
93
|
check_neo4j_version_3 do
|
94
|
-
require '
|
94
|
+
require 'active_graph/migrations/schema'
|
95
95
|
|
96
96
|
args.with_defaults(remove_missing: false)
|
97
97
|
|
98
98
|
schema_data = YAML.safe_load(File.read(SCHEMA_YAML_PATH), [Symbol])
|
99
99
|
|
100
|
-
|
100
|
+
ActiveGraph::Transaction.subscribe_to_query(&method(:puts))
|
101
101
|
|
102
|
-
|
103
|
-
|
102
|
+
ActiveGraph::Base.run_transaction do
|
103
|
+
ActiveGraph::Migrations::Schema.synchronize_schema_data(ActiveGraph::Base.transaction, schema_data, args[:remove_missing])
|
104
104
|
end
|
105
105
|
|
106
|
-
|
107
|
-
runner =
|
106
|
+
ActiveGraph::Base.run_transaction do
|
107
|
+
runner = ActiveGraph::Migrations::Runner.new
|
108
108
|
runner.mark_versions_as_complete(schema_data[:versions]) # Run in test mode?
|
109
109
|
end
|
110
110
|
end
|
@@ -114,7 +114,7 @@ COMMENT
|
|
114
114
|
namespace :migrate do
|
115
115
|
desc 'Run all pending migrations'
|
116
116
|
task all: [:allow_migrations, :environment] do
|
117
|
-
runner =
|
117
|
+
runner = ActiveGraph::Migrations::Runner.new
|
118
118
|
runner.all
|
119
119
|
|
120
120
|
Rake::Task['neo4j:schema:dump'].invoke
|
@@ -123,7 +123,7 @@ COMMENT
|
|
123
123
|
desc 'Run a migration given its VERSION'
|
124
124
|
task up: [:allow_migrations, :environment] do
|
125
125
|
version = ENV['VERSION'] || fail(ArgumentError, 'VERSION is required')
|
126
|
-
runner =
|
126
|
+
runner = ActiveGraph::Migrations::Runner.new
|
127
127
|
runner.up version
|
128
128
|
|
129
129
|
Rake::Task['neo4j:schema:dump'].invoke
|
@@ -132,7 +132,7 @@ COMMENT
|
|
132
132
|
desc 'Revert a migration given its VERSION'
|
133
133
|
task down: [:allow_migrations, :environment] do
|
134
134
|
version = ENV['VERSION'] || fail(ArgumentError, 'VERSION is required')
|
135
|
-
runner =
|
135
|
+
runner = ActiveGraph::Migrations::Runner.new
|
136
136
|
runner.down version
|
137
137
|
|
138
138
|
Rake::Task['neo4j:schema:dump'].invoke
|
@@ -140,21 +140,21 @@ COMMENT
|
|
140
140
|
|
141
141
|
desc 'Print a report of migrations status'
|
142
142
|
task status: [:allow_migrations, :environment] do
|
143
|
-
runner =
|
143
|
+
runner = ActiveGraph::Migrations::Runner.new
|
144
144
|
runner.status
|
145
145
|
end
|
146
146
|
|
147
147
|
desc 'Resolve an incomplete version state'
|
148
148
|
task resolve: [:allow_migrations, :environment] do
|
149
149
|
version = ENV['VERSION'] || fail(ArgumentError, 'VERSION is required')
|
150
|
-
runner =
|
150
|
+
runner = ActiveGraph::Migrations::Runner.new
|
151
151
|
runner.resolve version
|
152
152
|
end
|
153
153
|
|
154
154
|
desc 'Resolve an incomplete version state'
|
155
155
|
task reset: [:allow_migrations, :environment] do
|
156
156
|
version = ENV['VERSION'] || fail(ArgumentError, 'VERSION is required')
|
157
|
-
runner =
|
157
|
+
runner = ActiveGraph::Migrations::Runner.new
|
158
158
|
runner.reset version
|
159
159
|
end
|
160
160
|
end
|
@@ -162,7 +162,7 @@ COMMENT
|
|
162
162
|
desc 'Rollbacks migrations given a STEP number'
|
163
163
|
task rollback: [:allow_migrations, :environment] do
|
164
164
|
steps = (ENV['STEP'] || 1).to_i
|
165
|
-
runner =
|
165
|
+
runner = ActiveGraph::Migrations::Runner.new
|
166
166
|
runner.rollback(steps)
|
167
167
|
|
168
168
|
Rake::Task['neo4j:schema:dump'].invoke
|
@@ -186,7 +186,7 @@ COMMENT
|
|
186
186
|
path = File.join('db/neo4j/migrate', "#{DateTime.now.utc.strftime('%Y%m%d%H%M%S')}_#{migration_class_name.underscore}.rb")
|
187
187
|
|
188
188
|
content = <<-CONTENT
|
189
|
-
class #{migration_class_name} <
|
189
|
+
class #{migration_class_name} < ActiveGraph::Migrations::Base
|
190
190
|
def up
|
191
191
|
add_#{index_or_constraint} #{label.to_sym.inspect}, #{property_name.to_sym.inspect}, force: true
|
192
192
|
end
|