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
      13 14 15 16 17  | 
    
      # File 'lib/active_graph/railtie.rb', line 13 def empty_config ActiveSupport::OrderedOptions.new.tap do |cfg| cfg.driver = ActiveSupport::OrderedOptions.new end end  | 
  
#final_driver_config!(config) ⇒ Object
      82 83 84  | 
    
      # File 'lib/active_graph/railtie.rb', line 82 def final_driver_config!(config) { url: ENV['NEO4J_URL'] }.compact.merge(config[:driver]).merge(yaml_config_data) end  | 
  
#register_neo4j_cypher_logging ⇒ Object
      98 99 100 101 102 103 104 105 106 107 108 109 110  | 
    
      # File 'lib/active_graph/railtie.rb', line 98 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
      66 67 68 69 70 71 72 73 74 75 76 77 78 79 80  | 
    
      # File 'lib/active_graph/railtie.rb', line 66 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
      86 87 88 89  | 
    
      # File 'lib/active_graph/railtie.rb', line 86 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
      91 92 93 94 95 96  | 
    
      # File 'lib/active_graph/railtie.rb', line 91 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  |