dm-rails 1.0.0.rc1
Sign up to get free protection for your applications and to get access to all the features.
- data/.document +5 -0
- data/.gitignore +36 -0
- data/Gemfile +37 -0
- data/LICENSE +20 -0
- data/README.rdoc +506 -0
- data/Rakefile +33 -0
- data/VERSION +1 -0
- data/dm-rails.gemspec +85 -0
- data/lib/dm-rails.rb +1 -0
- data/lib/dm-rails/configuration.rb +70 -0
- data/lib/dm-rails/middleware/identity_map.rb +19 -0
- data/lib/dm-rails/railtie.rb +103 -0
- data/lib/dm-rails/railties/benchmarking_mixin.rb +23 -0
- data/lib/dm-rails/railties/controller_runtime.rb +45 -0
- data/lib/dm-rails/railties/database.rake +124 -0
- data/lib/dm-rails/railties/i18n_support.rb +12 -0
- data/lib/dm-rails/railties/log_subscriber.rb +31 -0
- data/lib/dm-rails/session_store.rb +61 -0
- data/lib/dm-rails/setup.rb +41 -0
- data/lib/dm-rails/storage.rb +165 -0
- data/lib/generators/data_mapper.rb +82 -0
- data/lib/generators/data_mapper/migration/migration_generator.rb +30 -0
- data/lib/generators/data_mapper/migration/templates/migration.rb +23 -0
- data/lib/generators/data_mapper/model/model_generator.rb +23 -0
- data/lib/generators/data_mapper/model/templates/model.rb +11 -0
- data/lib/generators/data_mapper/observer/observer_generator.rb +19 -0
- data/lib/generators/data_mapper/observer/templates/observer.rb +7 -0
- data/tasks/ci.rake +1 -0
- data/tasks/clean.rake +6 -0
- data/tasks/local_gemfile.rake +18 -0
- data/tasks/metrics.rake +37 -0
- data/tasks/yard.rake +9 -0
- data/tasks/yardstick.rake +20 -0
- metadata +171 -0
data/.document
ADDED
data/.gitignore
ADDED
@@ -0,0 +1,36 @@
|
|
1
|
+
## MAC OS
|
2
|
+
.DS_Store
|
3
|
+
|
4
|
+
## TEXTMATE
|
5
|
+
*.tmproj
|
6
|
+
tmtags
|
7
|
+
|
8
|
+
## EMACS
|
9
|
+
*~
|
10
|
+
\#*
|
11
|
+
.\#*
|
12
|
+
|
13
|
+
## VIM
|
14
|
+
*.swp
|
15
|
+
|
16
|
+
## Rubinius
|
17
|
+
*.rbc
|
18
|
+
|
19
|
+
## PROJECT::GENERAL
|
20
|
+
*.gem
|
21
|
+
coverage
|
22
|
+
rdoc
|
23
|
+
pkg
|
24
|
+
tmp
|
25
|
+
doc
|
26
|
+
log
|
27
|
+
.yardoc
|
28
|
+
measurements
|
29
|
+
|
30
|
+
## BUNDLER
|
31
|
+
.bundle
|
32
|
+
Gemfile.local
|
33
|
+
Gemfile.lock
|
34
|
+
|
35
|
+
## PROJECT::SPECIFIC
|
36
|
+
vendor
|
data/Gemfile
ADDED
@@ -0,0 +1,37 @@
|
|
1
|
+
source 'http://rubygems.org'
|
2
|
+
|
3
|
+
DATAMAPPER = 'git://github.com/datamapper'
|
4
|
+
DM_VERSION = '~> 1.0.0.rc1'
|
5
|
+
|
6
|
+
group :runtime do
|
7
|
+
|
8
|
+
git 'git://github.com/rails/rails.git' do
|
9
|
+
|
10
|
+
gem 'activesupport', '~> 3.0.0.beta3', :require => 'active_support'
|
11
|
+
gem 'actionpack', '~> 3.0.0.beta3', :require => 'action_pack'
|
12
|
+
gem 'railties', '~> 3.0.0.beta3', :require => 'rails'
|
13
|
+
|
14
|
+
end
|
15
|
+
|
16
|
+
gem 'dm-core', DM_VERSION, :git => "#{DATAMAPPER}/dm-core.git"
|
17
|
+
gem 'dm-active_model', '~> 0.4', :git => "#{DATAMAPPER}/dm-active_model.git"
|
18
|
+
|
19
|
+
end
|
20
|
+
|
21
|
+
group :development do
|
22
|
+
|
23
|
+
gem 'rake', '~> 0.8.7'
|
24
|
+
gem 'jeweler', '~> 1.4'
|
25
|
+
|
26
|
+
end
|
27
|
+
|
28
|
+
group :quality do # These gems contain rake tasks that check the quality of the source code
|
29
|
+
|
30
|
+
gem 'metric_fu', '~> 1.3'
|
31
|
+
gem 'rcov', '~> 0.9.7'
|
32
|
+
gem 'reek', '~> 1.2.7'
|
33
|
+
gem 'roodi', '~> 2.1'
|
34
|
+
gem 'yard', '~> 0.5'
|
35
|
+
gem 'yardstick', '~> 0.1'
|
36
|
+
|
37
|
+
end
|
data/LICENSE
ADDED
@@ -0,0 +1,20 @@
|
|
1
|
+
Copyright (c) 2009-2010 The dm-rails team
|
2
|
+
|
3
|
+
Permission is hereby granted, free of charge, to any person obtaining
|
4
|
+
a copy of this software and associated documentation files (the
|
5
|
+
"Software"), to deal in the Software without restriction, including
|
6
|
+
without limitation the rights to use, copy, modify, merge, publish,
|
7
|
+
distribute, sublicense, and/or sell copies of the Software, and to
|
8
|
+
permit persons to whom the Software is furnished to do so, subject to
|
9
|
+
the following conditions:
|
10
|
+
|
11
|
+
The above copyright notice and this permission notice shall be
|
12
|
+
included in all copies or substantial portions of the Software.
|
13
|
+
|
14
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
|
15
|
+
EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
|
16
|
+
MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
|
17
|
+
NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
|
18
|
+
LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
|
19
|
+
OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
|
20
|
+
WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
|
data/README.rdoc
ADDED
@@ -0,0 +1,506 @@
|
|
1
|
+
= dm-rails
|
2
|
+
|
3
|
+
This gem provides the railtie that allows {datamapper}[http://github.com/datamapper/dm-core] to hook into {rails3}[http://github.com/rails/rails] and thus behave like a rails framework component. Just like activercord does in rails, {dm-rails}[http://github.com/datamapper/dm-rails] uses the railtie API to hook into rails. The two are actually hooked into rails almost identically.
|
4
|
+
|
5
|
+
Creating new datamapper apps on rails3 from scratch is actually really easy. Like, *really* easy. The following will guide you through the process.
|
6
|
+
|
7
|
+
== Generating a new application from scratch
|
8
|
+
|
9
|
+
It's really easy to go from zero gems to a working rails3 app using datamapper. All you need is the latest {rubygems}[http://docs.rubygems.org/read/chapter/3] release and {rails}[http://github.com/rails/rails]
|
10
|
+
|
11
|
+
gem update —system # you will need rubygems-1.3.6 for the command below to work
|
12
|
+
gem install rails --pre
|
13
|
+
|
14
|
+
Once you have {rails}[http://github.com/rails/rails] and thus {bundler}[http://github.com/carlhuda/bundler] installed, you can bootstrap a rails master branch application with a single command. Yes! A single command. Cool.
|
15
|
+
|
16
|
+
rails dm_rails3_app -m http://github.com/snusnu/rails-templates/raw/master/dm_rails_master.rb
|
17
|
+
|
18
|
+
Now that was easy! Follow the instructions and point your browser to
|
19
|
+
|
20
|
+
http://localhost:3000/people
|
21
|
+
|
22
|
+
Awesome.
|
23
|
+
|
24
|
+
In the future, http://github.com/snusnu/rails-templates will host a more comprehensive set of rails application templates. Currently only the above are supported but you can expect some reasonable defaults to follow soon. Things like rspec and jquery support are definitely on the list, maybe also support for {devise}[http://github.com/plataformatec/devise] and {inherited_resources}[http://github.com/josevalim/inherited_resources]. These will of course be on a pluggable basis. Nothing will be forced upon you. We heavily encourage you to build your own customized application templates and maybe send us a note if you think they could be interesting to more people.
|
25
|
+
|
26
|
+
|
27
|
+
== rspec support
|
28
|
+
|
29
|
+
Unfortunately, I haven't yet been able to get rspec to work with the default sqlite3 database.yml setup. In order to get rspec working you would need to change to another database for now, like mysql. Edit your database.yml file to look something like this:
|
30
|
+
|
31
|
+
defaults: &defaults
|
32
|
+
adapter: mysql
|
33
|
+
username: root
|
34
|
+
password:
|
35
|
+
host: localhost
|
36
|
+
|
37
|
+
development:
|
38
|
+
database: dm_rails3_app_development
|
39
|
+
<<: *defaults
|
40
|
+
|
41
|
+
# Add more repositories
|
42
|
+
# repositories:
|
43
|
+
# repo1:
|
44
|
+
# adapter: postgresql
|
45
|
+
# database: sample_development
|
46
|
+
# username: the_user
|
47
|
+
# password: secrets
|
48
|
+
# host: localhost
|
49
|
+
# repo2:
|
50
|
+
# ...
|
51
|
+
|
52
|
+
test:
|
53
|
+
database: dm_rails3_app_test
|
54
|
+
<<: *defaults
|
55
|
+
production:
|
56
|
+
database: dm_rails3_app_production
|
57
|
+
<<: *defaults
|
58
|
+
|
59
|
+
and you should be good to and use rspec.
|
60
|
+
|
61
|
+
|
62
|
+
== Developing dm-rails
|
63
|
+
|
64
|
+
Issue the following commands to get a fully functional development environment including datamapper and rails up and running within a minute.
|
65
|
+
|
66
|
+
gem install bundler # if this is new for you
|
67
|
+
bundle install
|
68
|
+
rake spec
|
69
|
+
|
70
|
+
Now that was easy, wasn't it? Whenever you want to update your dependencies because you want to make sure you develop against master branches, just issue
|
71
|
+
|
72
|
+
bundle install
|
73
|
+
|
74
|
+
again and {bundler}[http://github.com/carlhuda/bundler] will go ahead and fetch the latest commits from the gems you depend on.
|
75
|
+
|
76
|
+
|
77
|
+
== Minimal sample application
|
78
|
+
|
79
|
+
Have a look at {datamapper_on_rails3}[http://github.com/snusnu/datamapper_on_rails3] for a very minimal sample application that was built following the previous instructions on how to build a new application from scratch.
|
80
|
+
|
81
|
+
== Sample Gemfile
|
82
|
+
|
83
|
+
Using {bundler}[http://github.com/carlhuda/bundler] it's really easy to get an app going with datamapper and rails3. Just use a Gemfile like this, and bundler will pull in everything needed to run your app. Note that you also must add any additional datamapper plugin or any other gem that you'd like to use to the Gemfile. This makes sure that bundler is able to provide a complete environment containing all required dependencies for your app.
|
84
|
+
|
85
|
+
source 'http://rubygems.org'
|
86
|
+
|
87
|
+
git 'git://github.com/carlhuda/bundler.git'
|
88
|
+
|
89
|
+
gem 'bundler', '~> 0.9.3'
|
90
|
+
|
91
|
+
git 'git://github.com/rails/rails.git'
|
92
|
+
|
93
|
+
gem 'activesupport', '~> 3.0.0.beta1', :require => 'active_support'
|
94
|
+
gem 'actionpack', '~> 3.0.0.beta1', :require => 'action_pack'
|
95
|
+
gem 'railties', '~> 3.0.0.beta1', :require => 'rails'
|
96
|
+
|
97
|
+
# Uncomment this if you need actionmailer
|
98
|
+
# gem 'actionmailer', '~> 3.0.0.beta1', :require => 'action_mailer'
|
99
|
+
|
100
|
+
gem 'data_objects', '~> 0.10.1'
|
101
|
+
gem 'do_sqlite3', '~> 0.10.1'
|
102
|
+
|
103
|
+
# You can use any of the other available database adapters.
|
104
|
+
# This is only a small excerpt of the list of all available adapters
|
105
|
+
# Have a look at
|
106
|
+
#
|
107
|
+
# http://wiki.github.com/datamapper/dm-core/adapters
|
108
|
+
# http://wiki.github.com/datamapper/dm-core/community-plugins
|
109
|
+
#
|
110
|
+
# for a rather complete list of available datamapper adapters and plugins
|
111
|
+
|
112
|
+
# gem 'do_mysql', '~> 0.10.1'
|
113
|
+
# gem 'do_postgres', '~> 0.10.1'
|
114
|
+
# gem 'do_oracle', '~> 0.10.1'
|
115
|
+
|
116
|
+
git 'git://github.com/snusnu/dm-core.git', 'branch' => 'active_support'
|
117
|
+
git "git://github.com/snusnu/dm-more.git", 'branch' => 'active_support'
|
118
|
+
|
119
|
+
gem 'dm-core', '~> 1.0.0.rc1'
|
120
|
+
gem 'dm-types', '~> 1.0.0.rc1'
|
121
|
+
gem 'dm-validations', '~> 1.0.0.rc1'
|
122
|
+
gem 'dm-constraints', '~> 1.0.0.rc1'
|
123
|
+
gem 'dm-aggregates', '~> 1.0.0.rc1'
|
124
|
+
gem 'dm-timestamps', '~> 1.0.0.rc1'
|
125
|
+
gem 'dm-migrations', '~> 1.0.0.rc1'
|
126
|
+
gem 'dm-observer', '~> 1.0.0.rc1'
|
127
|
+
|
128
|
+
# Use this instead of git if you're working on dm-rails
|
129
|
+
# path '/full/path/to/your/local/clone/of/dm-rails'
|
130
|
+
|
131
|
+
git 'git://github.com/datamapper/dm-rails.git'
|
132
|
+
|
133
|
+
gem 'dm-rails', '~> 1.0.0.rc1'
|
134
|
+
|
135
|
+
git 'git://github.com/rspec/rspec.git'
|
136
|
+
git 'git://github.com/rspec/rspec-core.git'
|
137
|
+
git 'git://github.com/rspec/rspec-expectations.git'
|
138
|
+
git 'git://github.com/rspec/rspec-mocks.git'
|
139
|
+
git 'git://github.com/rspec/rspec-rails.git'
|
140
|
+
|
141
|
+
group(:test) do
|
142
|
+
gem 'rspec', '2.0.0.a8'
|
143
|
+
gem 'rspec-core', '2.0.0.a8', :require => 'rspec/core'
|
144
|
+
gem 'rspec-expectations', '2.0.0.a8', :require => 'rspec/expectations'
|
145
|
+
gem 'rspec-mocks', '2.0.0.a8', :require => 'rspec/mocks'
|
146
|
+
gem 'rspec-rails', '2.0.0.a9'
|
147
|
+
end
|
148
|
+
|
149
|
+
|
150
|
+
== Sample database.yml files
|
151
|
+
|
152
|
+
DataMapper supports connecting to and working with multiple repositories easily. In order to be able to take full advantage of that feature in rails, you can configure as many repositories for your different environments as you wish. All you need to do is follow some simple naming conventions and you're good to go. Have a look at the #{adapter}_defaults declarations in the sample files below. That's the only convention you need to follow. Your default declarations should always end with "defaults". This is necessary for dm-rails to not confuse these with any of your environment declarations. In fact, dm-rails looks at the content of your database.yml and rejects every key that matches /defaults/. The remaining entries represent the repository configurations for the available environments.
|
153
|
+
|
154
|
+
An example for setting up a single repository for every environment.
|
155
|
+
|
156
|
+
defaults: &defaults
|
157
|
+
adapter: mysql
|
158
|
+
username: root
|
159
|
+
password:
|
160
|
+
host: localhost
|
161
|
+
|
162
|
+
development:
|
163
|
+
database: rails3_app_development
|
164
|
+
<<: *defaults
|
165
|
+
test:
|
166
|
+
database: rails3_app_test
|
167
|
+
<<: *defaults
|
168
|
+
production:
|
169
|
+
database: rails3_app_production
|
170
|
+
<<: *defaults
|
171
|
+
|
172
|
+
|
173
|
+
An example for setting up multiple repositories for every environment.
|
174
|
+
|
175
|
+
mysql_defaults: &mysql_defaults
|
176
|
+
adapter: mysql
|
177
|
+
username: mysql_user
|
178
|
+
password: mysql_sekret
|
179
|
+
host: localhost
|
180
|
+
|
181
|
+
postgres_defaults: &postgres_defaults
|
182
|
+
adapter: postgres
|
183
|
+
username: postgres_user
|
184
|
+
password: postgres_sekret
|
185
|
+
host: postgres_host
|
186
|
+
|
187
|
+
oracle_defaults: &oracle_defaults
|
188
|
+
adapter: oracle
|
189
|
+
username: oracle_user
|
190
|
+
password: oracle_sekret
|
191
|
+
host: oracle_host
|
192
|
+
|
193
|
+
|
194
|
+
development:
|
195
|
+
database: rails3_mysql_development
|
196
|
+
<<: *mysql_defaults
|
197
|
+
repositories:
|
198
|
+
foo:
|
199
|
+
database: rails3_postgres_development
|
200
|
+
<<: *postgres_defaults
|
201
|
+
bar:
|
202
|
+
database: rails3_oracle_development
|
203
|
+
<<: *oracle_defaults
|
204
|
+
|
205
|
+
test:
|
206
|
+
database: rails3_mysql_test
|
207
|
+
<<: *mysql_defaults
|
208
|
+
repositories:
|
209
|
+
foo:
|
210
|
+
database: rails3_postgres_test
|
211
|
+
<<: *postgres_defaults
|
212
|
+
bar:
|
213
|
+
database: rails3_oracle_test
|
214
|
+
<<: *oracle_defaults
|
215
|
+
|
216
|
+
production:
|
217
|
+
database: rails3_mysql_production
|
218
|
+
<<: *mysql_defaults
|
219
|
+
repositories:
|
220
|
+
foo:
|
221
|
+
database: rails3_postgres_production
|
222
|
+
<<: *postgres_defaults
|
223
|
+
bar:
|
224
|
+
database: rails3_oracle_production
|
225
|
+
<<: *oracle_defaults
|
226
|
+
|
227
|
+
Once you have defined your database.yml file, dm-rails's rake tasks will be able to create, drop, auto_migrate! and auto_upgrade! all your defined repositories.
|
228
|
+
|
229
|
+
== Available generators
|
230
|
+
|
231
|
+
Due to the awesomeness of rails3 generators we get some cool generators almost for free. Since the new generators provide hooks that allow the dm-rails gem to provide generators that hook into parts like model, scaffolds or test generation, everything just works like it would with active_record.
|
232
|
+
|
233
|
+
The following generators are available to help you get started with the typical components of any rails application.
|
234
|
+
|
235
|
+
vendor/bin/rails generate controller
|
236
|
+
vendor/bin/rails generate generator
|
237
|
+
vendor/bin/rails generate helper
|
238
|
+
vendor/bin/rails generate integration_test
|
239
|
+
vendor/bin/rails generate mailer
|
240
|
+
vendor/bin/rails generate metal
|
241
|
+
vendor/bin/rails generate migration
|
242
|
+
vendor/bin/rails generate model
|
243
|
+
vendor/bin/rails generate model_subclass
|
244
|
+
vendor/bin/rails generate observer
|
245
|
+
vendor/bin/rails generate performance_test
|
246
|
+
vendor/bin/rails generate plugin
|
247
|
+
vendor/bin/rails generate resource
|
248
|
+
vendor/bin/rails generate scaffold
|
249
|
+
vendor/bin/rails generate scaffold_controller
|
250
|
+
vendor/bin/rails generate session_migration
|
251
|
+
vendor/bin/rails generate stylesheets
|
252
|
+
|
253
|
+
|
254
|
+
== Available datamapper specific rake tasks
|
255
|
+
|
256
|
+
To get a list of all available rake tasks in your rails3 app, issue the usual
|
257
|
+
|
258
|
+
vendor/bin/rake -T
|
259
|
+
|
260
|
+
Once you do that, you will see the following rake tasks among others. These are the ones that dm-rails added for us.
|
261
|
+
|
262
|
+
...
|
263
|
+
vendor/bin/rake db:automigrate # Perform destructive automigration
|
264
|
+
vendor/bin/rake db:autoupgrade # Perform non destructive automigration
|
265
|
+
vendor/bin/rake db:create # Create the database(s) defined in config/database.yml for the current Rails.env - also creates the test database(s) if Rails.env.development?
|
266
|
+
vendor/bin/rake db:create:all # Create all the local databases defined in config/database.yml
|
267
|
+
vendor/bin/rake db:drop # Drops the database(s) for the current Rails.env - also drops the test database(s) if Rails.env.development?
|
268
|
+
vendor/bin/rake db:drop:all # Drop all the local databases defined in config/database.yml
|
269
|
+
vendor/bin/rake db:migrate # Migrate the database to the latest version
|
270
|
+
vendor/bin/rake db:migrate:down[version] # Migrate down using migrations
|
271
|
+
vendor/bin/rake db:migrate:up[version] # Migrate up using migrations
|
272
|
+
vendor/bin/rake db:seed # Load the seed data from db/seeds.rb
|
273
|
+
vendor/bin/rake db:sessions:clear # Clear the sessions table for DataMapperStore
|
274
|
+
vendor/bin/rake db:sessions:create # Creates the sessions table for DataMapperStore
|
275
|
+
vendor/bin/rake db:setup # Create the database, load the schema, and initialize with the seed data
|
276
|
+
|
277
|
+
...
|
278
|
+
|
279
|
+
|
280
|
+
== Configuring and introspecting dm-rails
|
281
|
+
|
282
|
+
Rails3 makes it easy to expose framework component specific configuration to application developers in a uniform and easy to use way. To build on this philosophy, dm-rails exposes its configuration via a single object that is used throughout dm-rails's code to store configuration relevant to datamapper and to rails. You can access it from within your application and of course alter it's settings in your config/application.rb or config/environments files. Here's a quick overview of the API the configuration object exposes. Expect this to grow as we come up with additional useful stuff to configure.
|
283
|
+
|
284
|
+
|
285
|
+
Rails::DataMapper.configuration
|
286
|
+
Rails::DataMapper::Configuration.for(database_yml_hash)
|
287
|
+
|
288
|
+
Rails::DataMapper::Configuration#raw
|
289
|
+
Rails::DataMapper::Configuration#environments
|
290
|
+
Rails::DataMapper::Configuration#repositories
|
291
|
+
Rails::DataMapper::Configuration#identity_map=(value)
|
292
|
+
Rails::DataMapper::Configuration#identity_map
|
293
|
+
Rails::DataMapper::Configuration#adapter_cascade
|
294
|
+
|
295
|
+
|
296
|
+
|
297
|
+
As promised, you can easily inspect the configuration from your running rails application. Let's start a rails console and have a look what's configured for our app.
|
298
|
+
|
299
|
+
ree-1.8.7-2010.01 mungo:datamapper_on_rails3 snusnu$ vendor/bin/rails console
|
300
|
+
Loading development environment (Rails 3.0.0.beta)
|
301
|
+
ruby-1.8.7-p248 > require 'pp'
|
302
|
+
=> ["PP"]
|
303
|
+
ruby-1.8.7-p248 > pp Rails::DataMapper.configuration
|
304
|
+
#<Rails::DataMapper::Configuration:0x1025bbc58
|
305
|
+
@adapter_cascade=Rails::DataMapper::Adapters::Cascade,
|
306
|
+
@identity_map=true,
|
307
|
+
@plugins=["dm-validations", "dm-timestamps", "dm-observer", "dm-migrations"],
|
308
|
+
@raw=
|
309
|
+
{"production"=>
|
310
|
+
{"adapter"=>"mysql",
|
311
|
+
"username"=>"root",
|
312
|
+
"database"=>"rails3_app_production",
|
313
|
+
"host"=>"localhost",
|
314
|
+
"password"=>nil},
|
315
|
+
"development"=>
|
316
|
+
{"adapter"=>"mysql",
|
317
|
+
"username"=>"root",
|
318
|
+
"database"=>"rails3_app_development",
|
319
|
+
"host"=>"localhost",
|
320
|
+
"password"=>nil},
|
321
|
+
"defaults"=>
|
322
|
+
{"username"=>"root",
|
323
|
+
"adapter"=>"mysql",
|
324
|
+
"host"=>"localhost",
|
325
|
+
"password"=>nil},
|
326
|
+
"test"=>
|
327
|
+
{"adapter"=>"mysql",
|
328
|
+
"username"=>"root",
|
329
|
+
"database"=>"rails3_app_test",
|
330
|
+
"host"=>"localhost",
|
331
|
+
"password"=>nil}},
|
332
|
+
@repositories=
|
333
|
+
{"production"=>
|
334
|
+
{"default"=>
|
335
|
+
{"adapter"=>"mysql",
|
336
|
+
"username"=>"root",
|
337
|
+
"database"=>"rails3_app_production",
|
338
|
+
"host"=>"localhost",
|
339
|
+
"password"=>nil}},
|
340
|
+
"development"=>
|
341
|
+
{"default"=>
|
342
|
+
{"adapter"=>"mysql",
|
343
|
+
"username"=>"root",
|
344
|
+
"database"=>"rails3_app_development",
|
345
|
+
"host"=>"localhost",
|
346
|
+
"password"=>nil}},
|
347
|
+
"test"=>
|
348
|
+
{"default"=>
|
349
|
+
{"adapter"=>"mysql",
|
350
|
+
"username"=>"root",
|
351
|
+
"database"=>"rails3_app_test",
|
352
|
+
"host"=>"localhost",
|
353
|
+
"password"=>nil}}}>
|
354
|
+
=> nil
|
355
|
+
|
356
|
+
Additionally, you can reach the configuration object via the standard way that rails provides to expose configuration for framework components and plugins.
|
357
|
+
|
358
|
+
Rails.application.config.data_mapper.configuration
|
359
|
+
|
360
|
+
This will give you the exact same object we inspected in the previous pretty print output from rails console.
|
361
|
+
|
362
|
+
|
363
|
+
== Extending dm-rails
|
364
|
+
|
365
|
+
It's easy to extend or adapt dm-rails to meet your specific needs. Thanks to the railties API it's possible to hook into any part of the initialization process. In order to customize dm-rails, all you need to do is define your own Rails::Railtie class that inherits from Rails::DataMapper::Railtie and require that instead of the standard dm-rails/railtie. During initialization of any rails plugin, the initializers defined by that plugin are run in the order specified. Since dm-rails defines every action that gets called by its initializers as a method on either the Railtie instance or the class, you can just go ahead and overwrite these in your subclass. All those methods get called with the running Rails::Application (always reachable via Rails.application) as single parameter, so you can customize depending on the app's state as much as you wish. Additionally, the initializers are all named, and you can hook your own additional initializers before or after any of the named rails (or dm-rails) initializers.
|
366
|
+
|
367
|
+
To give you an idea of what you get when inheriting from Rails::DataMapper::Railtie have a look at the list of methods provided by that object.
|
368
|
+
|
369
|
+
Rails::DataMapper::Railtie.setup_data_mapper(app)
|
370
|
+
Rails::DataMapper::Railtie.preload_lib(app)
|
371
|
+
Rails::DataMapper::Railtie.preload_models(app)
|
372
|
+
|
373
|
+
Rails::DataMapper::Railtie#configure_data_mapper(app)
|
374
|
+
Rails::DataMapper::Railtie#setup_adapter_cascade(app)
|
375
|
+
Rails::DataMapper::Railtie#setup_routing_support(app)
|
376
|
+
Rails::DataMapper::Railtie#setup_controller_runtime(app)
|
377
|
+
Rails::DataMapper::Railtie#setup_identity_map(app)
|
378
|
+
Rails::DataMapper::Railtie#setup_logger(app)
|
379
|
+
|
380
|
+
|
381
|
+
To complete the picture of dm-rails's initialization process, here's an overview of the defined initializers in the order they are called by rails during bootup. Note that every one of these initializers does one single thing; calling one of the methods listed above. This makes it easy to customize each of these steps by overwriting the respective method.
|
382
|
+
|
383
|
+
initializer 'data_mapper.configuration' do |app|
|
384
|
+
configure_data_mapper(app)
|
385
|
+
end
|
386
|
+
|
387
|
+
initializer 'data_mapper.logger' do |app|
|
388
|
+
setup_logger(app, Rails.logger)
|
389
|
+
end
|
390
|
+
|
391
|
+
initializer 'data_mapper.adapter_cascade' do |app|
|
392
|
+
setup_adapter_cascade(app)
|
393
|
+
end
|
394
|
+
|
395
|
+
initializer 'data_mapper.routing_support' do |app|
|
396
|
+
setup_routing_support(app)
|
397
|
+
end
|
398
|
+
|
399
|
+
# Expose database runtime to controller for logging.
|
400
|
+
initializer "data_mapper.log_runtime" do |app|
|
401
|
+
setup_controller_runtime(app)
|
402
|
+
end
|
403
|
+
|
404
|
+
initializer 'data_mapper.setup_identity_map' do |app|
|
405
|
+
setup_identity_map(app)
|
406
|
+
end
|
407
|
+
|
408
|
+
# Run setup code after_initialize to make sure all config/initializers
|
409
|
+
# are in effect once we setup the connection. This is especially necessary
|
410
|
+
# for the cascaded adapter wrappers that need to be declared before setup.
|
411
|
+
# Note that setup_datamapper (and needed methods are defined in class scope)
|
412
|
+
|
413
|
+
config.after_initialize do |app|
|
414
|
+
setup_data_mapper(app)
|
415
|
+
end
|
416
|
+
|
417
|
+
If you want to add additional rake tasks in your extension, you can do so by adding the following to your railtie.
|
418
|
+
|
419
|
+
rake_tasks do
|
420
|
+
load 'path/to/your/tasks.rake'
|
421
|
+
end
|
422
|
+
|
423
|
+
|
424
|
+
== Identity Map support
|
425
|
+
|
426
|
+
By default, dm-rails enables the use of the {identity map}[http://datamapper.org/why.html]. If for any reason you want to turn that off, just add the following line to your config/application.rb or your config/environments/*.rb file.
|
427
|
+
|
428
|
+
config.data_mapper.identity_map = false
|
429
|
+
|
430
|
+
Activating the identity map is achieved by installing a middleware that wraps the whole request inside
|
431
|
+
|
432
|
+
DataMapper.repository { ... }
|
433
|
+
|
434
|
+
Note that this scopes every call to datamapper to the :default repository specified in your database.yml file. If you need to access a different repository from within your actions, just wrap the calls in another DataMapper.repository block. DataMapper stacks the repositories it uses and the innermost will always win.
|
435
|
+
|
436
|
+
|
437
|
+
== Using additional datamapper plugins
|
438
|
+
|
439
|
+
In order to use additional plugins add them to the Gemfile and require them from inside a file in config/initializers. Once you've done that, update your bundle and you should be ready to use the plugin(s)
|
440
|
+
|
441
|
+
cd /path/to/your/app
|
442
|
+
# edit Gemfile
|
443
|
+
bundle install
|
444
|
+
|
445
|
+
Have a look at this application's {Gemfile}[http://github.com/snusnu/datamapper_on_rails3/blob/master/Gemfile] for an idea of how to use gems from git repositories.
|
446
|
+
|
447
|
+
|
448
|
+
== Rails notification system
|
449
|
+
|
450
|
+
Currently dm-rails publishes the same benchmarking information like active_record does. This means that you will get output like this in your log files.
|
451
|
+
|
452
|
+
Completed in 9ms (Views: 7.6ms | Models: 0.6ms) with 200
|
453
|
+
|
454
|
+
While the SQL issued by DO adapters is already being logged properly, it is not yet published to possible rails subscribers. This is basically the only thing we're still missing in terms of datamapper rails3 notifications integration, compared with active_record. Of course we're not tied to only publishing these messages. If anyone can think of other useful information to publish, it's easy to hook into rails' notification system.
|
455
|
+
|
456
|
+
|
457
|
+
== Current Issues
|
458
|
+
|
459
|
+
* migrations might not work perfectly
|
460
|
+
* rspec-2 is not yet integrated
|
461
|
+
|
462
|
+
|
463
|
+
== TODO (not necessarily in that order)
|
464
|
+
|
465
|
+
* SPECS !!!
|
466
|
+
* Think about a release strategy supporting both beta releases and master branch
|
467
|
+
* Further README updates
|
468
|
+
* More work on migrations
|
469
|
+
* Check if the {session store}[http://github.com/datamapper/dm-rails/blob/master/lib/dm-rails/session_store.rb] support works
|
470
|
+
* Provide a rails template for generating tailored apps for datamapper
|
471
|
+
* Publish SQL issued by DO (and eventually every adapter) to rails subscribers
|
472
|
+
* Think about integrating with {dana}[http://github.com/snusnu/dm-accepts_nested_attributes]
|
473
|
+
* Think about integrating {dm-serializer}[http://github.com/datamapper/dm-more/tree/master/dm-serializer/]
|
474
|
+
|
475
|
+
== Credits
|
476
|
+
|
477
|
+
Big thanks to everyone working on {datamapper}[http://github.com/datamapper/dm-core], {rails}[http://github.com/rails/rails], {bundler}[http://github.com/carlhuda/bundler] and open source in general. This will be (and actually already is) an awesome platform for developing web applications.
|
478
|
+
|
479
|
+
|
480
|
+
== Note on Patches/Pull Requests
|
481
|
+
|
482
|
+
* Fork the project.
|
483
|
+
* Make your feature addition or bug fix.
|
484
|
+
* Add tests for it. This is important so I don't break it in a
|
485
|
+
future version unintentionally.
|
486
|
+
* Commit, do not mess with rakefile, version, or history.
|
487
|
+
(if you want to have your own version, that is fine but bump version in a commit by itself I can ignore when I pull)
|
488
|
+
* Send me a pull request. Bonus points for topic branches.
|
489
|
+
|
490
|
+
|
491
|
+
== The dm-rails team
|
492
|
+
|
493
|
+
Thx to all contributors, every patch, big or small is very much appreciated!
|
494
|
+
|
495
|
+
* Martin Gamsjaeger (snusnu)
|
496
|
+
* Dan Kubb (dkubb)
|
497
|
+
* Alex Coles (myabc)
|
498
|
+
* Alex Mankuta
|
499
|
+
* Foy Savas
|
500
|
+
* Randall Brewer
|
501
|
+
* Josh Huckabee
|
502
|
+
* Patrik Sundberg
|
503
|
+
|
504
|
+
== Copyright
|
505
|
+
|
506
|
+
Copyright (c) 2009-2010 The dm-rails team. See {LICENSE}[http://github.com/datamapper/dm-rails/blob/master/LICENSE] for details.
|