Class: ActiveCypher::ConnectionAdapters::AbstractAdapter
- Inherits:
-
Object
- Object
- ActiveCypher::ConnectionAdapters::AbstractAdapter
- Defined in:
- lib/active_cypher/connection_adapters/abstract_adapter.rb
Overview
Because every project needs an abstract class to remind you that nothing is ever truly implemented.
Minimal contract every graph adapter must fulfil.
Direct Known Subclasses
Instance Attribute Summary collapse
-
#config ⇒ Object
readonly
Returns the value of attribute config.
Instance Method Summary collapse
- #active? ⇒ Boolean
-
#begin_transaction ⇒ Object
—- transactions (optional) —————————————— Transaction methods: for when you want to pretend you have ACID.
- #commit_transaction(_) ⇒ Object
-
#connect ⇒ Object
—- lifecycle ——————————————————— The lifecycle methods.
- #disconnect ⇒ Object
-
#execute_cypher ⇒ Object
—- Cypher ———————————————————— Executes a Cypher query, or at least raises an error about it.
-
#hydrate_record(record, node_alias) ⇒ Hash
Hydrates attributes from a database record.
-
#initialize(config) ⇒ AbstractAdapter
constructor
Initializes the adapter, because you can’t spell “configuration” without “con.”.
-
#inspect ⇒ String
Override inspect to hide sensitive information.
-
#prepare_params(raw) ⇒ Object
—- helpers ———————————————————– Prepares parameters for Cypher, because the database can’t read your mind.
-
#process_records(rows) ⇒ Array<Hash>
Turns rows into symbols, because Rubyists fear strings.
- #reconnect ⇒ Object
- #rollback_transaction(_) ⇒ Object
Constructor Details
#initialize(config) ⇒ AbstractAdapter
Initializes the adapter, because you can’t spell “configuration” without “con.”
16 |
# File 'lib/active_cypher/connection_adapters/abstract_adapter.rb', line 16 def initialize(config) = (@config = config) |
Instance Attribute Details
#config ⇒ Object (readonly)
Returns the value of attribute config.
12 13 14 |
# File 'lib/active_cypher/connection_adapters/abstract_adapter.rb', line 12 def config @config end |
Instance Method Details
#active? ⇒ Boolean
22 |
# File 'lib/active_cypher/connection_adapters/abstract_adapter.rb', line 22 def active? = false |
#begin_transaction ⇒ Object
—- transactions (optional) —————————————— Transaction methods: for when you want to pretend you have ACID.
34 |
# File 'lib/active_cypher/connection_adapters/abstract_adapter.rb', line 34 def begin_transaction = nil |
#commit_transaction(_) ⇒ Object
35 |
# File 'lib/active_cypher/connection_adapters/abstract_adapter.rb', line 35 def commit_transaction(_) = true |
#connect ⇒ Object
—- lifecycle ——————————————————— The lifecycle methods. Spoiler: most of them do nothing.
20 |
# File 'lib/active_cypher/connection_adapters/abstract_adapter.rb', line 20 def connect = raise(AdapterNotFoundError) |
#disconnect ⇒ Object
21 |
# File 'lib/active_cypher/connection_adapters/abstract_adapter.rb', line 21 def disconnect = true |
#execute_cypher ⇒ Object
—- Cypher ———————————————————— Executes a Cypher query, or at least raises an error about it.
28 29 30 |
# File 'lib/active_cypher/connection_adapters/abstract_adapter.rb', line 28 def execute_cypher(*) raise NotImplementedError, "#{self.class} must implement #execute_cypher" end |
#hydrate_record(record, node_alias) ⇒ Hash
Hydrates attributes from a database record
56 57 58 |
# File 'lib/active_cypher/connection_adapters/abstract_adapter.rb', line 56 def hydrate_record(record, node_alias) raise NotImplementedError, "#{self.class} must implement #hydrate_record" end |
#inspect ⇒ String
Override inspect to hide sensitive information
67 68 69 70 71 72 |
# File 'lib/active_cypher/connection_adapters/abstract_adapter.rb', line 67 def inspect filtered_config = ActiveCypher::Redaction.filter_hash(config) # Return a safe representation "#<#{self.class}:0x#{object_id.to_s(16)} @config=#{filtered_config.inspect}>" end |
#prepare_params(raw) ⇒ Object
—- helpers ———————————————————– Prepares parameters for Cypher, because the database can’t read your mind. Yet.
42 43 44 45 46 47 48 49 50 |
# File 'lib/active_cypher/connection_adapters/abstract_adapter.rb', line 42 def prepare_params(raw) case raw when Hash then raw.transform_keys(&:to_s).transform_values { |v| prepare_params(v) } when Array then raw.each_with_index.to_h { |v, i| ["p#{i + 1}", prepare_params(v)] } when Time, Date, DateTime then raw.iso8601 when Symbol then raw.to_s else raw # String/Integer/Float/Boolean/NilClass end end |
#process_records(rows) ⇒ Array<Hash>
Turns rows into symbols, because Rubyists fear strings.
63 |
# File 'lib/active_cypher/connection_adapters/abstract_adapter.rb', line 63 def process_records(rows) = rows.map { |r| deep_symbolize(r) } |
#reconnect ⇒ Object
23 |
# File 'lib/active_cypher/connection_adapters/abstract_adapter.rb', line 23 def reconnect = disconnect && connect |
#rollback_transaction(_) ⇒ Object
36 |
# File 'lib/active_cypher/connection_adapters/abstract_adapter.rb', line 36 def rollback_transaction(_) = true |