activerecord 1.0.0 → 3.0.0
Sign up to get free protection for your applications and to get access to all the features.
Potentially problematic release.
This version of activerecord might be problematic. Click here for more details.
- data/CHANGELOG +5518 -76
- data/README.rdoc +222 -0
- data/examples/performance.rb +162 -0
- data/examples/simple.rb +14 -0
- data/lib/active_record/aggregations.rb +192 -80
- data/lib/active_record/association_preload.rb +403 -0
- data/lib/active_record/associations/association_collection.rb +545 -53
- data/lib/active_record/associations/association_proxy.rb +295 -0
- data/lib/active_record/associations/belongs_to_association.rb +91 -0
- data/lib/active_record/associations/belongs_to_polymorphic_association.rb +78 -0
- data/lib/active_record/associations/has_and_belongs_to_many_association.rb +127 -36
- data/lib/active_record/associations/has_many_association.rb +108 -84
- data/lib/active_record/associations/has_many_through_association.rb +116 -0
- data/lib/active_record/associations/has_one_association.rb +143 -0
- data/lib/active_record/associations/has_one_through_association.rb +40 -0
- data/lib/active_record/associations/through_association_scope.rb +154 -0
- data/lib/active_record/associations.rb +2086 -368
- data/lib/active_record/attribute_methods/before_type_cast.rb +33 -0
- data/lib/active_record/attribute_methods/dirty.rb +95 -0
- data/lib/active_record/attribute_methods/primary_key.rb +50 -0
- data/lib/active_record/attribute_methods/query.rb +39 -0
- data/lib/active_record/attribute_methods/read.rb +116 -0
- data/lib/active_record/attribute_methods/time_zone_conversion.rb +61 -0
- data/lib/active_record/attribute_methods/write.rb +37 -0
- data/lib/active_record/attribute_methods.rb +60 -0
- data/lib/active_record/autosave_association.rb +369 -0
- data/lib/active_record/base.rb +1603 -721
- data/lib/active_record/callbacks.rb +176 -225
- data/lib/active_record/connection_adapters/abstract/connection_pool.rb +365 -0
- data/lib/active_record/connection_adapters/abstract/connection_specification.rb +113 -0
- data/lib/active_record/connection_adapters/abstract/database_limits.rb +57 -0
- data/lib/active_record/connection_adapters/abstract/database_statements.rb +329 -0
- data/lib/active_record/connection_adapters/abstract/query_cache.rb +81 -0
- data/lib/active_record/connection_adapters/abstract/quoting.rb +72 -0
- data/lib/active_record/connection_adapters/abstract/schema_definitions.rb +739 -0
- data/lib/active_record/connection_adapters/abstract/schema_statements.rb +543 -0
- data/lib/active_record/connection_adapters/abstract_adapter.rb +165 -279
- data/lib/active_record/connection_adapters/mysql_adapter.rb +594 -82
- data/lib/active_record/connection_adapters/postgresql_adapter.rb +988 -135
- data/lib/active_record/connection_adapters/sqlite3_adapter.rb +53 -0
- data/lib/active_record/connection_adapters/sqlite_adapter.rb +365 -71
- data/lib/active_record/counter_cache.rb +115 -0
- data/lib/active_record/dynamic_finder_match.rb +53 -0
- data/lib/active_record/dynamic_scope_match.rb +32 -0
- data/lib/active_record/errors.rb +172 -0
- data/lib/active_record/fixtures.rb +941 -105
- data/lib/active_record/locale/en.yml +40 -0
- data/lib/active_record/locking/optimistic.rb +172 -0
- data/lib/active_record/locking/pessimistic.rb +55 -0
- data/lib/active_record/log_subscriber.rb +48 -0
- data/lib/active_record/migration.rb +617 -0
- data/lib/active_record/named_scope.rb +138 -0
- data/lib/active_record/nested_attributes.rb +417 -0
- data/lib/active_record/observer.rb +105 -36
- data/lib/active_record/persistence.rb +291 -0
- data/lib/active_record/query_cache.rb +36 -0
- data/lib/active_record/railtie.rb +91 -0
- data/lib/active_record/railties/controller_runtime.rb +38 -0
- data/lib/active_record/railties/databases.rake +512 -0
- data/lib/active_record/reflection.rb +364 -87
- data/lib/active_record/relation/batches.rb +89 -0
- data/lib/active_record/relation/calculations.rb +286 -0
- data/lib/active_record/relation/finder_methods.rb +355 -0
- data/lib/active_record/relation/predicate_builder.rb +41 -0
- data/lib/active_record/relation/query_methods.rb +261 -0
- data/lib/active_record/relation/spawn_methods.rb +112 -0
- data/lib/active_record/relation.rb +393 -0
- data/lib/active_record/schema.rb +59 -0
- data/lib/active_record/schema_dumper.rb +195 -0
- data/lib/active_record/serialization.rb +60 -0
- data/lib/active_record/serializers/xml_serializer.rb +244 -0
- data/lib/active_record/session_store.rb +340 -0
- data/lib/active_record/test_case.rb +67 -0
- data/lib/active_record/timestamp.rb +88 -0
- data/lib/active_record/transactions.rb +329 -75
- data/lib/active_record/validations/associated.rb +48 -0
- data/lib/active_record/validations/uniqueness.rb +185 -0
- data/lib/active_record/validations.rb +58 -179
- data/lib/active_record/version.rb +9 -0
- data/lib/active_record.rb +100 -24
- data/lib/rails/generators/active_record/migration/migration_generator.rb +25 -0
- data/lib/rails/generators/active_record/migration/templates/migration.rb +17 -0
- data/lib/rails/generators/active_record/model/model_generator.rb +38 -0
- data/lib/rails/generators/active_record/model/templates/migration.rb +16 -0
- data/lib/rails/generators/active_record/model/templates/model.rb +5 -0
- data/lib/rails/generators/active_record/model/templates/module.rb +5 -0
- data/lib/rails/generators/active_record/observer/observer_generator.rb +15 -0
- data/lib/rails/generators/active_record/observer/templates/observer.rb +2 -0
- data/lib/rails/generators/active_record/session_migration/session_migration_generator.rb +24 -0
- data/lib/rails/generators/active_record/session_migration/templates/migration.rb +16 -0
- data/lib/rails/generators/active_record.rb +27 -0
- metadata +216 -158
- data/README +0 -361
- data/RUNNING_UNIT_TESTS +0 -36
- data/dev-utils/eval_debugger.rb +0 -9
- data/examples/associations.rb +0 -87
- data/examples/shared_setup.rb +0 -15
- data/examples/validation.rb +0 -88
- data/install.rb +0 -60
- data/lib/active_record/deprecated_associations.rb +0 -70
- data/lib/active_record/support/class_attribute_accessors.rb +0 -43
- data/lib/active_record/support/class_inheritable_attributes.rb +0 -37
- data/lib/active_record/support/clean_logger.rb +0 -10
- data/lib/active_record/support/inflector.rb +0 -70
- data/lib/active_record/vendor/mysql.rb +0 -1117
- data/lib/active_record/vendor/simple.rb +0 -702
- data/lib/active_record/wrappers/yaml_wrapper.rb +0 -15
- data/lib/active_record/wrappings.rb +0 -59
- data/rakefile +0 -122
- data/test/abstract_unit.rb +0 -16
- data/test/aggregations_test.rb +0 -34
- data/test/all.sh +0 -8
- data/test/associations_test.rb +0 -477
- data/test/base_test.rb +0 -513
- data/test/class_inheritable_attributes_test.rb +0 -33
- data/test/connections/native_mysql/connection.rb +0 -24
- data/test/connections/native_postgresql/connection.rb +0 -24
- data/test/connections/native_sqlite/connection.rb +0 -24
- data/test/deprecated_associations_test.rb +0 -336
- data/test/finder_test.rb +0 -67
- data/test/fixtures/accounts/signals37 +0 -3
- data/test/fixtures/accounts/unknown +0 -2
- data/test/fixtures/auto_id.rb +0 -4
- data/test/fixtures/column_name.rb +0 -3
- data/test/fixtures/companies/first_client +0 -6
- data/test/fixtures/companies/first_firm +0 -4
- data/test/fixtures/companies/second_client +0 -6
- data/test/fixtures/company.rb +0 -37
- data/test/fixtures/company_in_module.rb +0 -33
- data/test/fixtures/course.rb +0 -3
- data/test/fixtures/courses/java +0 -2
- data/test/fixtures/courses/ruby +0 -2
- data/test/fixtures/customer.rb +0 -30
- data/test/fixtures/customers/david +0 -6
- data/test/fixtures/db_definitions/mysql.sql +0 -96
- data/test/fixtures/db_definitions/mysql2.sql +0 -4
- data/test/fixtures/db_definitions/postgresql.sql +0 -113
- data/test/fixtures/db_definitions/postgresql2.sql +0 -4
- data/test/fixtures/db_definitions/sqlite.sql +0 -85
- data/test/fixtures/db_definitions/sqlite2.sql +0 -4
- data/test/fixtures/default.rb +0 -2
- data/test/fixtures/developer.rb +0 -8
- data/test/fixtures/developers/david +0 -2
- data/test/fixtures/developers/jamis +0 -2
- data/test/fixtures/developers_projects/david_action_controller +0 -2
- data/test/fixtures/developers_projects/david_active_record +0 -2
- data/test/fixtures/developers_projects/jamis_active_record +0 -2
- data/test/fixtures/entrant.rb +0 -3
- data/test/fixtures/entrants/first +0 -3
- data/test/fixtures/entrants/second +0 -3
- data/test/fixtures/entrants/third +0 -3
- data/test/fixtures/fixture_database.sqlite +0 -0
- data/test/fixtures/fixture_database_2.sqlite +0 -0
- data/test/fixtures/movie.rb +0 -5
- data/test/fixtures/movies/first +0 -2
- data/test/fixtures/movies/second +0 -2
- data/test/fixtures/project.rb +0 -3
- data/test/fixtures/projects/action_controller +0 -2
- data/test/fixtures/projects/active_record +0 -2
- data/test/fixtures/reply.rb +0 -21
- data/test/fixtures/subscriber.rb +0 -5
- data/test/fixtures/subscribers/first +0 -2
- data/test/fixtures/subscribers/second +0 -2
- data/test/fixtures/topic.rb +0 -20
- data/test/fixtures/topics/first +0 -9
- data/test/fixtures/topics/second +0 -8
- data/test/fixtures_test.rb +0 -20
- data/test/inflector_test.rb +0 -104
- data/test/inheritance_test.rb +0 -125
- data/test/lifecycle_test.rb +0 -110
- data/test/modules_test.rb +0 -21
- data/test/multiple_db_test.rb +0 -46
- data/test/pk_test.rb +0 -57
- data/test/reflection_test.rb +0 -78
- data/test/thread_safety_test.rb +0 -33
- data/test/transactions_test.rb +0 -83
- data/test/unconnected_test.rb +0 -24
- data/test/validations_test.rb +0 -126
@@ -1,15 +0,0 @@
|
|
1
|
-
require 'yaml'
|
2
|
-
|
3
|
-
module ActiveRecord
|
4
|
-
module Wrappings #:nodoc:
|
5
|
-
class YamlWrapper < AbstractWrapper #:nodoc:
|
6
|
-
def wrap(attribute) attribute.to_yaml end
|
7
|
-
def unwrap(attribute) YAML::load(attribute) end
|
8
|
-
end
|
9
|
-
|
10
|
-
module ClassMethods #:nodoc:
|
11
|
-
# Wraps the attribute in Yaml encoding
|
12
|
-
def wrap_in_yaml(*attributes) wrap_with(YamlWrapper, attributes) end
|
13
|
-
end
|
14
|
-
end
|
15
|
-
end
|
@@ -1,59 +0,0 @@
|
|
1
|
-
module ActiveRecord
|
2
|
-
# A plugin framework for wrapping attribute values before they go in and unwrapping them after they go out of the database.
|
3
|
-
# This was intended primarily for YAML wrapping of arrays and hashes, but this behavior is now native in the Base class.
|
4
|
-
# So for now this framework is laying dorment until a need pops up.
|
5
|
-
module Wrappings #:nodoc:
|
6
|
-
module ClassMethods #:nodoc:
|
7
|
-
def wrap_with(wrapper, *attributes)
|
8
|
-
[ attributes ].flat.each { |attribute| wrapper.wrap(attribute) }
|
9
|
-
end
|
10
|
-
end
|
11
|
-
|
12
|
-
def self.append_features(base)
|
13
|
-
super
|
14
|
-
base.extend(ClassMethods)
|
15
|
-
end
|
16
|
-
|
17
|
-
class AbstractWrapper #:nodoc:
|
18
|
-
def self.wrap(attribute, record_binding) #:nodoc:
|
19
|
-
%w( before_save after_save after_initialize ).each do |callback|
|
20
|
-
eval "#{callback} #{name}.new('#{attribute}')", record_binding
|
21
|
-
end
|
22
|
-
end
|
23
|
-
|
24
|
-
def initialize(attribute) #:nodoc:
|
25
|
-
@attribute = attribute
|
26
|
-
end
|
27
|
-
|
28
|
-
def save_wrapped_attribute(record) #:nodoc:
|
29
|
-
if record.attribute_present?(@attribute)
|
30
|
-
record.send(
|
31
|
-
"write_attribute",
|
32
|
-
@attribute,
|
33
|
-
wrap(record.send("read_attribute", @attribute))
|
34
|
-
)
|
35
|
-
end
|
36
|
-
end
|
37
|
-
|
38
|
-
def load_wrapped_attribute(record) #:nodoc:
|
39
|
-
if record.attribute_present?(@attribute)
|
40
|
-
record.send(
|
41
|
-
"write_attribute",
|
42
|
-
@attribute,
|
43
|
-
unwrap(record.send("read_attribute", @attribute))
|
44
|
-
)
|
45
|
-
end
|
46
|
-
end
|
47
|
-
|
48
|
-
alias_method :before_save, :save_wrapped_attribute #:nodoc:
|
49
|
-
alias_method :after_save, :load_wrapped_attribute #:nodoc:
|
50
|
-
alias_method :after_initialize, :after_save #:nodoc:
|
51
|
-
|
52
|
-
# Overwrite to implement the logic that'll take the regular attribute and wrap it.
|
53
|
-
def wrap(attribute) end
|
54
|
-
|
55
|
-
# Overwrite to implement the logic that'll take the wrapped attribute and unwrap it.
|
56
|
-
def unwrap(attribute) end
|
57
|
-
end
|
58
|
-
end
|
59
|
-
end
|
data/rakefile
DELETED
@@ -1,122 +0,0 @@
|
|
1
|
-
require 'rubygems'
|
2
|
-
require 'rake'
|
3
|
-
require 'rake/testtask'
|
4
|
-
require 'rake/rdoctask'
|
5
|
-
require 'rake/packagetask'
|
6
|
-
require 'rake/gempackagetask'
|
7
|
-
require 'rake/contrib/rubyforgepublisher'
|
8
|
-
|
9
|
-
PKG_VERSION = "1.0.0"
|
10
|
-
|
11
|
-
PKG_FILES = FileList[
|
12
|
-
"lib/**/*", "test/**/*", "examples/**/*", "doc/**/*", "[A-Z]*", "install.rb", "rakefile"
|
13
|
-
].exclude(/\bCVS\b|~$/)
|
14
|
-
|
15
|
-
|
16
|
-
desc "Default Task"
|
17
|
-
task :default => [ :test_ruby_mysql, :test_mysql_ruby, :test_sqlite, :test_postgresql ]
|
18
|
-
|
19
|
-
# Run the unit tests
|
20
|
-
|
21
|
-
Rake::TestTask.new("test_ruby_mysql") { |t|
|
22
|
-
t.libs << "test" << "test/connections/native_mysql"
|
23
|
-
t.test_files = "lib/active_record/vendor/mysql.rb"
|
24
|
-
t.pattern = 'test/*_test.rb'
|
25
|
-
t.verbose = true
|
26
|
-
}
|
27
|
-
|
28
|
-
Rake::TestTask.new("test_mysql_ruby") { |t|
|
29
|
-
t.libs << "test" << "test/connections/native_mysql"
|
30
|
-
t.pattern = 'test/*_test.rb'
|
31
|
-
t.verbose = true
|
32
|
-
}
|
33
|
-
|
34
|
-
Rake::TestTask.new("test_postgresql") { |t|
|
35
|
-
t.libs << "test" << "test/connections/native_postgresql"
|
36
|
-
t.pattern = 'test/*_test.rb'
|
37
|
-
t.verbose = true
|
38
|
-
}
|
39
|
-
|
40
|
-
Rake::TestTask.new("test_sqlite") { |t|
|
41
|
-
t.libs << "test" << "test/connections/native_sqlite"
|
42
|
-
t.pattern = 'test/*_test.rb'
|
43
|
-
t.verbose = true
|
44
|
-
}
|
45
|
-
|
46
|
-
# Genereate the RDoc documentation
|
47
|
-
|
48
|
-
Rake::RDocTask.new { |rdoc|
|
49
|
-
rdoc.rdoc_dir = 'doc'
|
50
|
-
rdoc.title = "Active Record -- Object-relation mapping put on rails"
|
51
|
-
rdoc.options << '--line-numbers --inline-source --accessor cattr_accessor=object'
|
52
|
-
rdoc.rdoc_files.include('README', 'RUNNING_UNIT_TESTS', 'CHANGELOG')
|
53
|
-
rdoc.rdoc_files.include('lib/**/*.rb')
|
54
|
-
rdoc.rdoc_files.exclude('lib/active_record/vendor/*')
|
55
|
-
rdoc.rdoc_files.include('dev-utils/*.rb')
|
56
|
-
}
|
57
|
-
|
58
|
-
|
59
|
-
# Publish documentation
|
60
|
-
desc "Publish the API documentation"
|
61
|
-
task :pdoc => [:rdoc] do
|
62
|
-
Rake::SshDirPublisher.new("davidhh@one.textdrive.com", "domains/rubyonrails.org/ar", "doc").upload
|
63
|
-
end
|
64
|
-
|
65
|
-
desc "Publish to RubyForge"
|
66
|
-
task :rubyforge do
|
67
|
-
Rake::RubyForgePublisher.new('activerecord', 'webster132').upload
|
68
|
-
end
|
69
|
-
|
70
|
-
|
71
|
-
# Create compressed packages
|
72
|
-
|
73
|
-
dist_dirs = [ "lib", "test", "examples", "dev-utils" ]
|
74
|
-
|
75
|
-
spec = Gem::Specification.new do |s|
|
76
|
-
s.name = 'activerecord'
|
77
|
-
s.version = PKG_VERSION
|
78
|
-
s.summary = "Implements the ActiveRecord pattern for ORM."
|
79
|
-
s.description = %q{Implements the ActiveRecord pattern (Fowler, PoEAA) for ORM. It ties database tables and classes together for business objects, like Customer or Subscription, that can find, save, and destroy themselves without resorting to manual SQL.}
|
80
|
-
|
81
|
-
s.files = [ "rakefile", "install.rb", "README", "RUNNING_UNIT_TESTS", "CHANGELOG" ]
|
82
|
-
dist_dirs.each do |dir|
|
83
|
-
s.files = s.files + Dir.glob( "#{dir}/**/*" ).delete_if { |item| item.include?( "CVS" ) }
|
84
|
-
end
|
85
|
-
s.files.delete "test/fixtures/fixture_database.sqlite"
|
86
|
-
s.require_path = 'lib'
|
87
|
-
s.autorequire = 'active_record'
|
88
|
-
|
89
|
-
s.has_rdoc = true
|
90
|
-
s.extra_rdoc_files = %w( README )
|
91
|
-
s.rdoc_options.concat ['--main', 'README']
|
92
|
-
|
93
|
-
s.author = "David Heinemeier Hansson"
|
94
|
-
s.email = "david@loudthinking.com"
|
95
|
-
s.homepage = "http://activerecord.rubyonrails.org"
|
96
|
-
s.rubyforge_project = "activerecord"
|
97
|
-
end
|
98
|
-
|
99
|
-
Rake::GemPackageTask.new(spec) do |p|
|
100
|
-
p.gem_spec = spec
|
101
|
-
p.need_tar = true
|
102
|
-
p.need_zip = true
|
103
|
-
end
|
104
|
-
|
105
|
-
|
106
|
-
task :lines do
|
107
|
-
lines = 0
|
108
|
-
codelines = 0
|
109
|
-
Dir.foreach("lib/active_record") { |file_name|
|
110
|
-
next unless file_name =~ /.*rb/
|
111
|
-
|
112
|
-
f = File.open("lib/active_record/" + file_name)
|
113
|
-
|
114
|
-
while line = f.gets
|
115
|
-
lines += 1
|
116
|
-
next if line =~ /^\s*$/
|
117
|
-
next if line =~ /^\s*#/
|
118
|
-
codelines += 1
|
119
|
-
end
|
120
|
-
}
|
121
|
-
puts "Lines #{lines}, LOC #{codelines}"
|
122
|
-
end
|
data/test/abstract_unit.rb
DELETED
@@ -1,16 +0,0 @@
|
|
1
|
-
$:.unshift(File.dirname(__FILE__) + '/../lib')
|
2
|
-
|
3
|
-
require 'test/unit'
|
4
|
-
require 'active_record'
|
5
|
-
require 'active_record/fixtures'
|
6
|
-
require 'connection'
|
7
|
-
|
8
|
-
class Test::Unit::TestCase #:nodoc:
|
9
|
-
def create_fixtures(*table_names)
|
10
|
-
if block_given?
|
11
|
-
Fixtures.create_fixtures(File.dirname(__FILE__) + "/fixtures/", table_names) { yield }
|
12
|
-
else
|
13
|
-
Fixtures.create_fixtures(File.dirname(__FILE__) + "/fixtures/", table_names)
|
14
|
-
end
|
15
|
-
end
|
16
|
-
end
|
data/test/aggregations_test.rb
DELETED
@@ -1,34 +0,0 @@
|
|
1
|
-
require 'abstract_unit'
|
2
|
-
# require File.dirname(__FILE__) + '/../dev-utils/eval_debugger'
|
3
|
-
require 'fixtures/customer'
|
4
|
-
|
5
|
-
class AggregationsTest < Test::Unit::TestCase
|
6
|
-
def setup
|
7
|
-
@customers = create_fixtures "customers"
|
8
|
-
@david = Customer.find(1)
|
9
|
-
end
|
10
|
-
|
11
|
-
def test_find_single_value_object
|
12
|
-
assert_equal 50, @david.balance.amount
|
13
|
-
assert_kind_of Money, @david.balance
|
14
|
-
assert_equal 300, @david.balance.exchange_to("DKK").amount
|
15
|
-
end
|
16
|
-
|
17
|
-
def test_find_multiple_value_object
|
18
|
-
assert_equal @customers["david"]["address_street"], @david.address.street
|
19
|
-
assert(
|
20
|
-
@david.address.close_to?(Address.new("Different Street", @customers["david"]["address_city"], @customers["david"]["address_country"]))
|
21
|
-
)
|
22
|
-
end
|
23
|
-
|
24
|
-
def test_change_single_value_object
|
25
|
-
@david.balance = Money.new(100)
|
26
|
-
@david.save
|
27
|
-
assert_equal 100, Customer.find(1).balance.amount
|
28
|
-
end
|
29
|
-
|
30
|
-
def test_immutable_value_objects
|
31
|
-
@david.balance = Money.new(100)
|
32
|
-
assert_raises(TypeError) { @david.balance.instance_eval { @amount = 20 } }
|
33
|
-
end
|
34
|
-
end
|