Class: Tina4::GraphUrl
- Inherits:
-
Object
- Object
- Tina4::GraphUrl
- Defined in:
- lib/tina4/graph.rb
Overview
A parsed graph connection URL — the DatabaseUrl sibling for graph engines.
engine is the CANONICAL name the factory selects an adapter by; a scheme
alias resolves to its engine here. bolt/neo4j/memgraph all speak Bolt/Cypher
and share ONE adapter ("bolt"); the engine label only tunes per-engine
defaults.
Constant Summary collapse
- SCHEME_ENGINE =
{ "ultipa" => "ultipa", "ultipas" => "ultipa", # TLS variant "neo4j" => "bolt", "neo4j+s" => "bolt", "bolt" => "bolt", "bolt+s" => "bolt", "memgraph" => "bolt", "arango" => "arango", "arangodb" => "arango", }.freeze
- ENGINE_DEFAULT_PORT =
Default port per engine when the URL omits one.
{ "ultipa" => 60_061, "bolt" => 7687, "arango" => 8529, }.freeze
Instance Attribute Summary collapse
-
#engine ⇒ Object
readonly
Returns the value of attribute engine.
-
#graph ⇒ Object
readonly
Returns the value of attribute graph.
-
#host ⇒ Object
readonly
Returns the value of attribute host.
-
#params ⇒ Object
readonly
Returns the value of attribute params.
-
#password ⇒ Object
readonly
Returns the value of attribute password.
-
#port ⇒ Object
readonly
Returns the value of attribute port.
-
#raw ⇒ Object
readonly
Returns the value of attribute raw.
-
#scheme ⇒ Object
readonly
Returns the value of attribute scheme.
-
#use_tls ⇒ Object
readonly
Returns the value of attribute use_tls.
-
#username ⇒ Object
readonly
Returns the value of attribute username.
Class Method Summary collapse
-
.from_env(env_key = "TINA4_GRAPH_URL") ⇒ Object
Parse the configured URL, or
nilwhen the variable is not set.
Instance Method Summary collapse
-
#dsn ⇒ Object
host:port/graph — for messages, never carrying credentials.
-
#initialize(url) ⇒ GraphUrl
constructor
A new instance of GraphUrl.
Constructor Details
#initialize(url) ⇒ GraphUrl
Returns a new instance of GraphUrl.
79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 |
# File 'lib/tina4/graph.rb', line 79 def initialize(url) @raw = url parsed = begin URI.parse(url.to_s) rescue URI::InvalidURIError raise ArgumentError, "GraphUrl: Invalid URL format — expected scheme://host:port/graph" end scheme = (parsed.scheme || "").downcase engine = SCHEME_ENGINE[scheme] if engine.nil? raise ArgumentError, "GraphUrl: Unsupported graph URL scheme '#{scheme}'. Supported: " \ "#{SCHEME_ENGINE.keys.sort.join(', ')} (e.g. ultipa://host:60061/mygraph)." end @scheme = scheme @engine = engine @host = parsed.host && !parsed.host.empty? ? parsed.host : "localhost" @port = parsed.port || ENGINE_DEFAULT_PORT[engine] # The path is the graph/database name (one leading slash stripped). graph = (parsed.path || "").sub(%r{\A/}, "") @graph = graph.empty? ? nil : graph @username = parsed.user ? URI.decode_www_form_component(parsed.user) : nil @password = parsed.password ? URI.decode_www_form_component(parsed.password) : nil @params = URI.decode_www_form(parsed.query || "").to_h # TLS if the scheme says so (…s) or ?tls=1. @use_tls = scheme.end_with?("s") || %w[1 true].include?(@params["tls"]) end |
Instance Attribute Details
#engine ⇒ Object (readonly)
Returns the value of attribute engine.
76 77 78 |
# File 'lib/tina4/graph.rb', line 76 def engine @engine end |
#graph ⇒ Object (readonly)
Returns the value of attribute graph.
76 77 78 |
# File 'lib/tina4/graph.rb', line 76 def graph @graph end |
#host ⇒ Object (readonly)
Returns the value of attribute host.
76 77 78 |
# File 'lib/tina4/graph.rb', line 76 def host @host end |
#params ⇒ Object (readonly)
Returns the value of attribute params.
76 77 78 |
# File 'lib/tina4/graph.rb', line 76 def params @params end |
#password ⇒ Object (readonly)
Returns the value of attribute password.
76 77 78 |
# File 'lib/tina4/graph.rb', line 76 def password @password end |
#port ⇒ Object (readonly)
Returns the value of attribute port.
76 77 78 |
# File 'lib/tina4/graph.rb', line 76 def port @port end |
#raw ⇒ Object (readonly)
Returns the value of attribute raw.
76 77 78 |
# File 'lib/tina4/graph.rb', line 76 def raw @raw end |
#scheme ⇒ Object (readonly)
Returns the value of attribute scheme.
76 77 78 |
# File 'lib/tina4/graph.rb', line 76 def scheme @scheme end |
#use_tls ⇒ Object (readonly)
Returns the value of attribute use_tls.
76 77 78 |
# File 'lib/tina4/graph.rb', line 76 def use_tls @use_tls end |
#username ⇒ Object (readonly)
Returns the value of attribute username.
76 77 78 |
# File 'lib/tina4/graph.rb', line 76 def username @username end |
Class Method Details
.from_env(env_key = "TINA4_GRAPH_URL") ⇒ Object
Parse the configured URL, or nil when the variable is not set.
116 117 118 119 |
# File 'lib/tina4/graph.rb', line 116 def self.from_env(env_key = "TINA4_GRAPH_URL") url = (ENV[env_key] || "").strip url.empty? ? nil : new(url) end |
Instance Method Details
#dsn ⇒ Object
host:port/graph — for messages, never carrying credentials.
110 111 112 113 |
# File 'lib/tina4/graph.rb', line 110 def dsn target = @port ? "#{@host}:#{@port}" : @host @graph ? "#{target}/#{@graph}" : target end |