Class: Neo4j::Config

Inherits:
Object
  • Object
show all
Defined in:
lib/neo4j/config.rb

Overview

Keeps configuration for neo4j

The most important configuration is storage_path which is used to locate where the neo4j database is stored on the filesystem. If this directory is empty then a new database will be created, otherwise it will use the database from that directory.

Configurations keys

storage_path   where the database is stored
timestamps     if timestamps should be used when saving the model (Neo4j::Rails::Model)
lucene         lucene configuration for fulltext and exact indices
enable_rules   if false the _all relationship to all instances will not be created and custom rules will not be available. (Neo4j::NodeMixin and Neo4j::Rails::Model)
identity_map   default false, See Neo4j::IdentityMap  (Neo4j::NodeMixin and Neo4j::Rails::Model)

Class Method Summary collapse

Class Method Details

.[](key) ⇒ Object

Returns the the value of a config entry.

Parameters:

  • key (Symbol)

    The key of the config entry value we want

Returns:

  • the the value of a config entry



76
77
78
# File 'lib/neo4j/config.rb', line 76

def [](key)
  (@configuration ||= setup)[key.to_s]
end

.[]=(key, val) ⇒ Object

Sets the value of a config entry.

Parameters:

  • key (Symbol)

    the key to set the parameter for

  • val

    the value of the parameter.



69
70
71
# File 'lib/neo4j/config.rb', line 69

def []=(key, val)
  (@configuration ||= setup)[key.to_s] = val
end

.default_fileFixnum

Returns The location of the default configuration file.

Returns:

  • (Fixnum)

    The location of the default configuration file.



24
25
26
# File 'lib/neo4j/config.rb', line 24

def default_file
  @default_file ||= File.expand_path(File.join(File.dirname(__FILE__), "..", "..", "config", "neo4j", "config.yml"))
end

.default_file=(file_path) ⇒ Object

Sets the location of the configuration YAML file and old deletes configurations.

Parameters:

  • file_path (String)

    represent the path to the file.



31
32
33
34
35
# File 'lib/neo4j/config.rb', line 31

def default_file=(file_path)
  @configuration = nil
  @defaults = nil
  @default_file = File.expand_path(file_path)
end

.defaultsHash

Returns the default file loaded by yaml.

Returns:

  • (Hash)

    the default file loaded by yaml



38
39
40
41
# File 'lib/neo4j/config.rb', line 38

def defaults
  require 'yaml'
  @defaults ||= Neo4j::Core::HashWithIndifferentAccess.new(YAML.load_file(default_file))
end

.delete(key) ⇒ Object

Remove the value of a config entry.

Parameters:

  • key (Symbol)

    the key of the configuration entry to delete

Returns:

  • The value of the removed entry.



85
86
87
# File 'lib/neo4j/config.rb', line 85

def delete(key)
  @configuration.delete(key)
end

.delete_allObject

Remove all configuration. This can be useful for testing purpose.

Returns:

  • nil



93
94
95
# File 'lib/neo4j/config.rb', line 93

def delete_all
  @configuration = nil
end

.setupObject

Returns The a new configuration using default values as a hash.

Returns:

  • The a new configuration using default values as a hash.



127
128
129
130
131
# File 'lib/neo4j/config.rb', line 127

def setup()
  @configuration = Neo4j::Core::HashWithIndifferentAccess.new
  @configuration.merge!(defaults)
  @configuration
end

.storage_pathString

Returns the expanded path of the Config property.

Returns:

  • (String)

    the expanded path of the Config property



44
45
46
# File 'lib/neo4j/config.rb', line 44

def storage_path
  File.expand_path(self[:storage_path])
end

.to_hashHash

Returns The config as a hash.

Returns:

  • (Hash)

    The config as a hash.



99
100
101
# File 'lib/neo4j/config.rb', line 99

def to_hash
  @configuration ||= setup
end

.to_java_mapObject

Converts the defaults hash to a Java HashMap used by the Neo4j API.

Returns:

  • a Java HashMap used by the Java Neo4j API as configuration for the GraphDatabase



110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
# File 'lib/neo4j/config.rb', line 110

def to_java_map
  map = java.util.HashMap.new
  to_hash.each_pair do |k, v|
    case v
      when TrueClass
        map[k.to_s] = "YES"
      when FalseClass
        map[k.to_s] = "NO"
      when String, Fixnum, Float
        map[k.to_s] = v.to_s
      # skip list and hash values - not accepted by the Java Neo4j API
    end
  end
  map
end

.to_yamlString

Returns The config as a YAML.

Returns:

  • (String)

    The config as a YAML



104
105
106
# File 'lib/neo4j/config.rb', line 104

def to_yaml
  @configuration.to_yaml
end

.use {|config| ... } ⇒ Object

Yields the configuration

Examples:

Neo4j::Config.use do |config|
  config[:storage_path] = '/var/neo4j'
end

Yields:

  • config

Yield Parameters:

Returns:

  • nil



58
59
60
61
62
# File 'lib/neo4j/config.rb', line 58

def use
  @configuration ||= Neo4j::Core::HashWithIndifferentAccess.new
  yield @configuration
  nil
end