Class: Tina4::GraphDatabase
- Inherits:
-
Object
- Object
- Tina4::GraphDatabase
- Defined in:
- lib/tina4/graph.rb
Overview
The URL-selected graph factory — the GraphDatabase sibling of Database.
Constant Summary collapse
- ENGINE_ADAPTERS =
engine -> { require:, class:, package:, install: }. Selected lazily so requiring
tina4/graphpulls in NO engine driver.ultipa wraps the OPTIONAL
tina4-ultipagem (a missing gem surfaces as the actionable install error). bolt (Neo4j/Memgraph) and arango are pure-Ruby over stdlib (+socket+ /Net::HTTP) — zero third-party gems, so theirrequirealways succeeds and the install line is never reached; it stays declared for a uniform registry shape. { "ultipa" => { require: "tina4/drivers/ultipa_graph_driver", class: "Tina4::Drivers::UltipaGraphDriver", package: "tina4-ultipa", install: "gem install tina4-ultipa # or add gem \"tina4-ultipa\" to your Gemfile", }, "bolt" => { require: "tina4/drivers/bolt_graph_driver", class: "Tina4::Drivers::BoltGraphDriver", package: "tina4ruby (built-in, stdlib socket)", install: "no install needed — the Bolt driver ships with tina4ruby", }, "arango" => { require: "tina4/drivers/arango_graph_driver", class: "Tina4::Drivers::ArangoGraphDriver", package: "tina4ruby (built-in, stdlib Net::HTTP)", install: "no install needed — the ArangoDB driver ships with tina4ruby", }, }
Class Method Summary collapse
-
.create(url, username: "", password: "") ⇒ Object
Parse the URL, pick the engine adapter, connect lazily.
-
.from_env(env_key: "TINA4_GRAPH_URL") ⇒ Object
Build from TINA4_GRAPH_URL (+ TINA4_GRAPH_USERNAME/_PASSWORD).
Class Method Details
.create(url, username: "", password: "") ⇒ Object
Parse the URL, pick the engine adapter, connect lazily.
The engine driver is required only here (first use of that engine); if it is absent the error names the package and the install command.
295 296 297 298 299 300 301 302 303 304 305 306 307 308 309 310 311 312 313 314 315 316 317 318 |
# File 'lib/tina4/graph.rb', line 295 def self.create(url, username: "", password: "") graph_url = GraphUrl.new(url) registration = ENGINE_ADAPTERS[graph_url.engine] if registration.nil? raise GraphError, "No graph adapter for engine '#{graph_url.engine}' yet " \ "(scheme '#{graph_url.scheme}'). Available: " \ "#{ENGINE_ADAPTERS.keys.sort.join(', ')}." end begin require registration[:require] rescue LoadError => e # The adapter file requires its driver gem at the top; a missing gem # surfaces here as an actionable install error, never a bare LoadError. raise GraphError, "The graph driver for '#{graph_url.engine}' is not installed " \ "(#{registration[:package]}). Install it with:\n #{registration[:install]}", cause: e end adapter_class = Object.const_get(registration[:class]) adapter_class.new(graph_url, username: username, password: password) end |
.from_env(env_key: "TINA4_GRAPH_URL") ⇒ Object
Build from TINA4_GRAPH_URL (+ TINA4_GRAPH_USERNAME/_PASSWORD).
321 322 323 324 325 326 327 328 |
# File 'lib/tina4/graph.rb', line 321 def self.from_env(env_key: "TINA4_GRAPH_URL") url = ENV[env_key] return nil if url.nil? || url.strip.empty? create(url, username: ENV["TINA4_GRAPH_USERNAME"].to_s, password: ENV["TINA4_GRAPH_PASSWORD"].to_s) end |