Class: Neo4j::Railtie
- Inherits:
-
Rails::Railtie
- Object
- Rails::Railtie
- Neo4j::Railtie
- Defined in:
- lib/neo4j/railtie.rb
Class Method Summary collapse
- .config_data ⇒ Object
- .default_session_path ⇒ Object
- .default_session_type ⇒ Object
- .java_platform? ⇒ Boolean
- .open_neo4j_session(options, wait_for_connection = false) ⇒ Object
- .setup_config_defaults!(cfg) ⇒ Object
- .setup_default_session(cfg) ⇒ Object
- .start_embedded_session(session) ⇒ Object
- .yaml_path ⇒ Object
Instance Method Summary collapse
Class Method Details
.config_data ⇒ Object
62 63 64 65 66 67 68 |
# File 'lib/neo4j/railtie.rb', line 62 def config_data @config_data ||= if yaml_path HashWithIndifferentAccess.new(YAML.load(ERB.new(yaml_path.read).result)[Rails.env]) else {} end end |
.default_session_path ⇒ Object
81 82 83 84 85 |
# File 'lib/neo4j/railtie.rb', line 81 def default_session_path ENV['NEO4J_URL'] || ENV['NEO4J_PATH'] || config_data[:url] || config_data[:path] || 'http://localhost:7474' end |
.default_session_type ⇒ Object
76 77 78 79 |
# File 'lib/neo4j/railtie.rb', line 76 def default_session_type type = ENV['NEO4J_TYPE'] || config_data[:type] || :server_db type.to_sym end |
.java_platform? ⇒ Boolean
43 44 45 |
# File 'lib/neo4j/railtie.rb', line 43 def java_platform? RUBY_PLATFORM =~ /java/ end |
.open_neo4j_session(options, wait_for_connection = false) ⇒ Object
96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 |
# File 'lib/neo4j/railtie.rb', line 96 def open_neo4j_session(, wait_for_connection = false) type, name, default, path = .values_at(:type, :name, :default, :path) if !java_platform? && type == :embedded_db fail "Tried to start embedded Neo4j db without using JRuby (got #{RUBY_PLATFORM}), please run `rvm jruby`" end session = wait_for_value(wait_for_connection) do if .key?(:name) Neo4j::Session.open_named(type, name, default, path) else Neo4j::Session.open(type, path, [:options]) end end (session) if type == :embedded_db end |
.setup_config_defaults!(cfg) ⇒ Object
55 56 57 58 59 60 |
# File 'lib/neo4j/railtie.rb', line 55 def setup_config_defaults!(cfg) cfg.session_type ||= default_session_type cfg.session_path ||= default_session_path cfg. ||= {} cfg.sessions ||= [] end |
.setup_default_session(cfg) ⇒ Object
47 48 49 50 51 52 53 |
# File 'lib/neo4j/railtie.rb', line 47 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..merge(default: true)} end |
.start_embedded_session(session) ⇒ Object
87 88 89 90 91 92 93 94 |
# File 'lib/neo4j/railtie.rb', line 87 def (session) # See https://github.com/jruby/jruby/wiki/UnlimitedStrengthCrypto security_class = java.lang.Class.for_name('javax.crypto.JceSecurity') restricted_field = security_class.get_declared_field('isRestricted') restricted_field.accessible = true restricted_field.set nil, false session.start end |
Instance Method Details
#register_neo4j_cypher_logging ⇒ Object
134 135 136 137 138 139 140 141 142 143 144 |
# File 'lib/neo4j/railtie.rb', line 134 def register_neo4j_cypher_logging return if @neo4j_cypher_logging_registered Neo4j::Core::Query.pretty_cypher = Neo4j::Config[:pretty_logged_cypher_queries] Neo4j::Server::CypherSession.log_with do || (Neo4j::Config[:logger] || Rails.logger).debug end @neo4j_cypher_logging_registered = true end |
#wait_for_value(wait) ⇒ Object
115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 |
# File 'lib/neo4j/railtie.rb', line 115 def wait_for_value(wait) session = nil Timeout.timeout(60) do until session begin if session = yield puts return session end rescue Faraday::ConnectionFailed => e raise e if !wait putc '.' sleep(1) end end end end |