diff --git a/lib/neography/connection.rb b/lib/neography/connection.rb index bdb1fe6..b3256e1 100644 --- a/lib/neography/connection.rb +++ b/lib/neography/connection.rb @@ -16,7 +16,7 @@ class Connection def initialize(options = ENV['NEO4J_URL'] || {}) config = merge_configuration(options) save_local_configuration(config) - @client = HTTPClient.new(config[:proxy]) + @client ||= HTTPClient.new(config[:proxy]) @client.send_timeout = 1200 # 10 minutes @client.receive_timeout = 1200 authenticate diff --git a/lib/neography/rest.rb b/lib/neography/rest.rb index a27cb85..8e2f8e1 100644 --- a/lib/neography/rest.rb +++ b/lib/neography/rest.rb @@ -48,31 +48,31 @@ class Rest def initialize(options = ENV['NEO4J_URL'] || {}) @connection = Connection.new(options) - @nodes = Nodes.new(@connection) - @node_properties = NodeProperties.new(@connection) - @node_relationships = NodeRelationships.new(@connection) - @other_node_relationships = OtherNodeRelationships.new(@connection) - @node_indexes = NodeIndexes.new(@connection) - @node_auto_indexes = NodeAutoIndexes.new(@connection) - @schema_indexes = SchemaIndexes.new(@connection) - @node_traversal = NodeTraversal.new(@connection) - @node_paths = NodePaths.new(@connection) - @node_labels = NodeLabels.new(@connection) - - @relationships = Relationships.new(@connection) - @relationship_properties = RelationshipProperties.new(@connection) - @relationship_indexes = RelationshipIndexes.new(@connection) - @relationship_auto_indexes = RelationshipAutoIndexes.new(@connection) - @relationship_types = RelationshipTypes.new(@connection) - - @cypher = Cypher.new(@connection) - @gremlin = Gremlin.new(@connection) - @extensions = Extensions.new(@connection) - @batch = Batch.new(@connection) - @clean = Clean.new(@connection) - @transactions = Transactions.new(@connection) - @spatial = Spatial.new(@connection) - @constraints = Constraints.new(@connection) + @nodes ||= Nodes.new(@connection) + @node_properties ||= NodeProperties.new(@connection) + @node_relationships ||= NodeRelationships.new(@connection) + @other_node_relationships ||= OtherNodeRelationships.new(@connection) + @node_indexes ||= NodeIndexes.new(@connection) + @node_auto_indexes ||= NodeAutoIndexes.new(@connection) + @schema_indexes ||= SchemaIndexes.new(@connection) + @node_traversal ||= NodeTraversal.new(@connection) + @node_paths ||= NodePaths.new(@connection) + @node_labels ||= NodeLabels.new(@connection) + + @relationships ||= Relationships.new(@connection) + @relationship_properties ||= RelationshipProperties.new(@connection) + @relationship_indexes ||= RelationshipIndexes.new(@connection) + @relationship_auto_indexes ||= RelationshipAutoIndexes.new(@connection) + @relationship_types ||= RelationshipTypes.new(@connection) + + @cypher ||= Cypher.new(@connection) + @gremlin ||= Gremlin.new(@connection) + @extensions ||= Extensions.new(@connection) + @batch ||= Batch.new(@connection) + @clean ||= Clean.new(@connection) + @transactions ||= Transactions.new(@connection) + @spatial ||= Spatial.new(@connection) + @constraints ||= Constraints.new(@connection) end # meta-data diff --git a/lib/neography/rest/auto_indexes.rb b/lib/neography/rest/auto_indexes.rb index bd2735e..f70d747 100644 --- a/lib/neography/rest/auto_indexes.rb +++ b/lib/neography/rest/auto_indexes.rb @@ -4,7 +4,7 @@ class AutoIndexes include Neography::Rest::Helpers def initialize(connection) - @connection = connection + @connection ||= connection end def get(key, value) diff --git a/lib/neography/rest/batch.rb b/lib/neography/rest/batch.rb index 65d7f62..56f774e 100644 --- a/lib/neography/rest/batch.rb +++ b/lib/neography/rest/batch.rb @@ -7,7 +7,7 @@ class Batch add_path :batch, "/batch" def initialize(connection) - @connection = connection + @connection ||= connection end def execute(*args) diff --git a/lib/neography/rest/clean.rb b/lib/neography/rest/clean.rb index 633094b..69a544d 100644 --- a/lib/neography/rest/clean.rb +++ b/lib/neography/rest/clean.rb @@ -7,7 +7,7 @@ class Clean add_path :clean, "/cleandb/secret-key" def initialize(connection) - @connection = connection + @connection ||= connection end def execute diff --git a/lib/neography/rest/constraints.rb b/lib/neography/rest/constraints.rb index 51d238b..7c56480 100644 --- a/lib/neography/rest/constraints.rb +++ b/lib/neography/rest/constraints.rb @@ -10,7 +10,7 @@ class Constraints add_path :unique, "/schema/constraint/:label/uniqueness/:property" def initialize(connection) - @connection = connection + @connection ||= connection end def drop(label, property) diff --git a/lib/neography/rest/cypher.rb b/lib/neography/rest/cypher.rb index 0c31232..02ceb4a 100644 --- a/lib/neography/rest/cypher.rb +++ b/lib/neography/rest/cypher.rb @@ -4,7 +4,7 @@ class Cypher include Neography::Rest::Helpers def initialize(connection) - @connection = connection + @connection ||= connection end def query(query, parameters = {}, cypher_options = nil) diff --git a/lib/neography/rest/extensions.rb b/lib/neography/rest/extensions.rb index 978e52d..48a64c6 100644 --- a/lib/neography/rest/extensions.rb +++ b/lib/neography/rest/extensions.rb @@ -4,7 +4,7 @@ class Extensions include Neography::Rest::Helpers def initialize(connection) - @connection = connection + @connection ||= connection end def get(path) diff --git a/lib/neography/rest/gremlin.rb b/lib/neography/rest/gremlin.rb index e794412..14ee0f3 100644 --- a/lib/neography/rest/gremlin.rb +++ b/lib/neography/rest/gremlin.rb @@ -4,7 +4,7 @@ class Gremlin include Neography::Rest::Helpers def initialize(connection) - @connection = connection + @connection ||= connection end def execute(script, parameters = {}) diff --git a/lib/neography/rest/indexes.rb b/lib/neography/rest/indexes.rb index 8e73f31..d453388 100644 --- a/lib/neography/rest/indexes.rb +++ b/lib/neography/rest/indexes.rb @@ -4,8 +4,8 @@ class Indexes include Neography::Rest::Helpers def initialize(connection, index_type) - @connection = connection - @index_type = index_type + @connection ||= connection + @index_type ||= index_type end def list diff --git a/lib/neography/rest/node_labels.rb b/lib/neography/rest/node_labels.rb index 85ab331..3189864 100644 --- a/lib/neography/rest/node_labels.rb +++ b/lib/neography/rest/node_labels.rb @@ -11,7 +11,7 @@ class NodeLabels add_path :delete, "/node/:id/labels/:label" def initialize(connection) - @connection = connection + @connection ||= connection end def list diff --git a/lib/neography/rest/node_paths.rb b/lib/neography/rest/node_paths.rb index c18abbc..2495ff9 100644 --- a/lib/neography/rest/node_paths.rb +++ b/lib/neography/rest/node_paths.rb @@ -8,7 +8,7 @@ class NodePaths add_path :all, "/node/:id/paths" def initialize(connection) - @connection = connection + @connection ||= connection end def get(from, to, relationships, depth = 1, algorithm = "shortestPath") diff --git a/lib/neography/rest/node_relationships.rb b/lib/neography/rest/node_relationships.rb index a819438..ee088dd 100644 --- a/lib/neography/rest/node_relationships.rb +++ b/lib/neography/rest/node_relationships.rb @@ -9,7 +9,7 @@ class NodeRelationships add_path :type, "/node/:id/relationships/:direction/:types" def initialize(connection) - @connection = connection + @connection ||= connection end def create(type, from, to, properties = nil) diff --git a/lib/neography/rest/node_traversal.rb b/lib/neography/rest/node_traversal.rb index 20f5ca4..2932139 100644 --- a/lib/neography/rest/node_traversal.rb +++ b/lib/neography/rest/node_traversal.rb @@ -7,7 +7,7 @@ class NodeTraversal add_path :traversal, "/node/:id/traverse/:type" def initialize(connection) - @connection = connection + @connection ||= connection end def traverse(id, return_type, description) diff --git a/lib/neography/rest/nodes.rb b/lib/neography/rest/nodes.rb index 7dc1e9f..0a18764 100644 --- a/lib/neography/rest/nodes.rb +++ b/lib/neography/rest/nodes.rb @@ -8,7 +8,7 @@ class Nodes add_path :base, "/node/:id" def initialize(connection) - @connection = connection + @connection ||= connection end def get(id) diff --git a/lib/neography/rest/other_node_relationships.rb b/lib/neography/rest/other_node_relationships.rb index 14f8d91..6c4c465 100644 --- a/lib/neography/rest/other_node_relationships.rb +++ b/lib/neography/rest/other_node_relationships.rb @@ -7,7 +7,7 @@ class OtherNodeRelationships add_path :base, "/node/:id/traverse/relationship" def initialize(connection) - @connection = connection + @connection ||= connection end def get(id, other_id, direction = "all", types = [nil]) diff --git a/lib/neography/rest/properties.rb b/lib/neography/rest/properties.rb index 35d6c18..896c444 100644 --- a/lib/neography/rest/properties.rb +++ b/lib/neography/rest/properties.rb @@ -4,7 +4,7 @@ class Properties include Neography::Rest::Helpers def initialize(connection) - @connection = connection + @connection ||= connection end def set(id, properties) diff --git a/lib/neography/rest/relationship_types.rb b/lib/neography/rest/relationship_types.rb index faada08..46a6a17 100644 --- a/lib/neography/rest/relationship_types.rb +++ b/lib/neography/rest/relationship_types.rb @@ -6,7 +6,7 @@ class RelationshipTypes add_path :all, "/relationship/types" def initialize(connection) - @connection = connection + @connection ||= connection end def list diff --git a/lib/neography/rest/relationships.rb b/lib/neography/rest/relationships.rb index 265ed95..4191df3 100644 --- a/lib/neography/rest/relationships.rb +++ b/lib/neography/rest/relationships.rb @@ -7,7 +7,7 @@ class Relationships add_path :base, "/relationship/:id" def initialize(connection) - @connection = connection + @connection ||= connection end def get(id) diff --git a/lib/neography/rest/schema_indexes.rb b/lib/neography/rest/schema_indexes.rb index 5b5d385..c538645 100644 --- a/lib/neography/rest/schema_indexes.rb +++ b/lib/neography/rest/schema_indexes.rb @@ -8,7 +8,7 @@ class SchemaIndexes add_path :drop, "/schema/index/:label/:index" def initialize(connection) - @connection = connection + @connection ||= connection end def list(label) diff --git a/lib/neography/rest/spatial.rb b/lib/neography/rest/spatial.rb index 0649522..8933e62 100644 --- a/lib/neography/rest/spatial.rb +++ b/lib/neography/rest/spatial.rb @@ -17,7 +17,7 @@ class Spatial add_path :add_to_index, "/index/node/:index" def initialize(connection) - @connection = connection + @connection ||= connection end def index diff --git a/lib/neography/rest/transactions.rb b/lib/neography/rest/transactions.rb index e8c7506..663aab1 100644 --- a/lib/neography/rest/transactions.rb +++ b/lib/neography/rest/transactions.rb @@ -9,7 +9,7 @@ class Transactions add_path :commit, "/transaction/:id/commit" def initialize(connection) - @connection = connection + @connection ||= connection end def begin(statements = [], commit = "")