lib/neo4j/railtie.rb in neo4j-8.0.0.alpha.7 vs lib/neo4j/railtie.rb in neo4j-8.0.0.alpha.8
- old
+ new
@@ -58,11 +58,12 @@
end
def setup!(neo4j_config = nil)
support_deprecated_session_configs!(neo4j_config)
- type, url, path, options, wait_for_connection = neo4j_config.session.values_at(:type, :path, :url, :options, :wait_for_connection)
+ 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)
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,
@@ -94,9 +95,23 @@
def default_session_path_or_url
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
+ end
+
+ def yaml_path
+ return unless defined?(Rails)
+ @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)