Module: GemStats::Connection

Defined in:
lib/gem_stats/connection.rb

Class Method Summary collapse

Class Method Details

.connect(options = {}) ⇒ Object



5
6
7
8
9
10
11
12
13
# File 'lib/gem_stats/connection.rb', line 5

def self.connect(options = {})
  if options.empty?
    env, path = defined?(Rails)? [Rails.env, [Rails.root, 'config/database.yml']] :
      [ENV['ENV'] || 'development', File.expand_path('../../../config/database.yml', __FILE__)]
    get_config(path) {|config| MongoMapper.setup(config, env) }
  else
    MongoMapper.setup(options[:config], options[:env])
  end
end

.get_config(*path) {|YAML::load(ERB.new(File.read File.join(path)).result)| ... } ⇒ Object

Yields:

  • (YAML::load(ERB.new(File.read File.join(path)).result))


15
16
17
# File 'lib/gem_stats/connection.rb', line 15

def self.get_config(*path)
  yield YAML::load(ERB.new(File.read File.join(path)).result)
end