activegraph 11.4.0 → 11.5.0.alpha.1

Sign up to get free protection for your applications and to get access to all the features.
Files changed (56) hide show
  1. checksums.yaml +4 -4
  2. data/Gemfile +1 -1
  3. data/activegraph.gemspec +3 -3
  4. data/lib/active_graph/attribute_set.rb +0 -4
  5. data/lib/active_graph/base.rb +0 -3
  6. data/lib/active_graph/config.rb +0 -1
  7. data/lib/active_graph/core/instrumentable.rb +0 -5
  8. data/lib/active_graph/core/querable.rb +0 -5
  9. data/lib/active_graph/core/query.rb +4 -7
  10. data/lib/active_graph/core/query_ext.rb +1 -1
  11. data/lib/active_graph/core/record.rb +0 -5
  12. data/lib/active_graph/core/result.rb +5 -0
  13. data/lib/active_graph/core/wrappable.rb +1 -1
  14. data/lib/active_graph/generators/active_model.rb +33 -0
  15. data/lib/active_graph/generators/generated_attribute.rb +17 -0
  16. data/lib/{rails/generators/active_graph/migration → active_graph/generators}/migration_generator.rb +0 -4
  17. data/lib/{rails/generators/active_graph_generator.rb → active_graph/generators/migration_helper.rb} +0 -75
  18. data/lib/{rails/generators/active_graph/model → active_graph/generators}/model_generator.rb +0 -4
  19. data/lib/active_graph/generators/source_path_helper.rb +10 -0
  20. data/lib/{rails/generators/active_graph/upgrade_v8 → active_graph/generators}/upgrade_v8_generator.rb +0 -4
  21. data/lib/active_graph/lazy_attribute_hash.rb +0 -2
  22. data/lib/active_graph/migration.rb +0 -3
  23. data/lib/active_graph/migrations/helpers.rb +0 -7
  24. data/lib/active_graph/migrations/runner.rb +0 -4
  25. data/lib/active_graph/migrations.rb +0 -8
  26. data/lib/active_graph/model_schema.rb +0 -1
  27. data/lib/active_graph/node/has_n/association.rb +0 -3
  28. data/lib/active_graph/node/labels.rb +1 -3
  29. data/lib/active_graph/node/orm_adapter.rb +0 -6
  30. data/lib/active_graph/node/scope.rb +4 -43
  31. data/lib/active_graph/node/wrapping.rb +52 -0
  32. data/lib/active_graph/node.rb +1 -0
  33. data/lib/active_graph/railtie.rb +0 -6
  34. data/lib/active_graph/relationship/property.rb +0 -2
  35. data/lib/active_graph/relationship/wrapping.rb +26 -0
  36. data/lib/active_graph/shared/attributes.rb +3 -2
  37. data/lib/active_graph/shared/node_query_factory.rb +15 -0
  38. data/lib/active_graph/shared/persistence.rb +1 -1
  39. data/lib/active_graph/shared/query_factory.rb +0 -60
  40. data/lib/active_graph/shared/rel_query_factory.rb +47 -0
  41. data/lib/active_graph/shared/type_converters.rb +0 -6
  42. data/lib/active_graph/tasks/migration.rake +0 -4
  43. data/lib/active_graph/timestamps.rb +0 -3
  44. data/lib/active_graph/version.rb +1 -1
  45. data/lib/active_graph.rb +43 -114
  46. metadata +32 -23
  47. data/lib/active_graph/core.rb +0 -14
  48. data/lib/active_graph/node/node_wrapper.rb +0 -54
  49. data/lib/active_graph/relationship/rel_wrapper.rb +0 -31
  50. data/lib/active_graph/wrapper.rb +0 -4
  51. /data/lib/active_graph/{errors.rb → error.rb} +0 -0
  52. /data/lib/{rails/generators/active_graph → active_graph/generators}/migration/templates/migration.erb +0 -0
  53. /data/lib/{rails/generators/active_graph → active_graph/generators}/model/templates/migration.erb +0 -0
  54. /data/lib/{rails/generators/active_graph → active_graph/generators}/model/templates/model.erb +0 -0
  55. /data/lib/{rails/generators/active_graph → active_graph/generators}/upgrade_v8/templates/migration.erb +0 -0
  56. /data/lib/active_graph/node/query/{query_proxy_link.rb → query_proxy/link.rb} +0 -0
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: f068da2126bbed4301cf9fb15c34a708ef7f7a152afbfe42af5482237a041f0d
4
- data.tar.gz: 0c87c4c2082a2e999ac8e0ff165e0cdbffe875f7f2eae407ea31f3f119d46a5f
3
+ metadata.gz: '0101891bd10ab15f40fe0b95d8f9801addbad38e6a9a620d6ed3172538f13b81'
4
+ data.tar.gz: 29cd3cdd821bdd01723767210820b441d175c20722d086791e3b6f96c60e7860
5
5
  SHA512:
6
- metadata.gz: 5c12b0fc53c6bb04d661ec6c1669843e3c59d2ce00a9c7ea909d49b87ba7ef7b4c58ba2196d2c880c70da4ed727d14851fa27a15cf948125e91ee7670a23ff9d
7
- data.tar.gz: e0dda99c677170338a7a470d00660fa20528e272452ee81a58722d055af969f0951e3344e0961e3b5ec49b6e0e316527dc0deab5f0ce01fe3dda0c029310ee01
6
+ metadata.gz: 236ae57612400438f2ea424600e5b4013790d9fe77840421727f83e5158ca4c8622cc8b2bda502d19c8f212956c86111f25b38fe5d3a68e2ef4819620432aa53
7
+ data.tar.gz: e699e3c4788af542fec9c1b74552b08309a8bd3611a25232445c0bf8a7a4f292067ee3cb86db5c7ed7a34dc134eff8a1fea59c772b778a58de2b1c3d1ec47bb1
data/Gemfile CHANGED
@@ -4,7 +4,7 @@ gemspec
4
4
 
5
5
  # gem 'neo4j-ruby-driver', path: '../neo4j-ruby-driver'
6
6
 
7
- gem 'listen', '< 3.1'
7
+ # gem 'listen', '< 3.1'
8
8
 
9
9
  active_model_version = ENV['ACTIVE_MODEL_VERSION']
10
10
  gem 'activemodel', "~> #{active_model_version}" if active_model_version&.length&.positive?
data/activegraph.gemspec CHANGED
@@ -33,8 +33,8 @@ DESCRIPTION
33
33
  s.add_dependency('activemodel', '>= 4.0')
34
34
  s.add_dependency('activesupport', '>= 4.0')
35
35
  s.add_dependency('i18n', '!= 1.8.8') # https://github.com/jruby/jruby/issues/6547
36
- s.add_dependency('neo4j-ruby-driver', '>= 4.4.1')
37
- s.add_dependency('orm_adapter', '~> 0.5.0')
36
+ s.add_dependency('neo4j-ruby-driver', '>= 4.4.1', '< 5')
37
+ s.add_dependency('orm_adapter', '>= 0.5.0')
38
38
  s.add_dependency('sorted_set')
39
39
  s.add_development_dependency('guard')
40
40
  s.add_development_dependency('guard-rspec')
@@ -47,5 +47,5 @@ DESCRIPTION
47
47
  s.add_development_dependency('rubocop', '>= 0.56.0')
48
48
  s.add_development_dependency('yard')
49
49
  s.add_development_dependency('dryspec')
50
- s.add_development_dependency('rspec', '< 3.10') # Cannot proxy frozen objects
50
+ s.add_development_dependency('rspec', '>= 3.10')
51
51
  end
@@ -1,7 +1,3 @@
1
- # frozen_string_literal: true
2
-
3
- require 'active_model/attribute_set'
4
-
5
1
  module ActiveGraph
6
2
  class AttributeSet < ActiveModel::AttributeSet
7
3
  def initialize(attr_hash, attr_list)
@@ -1,6 +1,3 @@
1
- require 'active_graph/core/querable'
2
- require 'active_graph/core/schema'
3
-
4
1
  module ActiveGraph
5
2
  # To contain any base login for Node/Relationship which
6
3
  # is external to the main classes
@@ -26,7 +26,6 @@ module ActiveGraph
26
26
 
27
27
  # @return [Hash] the default file loaded by yaml
28
28
  def defaults
29
- require 'yaml'
30
29
  @defaults ||= ActiveSupport::HashWithIndifferentAccess.new(YAML.load_file(default_file))
31
30
  end
32
31
 
@@ -1,8 +1,3 @@
1
- require 'active_support/concern'
2
- require 'active_support/notifications'
3
- require 'active_graph/ansi'
4
- require 'active_graph/core/logging'
5
-
6
1
  module ActiveGraph
7
2
  module Core
8
3
  module Instrumentable
@@ -1,8 +1,3 @@
1
- require 'active_graph/core/instrumentable'
2
- require 'active_graph/transaction'
3
- require 'active_graph/core/query_builder'
4
- require 'active_graph/core/record'
5
-
6
1
  module ActiveGraph
7
2
  module Core
8
3
  module Querable
@@ -1,7 +1,3 @@
1
- require 'active_graph/core/query_clauses'
2
- require 'active_graph/core/query_find_in_batches'
3
- require 'active_support/notifications'
4
-
5
1
  module ActiveGraph
6
2
  module Core
7
3
  # Allows for generation of cypher queries via ruby method calls (inspired by ActiveRecord / arel syntax)
@@ -15,9 +11,9 @@ module ActiveGraph
15
11
  class Query
16
12
  include ActiveGraph::Core::QueryClauses
17
13
  include ActiveGraph::Core::QueryFindInBatches
14
+ include QueryExt
18
15
  DEFINED_CLAUSES = {}
19
16
 
20
-
21
17
  attr_accessor :clauses
22
18
 
23
19
  class Parameters
@@ -247,7 +243,7 @@ module ActiveGraph
247
243
  neo_id = (node_object.respond_to?(:neo_id) ? node_object.neo_id : node_object)
248
244
 
249
245
  match_method = optional_match ? :optional_match : :match
250
- query.send(match_method, variable).where(variable => {neo_id: neo_id})
246
+ query.send(match_method, variable).where(variable => { neo_id: })
251
247
  end
252
248
  end
253
249
 
@@ -271,7 +267,6 @@ module ActiveGraph
271
267
  # @return [Array]
272
268
  # @raise [ActiveGraph::Server::CypherResponse::ResponseError] Raises errors from neo4j server
273
269
 
274
-
275
270
  # Executes a query without returning the result
276
271
  # @return [Boolean] true if successful
277
272
  # @raise [ActiveGraph::Server::CypherResponse::ResponseError] Raises errors from neo4j server
@@ -318,6 +313,7 @@ module ActiveGraph
318
313
  # @return [String] Resulting cypher query string
319
314
  EMPTY = ' '
320
315
  NEWLINE = "\n"
316
+
321
317
  def to_cypher(options = {})
322
318
  join_string = options[:pretty] ? NEWLINE : EMPTY
323
319
 
@@ -334,6 +330,7 @@ module ActiveGraph
334
330
  cypher_string = "CYPHER #{@options[:parser]} #{cypher_string}" if @options[:parser]
335
331
  cypher_string.tap(&:strip!)
336
332
  end
333
+
337
334
  alias cypher to_cypher
338
335
 
339
336
  def pretty_cypher
@@ -1,6 +1,6 @@
1
1
  module ActiveGraph
2
2
  module Core
3
- class Query
3
+ module QueryExt
4
4
  # Creates a ActiveGraph::Node::Query::QueryProxy object that builds off of a Core::Query object.
5
5
  #
6
6
  # @param [Class] model An Node model to be used as the start of a new QueryuProxy chain
@@ -1,8 +1,3 @@
1
- # frozen_string_literal: true
2
-
3
- require 'active_graph/core/result'
4
- require 'active_support/core_ext/module/attribute_accessors'
5
-
6
1
  module ActiveGraph
7
2
  module Core
8
3
  module Record
@@ -16,6 +16,11 @@ module ActiveGraph
16
16
  @records&.each(&block) || super
17
17
  end
18
18
 
19
+ ## To avoid to_a on Neo4j::Driver::Result as that one does not call the above block
20
+ def to_a
21
+ map.to_a
22
+ end
23
+
19
24
  def store
20
25
  return if @records
21
26
  keys
@@ -8,7 +8,7 @@ module ActiveGraph
8
8
  end
9
9
 
10
10
  class_methods do
11
- def wrapper_callback(proc)
11
+ def wrapper_callback(&proc)
12
12
  fail 'Callback already specified!' if @wrapper_callback
13
13
  @wrapper_callback = proc
14
14
  end
@@ -0,0 +1,33 @@
1
+ class ActiveGraph::Generators::ActiveModel < Rails::Generators::ActiveModel #:nodoc:
2
+ def self.all(klass)
3
+ "#{klass}.all"
4
+ end
5
+
6
+ def self.find(klass, params = nil)
7
+ "#{klass}.find(#{params})"
8
+ end
9
+
10
+ def self.build(klass, params = nil)
11
+ if params
12
+ "#{klass}.new(#{params})"
13
+ else
14
+ "#{klass}.new"
15
+ end
16
+ end
17
+
18
+ def save
19
+ "#{name}.save"
20
+ end
21
+
22
+ def update_attributes(params = nil)
23
+ "#{name}.update_attributes(#{params})"
24
+ end
25
+
26
+ def errors
27
+ "#{name}.errors"
28
+ end
29
+
30
+ def destroy
31
+ "#{name}.destroy"
32
+ end
33
+ end
@@ -0,0 +1,17 @@
1
+ module ActiveGraph
2
+ module Generators
3
+ module GeneratedAttribute #:nodoc:
4
+ def type_class
5
+ case type.to_s.downcase
6
+ when 'any' then 'any'
7
+ when 'datetime' then 'DateTime'
8
+ when 'date' then 'Date'
9
+ when 'integer', 'number', 'fixnum' then 'Integer'
10
+ when 'float' then 'Float'
11
+ else
12
+ 'String'
13
+ end
14
+ end
15
+ end
16
+ end
17
+ end
@@ -1,7 +1,3 @@
1
- # frozen_string_literal: true
2
-
3
- require File.join(File.dirname(__FILE__), '..', '..', '..', '..', 'active_graph.rb')
4
-
5
1
  module ActiveGraph
6
2
  module Generators
7
3
  class MigrationGenerator < ::Rails::Generators::NamedBase
@@ -1,13 +1,3 @@
1
- # frozen_string_literal: true
2
-
3
- require 'rails/generators/named_base'
4
- require 'rails/generators/active_model'
5
-
6
- module ActiveGraph
7
- module Generators #:nodoc:
8
- end
9
- end
10
-
11
1
  module ActiveGraph::Generators::MigrationHelper
12
2
  extend ActiveSupport::Concern
13
3
 
@@ -54,68 +44,3 @@ module ActiveGraph::Generators::MigrationHelper
54
44
  FileUtils.rm(real_file_name) if @behavior == :revoke
55
45
  end
56
46
  end
57
-
58
- module ActiveGraph::Generators::SourcePathHelper
59
- extend ActiveSupport::Concern
60
-
61
- module ClassMethods
62
- def source_root
63
- @_neo4j_source_root ||= File.expand_path(File.join(File.dirname(__FILE__),
64
- 'active_graph', generator_name, 'templates'))
65
- end
66
- end
67
- end
68
-
69
-
70
- class ActiveGraph::Generators::ActiveModel < Rails::Generators::ActiveModel #:nodoc:
71
- def self.all(klass)
72
- "#{klass}.all"
73
- end
74
-
75
- def self.find(klass, params = nil)
76
- "#{klass}.find(#{params})"
77
- end
78
-
79
- def self.build(klass, params = nil)
80
- if params
81
- "#{klass}.new(#{params})"
82
- else
83
- "#{klass}.new"
84
- end
85
- end
86
-
87
- def save
88
- "#{name}.save"
89
- end
90
-
91
- def update_attributes(params = nil)
92
- "#{name}.update_attributes(#{params})"
93
- end
94
-
95
- def errors
96
- "#{name}.errors"
97
- end
98
-
99
- def destroy
100
- "#{name}.destroy"
101
- end
102
- end
103
-
104
-
105
- module Rails
106
- module Generators
107
- class GeneratedAttribute #:nodoc:
108
- def type_class
109
- case type.to_s.downcase
110
- when 'any' then 'any'
111
- when 'datetime' then 'DateTime'
112
- when 'date' then 'Date'
113
- when 'integer', 'number', 'fixnum' then 'Integer'
114
- when 'float' then 'Float'
115
- else
116
- 'String'
117
- end
118
- end
119
- end
120
- end
121
- end
@@ -1,7 +1,3 @@
1
- # frozen_string_literal: true
2
-
3
- require File.join(File.dirname(__FILE__), '..', '..', '..', '..', 'active_graph.rb')
4
-
5
1
  class ActiveGraph::Generators::ModelGenerator < Rails::Generators::NamedBase #:nodoc:
6
2
  include ::ActiveGraph::Generators::SourcePathHelper
7
3
  include ::ActiveGraph::Generators::MigrationHelper
@@ -0,0 +1,10 @@
1
+ module ActiveGraph::Generators::SourcePathHelper
2
+ extend ActiveSupport::Concern
3
+
4
+ module ClassMethods
5
+ def source_root
6
+ @_neo4j_source_root ||= File.expand_path(File.join(File.dirname(__FILE__),
7
+ generator_name, 'templates'))
8
+ end
9
+ end
10
+ end
@@ -1,7 +1,3 @@
1
- # frozen_string_literal: true
2
-
3
- require File.join(File.dirname(__FILE__), '..', '..', '..', '..', 'active_graph.rb')
4
-
5
1
  module ActiveGraph
6
2
  module Generators
7
3
  class UpgradeV8Generator < ::Rails::Generators::Base
@@ -1,5 +1,3 @@
1
- require 'active_model/attribute_set'
2
-
3
1
  module ActiveGraph
4
2
  class LazyAttributeHash < ActiveModel::LazyAttributeHash
5
3
  def initialize(values, attr_list)
@@ -1,6 +1,3 @@
1
- require 'benchmark'
2
- require 'active_graph/migrations/helpers/id_property'
3
-
4
1
  module ActiveGraph
5
2
  class Migration
6
3
  def migrate
@@ -1,14 +1,7 @@
1
- require 'benchmark'
2
-
3
1
  module ActiveGraph
4
2
  module Migrations
5
3
  module Helpers
6
4
  extend ActiveSupport::Concern
7
- extend ActiveSupport::Autoload
8
-
9
- autoload :Schema
10
- autoload :IdProperty
11
- autoload :Relationships
12
5
 
13
6
  PROPERTY_ALREADY_DEFINED = 'Property `%{new_property}` is already defined in `%{label}`. '\
14
7
  'To overwrite, call `remove_property(:%{label}, :%{new_property})` before this method.'.freeze
@@ -1,7 +1,3 @@
1
- # frozen_string_literal: true
2
-
3
- require 'sorted_set'
4
-
5
1
  module ActiveGraph
6
2
  module Migrations
7
3
  class Runner
@@ -1,13 +1,5 @@
1
1
  module ActiveGraph
2
2
  module Migrations
3
- extend ActiveSupport::Autoload
4
- autoload :Helpers
5
- autoload :MigrationFile
6
- autoload :Base
7
- autoload :Runner
8
- autoload :SchemaMigration
9
- autoload :CheckPending
10
-
11
3
  class << self
12
4
  def check_for_pending_migrations!
13
5
  return if ActiveGraph::Config.configuration['skip_migration_check']
@@ -1,4 +1,3 @@
1
- require 'set'
2
1
  module ActiveGraph
3
2
  # This is here to support the removed functionality of being able to
4
3
  # defined indexes and constraints on models
@@ -1,6 +1,3 @@
1
- require 'active_support/inflector/inflections'
2
- require 'active_graph/class_arguments'
3
-
4
1
  module ActiveGraph
5
2
  module Node
6
3
  module HasN
@@ -1,5 +1,3 @@
1
- require 'active_graph/core/label'
2
-
3
1
  module ActiveGraph
4
2
  module Node
5
3
  # Provides a mapping between neo4j labels and Ruby classes
@@ -76,7 +74,7 @@ module ActiveGraph
76
74
 
77
75
  def self.clear_wrapped_models
78
76
  MODELS_FOR_LABELS_CACHE.clear
79
- ActiveGraph::NodeWrapping::CONSTANTS_FOR_LABELS_CACHE.clear
77
+ ActiveGraph::Node::Wrapping::CONSTANTS_FOR_LABELS_CACHE.clear
80
78
  end
81
79
 
82
80
  module ClassMethods
@@ -1,11 +1,5 @@
1
- require 'orm_adapter'
2
-
3
1
  module ActiveGraph
4
2
  module Node
5
- module ClassMethods
6
- include OrmAdapter::ToAdapter
7
- end
8
-
9
3
  class OrmAdapter < ::OrmAdapter::Base
10
4
  module ClassMethods
11
5
  include ActiveModel::Callbacks
@@ -1,9 +1,11 @@
1
- require 'active_support/per_thread_registry'
2
-
3
1
  module ActiveGraph::Node
4
2
  module Scope
5
3
  extend ActiveSupport::Concern
6
4
 
5
+ included do
6
+ thread_mattr_accessor :current_scope
7
+ end
8
+
7
9
  module ClassMethods
8
10
  # Similar to ActiveRecord scope
9
11
  #
@@ -86,14 +88,6 @@ module ActiveGraph::Node
86
88
  end
87
89
  end
88
90
 
89
- def current_scope #:nodoc:
90
- ScopeRegistry.value_for(:current_scope, base_class.to_s)
91
- end
92
-
93
- def current_scope=(scope) #:nodoc:
94
- ScopeRegistry.set_value_for(:current_scope, base_class.to_s, scope)
95
- end
96
-
97
91
  def all(new_var = nil)
98
92
  var = new_var || (current_scope ? current_scope.node_identity : :n)
99
93
  if current_scope
@@ -139,38 +133,5 @@ module ActiveGraph::Node
139
133
  @query_proxy_or_target ||= @query_proxy || @target
140
134
  end
141
135
  end
142
-
143
-
144
- # Stolen from ActiveRecord
145
- # https://github.com/rails/rails/blob/08754f12e65a9ec79633a605e986d0f1ffa4b251/activerecord/lib/active_record/scoping.rb#L57
146
- class ScopeRegistry # :nodoc:
147
- extend ActiveSupport::PerThreadRegistry
148
-
149
- VALID_SCOPE_TYPES = [:current_scope, :ignore_default_scope]
150
-
151
- def initialize
152
- @registry = Hash.new { |hash, key| hash[key] = {} }
153
- end
154
-
155
- # Obtains the value for a given +scope_name+ and +variable_name+.
156
- def value_for(scope_type, variable_name)
157
- raise_invalid_scope_type!(scope_type)
158
- @registry[scope_type][variable_name]
159
- end
160
-
161
- # Sets the +value+ for a given +scope_type+ and +variable_name+.
162
- def set_value_for(scope_type, variable_name, value)
163
- raise_invalid_scope_type!(scope_type)
164
- @registry[scope_type][variable_name] = value
165
- end
166
-
167
- private
168
-
169
- def raise_invalid_scope_type!(scope_type)
170
- return if VALID_SCOPE_TYPES.include?(scope_type)
171
-
172
- fail ArgumentError, "Invalid scope type '#{scope_type}' sent to the registry. Scope types must be included in VALID_SCOPE_TYPES"
173
- end
174
- end
175
136
  end
176
137
  end
@@ -0,0 +1,52 @@
1
+ module ActiveGraph
2
+ module Node
3
+ module Wrapping
4
+ # Only load classes once for performance
5
+ CONSTANTS_FOR_LABELS_CACHE = {}
6
+
7
+ class << self
8
+ def wrapper(node)
9
+ found_class = class_to_wrap(node.labels)
10
+ return node unless found_class
11
+
12
+ found_class.new.tap do |wrapped_node|
13
+ wrapped_node.init_on_load(node, node.properties)
14
+ end
15
+ end
16
+
17
+ def class_to_wrap(labels)
18
+ load_classes_from_labels(labels)
19
+ ActiveGraph::Node::Labels.model_for_labels(labels).tap do |model_class|
20
+ populate_constants_for_labels_cache(model_class, labels)
21
+ end
22
+ end
23
+
24
+ private
25
+
26
+ def load_classes_from_labels(labels)
27
+ labels.each { |label| constant_for_label(label) }
28
+ end
29
+
30
+ def constant_for_label(label)
31
+ CONSTANTS_FOR_LABELS_CACHE[label] ||= constantized_label(label)
32
+ end
33
+
34
+ def constantized_label(label)
35
+ "#{association_model_namespace}::#{label}".constantize
36
+ rescue NameError, LoadError
37
+ nil
38
+ end
39
+
40
+ def populate_constants_for_labels_cache(model_class, labels)
41
+ labels.each do |label|
42
+ CONSTANTS_FOR_LABELS_CACHE[label] ||= model_class
43
+ end
44
+ end
45
+
46
+ def association_model_namespace
47
+ ActiveGraph::Config.association_model_namespace_string
48
+ end
49
+ end
50
+ end
51
+ end
52
+ end
@@ -66,6 +66,7 @@ module ActiveGraph
66
66
  end
67
67
 
68
68
  module ClassMethods
69
+ include ::OrmAdapter::ToAdapter
69
70
  def nodeify(object)
70
71
  if object.is_a?(::ActiveGraph::Node) || object.nil?
71
72
  object
@@ -1,9 +1,3 @@
1
- require 'active_support/notifications'
2
- require 'rails/railtie'
3
- # Need the action_dispatch railtie to have action_dispatch.rescue_responses initialized correctly
4
- require 'action_dispatch/railtie'
5
- require 'active_graph'
6
-
7
1
  module ActiveGraph
8
2
  class Railtie < ::Rails::Railtie
9
3
  def empty_config
@@ -1,5 +1,3 @@
1
- require 'active_graph/class_arguments'
2
-
3
1
  module ActiveGraph::Relationship
4
2
  module Property
5
3
  extend ActiveSupport::Concern
@@ -0,0 +1,26 @@
1
+ module ActiveGraph
2
+ module Relationship
3
+ module Wrapping
4
+ class << self
5
+ def wrapper(rel)
6
+ rel.properties.symbolize_keys!
7
+ begin
8
+ most_concrete_class = class_from_type(rel.type).constantize
9
+ return rel unless most_concrete_class < ActiveGraph::Relationship
10
+ most_concrete_class.new
11
+ rescue NameError => e
12
+ raise e unless e.message =~ /(uninitialized|wrong) constant/
13
+
14
+ return rel
15
+ end.tap do |wrapped_rel|
16
+ wrapped_rel.init_on_load(rel, rel.start_node_id, rel.end_node_id, rel.type)
17
+ end
18
+ end
19
+
20
+ def class_from_type(type)
21
+ ActiveGraph::Relationship::Types::WRAPPED_CLASSES[type] || ActiveGraph::Relationship::Types::WRAPPED_CLASSES[type] = type.to_s.downcase.camelize
22
+ end
23
+ end
24
+ end
25
+ end
26
+ end
@@ -18,9 +18,10 @@ module ActiveGraph::Shared
18
18
 
19
19
  # Methods deprecated on the Object class which can be safely overridden
20
20
  DEPRECATED_OBJECT_METHODS = %w(id type)
21
+ ATTRIBUTES_METHOD_PATTERNS = Gem::Requirement.create('>= 7.1').satisfied_by?(Gem.loaded_specs["activesupport"].version) ? :attribute_method_patterns : :attribute_method_matchers
21
22
 
22
23
  included do
23
- attribute_method_suffix '' if attribute_method_matchers.none? { |matcher| matcher.prefix == '' && matcher.suffix == '' }
24
+ attribute_method_suffix '' if send(ATTRIBUTES_METHOD_PATTERNS).none? { |matcher| matcher.prefix == '' && matcher.suffix == '' }
24
25
  attribute_method_suffix '='
25
26
  attribute_method_suffix '?'
26
27
  end
@@ -204,7 +205,7 @@ module ActiveGraph::Shared
204
205
 
205
206
  # Expand an attribute name into its generated methods names
206
207
  def attribute_methods(name)
207
- attribute_method_matchers.map { |matcher| matcher.method_name name }
208
+ send(ATTRIBUTES_METHOD_PATTERNS).map { |matcher| matcher.method_name name }
208
209
  end
209
210
 
210
211
  # Ruby inherited hook to assign superclass attributes to subclasses
@@ -0,0 +1,15 @@
1
+ module ActiveGraph::Shared
2
+ class NodeQueryFactory < QueryFactory
3
+ protected
4
+
5
+ def match_string
6
+ "(#{identifier})"
7
+ end
8
+
9
+ def create_query
10
+ return match_query if graph_object.persisted?
11
+ labels = graph_object.labels_for_create.map { |l| ":`#{l}`" }.join
12
+ base_query.create("(#{identifier}#{labels} $#{identifier}_params)").params(identifier_params => graph_object.props_for_create)
13
+ end
14
+ end
15
+ end