Class: ActiveCypher::Base
- Inherits:
-
Object
- Object
- ActiveCypher::Base
- Includes:
- Logging, Model::Abstract, Model::Attributes, Model::Callbacks, Model::ConnectionOwner, Model::Core, Model::Countable, Model::Destruction, Model::Labelling, Model::Persistence, Model::Querying, ActiveModel::Attributes, ActiveModel::Callbacks, ActiveModel::Dirty, ActiveModel::Model, ActiveModel::Validations
- Defined in:
- lib/active_cypher/base.rb
Direct Known Subclasses
Constant Summary
Constants included from Model::Callbacks
Instance Attribute Summary collapse
-
#connects_to_mappings ⇒ Hash
Because every base class needs a mapping it will never use directly.
Attributes included from Model::Core
Class Method Summary collapse
-
.connection ⇒ Object
Attempts to retrieve a connection from the handler.
Instance Method Summary collapse
-
#inspect ⇒ Object
Custom object inspection method for pretty-printing a compact, single-line summary of the object.
Methods included from Model::Destruction
Methods included from Model::Persistence
#new_record?, #persisted?, #reload, #save, #update
Methods included from Model::ConnectionOwner
Methods included from Logging
#log_bench, #log_debug, #log_error, #log_info, #log_warn, #logger, logger
Methods included from Model::Core
Instance Attribute Details
#connects_to_mappings ⇒ Hash
Returns Because every base class needs a mapping it will never use directly.
16 |
# File 'lib/active_cypher/base.rb', line 16 class_attribute :connects_to_mappings, default: {} |
Class Method Details
.connection ⇒ Object
Attempts to retrieve a connection from the handler. If you don’t have a pool, you get to enjoy the fallback logic. If you still don’t have a connection, you get an error. It’s the circle of life.
43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 |
# File 'lib/active_cypher/base.rb', line 43 def connection # Determine the current role (e.g., :writing, :reading) # ActiveCypher::RuntimeRegistry.current_role defaults to :writing # Only use db_key for pool lookup if respond_to?(:connects_to_mappings) && connects_to_mappings.is_a?(Hash) db_key = connects_to_mappings[:writing] # or whichever role is appropriate if db_key && (pool = connection_handler.pool(db_key)) return pool.connection end end return @connection if defined?(@connection) && @connection&.active? raise ActiveCypher::ConnectionNotEstablished, "No connection pool found for graph #{name}, db_key=#{db_key.inspect}. " \ 'Ensure `connects_to` is configured for this model or its ancestors, ' \ 'and `cypher_databases.yml` has the corresponding entries.' end |
Instance Method Details
#inspect ⇒ Object
Custom object inspection method for pretty-printing a compact, single-line summary of the object. Output examples:
#<UserNode id="26" name="Alice" age=34> => persisted object
#<UserNode (new) name="Bob"> => object not yet saved
69 70 71 72 73 74 75 76 77 78 79 |
# File 'lib/active_cypher/base.rb', line 69 def inspect # Put 'internal_id' first like it's the main character (even if it's nil) ordered = attributes.dup ordered = ordered.slice('internal_id').merge(ordered.except('internal_id')) # Turn each attr into "key: value" because we humans fear raw hashes parts = ordered.map { |k, v| "#{k}: #{v.inspect}" } # Wrap it all up in a fake-sane object string, so you can pretend your data is organized. "#<#{self.class} #{parts.join(', ')}>" end |