Class: RubyPitaya::ConfigCore
- Inherits:
-
Object
- Object
- RubyPitaya::ConfigCore
- Defined in:
- lib/rubypitaya/core/config_core.rb
Instance Method Summary collapse
- #[](key) ⇒ Object
- #auto_reload ⇒ Object
-
#initialize ⇒ ConfigCore
constructor
A new instance of ConfigCore.
Constructor Details
#initialize ⇒ ConfigCore
Returns a new instance of ConfigCore.
7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 |
# File 'lib/rubypitaya/core/config_core.rb', line 7 def initialize() @config = {} @config.extend(ConfigHashExtension) 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
23 24 25 |
# File 'lib/rubypitaya/core/config_core.rb', line 23 def [](key) @config[key] end |
#auto_reload ⇒ Object
27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 |
# File 'lib/rubypitaya/core/config_core.rb', line 27 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 |