Skip to content
This repository

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Browse code

* no more dependency to rails_datamapper

* allow to configure multiple repositories
  • Loading branch information...
commit 6c3d180561f31298488858ceaed9ef91941b1735 1 parent 15dc5fa
Christian Meier authored December 01, 2009
1  Manifest.txt
@@ -28,6 +28,7 @@ lib/datamapper4rails/integration_test.rb
28 28
 lib/datamapper4rails/identity_maps.rb
29 29
 lib/datamapper4rails/overlay.rb
30 30
 lib/datamapper4rails/preload_models.rb
  31
+lib/datamapper4rails/rails_datamapper.rb
31 32
 lib/datamapper4rails/restful_transactions.rb
32 33
 lib/datamapper4rails/rspec_default_values.rb
33 34
 lib/datamapper4rails/rspec.rb
2  Rakefile
@@ -12,7 +12,7 @@ require './lib/datamapper4rails/version.rb'
12 12
 Hoe.spec('datamapper4rails') do |p|
13 13
   p.rubyforge_name = 'datamapper4rail'
14 14
   p.developer('mkristian', 'm.kristian@web.de')
15  
-  p.extra_deps = [['rack-datamapper', '~>0.2'], ['rails_datamapper', '>= 0']]
  15
+  p.extra_deps = [['rack-datamapper', '~>0.2']]
16 16
   p.remote_rdoc_dir = '' # Release to root
17 17
   p.rspec_options << '--options' << 'spec/spec.opts'
18 18
 end
2  lib/datamapper4rails.rb
... ...
@@ -1,4 +1,4 @@
1  
-require 'rails_datamapper'
  1
+require 'datamapper4rails/rails_datamapper'
2 2
 require 'rack-datamapper'
3 3
 require 'datamapper4rails/datamapper_store'
4 4
 
65  lib/datamapper4rails/rails_datamapper.rb
... ...
@@ -0,0 +1,65 @@
  1
+# taken from http://github.com/datamapper/dm-more/tree/master/rails_datamapper
  2
+# added multi repositories config
  3
+
  4
+module Rails
  5
+  module DataMapper
  6
+    class << self
  7
+      extend ActiveSupport::Memoizable
  8
+
  9
+      def create_connection
  10
+        # TODO: handle Rails and Merb style database.yml files
  11
+        conf = config.dup
  12
+        repositories = conf.delete(:repositories)
  13
+        if(repositories)
  14
+          repositories.each do |key, config|
  15
+            ::DataMapper.setup(key.to_sym, config)
  16
+          end
  17
+        else
  18
+          ::DataMapper.setup(:default, conf) unless conf.empty?
  19
+        end
  20
+      end
  21
+
  22
+    private
  23
+
  24
+      def config_file
  25
+        Rails.root / 'config' / 'database.yml'
  26
+      end
  27
+
  28
+      def full_config
  29
+        YAML::load(ERB.new(config_file.read).result)
  30
+      end
  31
+
  32
+      memoize :full_config
  33
+
  34
+      def config
  35
+        if hash = full_config[Rails.env] || full_config[Rails.env.to_sym]
  36
+          normalize_config(hash)
  37
+        else
  38
+          raise ArgumentError, "missing environment '#{Rails.env}' in config file #{config_file}"
  39
+        end
  40
+      end
  41
+
  42
+      memoize :config
  43
+
  44
+      def normalize_config(hash)
  45
+        config = {}
  46
+
  47
+        hash.symbolize_keys.each do |key, value|
  48
+          config[key] = if value.kind_of?(Hash)
  49
+            normalize_config(value)
  50
+          elsif key == :port
  51
+            value.to_i
  52
+          elsif key == :adapter && value == 'postgresql'
  53
+            'postgres'
  54
+          else
  55
+            value
  56
+          end
  57
+        end
  58
+
  59
+        config
  60
+      end
  61
+    end
  62
+  end
  63
+end
  64
+
  65
+Rails::DataMapper.create_connection
2  lib/datamapper4rails/version.rb
... ...
@@ -1,3 +1,3 @@
1 1
 class Datamapper4rails
2  
-  VERSION = '0.3.2'.freeze
  2
+  VERSION = '0.4.0'.freeze
3 3
 end

0 notes on commit 6c3d180

Please sign in to comment.
Something went wrong with that request. Please try again.