class Neo4j::Config

Keeps configuration for neo4j

The most important configuration is Neo4j::Config[: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.

Default Configurations

:storage_path

default tmp/neo4j where the database is stored

:timestamps

default true for Rails Neo4j::Model - if timestamps should be used when saving the model

:lucene

default hash keys: :fulltext, :exact configuration how the lucene index is stored

:enable_rules

default true, if false the _all relationship to all instances will not be created and custom rules will not be available.

:identity_map

default false, See Neo4j::IdentityMap

Public Class Methods

[](key) click to toggle source

Gets the the value of a config entry

Parameters

key

The key of the config entry value we want

# File lib/neo4j/config.rb, line 102
def [](key)
  (@configuration ||= setup)[key]
end
[]=(key, val) click to toggle source

Set the value of a config entry.

Parameters

key

The key to set the parameter for.

val

The value of the parameter.

# File lib/neo4j/config.rb, line 92
def []=(key, val)
  (@configuration ||= setup)[key] = val
end
default_file() click to toggle source

The location of the default configuration file

# 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) click to toggle source

You can keep all the configuration in your own yaml file Also deletes all old configurations.

# File lib/neo4j/config.rb, line 30
def default_file=(file_path)
  @configuration = nil
  @defaults = nil
  @default_file = File.expand_path(file_path)
end
defaults() click to toggle source

Returns the hash of default config values for neo4j.

Returns

Hash

The defaults for the config.

# File lib/neo4j/config.rb, line 40
def defaults
  @defaults ||= YAML.load_file(default_file)
end
delete(key) click to toggle source

Remove the value of a config entry.

Parameters

key<Object>

The key of the parameter to delete.

Returns

The value of the removed entry.

# File lib/neo4j/config.rb, line 115
def delete(key)
  @configuration.delete(key)
end
delete_all() click to toggle source

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

Returns

nil

# File lib/neo4j/config.rb, line 126
def delete_all
  @configuration = nil
end
fetch(key, default) click to toggle source

Retrieve the value of a config entry, returning the provided default if the key is not present

Parameters

key

The key to retrieve the parameter for.

default::The default value to return if the parameter is not set.

Returns

The value of the configuration parameter or the default.

# File lib/neo4j/config.rb, line 140
def fetch(key, default)
  @configuration.fetch(key, default)
end
setup() click to toggle source

Sets up the configuration to use the default.

Returns

The a new configuration using default values as a hash.

# File lib/neo4j/config.rb, line 149
def setup()
  @configuration = defaults.with_indifferent_access #nested_under_indifferent_access
  @configuration.merge!(defaults)
  @configuration
end
storage_path() click to toggle source

Returns the expanded path of the Config property

# File lib/neo4j/config.rb, line 63
def storage_path
  File.expand_path(self[:storage_path])
end
to_hash() click to toggle source

Returns the configuration as a hash.

Returns

The config as a hash.

# File lib/neo4j/config.rb, line 161
def to_hash
  @configuration ||= setup
end
to_java_map() click to toggle source

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

# File lib/neo4j/config.rb, line 45
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_yaml() click to toggle source

Returns the config as YAML.

Returns

The config as YAML.

# File lib/neo4j/config.rb, line 170
def to_yaml
  require "yaml"
  @configuration.to_yaml
end
use() { |configuration| ... } click to toggle source

Yields the configuration.

Block parameters

c

The configuration parameters, a hash.

Examples

::use do |config|

config[:storage_path] = '/var/neo4j'

end

Returns

nil

# File lib/neo4j/config.rb, line 79
def use
  @configuration ||= {}
  yield @configuration
  nil
end