Sha256: 9cca3b093ddb5cdb356934f0141449660db40961e307f1a7734674800b7bedd4

Contents?: true

Size: 1.6 KB

Versions: 4

Compression:

Stored size: 1.6 KB

Contents

require 'active_support/core_ext/module/attribute_accessors'
require 'neo4j/core/logging'
require 'neo4j/core/has_uri'
require 'neo4j/version'

module Neo4j
  module Core
    class Driver
      include HasUri

      USER_AGENT_STRING = "neo4j-gem/#{::Neo4j::VERSION} (https://github.com/neo4jrb/neo4j)"

      attr_accessor :wrap_level
      attr_reader :options, :driver
      delegate :close, to: :driver

      default_url('bolt://neo4:neo4j@localhost:7687')

      validate_uri do |uri|
        uri.scheme == 'bolt'
      end

      class << self
        def new_instance(url)
          uri = URI(url)
          user = uri.user
          password = uri.password
          auth_token = if user
                         Neo4j::Driver::AuthTokens.basic(user, password)
                       else
                         Neo4j::Driver::AuthTokens.none
                       end
          Neo4j::Driver::GraphDatabase.driver(url, auth_token)
        end
      end

      def initialize(url, options = {})
        self.url = url
        @driver = self.class.new_instance(url)
        @options = options
      end

      def logger
        return @logger if @logger

        @logger = if @options[:logger]
                    @options[:logger]
                  else
                    Logger.new(logger_location).tap do |logger|
                      logger.level = logger_level
                    end
                  end
      end

      private

      def logger_location
        @options[:logger_location] || STDOUT
      end

      def logger_level
        @options[:logger_level] || Logger::WARN
      end
    end
  end
end

Version data entries

4 entries across 4 versions & 2 rubygems

Version Path
activegraph-10.0.0.pre.alpha.6 lib/neo4j/core/driver.rb
neo4j-10.0.0.pre.alpha.5 lib/neo4j/core/driver.rb
neo4j-10.0.0.pre.alpha.4 lib/neo4j/core/driver.rb
neo4j-10.0.0.pre.alpha.3 lib/neo4j/core/driver.rb