Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Browse files

* no more dependency to rails_datamapper

* allow to configure multiple repositories
  • Loading branch information...
commit 6c3d180561f31298488858ceaed9ef91941b1735 1 parent 15dc5fa
@mkristian authored
View
1  Manifest.txt
@@ -28,6 +28,7 @@ lib/datamapper4rails/integration_test.rb
lib/datamapper4rails/identity_maps.rb
lib/datamapper4rails/overlay.rb
lib/datamapper4rails/preload_models.rb
+lib/datamapper4rails/rails_datamapper.rb
lib/datamapper4rails/restful_transactions.rb
lib/datamapper4rails/rspec_default_values.rb
lib/datamapper4rails/rspec.rb
View
2  Rakefile
@@ -12,7 +12,7 @@ require './lib/datamapper4rails/version.rb'
Hoe.spec('datamapper4rails') do |p|
p.rubyforge_name = 'datamapper4rail'
p.developer('mkristian', 'm.kristian@web.de')
- p.extra_deps = [['rack-datamapper', '~>0.2'], ['rails_datamapper', '>= 0']]
+ p.extra_deps = [['rack-datamapper', '~>0.2']]
p.remote_rdoc_dir = '' # Release to root
p.rspec_options << '--options' << 'spec/spec.opts'
end
View
2  lib/datamapper4rails.rb
@@ -1,4 +1,4 @@
-require 'rails_datamapper'
+require 'datamapper4rails/rails_datamapper'
require 'rack-datamapper'
require 'datamapper4rails/datamapper_store'
View
65 lib/datamapper4rails/rails_datamapper.rb
@@ -0,0 +1,65 @@
+# taken from http://github.com/datamapper/dm-more/tree/master/rails_datamapper
+# added multi repositories config
+
+module Rails
+ module DataMapper
+ class << self
+ extend ActiveSupport::Memoizable
+
+ def create_connection
+ # TODO: handle Rails and Merb style database.yml files
+ conf = config.dup
+ repositories = conf.delete(:repositories)
+ if(repositories)
+ repositories.each do |key, config|
+ ::DataMapper.setup(key.to_sym, config)
+ end
+ else
+ ::DataMapper.setup(:default, conf) unless conf.empty?
+ end
+ end
+
+ private
+
+ def config_file
+ Rails.root / 'config' / 'database.yml'
+ end
+
+ def full_config
+ YAML::load(ERB.new(config_file.read).result)
+ end
+
+ memoize :full_config
+
+ def config
+ if hash = full_config[Rails.env] || full_config[Rails.env.to_sym]
+ normalize_config(hash)
+ else
+ raise ArgumentError, "missing environment '#{Rails.env}' in config file #{config_file}"
+ end
+ end
+
+ memoize :config
+
+ def normalize_config(hash)
+ config = {}
+
+ hash.symbolize_keys.each do |key, value|
+ config[key] = if value.kind_of?(Hash)
+ normalize_config(value)
+ elsif key == :port
+ value.to_i
+ elsif key == :adapter && value == 'postgresql'
+ 'postgres'
+ else
+ value
+ end
+ end
+
+ config
+ end
+ end
+ end
+end
+
+Rails::DataMapper.create_connection
View
2  lib/datamapper4rails/version.rb
@@ -1,3 +1,3 @@
class Datamapper4rails
- VERSION = '0.3.2'.freeze
+ VERSION = '0.4.0'.freeze
end
Please sign in to comment.
Something went wrong with that request. Please try again.