Class: AppConfiguration::Config

Inherits:
Object
  • Object
show all
Includes:
OptionalAttr
Defined in:
lib/app_configuration/config.rb

Class Method Summary collapse

Instance Method Summary collapse

Methods included from OptionalAttr

included

Constructor Details

#initialize(config_file_name = nil, &block) ⇒ Config

Instance Methods



30
31
32
33
34
# File 'lib/app_configuration/config.rb', line 30

def initialize(config_file_name = nil, &block)
  super() # Sets default values for optional attributes
  @config_file_name = config_file_name if config_file_name
  self.instance_eval(&block) if block_given?
end

Dynamic Method Handling

This class handles dynamic methods through the method_missing method

#method_missing(method, *args, &block) ⇒ Object



55
56
57
# File 'lib/app_configuration/config.rb', line 55

def method_missing(method, *args, &block)
  self[method.to_s]
end

Class Method Details

.default_global_path=(default_global_path) ⇒ Object



22
23
24
# File 'lib/app_configuration/config.rb', line 22

def default_global_path=(default_global_path)
  defaults[:base_global_path] = default_global_path
end

.default_local_path=(default_local_path) ⇒ Object



18
19
20
# File 'lib/app_configuration/config.rb', line 18

def default_local_path=(default_local_path)
  defaults[:base_local_path] = default_local_path
end

Instance Method Details

#[](name) ⇒ Object



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

def [](name)
  env_name = ''
  env_name << "#{@prefix.upcase}_" if @prefix
  env_name << name.to_s.upcase
  if @use_env_variables && ENV[env_name]
    ENV[env_name]
  else
    config[name]
  end
end

#global_config_pathObject



40
41
42
# File 'lib/app_configuration/config.rb', line 40

def global_config_path
  @global_config_path ||= config_path(@base_global_path)
end

#local_config_pathObject



36
37
38
# File 'lib/app_configuration/config.rb', line 36

def local_config_path
  @local_config_path ||= config_path(@base_local_path)
end