Class: RubyPitaya::Setup
- Inherits:
-
Object
- Object
- RubyPitaya::Setup
- Defined in:
- lib/rubypitaya/core/setup.rb
Instance Method Summary collapse
- #[](key) ⇒ Object
- #auto_reload ⇒ Object
- #fetch(*args) ⇒ Object
- #get_config ⇒ Object
-
#initialize ⇒ Setup
constructor
A new instance of Setup.
Constructor Details
#initialize ⇒ Setup
Returns a new instance of Setup.
7 8 9 10 11 12 13 14 15 16 17 18 19 20 |
# File 'lib/rubypitaya/core/setup.rb', line 7 def initialize() @config = {} @empty_hash = {} configs_folder_paths = Path::Plugins::APP_SETUP_FOLDER_PATHS + [Path::APP_SETUP_FOLDER_PATH] configs_folder_paths.each do |configs_folder_path| path_to_all_files = File.join(configs_folder_path, '**/*.yml') 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
22 23 24 25 26 27 28 |
# File 'lib/rubypitaya/core/setup.rb', line 22 def [](key) result = get_config_from_env_var(key) return result unless result.nil? split_key = key.split('.') @config.dig(*split_key) end |
#auto_reload ⇒ Object
41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 |
# File 'lib/rubypitaya/core/setup.rb', line 41 def auto_reload require 'listen' configs_folder_path = Path::APP_CONFIG_FOLDER_PATH config_files_listener = Listen.to(configs_folder_path, only: /\.yml$/, 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 |
#fetch(*args) ⇒ Object
30 31 32 33 34 35 |
# File 'lib/rubypitaya/core/setup.rb', line 30 def fetch(*args) result = self[args[0]] return result unless result.nil? @empty_hash.fetch(*args) end |
#get_config ⇒ Object
37 38 39 |
# File 'lib/rubypitaya/core/setup.rb', line 37 def get_config @config.deep_dup end |