Class: Neo4j::Config

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

Overview

Keeps configuration for neo4j

Configurations keys

Constant Summary collapse

DEFAULT_FILE =
File.expand_path(File.join(File.dirname(__FILE__), '..', '..', 'config', 'neo4j', 'config.yml'))

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



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

def [](key)
  configuration[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.



63
64
65
# File 'lib/neo4j/config.rb', line 63

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

.association_model_namespaceObject



120
121
122
# File 'lib/neo4j/config.rb', line 120

def association_model_namespace
  Neo4j::Config[:association_model_namespace] || nil
end

.association_model_namespace_stringObject



124
125
126
127
128
# File 'lib/neo4j/config.rb', line 124

def association_model_namespace_string
  namespace = Neo4j::Config[:association_model_namespace]
  return nil if namespace.nil?
  "::#{namespace}"
end

.configurationHash

Reads from the default_file if configuration is not set already

Returns:

  • (Hash)

    the configuration



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

def configuration
  return @configuration if @configuration

  @configuration = ActiveSupport::HashWithIndifferentAccess.new
  @configuration.merge!(defaults)
  @configuration
end

.default_fileInteger

Returns The location of the default configuration file.

Returns:

  • (Integer)

    The location of the default configuration file.



15
16
17
# File 'lib/neo4j/config.rb', line 15

def default_file
  @default_file ||= DEFAULT_FILE
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.



21
22
23
24
25
# File 'lib/neo4j/config.rb', line 21

def default_file=(file_path)
  delete_all
  @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



28
29
30
31
# File 'lib/neo4j/config.rb', line 28

def defaults
  require 'yaml'
  @defaults ||= ActiveSupport::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.



81
82
83
# File 'lib/neo4j/config.rb', line 81

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

.delete_allObject

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

Returns:

  • nil



88
89
90
# File 'lib/neo4j/config.rb', line 88

def delete_all
  @configuration = nil
end

.enums_case_sensitiveObject



130
131
132
# File 'lib/neo4j/config.rb', line 130

def enums_case_sensitive
  Neo4j::Config[:enums_case_sensitive] || false
end

.fail_on_pending_migrationsObject



102
103
104
# File 'lib/neo4j/config.rb', line 102

def fail_on_pending_migrations
  Neo4j::Config[:fail_on_pending_migrations].nil? ? true : Neo4j::Config[:fail_on_pending_migrations]
end

.fetch(key, default) ⇒ Object



73
74
75
# File 'lib/neo4j/config.rb', line 73

def fetch(key, default)
  configuration.fetch(key, default)
end

.include_root_in_jsonObject



106
107
108
109
# File 'lib/neo4j/config.rb', line 106

def include_root_in_json
  # we use ternary because a simple || will always evaluate true
  Neo4j::Config[:include_root_in_json].nil? ? true : Neo4j::Config[:include_root_in_json]
end

.module_handlingObject



111
112
113
# File 'lib/neo4j/config.rb', line 111

def module_handling
  Neo4j::Config[:module_handling] || :none
end

.timestamp_typeClass

Returns The configured timestamps type (e.g. Integer) or the default DateTime.

Returns:

  • (Class)

    The configured timestamps type (e.g. Integer) or the default DateTime.



116
117
118
# File 'lib/neo4j/config.rb', line 116

def timestamp_type
  Neo4j::Config[:timestamp_type] || DateTime
end

.to_hashHash

Returns The config as a hash.

Returns:

  • (Hash)

    The config as a hash.



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

def to_hash
  configuration.to_hash
end

.to_yamlString

Returns The config as a YAML.

Returns:

  • (String)

    The config as a YAML



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

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



53
54
55
56
57
# File 'lib/neo4j/config.rb', line 53

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