Class: ConfigLoader::Map

Inherits:
Object
  • Object
show all
Defined in:
lib/config_loader/map.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(file_name, running_env, project_root) ⇒ Map

Returns a new instance of Map.



8
9
10
11
12
13
# File 'lib/config_loader/map.rb', line 8

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



28
29
30
# File 'lib/config_loader/map.rb', line 28

def method_missing(method_name)
  self[method_name]
end

Instance Attribute Details

#file_nameObject (readonly)

Returns the value of attribute file_name.



6
7
8
# File 'lib/config_loader/map.rb', line 6

def file_name
  @file_name
end

#project_rootObject (readonly)

Returns the value of attribute project_root.



6
7
8
# File 'lib/config_loader/map.rb', line 6

def project_root
  @project_root
end

#running_envObject (readonly)

Returns the value of attribute running_env.



6
7
8
# File 'lib/config_loader/map.rb', line 6

def running_env
  @running_env
end

Instance Method Details

#file_contentObject



15
16
17
18
# File 'lib/config_loader/map.rb', line 15

def file_content
  raise MissingConfigFileError.new(full_file_name) unless File.exists?(full_file_name)
  YAML.load(ERB.new(File.read(full_file_name)).result)
end

#full_file_nameObject



20
21
22
# File 'lib/config_loader/map.rb', line 20

def full_file_name
  "#{project_root}/config/#{file_name}"
end

#loadObject



24
25
26
# File 'lib/config_loader/map.rb', line 24

def load
  file_content[@running_env]
end