Class: DTK::Configuration

Inherits:
Object
  • Object
show all
Includes:
Singleton
Defined in:
lib/config/configuration.rb

Constant Summary collapse

EXTERNAL_APP_CONF =
"client.conf"
DEVELOPMENT_CONF =
'local.conf'
DEFAULT_CONF =
'default.conf'

Class Method Summary collapse

Instance Method Summary collapse

Constructor Details

#initializeConfiguration

Returns a new instance of Configuration.



54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
# File 'lib/config/configuration.rb', line 54

def initialize
  # default configuration
  @cache = load_configuration_to_hash(File.expand_path("../#{DEFAULT_CONF}",__FILE__))

  # we will not use local.conf from gemfile because client.conf is required so this is deprecated
  if File.exist?(File.expand_path("../#{DEVELOPMENT_CONF}",__FILE__))
    local_configuration = load_configuration_to_hash(File.expand_path("../#{DEVELOPMENT_CONF}",__FILE__))
    # we override only values from local configuration
    # that way developer does not have updates its local configuration all the time
    @cache.merge!(local_configuration)
    # if we have loaded local configuration we will not check external
    return
  end

  # We load this if there is no local configuration
  external_file_location = File.join(::DTK::Client::OsUtil.dtk_local_folder(), "#{EXTERNAL_APP_CONF}")

  if File.exist?(external_file_location)
    external_configuration = load_configuration_to_hash(external_file_location)
    @cache.merge!(external_configuration)
  end
end

Class Method Details

.[](k) ⇒ Object



50
51
52
# File 'lib/config/configuration.rb', line 50

def self.[](k)
  Configuration.instance.get(k)
end

.get(name, default = nil) ⇒ Object



46
47
48
# File 'lib/config/configuration.rb', line 46

def self.get(name, default=nil)
  Configuration.instance.get(name, default)
end

Instance Method Details

#get(name, default = nil) ⇒ Object



77
78
79
# File 'lib/config/configuration.rb', line 77

def get(name, default=nil)
  return @cache[name.to_s] || default
end