lib/neo4j/railtie.rb in neo4j-4.1.5 vs lib/neo4j/railtie.rb in neo4j-5.0.0.rc.1

- old
+ new

@@ -19,23 +19,28 @@ def java_platform? RUBY_PLATFORM =~ /java/ end def setup_default_session(cfg) + setup_config_defaults!(cfg) + + return if !cfg.sessions.empty? + + cfg.sessions << {type: cfg.session_type, path: cfg.session_path, options: cfg.session_options} + end + + def setup_config_defaults!(cfg) cfg.session_type ||= :server_db cfg.session_path ||= 'http://localhost:7474' cfg.session_options ||= {} cfg.sessions ||= [] - unless (uri = URI(cfg.session_path)).user.blank? - cfg.session_options.reverse_merge!(basic_auth: {username: uri.user, password: uri.password}) - cfg.session_path = cfg.session_path.gsub("#{uri.user}:#{uri.password}@", '') - end + uri = URI(cfg.session_path) + return if uri.user.blank? - if cfg.sessions.empty? - cfg.sessions << {type: cfg.session_type, path: cfg.session_path, options: cfg.session_options} - end + cfg.session_options.reverse_merge!(basic_auth: {username: uri.user, password: uri.password}) + cfg.session_path = cfg.session_path.gsub("#{uri.user}:#{uri.password}@", '') end def start_embedded_session(session) # See https://github.com/jruby/jruby/wiki/UnlimitedStrengthCrypto @@ -61,10 +66,20 @@ start_embedded_session(session) if type == :embedded_db end end + def register_neo4j_cypher_logging + return if @neo4j_cypher_logging_registered + + Neo4j::Server::CypherSession.log_with do |message| + Rails.logger.info message + end + + @neo4j_cypher_logging_registered = true + end + # Starting Neo after :load_config_initializers allows apps to # register migrations in config/initializers initializer 'neo4j.start', after: :load_config_initializers do |app| cfg = app.config.neo4j # Set Rails specific defaults @@ -73,16 +88,13 @@ cfg.sessions.each do |session_opts| Neo4j::Railtie.open_neo4j_session(session_opts) end Neo4j::Config.configuration.merge!(cfg.to_hash) - clear = "\e[0m" - yellow = "\e[33m" - cyan = "\e[36m" + register_neo4j_cypher_logging + end - ActiveSupport::Notifications.subscribe('neo4j.cypher_query') do |_, start, finish, _id, payload| - ms = (finish - start) * 1000 - Rails.logger.info " #{cyan}#{payload[:context]}#{clear} #{yellow}#{ms.round}ms#{clear} #{payload[:cypher]}" + (payload[:params].size > 0 ? ' | ' + payload[:params].inspect : '') - end + console do + register_neo4j_cypher_logging end end end