Class: RubyPitaya::Config

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

Instance Method Summary collapse

Constructor Details

#initializeConfig

Returns a new instance of Config.



8
9
10
11
12
13
14
15
16
17
18
# File 'lib/rubypitaya/core/config.rb', line 8

def initialize
  @config_core = ConfigCore.new
  @config_core_override = nil
  @has_config_core_override = false

  @empty_hash = {}
  @result_cache = {}

  @empty_hash.extend(ConfigHashExtension)
  @result_cache.extend(ConfigHashExtension)
end

Instance Method Details

#[](key) ⇒ Object



20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
# File 'lib/rubypitaya/core/config.rb', line 20

def [](key)
  result = @result_cache[key]
  return result unless result.nil?

  if @has_config_core_override
    result = @config_core_override[key]
    result = @config_core[key] if result.nil?
  else
    result = @config_core[key]
  end

  @result_cache[key] = result

  result
end

#auto_reloadObject



43
44
45
46
# File 'lib/rubypitaya/core/config.rb', line 43

def auto_reload
  @config_core.auto_reload
  @config_core_override.auto_reload unless @config_core_override.nil?
end

#clear_cacheObject



48
49
50
# File 'lib/rubypitaya/core/config.rb', line 48

def clear_cache
  @result_cache.clear
end

#config_core_override=(value) ⇒ Object



52
53
54
55
# File 'lib/rubypitaya/core/config.rb', line 52

def config_core_override=(value)
  @config_core_override = value
  @has_config_core_override = !value.nil?
end

#fetch(*args) ⇒ Object



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

def fetch(*args)
  result = self[args[0]]
  return result unless result.nil?

  @empty_hash.fetch(*args)
end