Configuration¶
To configure any of these variables you can do the following:
In Rails¶
In either config/application.rb or one of the environment configurations (e.g. config/environments/development.rb) you can set config.neo4j.variable_name = value where variable_name and value are as described below.
Other Ruby apps¶
You can set configuration variables directly in the Neo4j configuration class like so: Neo4j::Config[:variable_name] = value where variable_name and value are as described below.
Variables¶
- association_model_namespace
Default:
nilAssociations defined in node models will try to match association names to classes. For example,
has_many :out, :studentwill look for aStudentclass. To avoid having to usemodel_class: 'MyModule::Student', this config option lets you specify the module that should be used globally for class name discovery.Of course, even with this option set, you can always override it by calling
model_class: 'ClassName'.- class_name_property
Default:
:_classnameWhich property should be used to determine the
ActiveNodeclass to wrap the node inIf there is no value for this property on a node the node`s labels will be used to determine the
ActiveNodeclassSee also
- enums_case_sensitive
Default:
falseDetermins whether enums property setters should be case sensitive or not.
See also
activenode-enums
- include_root_in_json
Default:
trueWhen serializing
ActiveNodeandActiveRelobjects, should there be a root in the JSON of the model name.- logger
Default:
nil(orRails.loggerin Rails)A Ruby
Loggerobject which is used to log Cypher queries (info level is used). This is only for theneo4jgem (that is, for models created with theActiveNodeandActiveRelmodules).- module_handling
Default:
:noneAvailable values:
:demodulize,:none,procDetermines what, if anything, should be done to module names when a model’s class is set. By default, there is a direct mapping of an
ActiveNodemodel name to the node label or anActiveRelmodel to the relationship type, so MyModule::MyClass results in a label with the same name.The :demodulize option uses ActiveSupport’s method of the same name to strip off modules. If you use a proc, it will the class name as an argument and you should return a string that modifies it as you see fit.
- pretty_logged_cypher_queries
Default:
nilIf true, format outputted queries with newlines and colors to be more easily readable by humans
- record_timestamps
Default:
falseA Rails-inspired configuration to manage inclusion of the Timestamps module. If set to true, all ActiveNode and ActiveRel models will include the Timestamps module and have
:created_atand:updated_atproperties.- skip_migration_check
Default:
falsePrevents the
neo4jgem from raisingNeo4j::PendingMigrationErrorin web requests when migrations haven’t been run. For environments (like testing) where you need to use theneo4j:schema:loadrake task to build the database instead of migrations. Automatically set totruein Rails test environments by default- timestamp_type
Default:
DateTimeThis method returns the specified default type for the
:created_atand:updated_attimestamps. You can also specify another type (e.g.Integer).- transform_rel_type
Default:
:upcaseAvailable values:
:upcase,:downcase,:legacy,:noneDetermines how relationship types for
ActiveRelmodels are transformed when stored in the database. By default this is upper-case to match with Neo4j convention so if you specify anActiveRelmodel ofHasPostthen the relationship type in the database will beHAS_POST:legacy- Causes the type to be downcased and preceded by a #
:none- Uses the type as specified
- wait_for_connection
Default:
falseThis allows you to tell the gem to wait for up to 60 seconds for Neo4j to be available. This is useful in environments such as Docker Compose. This is currently only for Rails
Instrumented events¶
The neo4j-core gem instruments a handful of events so that users can subscribe to them to do logging, metrics, or anything else that they need. For example, to create a block which is called any time a query is made via the neo4j-core gem:
Neo4j::Core::CypherSession::Adaptors::Base.subscribe_to_query do |message|
puts message
end
The argument to the block (message in this case) will be an ANSI formatted string which can be outputted or stored. If you want to access this event at a lower level, subscribe_to_query is actually tied to the neo4j.core.cypher_query event to which you could subscribe to like:
ActiveSupport::Notifications.subscribe('neo4j.core.cypher_query') do |name, start, finish, id, payload|
puts payload[:query].to_cypher
# or
payload[:query].print_cypher
puts "Query took: #{(finish - start)} seconds"
end
All methods and their corresponding events:
- Neo4j::Core::CypherSession::Adaptors::Base.subscribe_to_query
- neo4j.core.cypher_query
- Neo4j::Core::CypherSession::Adaptors::HTTP.subscribe_to_request
- neo4j.core.http.request
- Neo4j::Core::CypherSession::Adaptors::Bolt.subscribe_to_request
- neo4j.core.bolt.request
- Neo4j::Core::CypherSession::Adaptors::Embedded.subscribe_to_transaction
- neo4j.core.embedded.transaction