lib/neo4j/config.rb in neo4j-4.0.0 vs lib/neo4j/config.rb in neo4j-4.1.0
- old
+ new
@@ -1,18 +1,14 @@
module Neo4j
-
-
# == Keeps configuration for neo4j
#
# == Configurations keys
#
class Config
+ DEFAULT_FILE = File.expand_path(File.join(File.dirname(__FILE__), '..', '..', 'config', 'neo4j', 'config.yml'))
- DEFAULT_FILE = File.expand_path(File.join(File.dirname(__FILE__), "..", "..", "config", "neo4j", "config.yml"))
-
class << self
-
# @return [Fixnum] The location of the default configuration file.
def default_file
@default_file ||= DEFAULT_FILE
end
@@ -31,17 +27,16 @@
@defaults ||= ActiveSupport::HashWithIndifferentAccess.new(YAML.load_file(default_file))
end
# Reads from the default_file if configuration is not set already
# @return [Hash] the configuration
- def get_or_setup_configuration
- @configuration ||= setup
- end
-
- # @return [Hash] the configuration
def configuration
- @configuration || {}
+ return @configuration if @configuration
+
+ @configuration = ActiveSupport::HashWithIndifferentAccess.new
+ @configuration.merge!(defaults)
+ @configuration
end
# Yields the configuration
#
# @example
@@ -62,27 +57,27 @@
# Sets the value of a config entry.
#
# @param [Symbol] key the key to set the parameter for
# @param val the value of the parameter.
def []=(key, val)
- get_or_setup_configuration[key.to_s] = val
+ configuration[key.to_s] = val
end
# @param [Symbol] key The key of the config entry value we want
# @return the the value of a config entry
def [](key)
- get_or_setup_configuration[key.to_s]
+ configuration[key.to_s]
end
# Remove the value of a config entry.
#
# @param [Symbol] key the key of the configuration entry to delete
# @return The value of the removed entry.
def delete(key)
- get_or_setup_configuration.delete(key)
+ configuration.delete(key)
end
# Remove all configuration. This can be useful for testing purpose.
#
@@ -92,22 +87,15 @@
end
# @return [Hash] The config as a hash.
def to_hash
- get_or_setup_configuration.to_hash
+ configuration.to_hash
end
# @return [String] The config as a YAML
def to_yaml
- get_or_setup_configuration.to_yaml
- end
-
- # @return The a new configuration using default values as a hash.
- def setup
- @configuration = ActiveSupport::HashWithIndifferentAccess.new
- @configuration.merge!(defaults)
- @configuration
+ configuration.to_yaml
end
def class_name_property
Neo4j::Config[:class_name_property] || :_classname
end