datamapper-dm-core 0.9.11
Sign up to get free protection for your applications and to get access to all the features.
- data/.autotest +26 -0
- data/.gitignore +18 -0
- data/CONTRIBUTING +51 -0
- data/FAQ +92 -0
- data/History.txt +41 -0
- data/MIT-LICENSE +22 -0
- data/Manifest.txt +130 -0
- data/QUICKLINKS +11 -0
- data/README.txt +143 -0
- data/Rakefile +30 -0
- data/SPECS +62 -0
- data/TODO +1 -0
- data/dm-core.gemspec +40 -0
- data/lib/dm-core.rb +217 -0
- data/lib/dm-core/adapters.rb +16 -0
- data/lib/dm-core/adapters/abstract_adapter.rb +209 -0
- data/lib/dm-core/adapters/data_objects_adapter.rb +716 -0
- data/lib/dm-core/adapters/in_memory_adapter.rb +87 -0
- data/lib/dm-core/adapters/mysql_adapter.rb +136 -0
- data/lib/dm-core/adapters/postgres_adapter.rb +189 -0
- data/lib/dm-core/adapters/sqlite3_adapter.rb +105 -0
- data/lib/dm-core/associations.rb +207 -0
- data/lib/dm-core/associations/many_to_many.rb +147 -0
- data/lib/dm-core/associations/many_to_one.rb +107 -0
- data/lib/dm-core/associations/one_to_many.rb +315 -0
- data/lib/dm-core/associations/one_to_one.rb +61 -0
- data/lib/dm-core/associations/relationship.rb +229 -0
- data/lib/dm-core/associations/relationship_chain.rb +81 -0
- data/lib/dm-core/auto_migrations.rb +105 -0
- data/lib/dm-core/collection.rb +670 -0
- data/lib/dm-core/dependency_queue.rb +32 -0
- data/lib/dm-core/hook.rb +11 -0
- data/lib/dm-core/identity_map.rb +42 -0
- data/lib/dm-core/is.rb +16 -0
- data/lib/dm-core/logger.rb +232 -0
- data/lib/dm-core/migrations/destructive_migrations.rb +17 -0
- data/lib/dm-core/migrator.rb +29 -0
- data/lib/dm-core/model.rb +526 -0
- data/lib/dm-core/naming_conventions.rb +84 -0
- data/lib/dm-core/property.rb +676 -0
- data/lib/dm-core/property_set.rb +169 -0
- data/lib/dm-core/query.rb +676 -0
- data/lib/dm-core/repository.rb +167 -0
- data/lib/dm-core/resource.rb +671 -0
- data/lib/dm-core/scope.rb +58 -0
- data/lib/dm-core/support.rb +7 -0
- data/lib/dm-core/support/array.rb +13 -0
- data/lib/dm-core/support/assertions.rb +8 -0
- data/lib/dm-core/support/errors.rb +23 -0
- data/lib/dm-core/support/kernel.rb +11 -0
- data/lib/dm-core/support/symbol.rb +41 -0
- data/lib/dm-core/transaction.rb +267 -0
- data/lib/dm-core/type.rb +160 -0
- data/lib/dm-core/type_map.rb +80 -0
- data/lib/dm-core/types.rb +19 -0
- data/lib/dm-core/types/boolean.rb +7 -0
- data/lib/dm-core/types/discriminator.rb +34 -0
- data/lib/dm-core/types/object.rb +24 -0
- data/lib/dm-core/types/paranoid_boolean.rb +34 -0
- data/lib/dm-core/types/paranoid_datetime.rb +33 -0
- data/lib/dm-core/types/serial.rb +9 -0
- data/lib/dm-core/types/text.rb +10 -0
- data/lib/dm-core/version.rb +3 -0
- data/script/all +4 -0
- data/script/performance.rb +282 -0
- data/script/profile.rb +87 -0
- data/spec/integration/association_spec.rb +1382 -0
- data/spec/integration/association_through_spec.rb +203 -0
- data/spec/integration/associations/many_to_many_spec.rb +449 -0
- data/spec/integration/associations/many_to_one_spec.rb +163 -0
- data/spec/integration/associations/one_to_many_spec.rb +188 -0
- data/spec/integration/auto_migrations_spec.rb +413 -0
- data/spec/integration/collection_spec.rb +1073 -0
- data/spec/integration/data_objects_adapter_spec.rb +32 -0
- data/spec/integration/dependency_queue_spec.rb +46 -0
- data/spec/integration/model_spec.rb +197 -0
- data/spec/integration/mysql_adapter_spec.rb +85 -0
- data/spec/integration/postgres_adapter_spec.rb +731 -0
- data/spec/integration/property_spec.rb +253 -0
- data/spec/integration/query_spec.rb +514 -0
- data/spec/integration/repository_spec.rb +61 -0
- data/spec/integration/resource_spec.rb +513 -0
- data/spec/integration/sqlite3_adapter_spec.rb +352 -0
- data/spec/integration/sti_spec.rb +273 -0
- data/spec/integration/strategic_eager_loading_spec.rb +156 -0
- data/spec/integration/transaction_spec.rb +75 -0
- data/spec/integration/type_spec.rb +275 -0
- data/spec/lib/logging_helper.rb +18 -0
- data/spec/lib/mock_adapter.rb +27 -0
- data/spec/lib/model_loader.rb +100 -0
- data/spec/lib/publicize_methods.rb +28 -0
- data/spec/models/content.rb +16 -0
- data/spec/models/vehicles.rb +34 -0
- data/spec/models/zoo.rb +48 -0
- data/spec/spec.opts +3 -0
- data/spec/spec_helper.rb +91 -0
- data/spec/unit/adapters/abstract_adapter_spec.rb +133 -0
- data/spec/unit/adapters/adapter_shared_spec.rb +15 -0
- data/spec/unit/adapters/data_objects_adapter_spec.rb +632 -0
- data/spec/unit/adapters/in_memory_adapter_spec.rb +98 -0
- data/spec/unit/adapters/postgres_adapter_spec.rb +133 -0
- data/spec/unit/associations/many_to_many_spec.rb +32 -0
- data/spec/unit/associations/many_to_one_spec.rb +159 -0
- data/spec/unit/associations/one_to_many_spec.rb +393 -0
- data/spec/unit/associations/one_to_one_spec.rb +7 -0
- data/spec/unit/associations/relationship_spec.rb +71 -0
- data/spec/unit/associations_spec.rb +242 -0
- data/spec/unit/auto_migrations_spec.rb +111 -0
- data/spec/unit/collection_spec.rb +182 -0
- data/spec/unit/data_mapper_spec.rb +35 -0
- data/spec/unit/identity_map_spec.rb +126 -0
- data/spec/unit/is_spec.rb +80 -0
- data/spec/unit/migrator_spec.rb +33 -0
- data/spec/unit/model_spec.rb +321 -0
- data/spec/unit/naming_conventions_spec.rb +36 -0
- data/spec/unit/property_set_spec.rb +90 -0
- data/spec/unit/property_spec.rb +753 -0
- data/spec/unit/query_spec.rb +571 -0
- data/spec/unit/repository_spec.rb +93 -0
- data/spec/unit/resource_spec.rb +649 -0
- data/spec/unit/scope_spec.rb +142 -0
- data/spec/unit/transaction_spec.rb +493 -0
- data/spec/unit/type_map_spec.rb +114 -0
- data/spec/unit/type_spec.rb +119 -0
- data/tasks/ci.rb +36 -0
- data/tasks/dm.rb +63 -0
- data/tasks/doc.rb +20 -0
- data/tasks/gemspec.rb +23 -0
- data/tasks/hoe.rb +46 -0
- data/tasks/install.rb +20 -0
- metadata +215 -0
data/.autotest
ADDED
@@ -0,0 +1,26 @@
|
|
1
|
+
Autotest.add_hook :initialize do |at|
|
2
|
+
ignore = %w[ .git burn www log plugins script tasks bin CHANGELOG FAQ MIT-LICENSE PERFORMANCE QUICKLINKS README ]
|
3
|
+
|
4
|
+
unless ENV['AUTOTEST'] == 'integration'
|
5
|
+
ignore << 'spec/integration'
|
6
|
+
end
|
7
|
+
|
8
|
+
ignore.each do |exception|
|
9
|
+
at.add_exception(exception)
|
10
|
+
end
|
11
|
+
|
12
|
+
at.clear_mappings
|
13
|
+
|
14
|
+
at.add_mapping(%r{^spec/.+_spec\.rb$}) do |filename,_|
|
15
|
+
filename
|
16
|
+
end
|
17
|
+
|
18
|
+
at.add_mapping(%r{^lib/data_mapper/(.+)\.rb$}) do |_,match|
|
19
|
+
[ "spec/unit/#{match[1]}_spec.rb" ] +
|
20
|
+
at.files_matching(%r{^spec/integration/.+_spec\.rb$})
|
21
|
+
end
|
22
|
+
|
23
|
+
at.add_mapping(%r{^spec/spec_helper\.rb$}) do
|
24
|
+
at.files_matching(%r{^spec/.+_spec\.rb$})
|
25
|
+
end
|
26
|
+
end
|
data/.gitignore
ADDED
data/CONTRIBUTING
ADDED
@@ -0,0 +1,51 @@
|
|
1
|
+
# NOTE: This is a work in progress. As of July 24, it applies only to dm-core.
|
2
|
+
|
3
|
+
# Contributing to Edge DataMapper
|
4
|
+
|
5
|
+
We have now implemented Hoe throughout the DataMapper suite, so there will be a
|
6
|
+
handful of new procedures for contributing to our git repositories. I'll give
|
7
|
+
you a run through of how to set up your machine, and then provide a few
|
8
|
+
commands that should be run before committing or pushing changes.
|
9
|
+
|
10
|
+
## Installing and configuring Hoe
|
11
|
+
|
12
|
+
The first step is to install hoe. You'll need at least version 1.7.0.
|
13
|
+
|
14
|
+
(sudo) gem install hoe --include-dependencies
|
15
|
+
|
16
|
+
Now you'll need to configure hoe. You'll need to run this from inside of
|
17
|
+
dm-core, or one of the other DataMapper projects.
|
18
|
+
|
19
|
+
rake config_hoe
|
20
|
+
|
21
|
+
The only thing you should need to change is the exclude regular expression,
|
22
|
+
which needs to look like this:
|
23
|
+
|
24
|
+
exclude: !ruby/regexp /tmp$|CVS|\.svn|\.git|.+\.gemspec/
|
25
|
+
|
26
|
+
Now you have the correct setup for contributing.
|
27
|
+
|
28
|
+
## Before committing changes
|
29
|
+
|
30
|
+
Before you commit changes, you must verify that `Manifest.txt` (the file which
|
31
|
+
contains the names of every file to be included in a gem release) and
|
32
|
+
`[project-name].gemspec` are up to date. We have create a rake task to make
|
33
|
+
this easy:
|
34
|
+
|
35
|
+
rake gemspec
|
36
|
+
|
37
|
+
This will check `Manifest.txt` (using Hoe's `rake check_manifest`) to ensure
|
38
|
+
there are no differences between the files in the project, and those listed in
|
39
|
+
the manifest. If there is a difference, it will display a warning and a list of
|
40
|
+
the differences in `diff` format.
|
41
|
+
|
42
|
+
If the changes in the diff are correct, then you can run the following command
|
43
|
+
to update the manifest.
|
44
|
+
|
45
|
+
rake check_manifest | patch
|
46
|
+
|
47
|
+
If there are files you do not want added to the manifest, then you should
|
48
|
+
remove the files from the project, and then run `rake gemspec` again.
|
49
|
+
|
50
|
+
If `rake gemspec` says it was successful, then you can proceed with committing
|
51
|
+
and pushing your changes.
|
data/FAQ
ADDED
@@ -0,0 +1,92 @@
|
|
1
|
+
:include:QUICKLINKS
|
2
|
+
|
3
|
+
= FAQ
|
4
|
+
|
5
|
+
=== So where's my :id column?
|
6
|
+
|
7
|
+
DataMapper will NOT create an auto-incrementing <tt>:id</tt> key for you
|
8
|
+
automatically, so you'll need to either explicitly create one with
|
9
|
+
|
10
|
+
property :id, Serial
|
11
|
+
|
12
|
+
You can choose to use a natural key by doing
|
13
|
+
|
14
|
+
property :slug, String, :key => true
|
15
|
+
|
16
|
+
Remember, DataMapper supports multiple keys ("composite keys"), so if your
|
17
|
+
model has two or more keys, no big deal
|
18
|
+
|
19
|
+
property :store_id, Integer, :key => true
|
20
|
+
property :invoice_id, Integer, :key => true
|
21
|
+
|
22
|
+
=== How do I make a model paranoid?
|
23
|
+
|
24
|
+
Create a property and make it a ParanoidDateTime or ParanoidBoolean type.
|
25
|
+
|
26
|
+
property :deleted_at, ParanoidDateTime
|
27
|
+
property :deleted, ParanoidBoolean
|
28
|
+
|
29
|
+
All of your calls to <tt>##all()</tt>, <tt>##first()</tt> will be scoped
|
30
|
+
with <tt>:deleted_at => nil</tt> or <tt>:deleted => false</tt>. Plus,
|
31
|
+
you won't see deleted objects in your associations.
|
32
|
+
|
33
|
+
=== Does DataMapper do Single Table Inheritance?
|
34
|
+
|
35
|
+
This is what the Discriminator data-type is for:
|
36
|
+
|
37
|
+
class Person
|
38
|
+
include DataMapper::Resource
|
39
|
+
property :id, Serial
|
40
|
+
property :type, Discriminator ## other shared properties here
|
41
|
+
end
|
42
|
+
|
43
|
+
class Salesperson < Person; end
|
44
|
+
|
45
|
+
You can claim a column to have the type <tt>Discriminator</tt> and DataMapper will
|
46
|
+
automatically drop the class name of the inherited classes into that field of
|
47
|
+
the data-store.
|
48
|
+
|
49
|
+
=== How do I run my own commands?
|
50
|
+
|
51
|
+
repository.adapter.query("select * from users where clue > 0")
|
52
|
+
repository(:integration).adapter.query("select * from users where clue > 0")
|
53
|
+
|
54
|
+
This does not return any Users (har har), but rather Struct's that will quack
|
55
|
+
like Users. They'll be read-only as well.
|
56
|
+
|
57
|
+
<tt>repository.adapter.query</tt> shouldn't be used if you aren't expecting a result set
|
58
|
+
back. If you want to just execute something against the database, use
|
59
|
+
<tt>repository.adapter.execute</tt> instead.
|
60
|
+
|
61
|
+
|
62
|
+
=== Can I get an query log of what DataMapper is issuing?
|
63
|
+
|
64
|
+
An example of how to modify an existing logger:
|
65
|
+
|
66
|
+
DataMapper.logger.set_log(STDOUT, :debug)
|
67
|
+
|
68
|
+
An example of how to create new logger:
|
69
|
+
|
70
|
+
DataMapper::Logger.new(STDOUT, :info)
|
71
|
+
|
72
|
+
To send a message to the DataMapper logger:
|
73
|
+
|
74
|
+
DataMapper.logger.debug("something")
|
75
|
+
DataMapper.logger.info ("something")
|
76
|
+
DataMapper.logger.warn ("something")
|
77
|
+
DataMapper.logger.error("something")
|
78
|
+
DataMapper.logger.fatal("something")
|
79
|
+
|
80
|
+
|
81
|
+
=== I want to run the specs, but I have a custom database setup
|
82
|
+
|
83
|
+
For example, if you installed MySQL using MacPorts, your socket may be located
|
84
|
+
at /opt/local/var/run/mysql5/mysqld.sock instead of /tmp/mysql.sock
|
85
|
+
|
86
|
+
In that case, setup an environment variable in your shell before running the
|
87
|
+
specs:
|
88
|
+
export MYSQL_SPEC_URI="mysql://localhost/dm_core_test?socket=/opt/local/var/run/mysql5/mysqld.sock"
|
89
|
+
rake spec
|
90
|
+
|
91
|
+
Using another kind of database? Note that spec_helper.rb will also look for
|
92
|
+
SQLITE3_SPEC_URI AND POSTGRES_SPEC_URI.
|
data/History.txt
ADDED
@@ -0,0 +1,41 @@
|
|
1
|
+
=== 0.9.11 / not released
|
2
|
+
|
3
|
+
* No changes this version
|
4
|
+
|
5
|
+
=== 0.9.10 / 2009-01-19
|
6
|
+
|
7
|
+
* 1 major enhancement:
|
8
|
+
|
9
|
+
* Ruby 1.9.1 compatibility
|
10
|
+
|
11
|
+
* 1 minor enhancement:
|
12
|
+
|
13
|
+
* Updated Resource marshaling to be more thorough
|
14
|
+
|
15
|
+
=== 0.9.9 / 2009-01-04
|
16
|
+
|
17
|
+
* 1 minor enhancement:
|
18
|
+
|
19
|
+
* Updated Resource and Collection to be serializable with Marshal
|
20
|
+
|
21
|
+
* 1 bug fix:
|
22
|
+
|
23
|
+
* Fixed Model#copy to copy properties that are the same in both
|
24
|
+
repositories.
|
25
|
+
|
26
|
+
=== 0.9.8 / 2008-12-07
|
27
|
+
|
28
|
+
* 3 minor enhancements:
|
29
|
+
|
30
|
+
* Updated Resource#inspect to not lazy-load unloaded attributes.
|
31
|
+
* Updated ManyToOne::Proxy to delegate #class to parent. This will
|
32
|
+
allow the Merb resource() route helper method to use the association
|
33
|
+
proxy to generate the URL.
|
34
|
+
* Updated Resource#attributes= to respect method visibility. This means
|
35
|
+
that only public mutators will set the attribute value.
|
36
|
+
|
37
|
+
* 1 bug fix:
|
38
|
+
|
39
|
+
* Fixed regression where an update to a resource with a lazy property
|
40
|
+
could cause the record to reload when accessing the lazy property,
|
41
|
+
clobbering any changes made prior.
|
data/MIT-LICENSE
ADDED
@@ -0,0 +1,22 @@
|
|
1
|
+
Copyright (c) 2007, 2008, 2009 Sam Smoot, Dan Kubb
|
2
|
+
|
3
|
+
Permission is hereby granted, free of charge, to any person
|
4
|
+
obtaining a copy of this software and associated documentation
|
5
|
+
files (the "Software"), to deal in the Software without
|
6
|
+
restriction, including without limitation the rights to use,
|
7
|
+
copy, modify, merge, publish, distribute, sublicense, and/or sell
|
8
|
+
copies of the Software, and to permit persons to whom the
|
9
|
+
Software is furnished to do so, subject to the following
|
10
|
+
conditions:
|
11
|
+
|
12
|
+
The above copyright notice and this permission notice shall be
|
13
|
+
included in all copies or substantial portions of the Software.
|
14
|
+
|
15
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
|
16
|
+
EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES
|
17
|
+
OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
|
18
|
+
NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT
|
19
|
+
HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY,
|
20
|
+
WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
|
21
|
+
FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR
|
22
|
+
OTHER DEALINGS IN THE SOFTWARE.
|
data/Manifest.txt
ADDED
@@ -0,0 +1,130 @@
|
|
1
|
+
.autotest
|
2
|
+
.gitignore
|
3
|
+
CONTRIBUTING
|
4
|
+
FAQ
|
5
|
+
History.txt
|
6
|
+
MIT-LICENSE
|
7
|
+
Manifest.txt
|
8
|
+
QUICKLINKS
|
9
|
+
README.txt
|
10
|
+
Rakefile
|
11
|
+
SPECS
|
12
|
+
TODO
|
13
|
+
dm-core.gemspec
|
14
|
+
lib/dm-core.rb
|
15
|
+
lib/dm-core/adapters.rb
|
16
|
+
lib/dm-core/adapters/abstract_adapter.rb
|
17
|
+
lib/dm-core/adapters/data_objects_adapter.rb
|
18
|
+
lib/dm-core/adapters/in_memory_adapter.rb
|
19
|
+
lib/dm-core/adapters/mysql_adapter.rb
|
20
|
+
lib/dm-core/adapters/postgres_adapter.rb
|
21
|
+
lib/dm-core/adapters/sqlite3_adapter.rb
|
22
|
+
lib/dm-core/associations.rb
|
23
|
+
lib/dm-core/associations/many_to_many.rb
|
24
|
+
lib/dm-core/associations/many_to_one.rb
|
25
|
+
lib/dm-core/associations/one_to_many.rb
|
26
|
+
lib/dm-core/associations/one_to_one.rb
|
27
|
+
lib/dm-core/associations/relationship.rb
|
28
|
+
lib/dm-core/associations/relationship_chain.rb
|
29
|
+
lib/dm-core/auto_migrations.rb
|
30
|
+
lib/dm-core/collection.rb
|
31
|
+
lib/dm-core/dependency_queue.rb
|
32
|
+
lib/dm-core/hook.rb
|
33
|
+
lib/dm-core/identity_map.rb
|
34
|
+
lib/dm-core/is.rb
|
35
|
+
lib/dm-core/logger.rb
|
36
|
+
lib/dm-core/migrations/destructive_migrations.rb
|
37
|
+
lib/dm-core/migrator.rb
|
38
|
+
lib/dm-core/model.rb
|
39
|
+
lib/dm-core/naming_conventions.rb
|
40
|
+
lib/dm-core/property.rb
|
41
|
+
lib/dm-core/property_set.rb
|
42
|
+
lib/dm-core/query.rb
|
43
|
+
lib/dm-core/repository.rb
|
44
|
+
lib/dm-core/resource.rb
|
45
|
+
lib/dm-core/scope.rb
|
46
|
+
lib/dm-core/support.rb
|
47
|
+
lib/dm-core/support/array.rb
|
48
|
+
lib/dm-core/support/assertions.rb
|
49
|
+
lib/dm-core/support/errors.rb
|
50
|
+
lib/dm-core/support/kernel.rb
|
51
|
+
lib/dm-core/support/symbol.rb
|
52
|
+
lib/dm-core/transaction.rb
|
53
|
+
lib/dm-core/type.rb
|
54
|
+
lib/dm-core/type_map.rb
|
55
|
+
lib/dm-core/types.rb
|
56
|
+
lib/dm-core/types/boolean.rb
|
57
|
+
lib/dm-core/types/discriminator.rb
|
58
|
+
lib/dm-core/types/object.rb
|
59
|
+
lib/dm-core/types/paranoid_boolean.rb
|
60
|
+
lib/dm-core/types/paranoid_datetime.rb
|
61
|
+
lib/dm-core/types/serial.rb
|
62
|
+
lib/dm-core/types/text.rb
|
63
|
+
lib/dm-core/version.rb
|
64
|
+
script/all
|
65
|
+
script/performance.rb
|
66
|
+
script/profile.rb
|
67
|
+
spec/integration/association_spec.rb
|
68
|
+
spec/integration/association_through_spec.rb
|
69
|
+
spec/integration/associations/many_to_many_spec.rb
|
70
|
+
spec/integration/associations/many_to_one_spec.rb
|
71
|
+
spec/integration/associations/one_to_many_spec.rb
|
72
|
+
spec/integration/auto_migrations_spec.rb
|
73
|
+
spec/integration/collection_spec.rb
|
74
|
+
spec/integration/data_objects_adapter_spec.rb
|
75
|
+
spec/integration/dependency_queue_spec.rb
|
76
|
+
spec/integration/model_spec.rb
|
77
|
+
spec/integration/mysql_adapter_spec.rb
|
78
|
+
spec/integration/postgres_adapter_spec.rb
|
79
|
+
spec/integration/property_spec.rb
|
80
|
+
spec/integration/query_spec.rb
|
81
|
+
spec/integration/repository_spec.rb
|
82
|
+
spec/integration/resource_spec.rb
|
83
|
+
spec/integration/sqlite3_adapter_spec.rb
|
84
|
+
spec/integration/sti_spec.rb
|
85
|
+
spec/integration/strategic_eager_loading_spec.rb
|
86
|
+
spec/integration/transaction_spec.rb
|
87
|
+
spec/integration/type_spec.rb
|
88
|
+
spec/lib/logging_helper.rb
|
89
|
+
spec/lib/mock_adapter.rb
|
90
|
+
spec/lib/model_loader.rb
|
91
|
+
spec/lib/publicize_methods.rb
|
92
|
+
spec/models/content.rb
|
93
|
+
spec/models/vehicles.rb
|
94
|
+
spec/models/zoo.rb
|
95
|
+
spec/spec.opts
|
96
|
+
spec/spec_helper.rb
|
97
|
+
spec/unit/adapters/abstract_adapter_spec.rb
|
98
|
+
spec/unit/adapters/adapter_shared_spec.rb
|
99
|
+
spec/unit/adapters/data_objects_adapter_spec.rb
|
100
|
+
spec/unit/adapters/in_memory_adapter_spec.rb
|
101
|
+
spec/unit/adapters/postgres_adapter_spec.rb
|
102
|
+
spec/unit/associations/many_to_many_spec.rb
|
103
|
+
spec/unit/associations/many_to_one_spec.rb
|
104
|
+
spec/unit/associations/one_to_many_spec.rb
|
105
|
+
spec/unit/associations/one_to_one_spec.rb
|
106
|
+
spec/unit/associations/relationship_spec.rb
|
107
|
+
spec/unit/associations_spec.rb
|
108
|
+
spec/unit/auto_migrations_spec.rb
|
109
|
+
spec/unit/collection_spec.rb
|
110
|
+
spec/unit/data_mapper_spec.rb
|
111
|
+
spec/unit/identity_map_spec.rb
|
112
|
+
spec/unit/is_spec.rb
|
113
|
+
spec/unit/migrator_spec.rb
|
114
|
+
spec/unit/model_spec.rb
|
115
|
+
spec/unit/naming_conventions_spec.rb
|
116
|
+
spec/unit/property_set_spec.rb
|
117
|
+
spec/unit/property_spec.rb
|
118
|
+
spec/unit/query_spec.rb
|
119
|
+
spec/unit/repository_spec.rb
|
120
|
+
spec/unit/resource_spec.rb
|
121
|
+
spec/unit/scope_spec.rb
|
122
|
+
spec/unit/transaction_spec.rb
|
123
|
+
spec/unit/type_map_spec.rb
|
124
|
+
spec/unit/type_spec.rb
|
125
|
+
tasks/ci.rb
|
126
|
+
tasks/dm.rb
|
127
|
+
tasks/doc.rb
|
128
|
+
tasks/gemspec.rb
|
129
|
+
tasks/hoe.rb
|
130
|
+
tasks/install.rb
|
data/QUICKLINKS
ADDED
@@ -0,0 +1,11 @@
|
|
1
|
+
= Quick Links
|
2
|
+
|
3
|
+
* Setup and Configuration - DataMapper
|
4
|
+
* Finders and CRUD -
|
5
|
+
* Properties - DataMapper::Property
|
6
|
+
* FAQ[link:/files/FAQ.html]
|
7
|
+
* Contact Us
|
8
|
+
* Website - http://www.datamapper.org
|
9
|
+
* Bug Reports - http://wm.lighthouseapp.com/projects/4819-datamapper/overview
|
10
|
+
* IRC Channel - <tt>##datamapper</tt> on irc.freenode.net
|
11
|
+
* Mailing List - http://groups.google.com/group/datamapper/
|
data/README.txt
ADDED
@@ -0,0 +1,143 @@
|
|
1
|
+
|
2
|
+
:include:QUICKLINKS
|
3
|
+
|
4
|
+
= Why DataMapper?
|
5
|
+
|
6
|
+
== Open Development
|
7
|
+
|
8
|
+
DataMapper sports a very accessible code-base and a welcoming community.
|
9
|
+
Outside contributions and feedback are welcome and encouraged, especially
|
10
|
+
constructive criticism. Make your voice heard! Submit a
|
11
|
+
ticket[http://wm.lighthouseapp.com/projects/4819-datamapper/overview] or
|
12
|
+
patch[http://wm.lighthouseapp.com/projects/4819-datamapper/overview], speak up
|
13
|
+
on our mailing-list[http://groups.google.com/group/datamapper/], chat with us
|
14
|
+
on irc[irc://irc.freenode.net/#datamapper], write a spec, get it reviewed, ask
|
15
|
+
for commit rights. It's as easy as that to become a contributor.
|
16
|
+
|
17
|
+
== Identity Map
|
18
|
+
|
19
|
+
One row in the data-store should equal one object reference. Pretty simple idea.
|
20
|
+
Pretty profound impact. If you run the following code in ActiveRecord you'll
|
21
|
+
see all <tt>false</tt> results. Do the same in DataMapper and it's
|
22
|
+
<tt>true</tt> all the way down.
|
23
|
+
|
24
|
+
@parent = Tree.find(:first, :conditions => ['name = ?', 'bob'])
|
25
|
+
|
26
|
+
@parent.children.each do |child|
|
27
|
+
puts @parent.object_id == child.parent.object_id
|
28
|
+
end
|
29
|
+
|
30
|
+
This makes DataMapper faster and allocate less resources to get things done.
|
31
|
+
|
32
|
+
== Dirty Tracking
|
33
|
+
|
34
|
+
When you save a model back to your data-store, DataMapper will only write
|
35
|
+
the fields that actually changed. So it plays well with others. You can
|
36
|
+
use it in an Integration data-store without worrying that your application will
|
37
|
+
be a bad actor causing trouble for all of your other processes.
|
38
|
+
|
39
|
+
You can also configure which strategy you'd like to use to track dirtiness.
|
40
|
+
|
41
|
+
== Eager Loading
|
42
|
+
|
43
|
+
Ready for something amazing? The following example executes only two queries.
|
44
|
+
|
45
|
+
zoos = Zoo.all
|
46
|
+
first = zoos.first
|
47
|
+
first.exhibits # Loads the exhibits for all the Zoo objects in the zoos variable.
|
48
|
+
|
49
|
+
Pretty impressive huh? The idea is that you aren't going to load a set of
|
50
|
+
objects and use only an association in just one of them. This should hold up
|
51
|
+
pretty well against a 99% rule. When you don't want it to work like this, just
|
52
|
+
load the item you want in it's own set. So the DataMapper thinks ahead. We
|
53
|
+
like to call it "performant by default". This feature single-handedly wipes
|
54
|
+
out the "N+1 Query Problem". No need to specify an <tt>include</tt> option in
|
55
|
+
your finders.
|
56
|
+
|
57
|
+
== Laziness Can Be A Virtue
|
58
|
+
|
59
|
+
Text fields are expensive in data-stores. They're generally stored in a
|
60
|
+
different place than the rest of your data. So instead of a fast sequential
|
61
|
+
read from your hard-drive, your data-store server has to hop around all over the
|
62
|
+
place to get what it needs. Since ActiveRecord returns everything by default,
|
63
|
+
adding a text field to a table slows everything down drastically, across the
|
64
|
+
board.
|
65
|
+
|
66
|
+
Not so with the DataMapper. Text fields are treated like in-row associations
|
67
|
+
by default, meaning they only load when you need them. If you want more
|
68
|
+
control you can enable or disable this feature for any field (not just
|
69
|
+
text-fields) by passing a @lazy@ option to your field mapping with a value of
|
70
|
+
<tt>true</tt> or <tt>false</tt>.
|
71
|
+
|
72
|
+
class Animal
|
73
|
+
include DataMapper::Resource
|
74
|
+
property :name, String
|
75
|
+
property :notes, Text, :lazy => false
|
76
|
+
end
|
77
|
+
|
78
|
+
Plus, lazy-loading of text fields happens automatically and intelligently when
|
79
|
+
working with associations. The following only issues 2 queries to load up all
|
80
|
+
of the notes fields on each animal:
|
81
|
+
|
82
|
+
animals = Animal.all
|
83
|
+
animals.each do |pet|
|
84
|
+
pet.notes
|
85
|
+
end
|
86
|
+
|
87
|
+
== Plays Well With Others
|
88
|
+
|
89
|
+
In ActiveRecord, all your fields are mapped, whether you want them or not.
|
90
|
+
This slows things down. In the DataMapper you define your mappings in your
|
91
|
+
model. So instead of an _ALTER TABLE ADD field_ in your data-store, you simply
|
92
|
+
add a <tt>property :name, :string</tt> to your model. DRY. No schema.rb. No
|
93
|
+
migration files to conflict or die without reverting changes. Your model
|
94
|
+
drives the data-store, not the other way around.
|
95
|
+
|
96
|
+
Unless of course you want to map to a legacy data-store. Raise your hand if you
|
97
|
+
like seeing a method called <tt>col2Name</tt> on your model just because
|
98
|
+
that's what it's called in an old data-store you can't afford to change right
|
99
|
+
now? In DataMapper you control the mappings:
|
100
|
+
|
101
|
+
class Fruit
|
102
|
+
include DataMapper::Resource
|
103
|
+
storage_names[:repo] = 'frt'
|
104
|
+
property :name, String, :field => 'col2Name'
|
105
|
+
end
|
106
|
+
|
107
|
+
== All Ruby, All The Time
|
108
|
+
|
109
|
+
It's great that ActiveRecord allows you to write SQL when you need to, but
|
110
|
+
should we have to so often?
|
111
|
+
|
112
|
+
DataMapper supports issuing your own query, but it also provides more helpers
|
113
|
+
and a unique hash-based condition syntax to cover more of the use-cases where
|
114
|
+
issuing your own SQL would have been the only way to go. For example, any
|
115
|
+
finder option that's non-standard is considered a condition. So you can write
|
116
|
+
<tt>Zoo.all(:name => 'Dallas')</tt> and DataMapper will look for zoos with the
|
117
|
+
name of 'Dallas'.
|
118
|
+
|
119
|
+
It's just a little thing, but it's so much nicer than writing
|
120
|
+
<tt>Zoo.find(:all, :conditions => ['name = ?', 'Dallas'])</tt>. What if you
|
121
|
+
need other comparisons though? Try these:
|
122
|
+
|
123
|
+
Zoo.first(:name => 'Galveston')
|
124
|
+
|
125
|
+
# 'gt' means greater-than. We also do 'lt'.
|
126
|
+
Person.all(:age.gt => 30)
|
127
|
+
|
128
|
+
# 'gte' means greather-than-or-equal-to. We also do 'lte'.
|
129
|
+
Person.all(:age.gte => 30)
|
130
|
+
|
131
|
+
Person.all(:name.not => 'bob')
|
132
|
+
|
133
|
+
# If the value of a pair is an Array, we do an IN-clause for you.
|
134
|
+
Person.all(:name.like => 'S%', :id => [1, 2, 3, 4, 5])
|
135
|
+
|
136
|
+
# An alias for Zoo.find(11)
|
137
|
+
Zoo[11]
|
138
|
+
|
139
|
+
# Does a NOT IN () clause for you.
|
140
|
+
Person.all(:name.not => ['bob','rick','steve'])
|
141
|
+
|
142
|
+
See? Fewer SQL fragments dirtying your Ruby code. And that's just a few of the
|
143
|
+
nice syntax tweaks DataMapper delivers out of the box...
|