Class: ActiveGraph::Railtie
- Inherits:
-
Rails::Railtie
- Object
- Rails::Railtie
- ActiveGraph::Railtie
- Defined in:
- lib/active_graph/railtie.rb
Instance Method Summary collapse
- #empty_config ⇒ Object
- #final_driver_config!(config) ⇒ Object
- #register_neo4j_cypher_logging ⇒ Object
- #setup!(config = empty_config) ⇒ Object
- #yaml_config_data ⇒ Object
- #yaml_path ⇒ Object
Instance Method Details
#empty_config ⇒ Object
8 9 10 11 12 |
# File 'lib/active_graph/railtie.rb', line 8 def empty_config ActiveSupport::OrderedOptions.new.tap do |cfg| cfg.driver = ActiveSupport::OrderedOptions.new end end |
#final_driver_config!(config) ⇒ Object
84 85 86 |
# File 'lib/active_graph/railtie.rb', line 84 def final_driver_config!(config) { url: ENV['NEO4J_URL'] }.compact.merge(config[:driver]).merge(yaml_config_data) end |
#register_neo4j_cypher_logging ⇒ Object
100 101 102 103 104 105 106 107 108 109 110 111 112 |
# File 'lib/active_graph/railtie.rb', line 100 def register_neo4j_cypher_logging return if @neo4j_cypher_logging_registered ActiveGraph::Core::Query.pretty_cypher = ActiveGraph::Config[:pretty_logged_cypher_queries] logger_proc = ->() do (ActiveGraph::Config[:logger] ||= Rails.logger).debug end ActiveGraph::Base.subscribe_to_query(&logger_proc) ActiveGraph::Base.subscribe_to_request(&logger_proc) @neo4j_cypher_logging_registered = true end |
#setup!(config = empty_config) ⇒ Object
68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 |
# File 'lib/active_graph/railtie.rb', line 68 def setup!(config = empty_config) config = final_driver_config!(config) scheme = config.delete(:scheme) || 'bolt' host = config.delete(:host) || 'localhost' port = config.delete(:port) || 7687 url = config.delete(:url) || URI::Generic.build( scheme: scheme, host: host, port: port ).to_s username = config.delete(:username) password = config.delete(:password) auth_token = config.delete(:auth_token) auth_token ||= username ? Neo4j::Driver::AuthTokens.basic(username, password) : Neo4j::Driver::AuthTokens.none register_neo4j_cypher_logging method = url.is_a?(Enumerable) ? :routing_driver : :driver Neo4j::Driver::GraphDatabase.send(method, url, auth_token, **config) end |
#yaml_config_data ⇒ Object
88 89 90 91 |
# File 'lib/active_graph/railtie.rb', line 88 def yaml_config_data @yaml_config_data ||= yaml_path ? YAML.load(ERB.new(yaml_path.read).result)[Rails.env].transform_keys!(&:to_sym) : {} end |
#yaml_path ⇒ Object
93 94 95 96 97 98 |
# File 'lib/active_graph/railtie.rb', line 93 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 |