Class: HammerCLI::Settings
- Inherits:
-
Object
- Object
- HammerCLI::Settings
- Defined in:
- lib/hammer_cli/settings.rb
Class Method Summary collapse
- .clear ⇒ Object
- .dump ⇒ Object
- .get(*keys) ⇒ Object
- .load(settings_hash) ⇒ Object
- .load_from_file(file_path) ⇒ Object
- .load_from_paths(files) ⇒ Object
- .path_history ⇒ Object
Class Method Details
.clear ⇒ Object
53 54 55 56 |
# File 'lib/hammer_cli/settings.rb', line 53 def self.clear settings.clear path_history.clear end |
.dump ⇒ Object
58 59 60 |
# File 'lib/hammer_cli/settings.rb', line 58 def self.dump settings end |
.get(*keys) ⇒ Object
8 9 10 11 12 13 |
# File 'lib/hammer_cli/settings.rb', line 8 def self.get(*keys) keys.inject(settings) do |value, key| return nil unless value value[key.to_sym] end end |
.load(settings_hash) ⇒ Object
49 50 51 |
# File 'lib/hammer_cli/settings.rb', line 49 def self.load(settings_hash) deep_merge!(settings, settings_hash) end |
.load_from_file(file_path) ⇒ Object
35 36 37 38 39 40 41 42 43 44 45 46 47 |
# File 'lib/hammer_cli/settings.rb', line 35 def self.load_from_file(file_path) if File.file? file_path begin config = YAML::load(File.open(file_path)) if config load(config) path_history << file_path end rescue Exception => e warn _("Warning: Couldn't load configuration file %{path}: %{message}") % { path: file_path, message: e. } end end end |
.load_from_paths(files) ⇒ Object
15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 |
# File 'lib/hammer_cli/settings.rb', line 15 def self.load_from_paths(files) files.reverse.each do |path| full_path = File. path if File.directory? full_path # check for cli_config.yml load_from_file(File.join(full_path, 'cli_config.yml')) load_from_file(File.join(full_path, 'defaults.yml')) # load config for modules Dir.glob(File.join(full_path, 'cli.modules.d/*.yml')).sort.each do |f| load_from_file(f) end Dir.glob(File.join(full_path, 'hammer.modules.d/*.yml')).sort.each do |f| warn _("Warning: location hammer.modules.d is deprecated, move your module configurations to cli.modules.d") warn " #{f} -> #{f.gsub('hammer.modules.d', 'cli.modules.d')}" load_from_file(f) end end end end |
.path_history ⇒ Object
62 63 64 65 |
# File 'lib/hammer_cli/settings.rb', line 62 def self.path_history @path_history ||= [] @path_history end |