class Neo4j::Railtie

Public Class Methods

config_data() click to toggle source
   # File lib/neo4j/railtie.rb
62 def config_data
63   @config_data ||= if yaml_path
64                      HashWithIndifferentAccess.new(YAML.load(ERB.new(yaml_path.read).result)[Rails.env])
65                    else
66                      {}
67                    end
68 end
default_session_path() click to toggle source
   # File lib/neo4j/railtie.rb
81 def default_session_path
82   ENV['NEO4J_URL'] || ENV['NEO4J_PATH'] ||
83     config_data[:url] || config_data[:path] ||
84     'http://localhost:7474'
85 end
default_session_type() click to toggle source
   # File lib/neo4j/railtie.rb
76 def default_session_type
77   type = ENV['NEO4J_TYPE'] || config_data[:type] || :server_db
78   type.to_sym
79 end
java_platform?() click to toggle source
   # File lib/neo4j/railtie.rb
43 def java_platform?
44   RUBY_PLATFORM =~ /java/
45 end
open_neo4j_session(options, wait_for_connection = false) click to toggle source
    # File lib/neo4j/railtie.rb
 96 def open_neo4j_session(options, wait_for_connection = false)
 97   type, name, default, path = options.values_at(:type, :name, :default, :path)
 98 
 99   if !java_platform? && type == :embedded_db
100     fail "Tried to start embedded Neo4j db without using JRuby (got #{RUBY_PLATFORM}), please run `rvm jruby`"
101   end
102 
103   session = wait_for_value(wait_for_connection) do
104     if options.key?(:name)
105       Neo4j::Session.open_named(type, name, default, path)
106     else
107       Neo4j::Session.open(type, path, options[:options])
108     end
109   end
110 
111   start_embedded_session(session) if type == :embedded_db
112 end
setup_config_defaults!(cfg) click to toggle source
   # File lib/neo4j/railtie.rb
55 def setup_config_defaults!(cfg)
56   cfg.session_type ||= default_session_type
57   cfg.session_path ||= default_session_path
58   cfg.session_options ||= {}
59   cfg.sessions ||= []
60 end
setup_default_session(cfg) click to toggle source
   # File lib/neo4j/railtie.rb
47 def setup_default_session(cfg)
48   setup_config_defaults!(cfg)
49 
50   return if !cfg.sessions.empty?
51 
52   cfg.sessions << {type: cfg.session_type, path: cfg.session_path, options: cfg.session_options.merge(default: true)}
53 end
start_embedded_session(session) click to toggle source
   # File lib/neo4j/railtie.rb
87 def start_embedded_session(session)
88   # See https://github.com/jruby/jruby/wiki/UnlimitedStrengthCrypto
89   security_class = java.lang.Class.for_name('javax.crypto.JceSecurity')
90   restricted_field = security_class.get_declared_field('isRestricted')
91   restricted_field.accessible = true
92   restricted_field.set nil, false
93   session.start
94 end
yaml_path() click to toggle source
   # File lib/neo4j/railtie.rb
70 def yaml_path
71   @yaml_path ||= %w(config/neo4j.yml config/neo4j.yaml).map do |path|
72     Rails.root.join(path)
73   end.detect(&:exist?)
74 end

Public Instance Methods

register_neo4j_cypher_logging() click to toggle source
    # File lib/neo4j/railtie.rb
134 def register_neo4j_cypher_logging
135   return if @neo4j_cypher_logging_registered
136 
137   Neo4j::Core::Query.pretty_cypher = Neo4j::Config[:pretty_logged_cypher_queries]
138 
139   Neo4j::Server::CypherSession.log_with do |message|
140     (Neo4j::Config[:logger] || Rails.logger).debug message
141   end
142 
143   @neo4j_cypher_logging_registered = true
144 end
wait_for_value(wait) { || ... } click to toggle source
    # File lib/neo4j/railtie.rb
115 def wait_for_value(wait)
116   session = nil
117   Timeout.timeout(60) do
118     until session
119       begin
120         if session = yield
121           puts
122           return session
123         end
124       rescue Faraday::ConnectionFailed => e
125         raise e if !wait
126 
127         putc '.'
128         sleep(1)
129       end
130     end
131   end
132 end