Class: SknUtils::Configuration

Inherits:
NestedResult show all
Defined in:
lib/skn_utils/configuration.rb

Instance Method Summary collapse

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”



44
45
46
47
48
49
50
51
52
53
# File 'lib/skn_utils/configuration.rb', line 44

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



84
85
86
87
88
# File 'lib/skn_utils/configuration.rb', line 84

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



55
56
57
58
# File 'lib/skn_utils/configuration.rb', line 55

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



65
66
67
68
# File 'lib/skn_utils/configuration.rb', line 65

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



60
61
62
63
# File 'lib/skn_utils/configuration.rb', line 60

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



91
92
93
94
95
# File 'lib/skn_utils/configuration.rb', line 91

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



71
72
73
74
# File 'lib/skn_utils/configuration.rb', line 71

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”)



77
78
79
80
81
# File 'lib/skn_utils/configuration.rb', line 77

def setting_files(config_root, environment_name) # returns a file array
  config_path!(config_root)
  @_default_mode = environment_name
  configuration_files(environment_name)
end