Skip to content
This repository

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Browse code

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

  • Loading branch information...
commit 475691f6b03a8eb0b1697ffe427f9b55aa0505ad 1 parent 4f1e648
Christian Meier authored October 07, 2009
1  Manifest.txt
@@ -3,7 +3,6 @@ Manifest.txt
3 3
 README.txt
4 4
 Rakefile
5 5
 datamapper_rails_templates.rb
6  
-generate.sh
7 6
 generators/datamapper_install/datamapper_install_generator.rb
8 7
 generators/datamapper_install/templates/datamapper.rake
9 8
 generators/datamapper_model/datamapper_model_generator.rb
94  README.txt
... ...
@@ -1,14 +1,15 @@
1 1
 = datamapper4rails
2 2
 
3 3
 * http://datamapper4rail.rubyforge.org
  4
+* http://github.org/mkristian/datamapper4rails
4 5
 
5 6
 == DESCRIPTION:
6 7
 
7  
-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.
  8
+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.
8 9
 
9 10
 == FEATURES/PROBLEMS:
10 11
 
11  
-* restful adapter does handle associations partially and does not handle collections
  12
+* 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.
12 13
 
13 14
 == SYNOPSIS:
14 15
 
@@ -20,7 +21,20 @@ credits of the main idea goes to http://www.redhillonrails.org
20 21
 
21 22
 is implemented as around filter in rails and gets prepend to the filters of the action_controller of rails
22 23
 
23  
-  require 'datamapper4rails/restful_transations
  24
+  require 'datamapper4rails/restful_transations'
  25
+
  26
+=== restful transactions, transactions or identity_maps from rack-datamapper
  27
+
  28
+inside rails add something like this to your config
  29
+
  30
+config.middleware.use 'DataMapper::IdentityMaps'
  31
+config.middleware.use 'DataMapper::RestfulTransactions'
  32
+
  33
+or add the repository name to it if you want something else then :default
  34
+
  35
+config.middleware.use 'DataMapper::IdentityMaps', :ldap
  36
+config.middleware.use 'DataMapper::RestfulTransactions', :users
  37
+
24 38
 
25 39
 === datamapper session store
26 40
 
@@ -34,40 +48,70 @@ in case you need a memory cache for your sessions on top of it add the following
34 48
 
35 49
 === generators for datamapper models
36 50
 
37  
-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.
  51
+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.
38 52
 
39  
-* dm-install: rake task for datamapper: automigrate, autoupgrade 
40  
-* dm_model
41  
-* rspec_dm_model
  53
+* datamapper-install: rake task for datamapper with automigrate, autoupgrade and migrate
  54
+* datamapper_model
  55
+* datamapper_rspec_model
  56
+* datamapper_scaffold
  57
+* datamapper_rspec_scaffold
42 58
 
43  
-=== database config
  59
+the last  four generators follow the parameters of  the underlying generator:
  60
+generator_name model_name [[attribute_name:attribute_type] ...]
44 61
 
45  
-this is also taken from dm-more/rails_datamapper and just uses the 
46  
-'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:
  62
+to use the overlay write the generator like this
47 63
 
48  
-  development:
49  
-    repositories:
50  
-      default:
51  
-        adapter: sqlite3
52  
-        database: db/development.sqlite3
53  
-        pool: 5
54  
-        timeout: 5000
55  
-      users:
56  
-        adapter: ldap
57  
-        host: localhost
58  
-        port: 389
59  
-        base: dc=example,dc=com
60  
-        bind_name: cn=admin,dc=example,dc=com
61  
-        password: secret
  64
+class MyModelGenerator < ModelGenerator
  65
+  def manifest
  66
+    overlay_dirs.add_generator("model")
  67
+    super
  68
+  end
  69
+end
62 70
 
  71
+and put whatever templates you want to overwrite in your templates directory, i.e. all your models need to have nice to_s methods.
63 72
 
64 73
 === restful adapter
65 74
 
  75
+DEPRECATED
66 76
 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.
67 77
 
  78
+== rails template
  79
+
  80
+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 'github.org/jeremy/rails-templates'
  81
+
  82
+=== to test the template there is helper class
  83
+
  84
+task :integration_tests => [:install] do
  85
+  require 'datamapper4rails/integration_test'
  86
+  Datamapper4Rails::IntegrationTest.new do |t|
  87
+    t.rails_template = 'my_template.rb'
  88
+    t.directory = 'tmp' # defaults to tmp and is also the generated application name
  89
+    t.generate "datamapper_model role name:string"
  90
+    t.generate "datamapper_scaffold domain name:string"
  91
+    t.generate "datamapper_rspec_model user name:string"
  92
+    t.generate "datamapper_rspec_scaffold group name:string"
  93
+  end
  94
+end
  95
+
  96
+== more examples 
  97
+
  98
+just run 'rake integration' and have a look at the sample rails application in 'tmp'
  99
+
  100
+== jruby
  101
+
  102
+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.
  103
+
  104
+if you are familiar with maven (maven.apache.org) you can use the maven plugin from github.org/mkristian/rails-maven-plugin to freeze rails gems and patch it in place
  105
+
  106
+mvn de.saumya.mojo:rails-maven-plugin:rails-freeze-gems
  107
+
  108
+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.
  109
+
  110
+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.
  111
+
68 112
 == REQUIREMENTS:
69 113
 
70  
-* datamapper
  114
+* rails_datamapper, rack-datamapper
71 115
 
72 116
 == INSTALL:
73 117
 
2  Rakefile
@@ -31,7 +31,7 @@ Spec::Rake::SpecTask.new(:spec) do |t|
31 31
 end
32 32
 
33 33
 desc 'generate rails using all generators and run the specs'
34  
-task :integration_tests => [:install] do
  34
+task :integration_tests => [:spec, :install] do
35 35
   require 'datamapper4rails/integration_test'
36 36
   Datamapper4Rails::IntegrationTest.new do |t|
37 37
     t.generate "datamapper_model role name:string"
5  datamapper_rails_templates.rb
@@ -11,6 +11,7 @@
11 11
 gem 'dm-validations'
12 12
 gem 'dm-timestamps'
13 13
 gem 'dm-migrations'
  14
+gem 'dm-serializer' # to allow xml interface to work
14 15
 
15 16
 # assume you prefer rspec over unit tests
16 17
 gem "rspec", :lib => false
@@ -99,7 +100,7 @@ def <<(arg)
99 100
 echo "\tmvn de.saumya.mojo:rails-maven-plugin:server"
100 101
 echo
101 102
 echo "more info on"
102  
-echo "\tgithub.org/mkristian/rails-maven-plugin"
  103
+echo "\thttp://github.org/mkristian/rails-maven-plugin"
103 104
 echo
104 105
 CODE
105 106
 
@@ -108,6 +109,6 @@ def <<(arg)
108 109
 logger.info 
109 110
 logger.info 
110 111
 logger.info "info mavenized rails application"
111  
-logger.info "\tgithub.org/mkristian/rails-maven-plugin"
  112
+logger.info "\thttp://github.org/mkristian/rails-maven-plugin"
112 113
 logger.info 
113 114
 logger.info 
6  generate.sh
... ...
@@ -1,6 +0,0 @@
1  
-script/generate datamapper_model datamapper_model name:string
2  
-script/generate rspec_datamapper_model rspec_datamapper_model name:string
3  
-script/generate datamapper_controller datamapper_controller index
4  
-script/generate rspec_datamapper_controller rspec_datamapper_controller index
5  
-#script/generate datamapper_scaffold datamapper_scaffold name:string
6  
-script/generate rspec_datamapper_scaffold rspec_datamapper_scaffold name:string
2  lib/datamapper4rails/identity_maps.rb
... ...
@@ -1,6 +1,8 @@
1 1
 module Datamapper4rails
2 2
   module IdentityMaps
3 3
 
  4
+    warn "deprecated use the one from rack-datamapper instead"
  5
+
4 6
     module Base
5 7
       def self.included(base)
6 8
         base.prepend_around_filter(IdentityMapFilter)
2  lib/datamapper4rails/integration_test.rb
@@ -17,7 +17,7 @@ def initialize
17 17
     end
18 18
 
19 19
     def generate(*args)
20  
-      @generator_args << args.map(&:to_s).join(" ")
  20
+      @generator_args << args.join(" ")
21 21
     end
22 22
 
23 23
     def execute

0 notes on commit 475691f

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