Class: SknUtils::Configuration
- Inherits:
-
NestedResult
- Object
- NestedResult
- SknUtils::Configuration
- Defined in:
- lib/skn_utils/configuration.rb
Instance Method Summary collapse
-
#add_source!(file_path_or_hash) ⇒ Object
:reload! required.
- #config_path!(config_root) ⇒ Object
-
#initialize(params = {}) ⇒ Configuration
constructor
“filename-only” “filename-only”.
- #load_and_set_settings(ordered_list_of_files) ⇒ Object (also: #reload_from_files)
- #load_config_basename!(environment_name = @_default_mode) ⇒ Object
-
#prepend_source!(file_path_or_hash) ⇒ Object
:reload! required.
- #reload! ⇒ Object
-
#setting_files(config_root, environment_name) ⇒ Object
Config.setting_files(“/path/to/config_root”, “your_project_environment”).
Methods inherited from NestedResult
#==, #[], #[]=, #delete_field, #encode_with, #eql?, #hash, #hash_from, #init_with, #keys, #to_hash, #to_json, #to_s, with_instance_vars, with_methods
Constructor Details
#initialize(params = {}) ⇒ Configuration
“filename-only” “filename-only”
42 43 44 45 46 47 48 49 50 51 |
# File 'lib/skn_utils/configuration.rb', line 42 def initialize(params={}) super() @_last_filelist = [] @_base_path = './config/' @_default_mode = ENV['RACK_ENV'] || 'development' cfg_file = params.is_a?(String) ? params : (params[:config_filename] || @_default_mode) test_mode = ENV.fetch('TEST_GEM', 'rails').eql?('gem') config_path!( test_mode ? './spec/factories/' : './config/' ) load_config_basename!(cfg_file) end |
Dynamic Method Handling
This class handles dynamic methods through the method_missing method in the class SknUtils::NestedResult
Instance Method Details
#add_source!(file_path_or_hash) ⇒ Object
:reload! required
82 83 84 85 86 |
# File 'lib/skn_utils/configuration.rb', line 82 def add_source!(file_path_or_hash) # load last return {} unless valid_file_path?(file_path_or_hash) @_last_filelist.push(file_path_or_hash).flatten self end |
#config_path!(config_root) ⇒ Object
53 54 55 56 |
# File 'lib/skn_utils/configuration.rb', line 53 def config_path!(config_root) @_base_path = config_root[-1].eql?('/') ? config_root : "#{config_root}/" self end |
#load_and_set_settings(ordered_list_of_files) ⇒ Object Also known as: reload_from_files
63 64 65 66 |
# File 'lib/skn_utils/configuration.rb', line 63 def load_and_set_settings(ordered_list_of_files) reset_from_empty!( load_ordered_list( ordered_list_of_files ), false ) self end |
#load_config_basename!(environment_name = @_default_mode) ⇒ Object
58 59 60 61 |
# File 'lib/skn_utils/configuration.rb', line 58 def load_config_basename!(environment_name=@_default_mode) reset_from_empty!(load_config(environment_name), false) # enable dot notation via defined methods(true) vs method_missing(false) self end |
#prepend_source!(file_path_or_hash) ⇒ Object
:reload! required
89 90 91 92 93 |
# File 'lib/skn_utils/configuration.rb', line 89 def prepend_source!(file_path_or_hash) # load first return {} unless valid_file_path?(file_path_or_hash) @_last_filelist.unshift(file_path_or_hash).flatten self end |
#reload! ⇒ Object
69 70 71 72 |
# File 'lib/skn_utils/configuration.rb', line 69 def reload! reset_from_empty!( load_ordered_list(@_last_filelist), false ) self end |
#setting_files(config_root, environment_name) ⇒ Object
Config.setting_files(“/path/to/config_root”, “your_project_environment”)
75 76 77 78 79 |
# File 'lib/skn_utils/configuration.rb', line 75 def setting_files(config_root, environment_name) # returns a file array config_path!(config_root) @_default_mode = environment_name configuration_files(environment_name) end |