Class: Neo4j::Config
- Inherits:
-
Object
- Object
- Neo4j::Config
- 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
-
.[](key) ⇒ Object
The the value of a config entry.
-
.[]=(key, val) ⇒ Object
Sets the value of a config entry.
-
.default_file ⇒ Fixnum
The location of the default configuration file.
-
.default_file=(file_path) ⇒ Object
Sets the location of the configuration YAML file and old deletes configurations.
-
.defaults ⇒ Hash
The default file loaded by yaml.
-
.delete(key) ⇒ Object
Remove the value of a config entry.
-
.delete_all ⇒ Object
Remove all configuration.
-
.setup ⇒ Object
The a new configuration using default values as a hash.
-
.storage_path ⇒ String
The expanded path of the Config property.
-
.to_hash ⇒ Hash
The config as a hash.
-
.to_java_map ⇒ Object
Converts the defaults hash to a Java HashMap used by the Neo4j API.
-
.to_yaml ⇒ String
The config as a YAML.
-
.use {|config| ... } ⇒ Object
Yields the configuration.
Class Method Details
.[](key) ⇒ Object
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.
69 70 71 |
# File 'lib/neo4j/config.rb', line 69 def []=(key, val) (@configuration ||= setup)[key.to_s] = val end |
.default_file ⇒ Fixnum
Returns The location of the default configuration file.
24 25 26 |
# File 'lib/neo4j/config.rb', line 24 def default_file @default_file ||= File.(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.
31 32 33 34 35 |
# File 'lib/neo4j/config.rb', line 31 def default_file=(file_path) @configuration = nil @defaults = nil @default_file = File.(file_path) end |
.defaults ⇒ Hash
Returns 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.
85 86 87 |
# File 'lib/neo4j/config.rb', line 85 def delete(key) @configuration.delete(key) end |
.delete_all ⇒ Object
Remove all configuration. This can be useful for testing purpose.
93 94 95 |
# File 'lib/neo4j/config.rb', line 93 def delete_all @configuration = nil end |
.setup ⇒ Object
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_path ⇒ String
Returns the expanded path of the Config property.
44 45 46 |
# File 'lib/neo4j/config.rb', line 44 def storage_path File.(self[:storage_path]) end |
.to_hash ⇒ Hash
Returns The config as a hash.
99 100 101 |
# File 'lib/neo4j/config.rb', line 99 def to_hash @configuration ||= setup end |
.to_java_map ⇒ Object
Converts the defaults hash to a Java HashMap used by the Neo4j API.
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_yaml ⇒ String
Returns 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
58 59 60 61 62 |
# File 'lib/neo4j/config.rb', line 58 def use @configuration ||= Neo4j::Core::HashWithIndifferentAccess.new yield @configuration nil end |