Class: RubyPitaya::Config

Inherits:
Object show all
Defined in:
lib/rubypitaya/core/config.rb,
lib/rubypitaya/app-template/vendor/bundle/ruby/3.1.0/gems/rubypitaya-3.12.1/lib/rubypitaya/core/config.rb

Instance Method Summary collapse

Constructor Details

#initializeConfig

Returns a new instance of Config.



7
8
9
10
11
12
13
14
# File 'lib/rubypitaya/core/config.rb', line 7

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

  @empty_hash = {}
  @result_cache = {}
end

Instance Method Details

#[](key) ⇒ Object



16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
# File 'lib/rubypitaya/core/config.rb', line 16

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



39
40
41
42
# File 'lib/rubypitaya/core/config.rb', line 39

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

#clear_cacheObject



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

def clear_cache
  @result_cache.clear
end

#config_core_override=(value) ⇒ Object



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

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

#fetch(*args) ⇒ Object



32
33
34
35
36
37
# File 'lib/rubypitaya/core/config.rb', line 32

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

  @empty_hash.fetch(*args)
end