Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Always spell adapter with a e #276

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 3 additions & 3 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,7 @@ This project adheres to [Semantic Versioning](http://semver.org/).

### Changed

- Raise standard `Neo4j::Core::CypherSession::ConnectionFailedError` error instead of individual errors from adaptors
- Raise standard `Neo4j::Core::CypherSession::ConnectionFailedError` error instead of individual errors from adapters

## [7.0.0.alpha.3] - 2016-08-04

Expand Down Expand Up @@ -145,7 +145,7 @@ This release contains no changes since the last alpha. Below are all modificatio

### Added

- New session, adaptors, and rewritten Node, Relationship, and Path classes. They are not yet in use but are part of ongoing refactoring and rebuilding.
- New session, adapters, and rewritten Node, Relationship, and Path classes. They are not yet in use but are part of ongoing refactoring and rebuilding.

### Fixed

Expand Down Expand Up @@ -190,7 +190,7 @@ This release contains no changes since the last alpha. Below are all modificatio
- Refactored `Neo4j::Label#create_index` and `Neo4j::Label#create_constraint` to have compatible signatures. As part of the refactoring of `Neo4j::Label#creator_index`, the method no longer accepts multiple properties. The method will need to be called once for each, when needed.

### Added
- New session, adaptors, and rewritten Node, Relationship, and Path classes. They are not yet in use but are part of ongoing refactoring and rebuilding.
- New session, adapters, and rewritten Node, Relationship, and Path classes. They are not yet in use but are part of ongoing refactoring and rebuilding.

## [5.1.12] - 2015-11-23

Expand Down
12 changes: 6 additions & 6 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -7,17 +7,17 @@ It can be used standalone without the neo4j gem.

### Executing Cypher queries

To make a basic connection to Neo4j to execute Cypher queries, first choose an adaptor. Adaptors for HTTP and Embedded mode (jRuby only) are available (support for Neo4j 3.0's [Bolt protocol](http://alpha.neohq.net/docs/server-manual/bolt.html) is planned). You can create an adaptor like:
To make a basic connection to Neo4j to execute Cypher queries, first choose an adapter. Adapters for HTTP and Embedded mode (jRuby only) are available (support for Neo4j 3.0's [Bolt protocol](http://alpha.neohq.net/docs/server-manual/bolt.html) is planned). You can create an adapter like:

http_adaptor = Neo4j::Core::CypherSession::Adaptors::HTTP.new('http://neo4j:pass@localhost:7474')
http_adapter = Neo4j::Core::CypherSession::Adapters::HTTP.new('http://neo4j:pass@localhost:7474')

# or

neo4j_adaptor = Neo4j::Core::CypherSession::Adaptors::Embedded.new('/file/path/to/graph.db')
neo4j_adapter = Neo4j::Core::CypherSession::Adapters::Embedded.new('/file/path/to/graph.db')

Once you have an adaptor you can create a session like so:
Once you have an adapter you can create a session like so:

neo4j_session = Neo4j::Core::CypherSession.new(http_adaptor)
neo4j_session = Neo4j::Core::CypherSession.new(http_adapter)

From there you can make queries with a Cypher string:

Expand All @@ -33,7 +33,7 @@ Or via the `Neo4j::Core::Query` class

neo4j_session.query(query_obj)

Making multiple queries with one request is support with the HTTP Adaptor:
Making multiple queries with one request is support with the HTTP Adapter:

results = neo4j_session.queries do
append 'MATCH (n:Foo) RETURN n LIMIT 10'
Expand Down
2 changes: 1 addition & 1 deletion lib/neo4j-embedded/embedded_session.rb
Original file line number Diff line number Diff line change
Expand Up @@ -77,7 +77,7 @@ def self.transaction_class
Neo4j::Embedded::EmbeddedTransaction
end

# Duplicate of CypherSession::Adaptor::Base#transaction
# Duplicate of CypherSession::Adapter::Base#transaction
def transaction
return self.class.transaction_class.new(self) if !block_given?

Expand Down
2 changes: 1 addition & 1 deletion lib/neo4j-server/cypher_session.rb
Original file line number Diff line number Diff line change
Expand Up @@ -94,7 +94,7 @@ def self.transaction_class
Neo4j::Server::CypherTransaction
end

# Duplicate of CypherSession::Adaptor::Base#transaction
# Duplicate of CypherSession::Adapter::Base#transaction
def transaction
return self.class.transaction_class.new(self) if !block_given?

Expand Down
14 changes: 7 additions & 7 deletions lib/neo4j/core/cypher_session.rb
Original file line number Diff line number Diff line change
@@ -1,14 +1,14 @@
module Neo4j
module Core
class CypherSession
attr_reader :adaptor
attr_reader :adapter

def initialize(adaptor)
fail ArgumentError, "Invalid adaptor: #{adaptor.inspect}" if !adaptor.is_a?(Adaptors::Base)
def initialize(adapter)
fail ArgumentError, "Invalid adapter: #{adapter.inspect}" if !adapter.is_a?(Adapters::Base)

@adaptor = adaptor
@adapter = adapter

@adaptor.connect
@adapter.connect
end

def transaction_class
Expand All @@ -19,7 +19,7 @@ def transaction_class
version
).each do |method, &_block|
define_method(method) do |*args, &block|
@adaptor.send(method, *args, &block)
@adapter.send(method, *args, &block)
end
end

Expand All @@ -33,7 +33,7 @@ def transaction_class
constraints
).each do |method, &_block|
define_method(method) do |*args, &block|
@adaptor.send(method, self, *args, &block)
@adapter.send(method, self, *args, &block)
end
end
end
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -47,7 +47,7 @@ class IndexAlreadyExistsError < CypherError; end
end
class ConnectionFailedError < StandardError; end

module Adaptors
module Adapters
MAP = {}

class Base
Expand Down Expand Up @@ -124,7 +124,7 @@ def queries(session, options = {}, &block)
:constraints,
:connected?].each do |method|
define_method(method) do |*_args|
fail "##{method} method not implemented on adaptor!"
fail "##{method} method not implemented on adapter!"
end
end

Expand Down Expand Up @@ -188,7 +188,7 @@ def instrument_queries(queries)
end

def transaction_class
fail '.transaction_class method not implemented on adaptor!'
fail '.transaction_class method not implemented on adapter!'
end
end

Expand Down
Original file line number Diff line number Diff line change
@@ -1,17 +1,17 @@
require 'neo4j/core/cypher_session/adaptors'
require 'neo4j/core/cypher_session/adaptors/has_uri'
require 'neo4j/core/cypher_session/adaptors/bolt/pack_stream'
require 'neo4j/core/cypher_session/adaptors/bolt/chunk_writer_io'
require 'neo4j/core/cypher_session/adapters'
require 'neo4j/core/cypher_session/adapters/has_uri'
require 'neo4j/core/cypher_session/adapters/bolt/pack_stream'
require 'neo4j/core/cypher_session/adapters/bolt/chunk_writer_io'
require 'neo4j/core/cypher_session/responses/bolt'
require 'io/wait'

# TODO: Work with `Query` objects
module Neo4j
module Core
class CypherSession
module Adaptors
module Adapters
class Bolt < Base
include Adaptors::HasUri
include Adapters::HasUri
default_url('bolt://neo4:neo4j@localhost:7687')
validate_uri do |uri|
uri.scheme == 'bolt'
Expand Down
Original file line number Diff line number Diff line change
@@ -1,11 +1,11 @@
require 'neo4j/core/cypher_session/adaptors'
require 'neo4j/core/cypher_session/adapters'
require 'neo4j/core/cypher_session/responses/embedded'
require 'active_support/hash_with_indifferent_access'

module Neo4j
module Core
class CypherSession
module Adaptors
module Adapters
class Embedded < Base
attr_reader :graph_db, :path

Expand Down Expand Up @@ -52,7 +52,7 @@ def version

def indexes(session, _label = nil)
Transaction.run(session) do
graph_db = session.adaptor.graph_db
graph_db = session.adapter.graph_db

graph_db.schema.get_indexes.map do |definition|
{properties: definition.property_keys.map(&:to_sym),
Expand Down Expand Up @@ -100,7 +100,7 @@ def execution_results(queries)
end

def all_labels(session)
Java::OrgNeo4jTooling::GlobalGraphOperations.at(session.adaptor.graph_db).get_all_labels.to_a
Java::OrgNeo4jTooling::GlobalGraphOperations.at(session.adapter.graph_db).get_all_labels.to_a
end

def indifferent_params(query)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,8 +3,8 @@
module Neo4j
module Core
class CypherSession
module Adaptors
# Containing the logic for dealing with adaptors which use URIs
module Adapters
# Containing the logic for dealing with adapters which use URIs
module HasUri
extend ActiveSupport::Concern

Expand Down
Original file line number Diff line number Diff line change
@@ -1,12 +1,12 @@
require 'neo4j/core/cypher_session/adaptors'
require 'neo4j/core/cypher_session/adaptors/has_uri'
require 'neo4j/core/cypher_session/adapters'
require 'neo4j/core/cypher_session/adapters/has_uri'
require 'neo4j/core/cypher_session/responses/http'

# TODO: Work with `Query` objects
module Neo4j
module Core
class CypherSession
module Adaptors
module Adapters
class HTTP < Base
attr_reader :requestor, :url

Expand Down Expand Up @@ -90,7 +90,7 @@ def connected?
# - Takes care of JSONifying objects passed as body (Hash/Array/Query)
# - Sets headers, including user agent string
class Requestor
include Adaptors::HasUri
include Adapters::HasUri
default_url('http://neo4:neo4j@localhost:7474')
validate_uri { |uri| uri.is_a?(URI::HTTP) }

Expand Down
10 changes: 5 additions & 5 deletions lib/neo4j/core/cypher_session/transactions.rb
Original file line number Diff line number Diff line change
Expand Up @@ -12,19 +12,19 @@ def query(*args)
end
options[:transaction] ||= self

adaptor.query(@session, *args)
adapter.query(@session, *args)
end

def queries(options = {}, &block)
adaptor.queries(@session, {transaction: self}.merge(options), &block)
adapter.queries(@session, {transaction: self}.merge(options), &block)
end

private

# Because we're inheriting from the old Transaction class
# but the new adaptors work much like the old sessions
def adaptor
@session.adaptor
# but the new adapters work much like the old sessions
def adapter
@session.adapter
end
end
end
Expand Down
4 changes: 2 additions & 2 deletions lib/neo4j/core/cypher_session/transactions/bolt.rb
Original file line number Diff line number Diff line change
Expand Up @@ -26,8 +26,8 @@ def started?
private

def tx_query(cypher)
query = Adaptors::Base::Query.new(cypher, {}, cypher)
adaptor.send(:query_set, self, [query], skip_instrumentation: true)
query = Adapters::Base::Query.new(cypher, {}, cypher)
adapter.send(:query_set, self, [query], skip_instrumentation: true)
end
end
end
Expand Down
2 changes: 1 addition & 1 deletion lib/neo4j/core/cypher_session/transactions/embedded.rb
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ module Transactions
class Embedded < Base
def initialize(*args)
super
@java_tx = adaptor.graph_db.begin_tx
@java_tx = adapter.graph_db.begin_tx
end

def commit
Expand Down
8 changes: 4 additions & 4 deletions lib/neo4j/core/cypher_session/transactions/http.rb
Original file line number Diff line number Diff line change
Expand Up @@ -5,15 +5,15 @@ module Core
class CypherSession
module Transactions
class HTTP < Base
# Should perhaps have transaction adaptors only define #close
# Should perhaps have transaction adapters only define #close
# commit/delete are, I think, an implementation detail

def commit
adaptor.requestor.request(:post, query_path(true)) if started?
adapter.requestor.request(:post, query_path(true)) if started?
end

def delete
adaptor.requestor.request(:delete, query_path) if started?
adapter.requestor.request(:delete, query_path) if started?
end

def query_path(commit = false)
Expand Down Expand Up @@ -43,7 +43,7 @@ def id
private

def connection
adaptor.connection
adapter.connection
end
end
end
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
# encoding: UTF-8

require './lib/neo4j/core/cypher_session/adaptors/bolt/pack_stream'
require './lib/neo4j/core/cypher_session/adapters/bolt/pack_stream'

module Neo4j
# rubocop:disable Metrics/ModuleLength
Expand Down
Original file line number Diff line number Diff line change
@@ -1,19 +1,19 @@
require 'spec_helper'
require 'neo4j/core/cypher_session/adaptors/bolt'
require './spec/neo4j/core/shared_examples/adaptor'
require 'neo4j/core/cypher_session/adapters/bolt'
require './spec/neo4j/core/shared_examples/adapter'

describe Neo4j::Core::CypherSession::Adaptors::Bolt, bolt: true do
let(:adaptor_class) { Neo4j::Core::CypherSession::Adaptors::Bolt }
describe Neo4j::Core::CypherSession::Adapters::Bolt, bolt: true do
let(:adapter_class) { Neo4j::Core::CypherSession::Adapters::Bolt }
let(:url) { ENV['NEO4J_BOLT_URL'] }

# let(:adaptor) { adaptor_class.new(url, logger_level: Logger::DEBUG) }
let(:adaptor) { adaptor_class.new(url) }
# let(:adapter) { adapter_class.new(url, logger_level: Logger::DEBUG) }
let(:adapter) { adapter_class.new(url) }

subject { adaptor }
subject { adapter }

describe '#initialize' do
before do
allow_any_instance_of(adaptor_class).to receive(:open_socket)
allow_any_instance_of(adapter_class).to receive(:open_socket)
end

let_context(url: 'url') { subject_should_raise ArgumentError, /Invalid URL/ }
Expand All @@ -32,9 +32,9 @@
let_context(url: 'bolt://foo:bar@localhost:7687') { subject_should_not_raise }
end

context 'connected adaptor' do
before { adaptor.connect }
context 'connected adapter' do
before { adapter.connect }

it_behaves_like 'Neo4j::Core::CypherSession::Adaptor'
it_behaves_like 'Neo4j::Core::CypherSession::Adapter'
end
end
33 changes: 33 additions & 0 deletions spec/neo4j/core/cypher_session/adapters/embedded_spec.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,33 @@
require 'spec_helper'
require 'neo4j/core/cypher_session/adapters/embedded'
require './spec/neo4j/core/shared_examples/adapter'
require 'tmpdir'

describe Neo4j::Core::CypherSession::Adapters::Embedded do
let(:adapter_class) { Neo4j::Core::CypherSession::Adapters::Embedded }

if Neo4j::Core::Config.using_new_session?
if RUBY_PLATFORM == 'java'
describe '#initialize' do
it 'validates path' do
expect { adapter_class.new('./spec/fixtures/notadirectory') }.to raise_error ArgumentError, /Invalid path:/
expect { adapter_class.new('./spec/fixtures/adirectory') }.not_to raise_error
end
end

before(:all) do
path = Dir.mktmpdir('neo4jrb_embedded_adapter_spec')
@adapter = Neo4j::Core::CypherSession::Adapters::Embedded.new(path)
@adapter.connect
end

let(:adapter) { @adapter }

it_behaves_like 'Neo4j::Core::CypherSession::Adapter'
else
it 'should raise an error' do
expect { adapter_class.new('/') }.to raise_error 'JRuby is required for embedded mode'
end
end
end
end
Loading