lib/neo4j/railtie.rb in neo4j-8.0.0.alpha.9 vs lib/neo4j/railtie.rb in neo4j-8.0.0.alpha.10

- old
+ new

@@ -56,22 +56,25 @@ Neo4j::Migrations.check_for_pending_migrations! end end def setup!(neo4j_config = nil) - support_deprecated_session_configs!(neo4j_config) - - session_data = neo4j_config.session.empty? ? yaml_config_data : neo4j_config.session - type, url, path, options, wait_for_connection = session_data.values_at(:type, :path, :url, :options, :wait_for_connection) + type, url, path, options, wait_for_connection = final_config!(neo4j_config).values_at(:type, :path, :url, :options, :wait_for_connection) register_neo4j_cypher_logging(type || default_session_type) Neo4j::SessionManager.open_neo4j_session(type || default_session_type, url || path || default_session_path_or_url, wait_for_connection, options || {}) end + def final_config!(neo4j_config) + support_deprecated_session_configs!(neo4j_config) + + neo4j_config.session.empty? ? yaml_config_data : neo4j_config.session + end + def support_deprecated_session_configs!(neo4j_config) ActiveSupport::Deprecation.warn('neo4j.config.sessions is deprecated, please use neo4j.config.session (not an array)') if neo4j_config.sessions.present? neo4j_config.session ||= (neo4j_config.sessions && neo4j_config.sessions[0]) || {} %w(type path url options).each do |key| @@ -83,13 +86,13 @@ end end def default_session_type if ENV['NEO4J_URL'] - URI(ENV['NEO4J_URL']).scheme.tap do |scheme| - fail "Invalid scheme for NEO4J_URL: #{scheme}" if !%w(http bolt).include?(scheme) - end + scheme = URI(ENV['NEO4J_URL']).scheme + fail "Invalid scheme for NEO4J_URL: #{scheme}" if !%w(http https bolt).include?(scheme) + scheme == 'https' ? 'http' : scheme else ENV['NEO4J_TYPE'] || :http end.to_sym end @@ -97,13 +100,13 @@ ENV['NEO4J_URL'] || ENV['NEO4J_PATH'] || 'http://localhost:7474' end def yaml_config_data @yaml_config_data ||= if yaml_path - HashWithIndifferentAccess.new(YAML.load(ERB.new(yaml_path.read).result)[Rails.env]) - else - {} - end + HashWithIndifferentAccess.new(YAML.load(ERB.new(yaml_path.read).result)[Rails.env]) + else + {} + end end def yaml_path return unless defined?(Rails) @yaml_path ||= %w(config/neo4j.yml config/neo4j.yaml).map do |path|