Browse files

jruby fixes, add dm-serializer to template, deprecated warning, ...

  • Loading branch information...
1 parent 4f1e648 commit 475691f6b03a8eb0b1697ffe427f9b55aa0505ad @mkristian committed Oct 7, 2009
Showing with 76 additions and 36 deletions.
  1. +0 −1 Manifest.txt
  2. +69 −25 README.txt
  3. +1 −1 Rakefile
  4. +3 −2 datamapper_rails_templates.rb
  5. +0 −6
  6. +2 −0 lib/datamapper4rails/identity_maps.rb
  7. +1 −1 lib/datamapper4rails/integration_test.rb
@@ -3,7 +3,6 @@ Manifest.txt
@@ -1,14 +1,15 @@
= datamapper4rails
-collection of datamapper related extensions. mostly needed to run within rails. the restful transactions is around filter for rails. the restful adapter can be outside of rails. datamapper store is a session store for rails which uses datamapper as persistent layer. the generators produces datamapper models for your rails application. quite a few things are "stolen" from dm-more/rails_datamapper. a lot of things do not work there and patches are still in process to be applied so until dm-more/rails_datamapper catches up, ut I hope these two project merge someday again.
+collection of datamapper related extensions. mostly needed to run within rails. the restful transactions is around filter for rails actions if needed to control such transaction on per action base otherwise use the rack extension from rack-datamapper. datamapper store is a session store for rails which uses datamapper as persistent layer and is just a wrapper around the datamapper session store from rack-datamapper. the generators produces datamapper models for your rails application.
-* restful adapter does handle associations partially and does not handle collections
+* the generators introduce an "overlay" of templates. with that a generator can reuse the generator code and just replace one or more templates. i.e. datamapper_model just replaces the model.rb template to produce model using datamapper.
@@ -20,7 +21,20 @@ credits of the main idea goes to
is implemented as around filter in rails and gets prepend to the filters of the action_controller of rails
- require 'datamapper4rails/restful_transations
+ require 'datamapper4rails/restful_transations'
+=== restful transactions, transactions or identity_maps from rack-datamapper
+inside rails add something like this to your config
+config.middleware.use 'DataMapper::IdentityMaps'
+config.middleware.use 'DataMapper::RestfulTransactions'
+or add the repository name to it if you want something else then :default
+config.middleware.use 'DataMapper::IdentityMaps', :ldap
+config.middleware.use 'DataMapper::RestfulTransactions', :users
=== datamapper session store
@@ -34,40 +48,70 @@ in case you need a memory cache for your sessions on top of it add the following
=== generators for datamapper models
-this is taken from dm-more/rails_datamapper and extended it - to my liking. patches are submitted upstream until they get applied this will remain here.
+IMPORTANT: datamapper_scaffold generate valid application code but the test do NOT run due to missing fixtures with datamapper. the rspec version works well though.
-* dm-install: rake task for datamapper: automigrate, autoupgrade
-* dm_model
-* rspec_dm_model
+* datamapper-install: rake task for datamapper with automigrate, autoupgrade and migrate
+* datamapper_model
+* datamapper_rspec_model
+* datamapper_scaffold
+* datamapper_rspec_scaffold
-=== database config
+the last four generators follow the parameters of the underlying generator:
+generator_name model_name [[attribute_name:attribute_type] ...]
-this is also taken from dm-more/rails_datamapper and just uses the
-'config/database.yml' to configure a database connection. it also allows to configure multiple repositories for a single environment just nest the config in such a way:
+to use the overlay write the generator like this
- development:
- repositories:
- default:
- adapter: sqlite3
- database: db/development.sqlite3
- pool: 5
- timeout: 5000
- users:
- adapter: ldap
- host: localhost
- port: 389
- base: dc=example,dc=com
- bind_name: cn=admin,dc=example,dc=com
- password: secret
+class MyModelGenerator < ModelGenerator
+ def manifest
+ overlay_dirs.add_generator("model")
+ super
+ end
+and put whatever templates you want to overwrite in your templates directory, i.e. all your models need to have nice to_s methods.
=== restful adapter
this comes partly from dm-ldap-adapter and partly from dm-more/adapter/rest_adapter. the restful adapter allows to Create, Retrieve, Update and Delete resources via a restful service.
+== rails template
+there is a rails template 'datamapper_rails_templates.rb' in root of the gem - do not know where and how to pack it. the latest I keep on ''
+=== to test the template there is helper class
+task :integration_tests => [:install] do
+ require 'datamapper4rails/integration_test'
+ do |t|
+ t.rails_template = 'my_template.rb'
+ = 'tmp' # defaults to tmp and is also the generated application name
+ t.generate "datamapper_model role name:string"
+ t.generate "datamapper_scaffold domain name:string"
+ t.generate "datamapper_rspec_model user name:string"
+ t.generate "datamapper_rspec_scaffold group name:string"
+ end
+== more examples
+just run 'rake integration' and have a look at the sample rails application in 'tmp'
+== jruby
+at the time of writing there is a bug/restriction in rails which prevents unpacked gems with java extension or version number postfixed with '-java' to work.
+if you are familiar with maven ( you can use the maven plugin from to freeze rails gems and patch it in place
+mvn de.saumya.mojo:rails-maven-plugin:rails-freeze-gems
+the 'rake integration_tests' does not work due to the fact that generating rails with a template falls back to native ruby for certain tasks which will fail due to missing (java) gems.
+same is true for using the rails template. in case you want to use a rails template directly with jruby consider the rails-maven-plugin which can setup a mavenized rails application with the help of rails templates.
-* datamapper
+* rails_datamapper, rack-datamapper
@@ -31,7 +31,7 @@ do |t|
desc 'generate rails using all generators and run the specs'
-task :integration_tests => [:install] do
+task :integration_tests => [:spec, :install] do
require 'datamapper4rails/integration_test' do |t|
t.generate "datamapper_model role name:string"
@@ -11,6 +11,7 @@
gem 'dm-validations'
gem 'dm-timestamps'
gem 'dm-migrations'
+gem 'dm-serializer' # to allow xml interface to work
# assume you prefer rspec over unit tests
gem "rspec", :lib => false
@@ -99,7 +100,7 @@ def <<(arg)
echo "\tmvn de.saumya.mojo:rails-maven-plugin:server"
echo "more info on"
-echo "\"
+echo "\t"
@@ -108,6 +109,6 @@ def <<(arg) "info mavenized rails application" "\" "\t"
@@ -1,6 +0,0 @@
-script/generate datamapper_model datamapper_model name:string
-script/generate rspec_datamapper_model rspec_datamapper_model name:string
-script/generate datamapper_controller datamapper_controller index
-script/generate rspec_datamapper_controller rspec_datamapper_controller index
-#script/generate datamapper_scaffold datamapper_scaffold name:string
-script/generate rspec_datamapper_scaffold rspec_datamapper_scaffold name:string
@@ -1,6 +1,8 @@
module Datamapper4rails
module IdentityMaps
+ warn "deprecated use the one from rack-datamapper instead"
module Base
def self.included(base)
@@ -17,7 +17,7 @@ def initialize
def generate(*args)
- @generator_args <<" ")
+ @generator_args << args.join(" ")
def execute

0 comments on commit 475691f

Please sign in to comment.