Module: MultiConfig::ORMs::ActiveRecord::Config

Defined in:
lib/multi_config/orms/active_record.rb

Overview

Defines helper methods to be used the the extension. Since this is in the enclosing module for ClassMethods Module. This will be searched first when Config is referenced. The Ruby Programming Language - Page 276

Class Method Summary collapse

Class Method Details

.load(file_name, namespace) ⇒ Object

Load a yaml file and modify the keys by appending <namespace>_ string in the keys. For e.g. if a yaml file with namespace other_db is loaded with environments test and development, the returned hash from this method would contain keys ‘other_db_test’ and ‘other_db_development’.



81
82
83
84
85
86
87
88
89
90
91
92
93
# File 'lib/multi_config/orms/active_record.rb', line 81

def self.load(file_name, namespace)
  begin
    require 'erb'
    YAML.load(ERB.new(IO.read(path(file_name))).result).inject({}) do |hash, (k, v)|
      hash["#{namespace}_#{k}"] = v
      hash
    end
  # ruby 1.9 raises SyntaxError exception which is not subclass of
  rescue StandardError, SyntaxError
    raise "File #{path file_name} does not exist in config" unless File.exists?(path(file_name))
    raise "Invalid config file #{path file_name}"
  end
end

.path(file_name) ⇒ Object

Returns the absolute path for the file specified. The file is supposed to be located in the config folder.



74
75
76
# File 'lib/multi_config/orms/active_record.rb', line 74

def self.path(file_name)
  File.join(Rails.root, 'config', file_name)
end