lib/neo4j/railtie.rb in neo4j-8.0.4 vs lib/neo4j/railtie.rb in neo4j-8.0.5
- old
+ new
@@ -120,26 +120,34 @@
@yaml_path ||= %w(config/neo4j.yml config/neo4j.yaml).map do |path|
Rails.root.join(path)
end.detect(&:exist?)
end
- TYPE_SUBSCRIBERS = {
- http: Neo4j::Core::CypherSession::Adaptors::HTTP.method(:subscribe_to_request),
- bolt: Neo4j::Core::CypherSession::Adaptors::Bolt.method(:subscribe_to_request),
- embedded: Neo4j::Core::CypherSession::Adaptors::Embedded.method(:subscribe_to_transaction)
- }
-
def register_neo4j_cypher_logging(session_type)
return if @neo4j_cypher_logging_registered
Neo4j::Core::Query.pretty_cypher = Neo4j::Config[:pretty_logged_cypher_queries]
logger_proc = ->(message) do
(Neo4j::Config[:logger] ||= Rails.logger).debug message
end
Neo4j::Core::CypherSession::Adaptors::Base.subscribe_to_query(&logger_proc)
- TYPE_SUBSCRIBERS[session_type.to_sym].call(&logger_proc)
+ subscribe_to_session_type_logging!(session_type, logger_proc)
@neo4j_cypher_logging_registered = true
+ end
+
+ TYPE_SUBSCRIBERS = {
+ http: Neo4j::Core::CypherSession::Adaptors::HTTP.method(:subscribe_to_request),
+ bolt: Neo4j::Core::CypherSession::Adaptors::Bolt.method(:subscribe_to_request),
+ embedded: Neo4j::Core::CypherSession::Adaptors::Embedded.method(:subscribe_to_transaction)
+ }
+
+ def subscribe_to_session_type_logging!(session_type, logger_proc)
+ if TYPE_SUBSCRIBERS.key?(session_type.to_sym)
+ TYPE_SUBSCRIBERS[session_type.to_sym].call(&logger_proc)
+ else
+ fail ArgumentError, "Invalid session type: #{session_type.inspect} (expected one of #{TYPE_SUBSCRIBERS.keys.inspect})"
+ end
end
end
end