Class: CliApplication::Config
- Inherits:
-
OpenStruct
- Object
- OpenStruct
- CliApplication::Config
- Defined in:
- lib/cli_application/config.rb
Instance Attribute Summary collapse
-
#config ⇒ Object
readonly
Returns the value of attribute config.
-
#filename ⇒ Object
readonly
Returns the value of attribute filename.
Instance Method Summary collapse
-
#add(filename, type) ⇒ Nil
Метод загружает конфиг и делает его доступным через единый интерфейс настроек конфигурации приложения (CliApplication::Config) При каждом вызове данного метода все конфиги перечитываются заново.
-
#initialize(folders) ⇒ Config
constructor
Конструктор.
Constructor Details
#initialize(folders) ⇒ Config
Конструктор. Вызывается при создании класса приложения. Данный класс доступен в главной функции приложения (main) через переменную config
19 20 21 22 23 24 25 26 27 |
# File 'lib/cli_application/config.rb', line 19 def initialize(folders) super(nil) return if folders.nil? @folders = folders @filenames = Array.new @config_filename = File.join([folders[:class], 'config.yml']) @filename = @config_filename load_config(@config_filename) end |
Instance Attribute Details
#config ⇒ Object (readonly)
Returns the value of attribute config.
12 13 14 |
# File 'lib/cli_application/config.rb', line 12 def config @config end |
#filename ⇒ Object (readonly)
Returns the value of attribute filename.
13 14 15 |
# File 'lib/cli_application/config.rb', line 13 def filename @filename end |
Instance Method Details
#add(filename, type) ⇒ Nil
Метод загружает конфиг и делает его доступным через единый интерфейс настроек конфигурации приложения (CliApplication::Config) При каждом вызове данного метода все конфиги перечитываются заново.
38 39 40 41 42 43 44 45 46 |
# File 'lib/cli_application/config.rb', line 38 def add(filename, type) if @folders.keys.include?(type) load_config(File.join(@folders[type], filename)) elsif type == :absolute load_config(filename) else warn "Предупреждение: попытка загрузить конфиг неизвестного типа (#{type.inspect}). Допустимы #{@folders.keys.inspect}" end end |