Class: Neo4j::Railtie
- Inherits:
-
Rails::Railtie
- Object
- Rails::Railtie
- Neo4j::Railtie
- Defined in:
- lib/neo4j/railtie.rb
Instance Method Summary collapse
- #default_session_path_or_url ⇒ Object
- #default_session_type ⇒ Object
- #empty_config ⇒ Object
- #final_session_config!(neo4j_config) ⇒ Object
- #register_neo4j_cypher_logging(session_type, options) ⇒ Object
- #setup!(neo4j_config = empty_config) ⇒ Object
- #subscribe_to_session_type_logging!(session_type, options, logger_proc) ⇒ Object
- #support_deprecated_session_configs!(neo4j_config) ⇒ Object
- #yaml_config_data ⇒ Object
- #yaml_path ⇒ Object
Instance Method Details
#default_session_path_or_url ⇒ Object
107 108 109 |
# File 'lib/neo4j/railtie.rb', line 107 def default_session_path_or_url ENV['NEO4J_URL'] || ENV['NEO4J_PATH'] || 'http://localhost:7474' end |
#default_session_type ⇒ Object
97 98 99 100 101 102 103 104 105 |
# File 'lib/neo4j/railtie.rb', line 97 def default_session_type if ENV['NEO4J_URL'] 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 |
#empty_config ⇒ Object
10 11 12 |
# File 'lib/neo4j/railtie.rb', line 10 def empty_config ActiveSupport::OrderedOptions.new.tap { |cfg| cfg.session = ActiveSupport::OrderedOptions.new } end |
#final_session_config!(neo4j_config) ⇒ Object
74 75 76 77 78 79 80 |
# File 'lib/neo4j/railtie.rb', line 74 def final_session_config!(neo4j_config) support_deprecated_session_configs!(neo4j_config) (neo4j_config[:session].empty? ? yaml_config_data : neo4j_config[:session]).dup.tap do |result| result[:type] ||= URI(result[:url]).scheme if result[:url] end end |
#register_neo4j_cypher_logging(session_type, options) ⇒ Object
126 127 128 129 130 131 132 133 134 135 136 137 138 |
# File 'lib/neo4j/railtie.rb', line 126 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 = ->() do (Neo4j::Config[:logger] ||= Rails.logger).debug end Neo4j::Core::CypherSession::Adaptors::Base.subscribe_to_query(&logger_proc) subscribe_to_session_type_logging!(session_type, , logger_proc) @neo4j_cypher_logging_registered = true end |
#setup!(neo4j_config = empty_config) ⇒ Object
61 62 63 64 65 66 67 68 69 70 71 72 |
# File 'lib/neo4j/railtie.rb', line 61 def setup!(neo4j_config = empty_config) wait_for_connection = neo4j_config.wait_for_connection type, url, path, = final_session_config!(neo4j_config).values_at(:type, :url, :path, :options) type ||= default_session_type ||= {} register_neo4j_cypher_logging(type, ) Neo4j::SessionManager.open_neo4j_session(type, url || path || default_session_path_or_url, wait_for_connection, ) end |
#subscribe_to_session_type_logging!(session_type, options, logger_proc) ⇒ Object
140 141 142 143 144 145 146 147 |
# File 'lib/neo4j/railtie.rb', line 140 def subscribe_to_session_type_logging!(session_type, , logger_proc) SessionManager .adaptor_class(session_type, ) .send( [:embedded, :embedded_db].include?(session_type.to_sym) ? :subscribe_to_transaction : :subscribe_to_request, &logger_proc ) end |
#support_deprecated_session_configs!(neo4j_config) ⇒ Object
82 83 84 85 86 87 88 89 90 91 92 93 94 95 |
# File 'lib/neo4j/railtie.rb', line 82 def support_deprecated_session_configs!(neo4j_config) if neo4j_config.sessions.present? ActiveSupport::Deprecation.warn('neo4j.config.sessions is deprecated, please use neo4j.config.session (not an array)') neo4j_config[:session] = neo4j_config.sessions[0] if neo4j_config[:session].empty? end %w(type path url options).each do |key| value = neo4j_config.send("session_#{key}") if value.present? ActiveSupport::Deprecation.warn("neo4j.config.session_#{key} is deprecated, please use neo4j.config.session.#{key}") neo4j_config[:session][key] = value end end end |
#yaml_config_data ⇒ Object
111 112 113 114 115 116 117 |
# File 'lib/neo4j/railtie.rb', line 111 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 |