activegraph 10.0.0.pre.alpha.6

Sign up to get free protection for your applications and to get access to all the features.
Files changed (142) hide show
  1. checksums.yaml +7 -0
  2. data/CHANGELOG.md +1989 -0
  3. data/CONTRIBUTORS +12 -0
  4. data/Gemfile +24 -0
  5. data/README.md +107 -0
  6. data/bin/rake +17 -0
  7. data/config/locales/en.yml +5 -0
  8. data/config/neo4j/add_classnames.yml +1 -0
  9. data/config/neo4j/config.yml +38 -0
  10. data/lib/neo4j.rb +116 -0
  11. data/lib/neo4j/active_base.rb +89 -0
  12. data/lib/neo4j/active_node.rb +108 -0
  13. data/lib/neo4j/active_node/callbacks.rb +8 -0
  14. data/lib/neo4j/active_node/dependent.rb +11 -0
  15. data/lib/neo4j/active_node/dependent/association_methods.rb +49 -0
  16. data/lib/neo4j/active_node/dependent/query_proxy_methods.rb +51 -0
  17. data/lib/neo4j/active_node/enum.rb +26 -0
  18. data/lib/neo4j/active_node/has_n.rb +612 -0
  19. data/lib/neo4j/active_node/has_n/association.rb +278 -0
  20. data/lib/neo4j/active_node/has_n/association/rel_factory.rb +61 -0
  21. data/lib/neo4j/active_node/has_n/association/rel_wrapper.rb +23 -0
  22. data/lib/neo4j/active_node/has_n/association_cypher_methods.rb +108 -0
  23. data/lib/neo4j/active_node/id_property.rb +224 -0
  24. data/lib/neo4j/active_node/id_property/accessor.rb +62 -0
  25. data/lib/neo4j/active_node/initialize.rb +21 -0
  26. data/lib/neo4j/active_node/labels.rb +207 -0
  27. data/lib/neo4j/active_node/labels/index.rb +37 -0
  28. data/lib/neo4j/active_node/labels/reloading.rb +21 -0
  29. data/lib/neo4j/active_node/node_list_formatter.rb +13 -0
  30. data/lib/neo4j/active_node/node_wrapper.rb +54 -0
  31. data/lib/neo4j/active_node/orm_adapter.rb +82 -0
  32. data/lib/neo4j/active_node/persistence.rb +187 -0
  33. data/lib/neo4j/active_node/property.rb +60 -0
  34. data/lib/neo4j/active_node/query.rb +76 -0
  35. data/lib/neo4j/active_node/query/query_proxy.rb +374 -0
  36. data/lib/neo4j/active_node/query/query_proxy_eager_loading.rb +177 -0
  37. data/lib/neo4j/active_node/query/query_proxy_eager_loading/association_tree.rb +75 -0
  38. data/lib/neo4j/active_node/query/query_proxy_enumerable.rb +110 -0
  39. data/lib/neo4j/active_node/query/query_proxy_find_in_batches.rb +19 -0
  40. data/lib/neo4j/active_node/query/query_proxy_link.rb +139 -0
  41. data/lib/neo4j/active_node/query/query_proxy_methods.rb +302 -0
  42. data/lib/neo4j/active_node/query/query_proxy_methods_of_mass_updating.rb +86 -0
  43. data/lib/neo4j/active_node/query_methods.rb +68 -0
  44. data/lib/neo4j/active_node/reflection.rb +86 -0
  45. data/lib/neo4j/active_node/rels.rb +11 -0
  46. data/lib/neo4j/active_node/scope.rb +166 -0
  47. data/lib/neo4j/active_node/unpersisted.rb +48 -0
  48. data/lib/neo4j/active_node/validations.rb +59 -0
  49. data/lib/neo4j/active_rel.rb +67 -0
  50. data/lib/neo4j/active_rel/callbacks.rb +15 -0
  51. data/lib/neo4j/active_rel/initialize.rb +28 -0
  52. data/lib/neo4j/active_rel/persistence.rb +134 -0
  53. data/lib/neo4j/active_rel/persistence/query_factory.rb +95 -0
  54. data/lib/neo4j/active_rel/property.rb +95 -0
  55. data/lib/neo4j/active_rel/query.rb +101 -0
  56. data/lib/neo4j/active_rel/rel_wrapper.rb +31 -0
  57. data/lib/neo4j/active_rel/related_node.rb +87 -0
  58. data/lib/neo4j/active_rel/types.rb +82 -0
  59. data/lib/neo4j/active_rel/validations.rb +8 -0
  60. data/lib/neo4j/ansi.rb +14 -0
  61. data/lib/neo4j/class_arguments.rb +39 -0
  62. data/lib/neo4j/config.rb +135 -0
  63. data/lib/neo4j/core.rb +14 -0
  64. data/lib/neo4j/core/connection_failed_error.rb +6 -0
  65. data/lib/neo4j/core/cypher_error.rb +37 -0
  66. data/lib/neo4j/core/driver.rb +66 -0
  67. data/lib/neo4j/core/has_uri.rb +63 -0
  68. data/lib/neo4j/core/instrumentable.rb +36 -0
  69. data/lib/neo4j/core/label.rb +158 -0
  70. data/lib/neo4j/core/logging.rb +44 -0
  71. data/lib/neo4j/core/node.rb +23 -0
  72. data/lib/neo4j/core/querable.rb +88 -0
  73. data/lib/neo4j/core/query.rb +487 -0
  74. data/lib/neo4j/core/query_builder.rb +32 -0
  75. data/lib/neo4j/core/query_clauses.rb +727 -0
  76. data/lib/neo4j/core/query_ext.rb +24 -0
  77. data/lib/neo4j/core/query_find_in_batches.rb +49 -0
  78. data/lib/neo4j/core/relationship.rb +13 -0
  79. data/lib/neo4j/core/responses.rb +50 -0
  80. data/lib/neo4j/core/result.rb +33 -0
  81. data/lib/neo4j/core/schema.rb +30 -0
  82. data/lib/neo4j/core/schema_errors.rb +12 -0
  83. data/lib/neo4j/core/wrappable.rb +30 -0
  84. data/lib/neo4j/errors.rb +57 -0
  85. data/lib/neo4j/migration.rb +148 -0
  86. data/lib/neo4j/migrations.rb +27 -0
  87. data/lib/neo4j/migrations/base.rb +77 -0
  88. data/lib/neo4j/migrations/check_pending.rb +20 -0
  89. data/lib/neo4j/migrations/helpers.rb +105 -0
  90. data/lib/neo4j/migrations/helpers/id_property.rb +75 -0
  91. data/lib/neo4j/migrations/helpers/relationships.rb +66 -0
  92. data/lib/neo4j/migrations/helpers/schema.rb +51 -0
  93. data/lib/neo4j/migrations/migration_file.rb +24 -0
  94. data/lib/neo4j/migrations/runner.rb +195 -0
  95. data/lib/neo4j/migrations/schema.rb +44 -0
  96. data/lib/neo4j/migrations/schema_migration.rb +14 -0
  97. data/lib/neo4j/model_schema.rb +139 -0
  98. data/lib/neo4j/paginated.rb +27 -0
  99. data/lib/neo4j/railtie.rb +105 -0
  100. data/lib/neo4j/schema/operation.rb +102 -0
  101. data/lib/neo4j/shared.rb +60 -0
  102. data/lib/neo4j/shared/attributes.rb +216 -0
  103. data/lib/neo4j/shared/callbacks.rb +68 -0
  104. data/lib/neo4j/shared/cypher.rb +37 -0
  105. data/lib/neo4j/shared/declared_properties.rb +204 -0
  106. data/lib/neo4j/shared/declared_property.rb +109 -0
  107. data/lib/neo4j/shared/declared_property/index.rb +37 -0
  108. data/lib/neo4j/shared/enum.rb +167 -0
  109. data/lib/neo4j/shared/filtered_hash.rb +79 -0
  110. data/lib/neo4j/shared/identity.rb +34 -0
  111. data/lib/neo4j/shared/initialize.rb +64 -0
  112. data/lib/neo4j/shared/marshal.rb +23 -0
  113. data/lib/neo4j/shared/mass_assignment.rb +64 -0
  114. data/lib/neo4j/shared/permitted_attributes.rb +28 -0
  115. data/lib/neo4j/shared/persistence.rb +282 -0
  116. data/lib/neo4j/shared/property.rb +240 -0
  117. data/lib/neo4j/shared/query_factory.rb +102 -0
  118. data/lib/neo4j/shared/rel_type_converters.rb +43 -0
  119. data/lib/neo4j/shared/serialized_properties.rb +30 -0
  120. data/lib/neo4j/shared/type_converters.rb +433 -0
  121. data/lib/neo4j/shared/typecasted_attributes.rb +98 -0
  122. data/lib/neo4j/shared/typecaster.rb +53 -0
  123. data/lib/neo4j/shared/validations.rb +44 -0
  124. data/lib/neo4j/tasks/migration.rake +202 -0
  125. data/lib/neo4j/timestamps.rb +11 -0
  126. data/lib/neo4j/timestamps/created.rb +9 -0
  127. data/lib/neo4j/timestamps/updated.rb +9 -0
  128. data/lib/neo4j/transaction.rb +139 -0
  129. data/lib/neo4j/type_converters.rb +7 -0
  130. data/lib/neo4j/undeclared_properties.rb +53 -0
  131. data/lib/neo4j/version.rb +3 -0
  132. data/lib/neo4j/wrapper.rb +4 -0
  133. data/lib/rails/generators/neo4j/migration/migration_generator.rb +14 -0
  134. data/lib/rails/generators/neo4j/migration/templates/migration.erb +9 -0
  135. data/lib/rails/generators/neo4j/model/model_generator.rb +88 -0
  136. data/lib/rails/generators/neo4j/model/templates/migration.erb +9 -0
  137. data/lib/rails/generators/neo4j/model/templates/model.erb +15 -0
  138. data/lib/rails/generators/neo4j/upgrade_v8/templates/migration.erb +17 -0
  139. data/lib/rails/generators/neo4j/upgrade_v8/upgrade_v8_generator.rb +32 -0
  140. data/lib/rails/generators/neo4j_generator.rb +119 -0
  141. data/neo4j.gemspec +51 -0
  142. metadata +421 -0
data/CONTRIBUTORS ADDED
@@ -0,0 +1,12 @@
1
+ Maintainers:
2
+ Heinrich Klobuczek <klobuczek @ GitHub>
3
+ Amit Suryanvanshi <amitsuryavanshi @ GitHub>
4
+
5
+ Previous Maintainers:
6
+ Chris Grigg <subvertallchris @ GitHub>
7
+ Brian Underwood <cheerfulstoic @ GitHub>
8
+
9
+ Creator:
10
+ Andreas Ronge <andreasronge @ GitHub>
11
+
12
+ See: https://github.com/neo4jrb/neo4j/graphs/contributors
data/Gemfile ADDED
@@ -0,0 +1,24 @@
1
+ source 'http://rubygems.org'
2
+
3
+ gemspec
4
+
5
+ # gem 'neo4j-ruby-driver', path: '../neo4j-ruby-driver'
6
+
7
+ gem 'listen', '< 3.1'
8
+
9
+ active_model_version = ENV['ACTIVE_MODEL_VERSION']
10
+ gem 'activemodel', "~> #{active_model_version}" if active_model_version
11
+
12
+ group 'test' do
13
+ gem 'coveralls', require: false
14
+ gem 'overcommit'
15
+ gem 'codecov', require: false
16
+ gem 'simplecov', require: false
17
+ gem 'simplecov-html', require: false
18
+ gem 'rspec', '~> 3.4'
19
+ gem 'its'
20
+ gem 'test-unit'
21
+ gem 'colored'
22
+ gem 'dotenv'
23
+ gem 'timecop'
24
+ end
data/README.md ADDED
@@ -0,0 +1,107 @@
1
+ # Welcome to Neo4j.rb
2
+
3
+ ## Code Status
4
+
5
+ [![Actively Maintained](https://img.shields.io/badge/Maintenance%20Level-Actively%20Maintained-green.svg)](https://gist.github.com/cheerfulstoic/d107229326a01ff0f333a1d3476e068d)
6
+ [![Build Status](https://secure.travis-ci.org/neo4jrb/neo4j.svg?branch=master)](http://travis-ci.org/neo4jrb/neo4j)
7
+ [![Coverage Status](https://coveralls.io/repos/neo4jrb/neo4j/badge.svg?branch=master)](https://coveralls.io/r/neo4jrb/neo4j?branch=master)
8
+ [![Code Climate](https://codeclimate.com/github/neo4jrb/neo4j.svg)](https://codeclimate.com/github/neo4jrb/neo4j)
9
+
10
+ ## Get Support
11
+
12
+ ### Documentation
13
+
14
+ All new documentation will be done via our [readthedocs](http://neo4jrb.readthedocs.org) site, though some old documentation has yet to be moved from our [wiki](https://github.com/neo4jrb/neo4j/wiki) (also there is the [neo4j-core wiki](https://github.com/neo4jrb/neo4j-core/wiki))
15
+
16
+ ### Contact Us
17
+
18
+ [![StackOverflow](https://img.shields.io/badge/StackOverflow-Ask%20a%20question!-blue.svg)](http://stackoverflow.com/questions/ask?tags=neo4j.rb+neo4j+ruby) [![Gitter](https://img.shields.io/badge/Gitter-Join%20our%20chat!-blue.svg)](https://gitter.im/neo4jrb/neo4j?utm_source=badge&utm_medium=badge&utm_campaign=pr-badge&utm_content=badge) [![Twitter](https://img.shields.io/badge/Twitter-Tweet%20with%20us!-blue.svg)](https://twitter.com/neo4jrb)
19
+
20
+
21
+
22
+ # Introduction
23
+
24
+ Neo4j.rb is an Active Model compliant Ruby/JRuby wrapper for [the Neo4j graph database](http://www.neo4j.org/). It uses the [neo4j-core](https://github.com/neo4jrb/neo4j-core) and [active_attr](https://github.com/cgriego/active_attr) gems.
25
+
26
+ Neo4j is a transactional, open-source graph database. A graph database manages data in a connected data structure, capable of representing any kind of data in a very accessible way. Information is stored in nodes and relationships connecting them, both of which can have arbitrary properties. To learn more visit [What is a Graph Database?](http://neo4j.com/developer/graph-database/)
27
+
28
+ With this gem you not only do you get a convenient higher level wrapper around Neo4j, but you have access to a powerful high-level query building interface which lets you take advantage of the power of Neo4j like this:
29
+
30
+ ```ruby
31
+ # Break down the top countries where friends' favorite beers come from
32
+ person.friends.favorite_beers.country_of_origin(:country).
33
+ order('count(country) DESC').
34
+ pluck(:country, count: 'count(country)')
35
+ ```
36
+
37
+ It can be installed in your `Gemfile` with a simple `gem 'neo4j'`
38
+
39
+ For a general overview see our website: http://neo4jrb.io/
40
+
41
+ Winner of a 2014 Graphie for "Best Community Contribution" at Neo4j's [Graph Connect](http://graphconnect.com) conference!
42
+ ![2014 Graphie](http://i.imgur.com/CkOoTTYm.jpg)
43
+
44
+ Neo4j.rb v4.1.0 was released in January of 2015. Its changes are outlined [here](https://github.com/neo4jrb/neo4j/wiki/Neo4j.rb-v4-Introduction) and in the [announcement message](http://neo4jrb.io/blog/2015/01/09/neo4j-rb_v4-1_released.html). It will take a little time before all documentation is updated to reflect the new release but unless otherwise noted, all 3.X documentation is totally valid for v4.
45
+
46
+ ## Neo4j version support
47
+
48
+ | **Neo4j Version** | v2.x | v3.x | >= v4.x | >= 7.0.3 |
49
+ |-------------------|------|-------|---------|----------|
50
+ | 1.9.x | Yes | No | No | No |
51
+ | 2.0.x | No | Yes | No | No |
52
+ | 2.1.x | No | Yes | Yes * | Yes |
53
+ | 2.2.x | No | No | Yes | Yes |
54
+ | 2.3.x | No | No | Yes | Yes |
55
+ | >= 3.0.0 | No | No | No | Yes |
56
+
57
+ `*` Neo4j.rb >= 4.x doesn't support Neo4j versions before 2.1.5. To use 2.1.x you should upgrade to a version >= 2.1.5
58
+
59
+ ## Neo4j feature support
60
+
61
+ | **Neo4j Feature** | v2.x | v3.x | >= v4.x | >= 8.x |
62
+ |----------------------------|--------|------|---------|--------|
63
+ | Bolt Protocol | No | No | No | Yes |
64
+ | Auth | No | No | Yes | Yes |
65
+ | Remote Cypher | Yes | Yes | Yes | Yes |
66
+ | Transactions | Yes | Yes | Yes | Yes |
67
+ | High Availability | No | Yes | Yes | Yes |
68
+ | Embedded JVM support | Yes | Yes | Yes | Yes |
69
+
70
+ ## Documentation
71
+
72
+ * [Website](http://neo4jrb.io/) (for an introduction)
73
+ * [readthedocs](http://neo4jrb.readthedocs.io/)
74
+ * **Note:** Our GitHub Wiki pages have outdated information. We are in the process of moving all documentation to [readthedocs](http://neo4jrb.readthedocs.io/)
75
+
76
+ ## Legacy (<= 2.x) Documentation
77
+
78
+ * [README](https://github.com/neo4jrb/neo4j/tree/2.x)
79
+ * [Wiki](https://github.com/neo4jrb/neo4j/wiki/Neo4j%3A%3ARails-Introduction)
80
+
81
+ ## Developers
82
+
83
+ ### Original Author
84
+
85
+ * [Andreas Ronge](https://github.com/andreasronge)
86
+
87
+ ### Previous Maintainers
88
+
89
+ * [Brian Underwood](https://github.com/cheerfulstoic)
90
+ * [Chris Grigg](https://github.com/subvertallchris)
91
+
92
+ ### Current Maintainers
93
+
94
+ * [Heinrich Klobuczek](https://github.com/klobuczek)
95
+ * [Amit Suryavanshi](https://github.com/amitsuryavanshi)
96
+
97
+ ## Contributing
98
+
99
+ Always welcome! Please review the [guidelines for contributing](CONTRIBUTING.md) to this repository.
100
+
101
+ ## License
102
+
103
+ * Neo4j.rb - MIT, see the [LICENSE](http://github.com/andreasronge/neo4j/tree/master/LICENSE).
104
+ * Neo4j - Dual free software/commercial license, see [Licensing Guide](http://www.neo4j.org/learn/licensing).
105
+
106
+ **Notice:** There are different licenses for the `neo4j-community`, `neo4j-advanced`, and `neo4j-enterprise` jar gems. Only the `neo4j-community` gem is required by default.
107
+
data/bin/rake ADDED
@@ -0,0 +1,17 @@
1
+ #!/usr/bin/env ruby
2
+ # frozen_string_literal: true
3
+ #
4
+ # This file was generated by Bundler.
5
+ #
6
+ # The application 'rake' is installed as part of a gem, and
7
+ # this file is here to facilitate running it.
8
+ #
9
+
10
+ require 'pathname'
11
+ ENV['BUNDLE_GEMFILE'] ||= File.expand_path('../../Gemfile',
12
+ Pathname.new(__FILE__).realpath)
13
+
14
+ require 'rubygems'
15
+ require 'bundler/setup'
16
+
17
+ load Gem.bin_path('rake', 'rake')
@@ -0,0 +1,5 @@
1
+ en:
2
+ errors:
3
+ messages:
4
+ nil: "can't be nil"
5
+ taken: "has already been taken"
@@ -0,0 +1 @@
1
+ # This file is used as the source for adding _classname properties to nodes and relationships.
@@ -0,0 +1,38 @@
1
+ #=== Neo4j.rb configuration settings
2
+
3
+
4
+ # Examples of not using the Neo4j id (neo_id)
5
+
6
+ # Generated UUID stored as a neo4j property on my_id
7
+ #id_property: my_id
8
+ #id_property_type: :auto
9
+ #id_property_type_value: :uuid
10
+
11
+ # Example, (probably more useful directly on Neo4j::ActiveNode classes instead as a global configuration)
12
+ #id_property: title_id
13
+ #id_property_type: :on
14
+ #id_property_type_value: :some_method
15
+
16
+ # TODO
17
+ # if identity map should be on or not
18
+ # It may impact the performance. Using the identity map will keep all loaded wrapper node/relationship
19
+ # object in memory for each thread and transaction - which may speed up or slow down operations.
20
+ identity_map: false
21
+
22
+ # TODO
23
+ # When using the Neo4j::Model you can let neo4j automatically set timestamps when updating/creating nodes.
24
+ # If set to true neo4j.rb automatically timestamps create and update operations if the model has properties named created_at/created_on or updated_at/updated_on
25
+ # (similar to ActiveRecord).
26
+ timestamps: true
27
+
28
+ # Store a property on objects to cache their ActiveNode/ActiveRel class. It prevents each object load from requiring two database queries.
29
+ # Strings shorter than 44 characters are classified, so this will have almost no impact on disk footprint. See http://docs.neo4j.org/chunked/stable/short-strings.html.
30
+ # Alternatively, call class method Neo4j::ActiveNode:cache_class to set this on specific models.
31
+ # By default, this property is called _classname, set as symbol to override.
32
+ cache_class_names: true
33
+ # class_name_property: :_classname
34
+
35
+ transform_rel_type: :upcase
36
+
37
+ # Enforce has_one relationship. When same reationship is created on reverse object with another object, raise the error.
38
+ enforce_has_one: false
data/lib/neo4j.rb ADDED
@@ -0,0 +1,116 @@
1
+ require 'forwardable'
2
+ require 'neo4j/version'
3
+
4
+ require 'neo4j/core'
5
+ require 'neo4j/core/query_ext' # From this gem
6
+
7
+ require 'neo4j/active_base'
8
+ require 'neo4j/model_schema'
9
+
10
+ require 'active_model'
11
+ require 'active_support/concern'
12
+ require 'active_support/core_ext/class/attribute.rb'
13
+ require 'active_support/core_ext/class/subclasses.rb'
14
+ require 'active_support/core_ext/module/attribute_accessors'
15
+ require 'json'
16
+
17
+ require 'neo4j/errors'
18
+ require 'neo4j/config'
19
+ require 'neo4j/wrapper'
20
+ require 'neo4j/active_rel/rel_wrapper'
21
+ require 'neo4j/active_node/node_wrapper'
22
+ require 'neo4j/shared/type_converters'
23
+ require 'neo4j/shared/rel_type_converters'
24
+ require 'neo4j/shared/marshal'
25
+ require 'neo4j/type_converters'
26
+ require 'neo4j/paginated'
27
+ require 'neo4j/schema/operation'
28
+
29
+ require 'neo4j/timestamps'
30
+ require 'neo4j/undeclared_properties'
31
+
32
+ require 'neo4j/shared/callbacks'
33
+ require 'neo4j/shared/filtered_hash'
34
+ require 'neo4j/shared/declared_property/index'
35
+ require 'neo4j/shared/declared_property'
36
+ require 'neo4j/shared/declared_properties'
37
+ require 'neo4j/shared/enum'
38
+ require 'neo4j/shared/mass_assignment'
39
+ require 'neo4j/shared/attributes'
40
+ require 'neo4j/shared/typecasted_attributes'
41
+ require 'neo4j/shared/property'
42
+ require 'neo4j/shared/persistence'
43
+ require 'neo4j/shared/validations'
44
+ require 'neo4j/shared/identity'
45
+ require 'neo4j/shared/serialized_properties'
46
+ require 'neo4j/shared/typecaster'
47
+ require 'neo4j/shared/initialize'
48
+ require 'neo4j/shared/query_factory'
49
+ require 'neo4j/shared/cypher'
50
+ require 'neo4j/shared/permitted_attributes'
51
+ require 'neo4j/shared'
52
+
53
+ require 'neo4j/active_rel/callbacks'
54
+ require 'neo4j/active_rel/initialize'
55
+ require 'neo4j/active_rel/property'
56
+ require 'neo4j/active_rel/persistence/query_factory'
57
+ require 'neo4j/active_rel/persistence'
58
+ require 'neo4j/active_rel/validations'
59
+ require 'neo4j/active_rel/query'
60
+ require 'neo4j/active_rel/related_node'
61
+ require 'neo4j/active_rel/types'
62
+ require 'neo4j/active_rel'
63
+
64
+ require 'neo4j/active_node/node_list_formatter'
65
+ require 'neo4j/active_node/dependent'
66
+ require 'neo4j/active_node/dependent/query_proxy_methods'
67
+ require 'neo4j/active_node/dependent/association_methods'
68
+ require 'neo4j/active_node/enum'
69
+ require 'neo4j/active_node/query_methods'
70
+ require 'neo4j/active_node/query/query_proxy_methods'
71
+ require 'neo4j/active_node/query/query_proxy_methods_of_mass_updating'
72
+ require 'neo4j/active_node/query/query_proxy_enumerable'
73
+ require 'neo4j/active_node/query/query_proxy_find_in_batches'
74
+ require 'neo4j/active_node/query/query_proxy_eager_loading'
75
+ require 'neo4j/active_node/query/query_proxy_eager_loading/association_tree'
76
+ require 'neo4j/active_node/query/query_proxy_link'
77
+ require 'neo4j/active_node/labels/index'
78
+ require 'neo4j/active_node/labels/reloading'
79
+ require 'neo4j/active_node/labels'
80
+ require 'neo4j/active_node/id_property/accessor'
81
+ require 'neo4j/active_node/id_property'
82
+ require 'neo4j/active_node/callbacks'
83
+ require 'neo4j/active_node/initialize'
84
+ require 'neo4j/active_node/property'
85
+ require 'neo4j/active_node/persistence'
86
+ require 'neo4j/active_node/validations'
87
+ require 'neo4j/active_node/rels'
88
+ require 'neo4j/active_node/reflection'
89
+ require 'neo4j/active_node/unpersisted'
90
+ require 'neo4j/active_node/has_n'
91
+ require 'neo4j/active_node/has_n/association_cypher_methods'
92
+ require 'neo4j/active_node/has_n/association/rel_wrapper'
93
+ require 'neo4j/active_node/has_n/association/rel_factory'
94
+ require 'neo4j/active_node/has_n/association'
95
+ require 'neo4j/active_node/query/query_proxy'
96
+ require 'neo4j/active_node/query'
97
+ require 'neo4j/active_node/scope'
98
+ require 'neo4j/active_node'
99
+
100
+ require 'active_support/concern'
101
+ require 'neo4j/core/cypher_error'
102
+ require 'neo4j/core/schema_errors'
103
+
104
+ module Neo4j
105
+ extend ActiveSupport::Autoload
106
+ autoload :Migrations
107
+ autoload :Migration
108
+ end
109
+
110
+ load 'neo4j/tasks/migration.rake'
111
+
112
+ require 'neo4j/active_node/orm_adapter'
113
+ if defined?(Rails)
114
+ require 'rails/generators'
115
+ require 'rails/generators/neo4j_generator'
116
+ end
@@ -0,0 +1,89 @@
1
+ module Neo4j
2
+ # To contain any base login for ActiveNode/ActiveRel which
3
+ # is external to the main classes
4
+ module ActiveBase
5
+ at_exit do
6
+ @driver&.close
7
+ end
8
+
9
+ class << self
10
+ # private?
11
+ def current_driver
12
+ (@driver ||= establish_session).tap do |session|
13
+ fail 'No session defined!' if session.nil?
14
+ end
15
+ end
16
+
17
+ def on_establish_session(&block)
18
+ @establish_session_block = block
19
+ end
20
+
21
+ def establish_session
22
+ @establish_session_block.call if @establish_session_block
23
+ end
24
+
25
+ def new_driver(url, options = {})
26
+ verbose_query_logs = Neo4j::Config.fetch(:verbose_query_logs, false)
27
+ Neo4j::Core::Driver
28
+ .new(url, options.merge(verbose_query_logs: verbose_query_logs))
29
+ end
30
+
31
+ def transaction
32
+ current_transaction || Transaction
33
+ end
34
+
35
+ def query(*args)
36
+ transaction.query(*args)
37
+ end
38
+
39
+ # Should support setting driver via config options
40
+ def driver=(driver)
41
+ @driver&.close
42
+ @driver = driver
43
+ end
44
+
45
+ def run_transaction(run_in_tx = true)
46
+ Transaction.run(current_driver, run_in_tx) do |tx|
47
+ yield tx
48
+ end
49
+ end
50
+
51
+ def new_transaction
52
+ validate_model_schema!
53
+ Neo4j::Transaction.new
54
+ end
55
+
56
+ def new_query(options = {})
57
+ validate_model_schema!
58
+ Neo4j::Core::Query.new({session: current_driver}.merge(options))
59
+ end
60
+
61
+ def magic_query(*args)
62
+ if args.empty? || args.map(&:class) == [Hash]
63
+ ActiveBase.new_query(*args)
64
+ else
65
+ ActiveBase.current_driver.query(*args)
66
+ end
67
+ end
68
+
69
+ def current_transaction
70
+ validate_model_schema!
71
+ Transaction.root
72
+ end
73
+
74
+ def label_object(label_name)
75
+ Neo4j::Core::Label.new(label_name)
76
+ end
77
+
78
+ def logger
79
+ @logger ||= (Neo4j::Config[:logger] || ActiveSupport::Logger.new(STDOUT))
80
+ end
81
+
82
+ private
83
+
84
+ def validate_model_schema!
85
+ Neo4j::ModelSchema.validate_model_schema! unless Neo4j::Migrations.currently_running_migrations
86
+ end
87
+ end
88
+ end
89
+ end
@@ -0,0 +1,108 @@
1
+ module Neo4j
2
+ # Makes Neo4j nodes and relationships behave like ActiveRecord objects.
3
+ # By including this module in your class it will create a mapping for the node to your ruby class
4
+ # by using a Neo4j Label with the same name as the class. When the node is loaded from the database it
5
+ # will check if there is a ruby class for the labels it has.
6
+ # If there Ruby class with the same name as the label then the Neo4j node will be wrapped
7
+ # in a new object of that class.
8
+ #
9
+ # = ClassMethods
10
+ # * {Neo4j::ActiveNode::Labels::ClassMethods} defines methods like: <tt>index</tt> and <tt>find</tt>
11
+ # * {Neo4j::ActiveNode::Persistence::ClassMethods} defines methods like: <tt>create</tt> and <tt>create!</tt>
12
+ # * {Neo4j::ActiveNode::Property::ClassMethods} defines methods like: <tt>property</tt>.
13
+ #
14
+ # @example Create a Ruby wrapper for a Neo4j Node
15
+ # class Company
16
+ # include Neo4j::ActiveNode
17
+ # property :name
18
+ # end
19
+ # company = Company.new
20
+ # company.name = 'My Company AB'
21
+ # Company.save
22
+ #
23
+ module ActiveNode
24
+ extend ActiveSupport::Concern
25
+
26
+ MARSHAL_INSTANCE_VARIABLES = [:@attributes, :@_persisted_obj, :@default_property_value]
27
+
28
+ include Neo4j::Shared
29
+ include Neo4j::Shared::Identity
30
+ include Neo4j::Shared::Marshal
31
+ include Neo4j::ActiveNode::Initialize
32
+ include Neo4j::ActiveNode::IdProperty
33
+ include Neo4j::Shared::SerializedProperties
34
+ include Neo4j::ActiveNode::Property
35
+ include Neo4j::ActiveNode::Reflection
36
+ include Neo4j::ActiveNode::Persistence
37
+ include Neo4j::ActiveNode::Validations
38
+ include Neo4j::ActiveNode::Callbacks
39
+ include Neo4j::ActiveNode::Query
40
+ include Neo4j::ActiveNode::Labels
41
+ include Neo4j::ActiveNode::Rels
42
+ include Neo4j::ActiveNode::Unpersisted
43
+ include Neo4j::ActiveNode::HasN
44
+ include Neo4j::ActiveNode::Scope
45
+ include Neo4j::ActiveNode::Dependent
46
+ include Neo4j::ActiveNode::Enum
47
+ include Neo4j::Shared::PermittedAttributes
48
+
49
+ def initialize(args = nil)
50
+ self.class.ensure_id_property_info! # So that we make sure all objects have an id_property
51
+
52
+ args = sanitize_input_parameters(args)
53
+ super(args)
54
+ end
55
+
56
+ def neo4j_obj
57
+ _persisted_obj || fail('Tried to access native neo4j object on a non persisted object')
58
+ end
59
+
60
+ LOADED_CLASSES = []
61
+
62
+ def self.loaded_classes
63
+ LOADED_CLASSES
64
+ end
65
+
66
+ module ClassMethods
67
+ def nodeify(object)
68
+ if object.is_a?(::Neo4j::ActiveNode) || object.nil?
69
+ object
70
+ else
71
+ self.find(object)
72
+ end
73
+ end
74
+ end
75
+
76
+ included do
77
+ include Neo4j::Timestamps if Neo4j::Config[:record_timestamps]
78
+ LOADED_CLASSES << self
79
+
80
+ def self.inherited?
81
+ !!@inherited
82
+ end
83
+
84
+ def self.inherited(other)
85
+ Neo4j::ActiveNode::Labels.clear_wrapped_models
86
+
87
+ LOADED_CLASSES << other
88
+ other.instance_variable_set('@inherited', true)
89
+ inherit_id_property(other)
90
+ attributes.each_pair do |k, v|
91
+ other.inherit_property k.to_sym, v.clone, declared_properties[k].options
92
+ end
93
+
94
+ Neo4j::ActiveNode::Labels.add_wrapped_class(other)
95
+ super
96
+ end
97
+
98
+ def self.inherit_id_property(other)
99
+ return if other.manual_id_property? || !self.id_property?
100
+ id_prop = self.id_property_info
101
+ conf = id_prop[:type].empty? && id_prop[:name] != :neo_id ? {auto: :uuid} : id_prop[:type]
102
+ other.id_property id_prop[:name], conf, true
103
+ end
104
+ end
105
+
106
+ ActiveSupport.run_load_hooks(:active_node, self)
107
+ end
108
+ end