Class: ActiveCypher::ConnectionUrlResolver

Inherits:
Object
  • Object
show all
Defined in:
lib/active_cypher/connection_url_resolver.rb

Overview

ConnectionUrlResolver accepts Cypher-based database URLs and converts them into a normalized configuration hash for adapter resolution.

Supported URL prefixes:

  • neo4j://

  • neo4j+s:// (alias for neo4j+ssc://)

  • neo4j+ssl://

  • neo4j+ssc://

  • memgraph://

  • memgraph+s:// (alias for memgraph+ssc://)

  • memgraph+ssl://

  • memgraph+ssc://

Database resolution:

  • If specified in path: neo4j://localhost:7687/custom_db → db=custom_db

  • Otherwise defaults based on adapter:

    • neo4j://localhost:7687 → db=neo4j

    • memgraph://localhost:7687 → db=memgraph

The output of to_hash follows a consistent pattern:

adapter: "neo4j", # or "memgraph"
username: "user",
password: "pass",
host: "localhost",
port: 7687,
database: "neo4j", # or "memgraph" or custom path value
ssl: true,
ssc: false,
options: { # future-proof for params like '?timeout=30'

}

Constant Summary collapse

SUPPORTED_ADAPTERS =
%w[neo4j memgraph].freeze
DEFAULT_PORT =
7687

Instance Method Summary collapse

Constructor Details

#initialize(url_string) ⇒ ConnectionUrlResolver

Initialize with a URL string

Parameters:

  • url_string (String)

    A connection URL string



44
45
46
47
# File 'lib/active_cypher/connection_url_resolver.rb', line 44

def initialize(url_string)
  @url_string = url_string
  @parsed = parse_url(url_string)
end

Instance Method Details

#ssl_connection_paramsHash

Returns SSL/TLS connection parameters based on ssl/ssc flags

Returns:

  • (Hash)

    Connection parameters for SSL/TLS



69
70
71
72
73
74
75
76
# File 'lib/active_cypher/connection_url_resolver.rb', line 69

def ssl_connection_params
  return {} unless @parsed

  {
    secure: @parsed[:ssl] ? true : false,
    verify_cert: @parsed[:ssc] ? false : true
  }
end

#to_hashHash

Convert the URL to a normalized hash configuration

Returns:

  • (Hash)

    Configuration hash with adapter, host, port, etc.



51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
# File 'lib/active_cypher/connection_url_resolver.rb', line 51

def to_hash
  return nil unless @parsed

  {
    adapter: @parsed[:adapter],
    host: @parsed[:host],
    port: @parsed[:port],
    username: @parsed[:username],
    password: @parsed[:password],
    database: @parsed[:database],
    ssl: @parsed[:ssl],
    ssc: @parsed[:ssc],
    options: @parsed[:options]
  }
end