Class: ConfigLoader::Map
- Inherits:
-
Hash
- Object
- Hash
- ConfigLoader::Map
- Defined in:
- lib/config_loader/map.rb
Instance Attribute Summary collapse
-
#file_name ⇒ Object
readonly
Returns the value of attribute file_name.
-
#project_root ⇒ Object
readonly
Returns the value of attribute project_root.
-
#running_env ⇒ Object
readonly
Returns the value of attribute running_env.
Instance Method Summary collapse
- #file_content ⇒ Object
- #full_file_name ⇒ Object
-
#initialize(file_name, running_env, project_root) ⇒ Map
constructor
A new instance of Map.
- #method_missing(method_name) ⇒ Object
- #populate ⇒ Object
Constructor Details
#initialize(file_name, running_env, project_root) ⇒ Map
Returns a new instance of Map.
7 8 9 10 11 12 |
# File 'lib/config_loader/map.rb', line 7 def initialize(file_name, running_env, project_root) raise MissingConfigFileNameError unless file_name @file_name = "#{file_name}.yml" @running_env = running_env @project_root = project_root end |
Dynamic Method Handling
This class handles dynamic methods through the method_missing method
#method_missing(method_name) ⇒ Object
30 31 32 |
# File 'lib/config_loader/map.rb', line 30 def method_missing(method_name) self[method_name] end |
Instance Attribute Details
#file_name ⇒ Object (readonly)
Returns the value of attribute file_name.
5 6 7 |
# File 'lib/config_loader/map.rb', line 5 def file_name @file_name end |
#project_root ⇒ Object (readonly)
Returns the value of attribute project_root.
5 6 7 |
# File 'lib/config_loader/map.rb', line 5 def project_root @project_root end |
#running_env ⇒ Object (readonly)
Returns the value of attribute running_env.
5 6 7 |
# File 'lib/config_loader/map.rb', line 5 def running_env @running_env end |
Instance Method Details
#file_content ⇒ Object
14 15 16 17 |
# File 'lib/config_loader/map.rb', line 14 def file_content raise MissingConfigFileError unless File.exists?(full_file_name) File.open(full_file_name) { |file| YAML::load(file) } end |
#full_file_name ⇒ Object
19 20 21 |
# File 'lib/config_loader/map.rb', line 19 def full_file_name "#{project_root}/config/#{file_name}" end |
#populate ⇒ Object
23 24 25 26 27 28 |
# File 'lib/config_loader/map.rb', line 23 def populate file_content[@running_env].each do |key, value| self[key] = value self[key.to_sym] = value end end |