Class: RubyPitaya::ConfigCore

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

Instance Method Summary collapse

Constructor Details

#initializeConfigCore

Returns a new instance of ConfigCore.



5
6
7
8
9
10
11
12
13
14
15
16
17
# File 'lib/rubypitaya/core/config_core.rb', line 5

def initialize()
  @config = {}
  configs_folder_paths = Path::Plugins::APP_CONFIG_FOLDER_PATHS + [Path::APP_CONFIG_FOLDER_PATH]

  configs_folder_paths.each do |configs_folder_path|
    path_to_all_files = File.join(configs_folder_path, '**/*.json')
    config_files = Dir.glob(path_to_all_files)

    config_files.each do |config_file|
      load_config_file(configs_folder_path, config_file)
    end
  end
end

Instance Method Details

#[](key) ⇒ Object



19
20
21
# File 'lib/rubypitaya/core/config_core.rb', line 19

def [](key)
  @config[key]
end

#auto_reloadObject



23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
# File 'lib/rubypitaya/core/config_core.rb', line 23

def auto_reload
  require 'listen'

  configs_folder_path = Path::APP_CONFIG_FOLDER_PATH

  config_files_listener = Listen.to(configs_folder_path,
                                    only: /\.json$/,
                                    force_polling: true,
                                    latency: 0.25,
                                    wait_for_delay: 0.1) do |modified, added, removed|
    import_added_files(configs_folder_path, added)
    reload_modified_files(configs_folder_path, modified)
  end

  config_files_listener.start
end