lib/alvid.rb in alvid-0.1.0 vs lib/alvid.rb in alvid-0.2.0
- old
+ new
@@ -5,10 +5,16 @@
def self.init
db_uri = if ENV['VCAP_SERVICES'].nil? || JSON.parse(ENV['VCAP_SERVICES']).empty?
require 'dm-sqlite-adapter'
'sqlite::memory:'
else
- JSON.parse(ENV['VCAP_SERVICES']).first[1].first.first[1]['uri']
+ product_name, service = JSON.parse(ENV['VCAP_SERVICES']).first
+ case product_name
+ when /mysql/
+ service.first.first[1]['uri']
+ when /cleardb/
+ service.first['credentials']['uri']
+ end
end
DataMapper.setup(:default, db_uri)
end
end