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.

Files changed (178) hide show
  1. data/CHANGELOG +5518 -76
  2. data/README.rdoc +222 -0
  3. data/examples/performance.rb +162 -0
  4. data/examples/simple.rb +14 -0
  5. data/lib/active_record/aggregations.rb +192 -80
  6. data/lib/active_record/association_preload.rb +403 -0
  7. data/lib/active_record/associations/association_collection.rb +545 -53
  8. data/lib/active_record/associations/association_proxy.rb +295 -0
  9. data/lib/active_record/associations/belongs_to_association.rb +91 -0
  10. data/lib/active_record/associations/belongs_to_polymorphic_association.rb +78 -0
  11. data/lib/active_record/associations/has_and_belongs_to_many_association.rb +127 -36
  12. data/lib/active_record/associations/has_many_association.rb +108 -84
  13. data/lib/active_record/associations/has_many_through_association.rb +116 -0
  14. data/lib/active_record/associations/has_one_association.rb +143 -0
  15. data/lib/active_record/associations/has_one_through_association.rb +40 -0
  16. data/lib/active_record/associations/through_association_scope.rb +154 -0
  17. data/lib/active_record/associations.rb +2086 -368
  18. data/lib/active_record/attribute_methods/before_type_cast.rb +33 -0
  19. data/lib/active_record/attribute_methods/dirty.rb +95 -0
  20. data/lib/active_record/attribute_methods/primary_key.rb +50 -0
  21. data/lib/active_record/attribute_methods/query.rb +39 -0
  22. data/lib/active_record/attribute_methods/read.rb +116 -0
  23. data/lib/active_record/attribute_methods/time_zone_conversion.rb +61 -0
  24. data/lib/active_record/attribute_methods/write.rb +37 -0
  25. data/lib/active_record/attribute_methods.rb +60 -0
  26. data/lib/active_record/autosave_association.rb +369 -0
  27. data/lib/active_record/base.rb +1603 -721
  28. data/lib/active_record/callbacks.rb +176 -225
  29. data/lib/active_record/connection_adapters/abstract/connection_pool.rb +365 -0
  30. data/lib/active_record/connection_adapters/abstract/connection_specification.rb +113 -0
  31. data/lib/active_record/connection_adapters/abstract/database_limits.rb +57 -0
  32. data/lib/active_record/connection_adapters/abstract/database_statements.rb +329 -0
  33. data/lib/active_record/connection_adapters/abstract/query_cache.rb +81 -0
  34. data/lib/active_record/connection_adapters/abstract/quoting.rb +72 -0
  35. data/lib/active_record/connection_adapters/abstract/schema_definitions.rb +739 -0
  36. data/lib/active_record/connection_adapters/abstract/schema_statements.rb +543 -0
  37. data/lib/active_record/connection_adapters/abstract_adapter.rb +165 -279
  38. data/lib/active_record/connection_adapters/mysql_adapter.rb +594 -82
  39. data/lib/active_record/connection_adapters/postgresql_adapter.rb +988 -135
  40. data/lib/active_record/connection_adapters/sqlite3_adapter.rb +53 -0
  41. data/lib/active_record/connection_adapters/sqlite_adapter.rb +365 -71
  42. data/lib/active_record/counter_cache.rb +115 -0
  43. data/lib/active_record/dynamic_finder_match.rb +53 -0
  44. data/lib/active_record/dynamic_scope_match.rb +32 -0
  45. data/lib/active_record/errors.rb +172 -0
  46. data/lib/active_record/fixtures.rb +941 -105
  47. data/lib/active_record/locale/en.yml +40 -0
  48. data/lib/active_record/locking/optimistic.rb +172 -0
  49. data/lib/active_record/locking/pessimistic.rb +55 -0
  50. data/lib/active_record/log_subscriber.rb +48 -0
  51. data/lib/active_record/migration.rb +617 -0
  52. data/lib/active_record/named_scope.rb +138 -0
  53. data/lib/active_record/nested_attributes.rb +417 -0
  54. data/lib/active_record/observer.rb +105 -36
  55. data/lib/active_record/persistence.rb +291 -0
  56. data/lib/active_record/query_cache.rb +36 -0
  57. data/lib/active_record/railtie.rb +91 -0
  58. data/lib/active_record/railties/controller_runtime.rb +38 -0
  59. data/lib/active_record/railties/databases.rake +512 -0
  60. data/lib/active_record/reflection.rb +364 -87
  61. data/lib/active_record/relation/batches.rb +89 -0
  62. data/lib/active_record/relation/calculations.rb +286 -0
  63. data/lib/active_record/relation/finder_methods.rb +355 -0
  64. data/lib/active_record/relation/predicate_builder.rb +41 -0
  65. data/lib/active_record/relation/query_methods.rb +261 -0
  66. data/lib/active_record/relation/spawn_methods.rb +112 -0
  67. data/lib/active_record/relation.rb +393 -0
  68. data/lib/active_record/schema.rb +59 -0
  69. data/lib/active_record/schema_dumper.rb +195 -0
  70. data/lib/active_record/serialization.rb +60 -0
  71. data/lib/active_record/serializers/xml_serializer.rb +244 -0
  72. data/lib/active_record/session_store.rb +340 -0
  73. data/lib/active_record/test_case.rb +67 -0
  74. data/lib/active_record/timestamp.rb +88 -0
  75. data/lib/active_record/transactions.rb +329 -75
  76. data/lib/active_record/validations/associated.rb +48 -0
  77. data/lib/active_record/validations/uniqueness.rb +185 -0
  78. data/lib/active_record/validations.rb +58 -179
  79. data/lib/active_record/version.rb +9 -0
  80. data/lib/active_record.rb +100 -24
  81. data/lib/rails/generators/active_record/migration/migration_generator.rb +25 -0
  82. data/lib/rails/generators/active_record/migration/templates/migration.rb +17 -0
  83. data/lib/rails/generators/active_record/model/model_generator.rb +38 -0
  84. data/lib/rails/generators/active_record/model/templates/migration.rb +16 -0
  85. data/lib/rails/generators/active_record/model/templates/model.rb +5 -0
  86. data/lib/rails/generators/active_record/model/templates/module.rb +5 -0
  87. data/lib/rails/generators/active_record/observer/observer_generator.rb +15 -0
  88. data/lib/rails/generators/active_record/observer/templates/observer.rb +2 -0
  89. data/lib/rails/generators/active_record/session_migration/session_migration_generator.rb +24 -0
  90. data/lib/rails/generators/active_record/session_migration/templates/migration.rb +16 -0
  91. data/lib/rails/generators/active_record.rb +27 -0
  92. metadata +216 -158
  93. data/README +0 -361
  94. data/RUNNING_UNIT_TESTS +0 -36
  95. data/dev-utils/eval_debugger.rb +0 -9
  96. data/examples/associations.rb +0 -87
  97. data/examples/shared_setup.rb +0 -15
  98. data/examples/validation.rb +0 -88
  99. data/install.rb +0 -60
  100. data/lib/active_record/deprecated_associations.rb +0 -70
  101. data/lib/active_record/support/class_attribute_accessors.rb +0 -43
  102. data/lib/active_record/support/class_inheritable_attributes.rb +0 -37
  103. data/lib/active_record/support/clean_logger.rb +0 -10
  104. data/lib/active_record/support/inflector.rb +0 -70
  105. data/lib/active_record/vendor/mysql.rb +0 -1117
  106. data/lib/active_record/vendor/simple.rb +0 -702
  107. data/lib/active_record/wrappers/yaml_wrapper.rb +0 -15
  108. data/lib/active_record/wrappings.rb +0 -59
  109. data/rakefile +0 -122
  110. data/test/abstract_unit.rb +0 -16
  111. data/test/aggregations_test.rb +0 -34
  112. data/test/all.sh +0 -8
  113. data/test/associations_test.rb +0 -477
  114. data/test/base_test.rb +0 -513
  115. data/test/class_inheritable_attributes_test.rb +0 -33
  116. data/test/connections/native_mysql/connection.rb +0 -24
  117. data/test/connections/native_postgresql/connection.rb +0 -24
  118. data/test/connections/native_sqlite/connection.rb +0 -24
  119. data/test/deprecated_associations_test.rb +0 -336
  120. data/test/finder_test.rb +0 -67
  121. data/test/fixtures/accounts/signals37 +0 -3
  122. data/test/fixtures/accounts/unknown +0 -2
  123. data/test/fixtures/auto_id.rb +0 -4
  124. data/test/fixtures/column_name.rb +0 -3
  125. data/test/fixtures/companies/first_client +0 -6
  126. data/test/fixtures/companies/first_firm +0 -4
  127. data/test/fixtures/companies/second_client +0 -6
  128. data/test/fixtures/company.rb +0 -37
  129. data/test/fixtures/company_in_module.rb +0 -33
  130. data/test/fixtures/course.rb +0 -3
  131. data/test/fixtures/courses/java +0 -2
  132. data/test/fixtures/courses/ruby +0 -2
  133. data/test/fixtures/customer.rb +0 -30
  134. data/test/fixtures/customers/david +0 -6
  135. data/test/fixtures/db_definitions/mysql.sql +0 -96
  136. data/test/fixtures/db_definitions/mysql2.sql +0 -4
  137. data/test/fixtures/db_definitions/postgresql.sql +0 -113
  138. data/test/fixtures/db_definitions/postgresql2.sql +0 -4
  139. data/test/fixtures/db_definitions/sqlite.sql +0 -85
  140. data/test/fixtures/db_definitions/sqlite2.sql +0 -4
  141. data/test/fixtures/default.rb +0 -2
  142. data/test/fixtures/developer.rb +0 -8
  143. data/test/fixtures/developers/david +0 -2
  144. data/test/fixtures/developers/jamis +0 -2
  145. data/test/fixtures/developers_projects/david_action_controller +0 -2
  146. data/test/fixtures/developers_projects/david_active_record +0 -2
  147. data/test/fixtures/developers_projects/jamis_active_record +0 -2
  148. data/test/fixtures/entrant.rb +0 -3
  149. data/test/fixtures/entrants/first +0 -3
  150. data/test/fixtures/entrants/second +0 -3
  151. data/test/fixtures/entrants/third +0 -3
  152. data/test/fixtures/fixture_database.sqlite +0 -0
  153. data/test/fixtures/fixture_database_2.sqlite +0 -0
  154. data/test/fixtures/movie.rb +0 -5
  155. data/test/fixtures/movies/first +0 -2
  156. data/test/fixtures/movies/second +0 -2
  157. data/test/fixtures/project.rb +0 -3
  158. data/test/fixtures/projects/action_controller +0 -2
  159. data/test/fixtures/projects/active_record +0 -2
  160. data/test/fixtures/reply.rb +0 -21
  161. data/test/fixtures/subscriber.rb +0 -5
  162. data/test/fixtures/subscribers/first +0 -2
  163. data/test/fixtures/subscribers/second +0 -2
  164. data/test/fixtures/topic.rb +0 -20
  165. data/test/fixtures/topics/first +0 -9
  166. data/test/fixtures/topics/second +0 -8
  167. data/test/fixtures_test.rb +0 -20
  168. data/test/inflector_test.rb +0 -104
  169. data/test/inheritance_test.rb +0 -125
  170. data/test/lifecycle_test.rb +0 -110
  171. data/test/modules_test.rb +0 -21
  172. data/test/multiple_db_test.rb +0 -46
  173. data/test/pk_test.rb +0 -57
  174. data/test/reflection_test.rb +0 -78
  175. data/test/thread_safety_test.rb +0 -33
  176. data/test/transactions_test.rb +0 -83
  177. data/test/unconnected_test.rb +0 -24
  178. data/test/validations_test.rb +0 -126
@@ -1,70 +0,0 @@
1
- module ActiveRecord
2
- module Associations # :nodoc:
3
- module ClassMethods
4
- def deprecated_collection_count_method(collection_name)# :nodoc:
5
- module_eval <<-"end_eval", __FILE__, __LINE__
6
- def #{collection_name}_count(force_reload = false)
7
- #{collection_name}.reload if force_reload
8
- #{collection_name}.size
9
- end
10
- end_eval
11
- end
12
-
13
- def deprecated_add_association_relation(association_name)# :nodoc:
14
- module_eval <<-"end_eval", __FILE__, __LINE__
15
- def add_#{association_name}(*items)
16
- #{association_name}.concat(items)
17
- end
18
- end_eval
19
- end
20
-
21
- def deprecated_remove_association_relation(association_name)# :nodoc:
22
- module_eval <<-"end_eval", __FILE__, __LINE__
23
- def remove_#{association_name}(items)
24
- #{association_name}.delete(items)
25
- end
26
- end_eval
27
- end
28
-
29
- def deprecated_has_collection_method(collection_name)# :nodoc:
30
- module_eval <<-"end_eval", __FILE__, __LINE__
31
- def has_#{collection_name}?(force_reload = false)
32
- !#{collection_name}(force_reload).empty?
33
- end
34
- end_eval
35
- end
36
-
37
- def deprecated_find_in_collection_method(collection_name)# :nodoc:
38
- module_eval <<-"end_eval", __FILE__, __LINE__
39
- def find_in_#{collection_name}(association_id)
40
- #{collection_name}.find(association_id)
41
- end
42
- end_eval
43
- end
44
-
45
- def deprecated_find_all_in_collection_method(collection_name)# :nodoc:
46
- module_eval <<-"end_eval", __FILE__, __LINE__
47
- def find_all_in_#{collection_name}(runtime_conditions = nil, orderings = nil, limit = nil, joins = nil)
48
- #{collection_name}.find_all(runtime_conditions, orderings, limit, joins)
49
- end
50
- end_eval
51
- end
52
-
53
- def deprecated_create_method(collection_name)# :nodoc:
54
- module_eval <<-"end_eval", __FILE__, __LINE__
55
- def create_in_#{collection_name}(attributes = {})
56
- #{collection_name}.create(attributes)
57
- end
58
- end_eval
59
- end
60
-
61
- def deprecated_build_method(collection_name)# :nodoc:
62
- module_eval <<-"end_eval", __FILE__, __LINE__
63
- def build_to_#{collection_name}(attributes = {})
64
- #{collection_name}.build(attributes)
65
- end
66
- end_eval
67
- end
68
- end
69
- end
70
- end
@@ -1,43 +0,0 @@
1
- # attr_* style accessors for class-variables that can accessed both on an instance and class level.
2
- class Class #:nodoc:
3
- def cattr_reader(*syms)
4
- syms.each do |sym|
5
- class_eval <<-EOS
6
- if ! defined? @@#{sym.id2name}
7
- @@#{sym.id2name} = nil
8
- end
9
-
10
- def self.#{sym.id2name}
11
- @@#{sym}
12
- end
13
-
14
- def #{sym.id2name}
15
- self.class.#{sym.id2name}
16
- end
17
- EOS
18
- end
19
- end
20
-
21
- def cattr_writer(*syms)
22
- syms.each do |sym|
23
- class_eval <<-EOS
24
- if ! defined? @@#{sym.id2name}
25
- @@#{sym.id2name} = nil
26
- end
27
-
28
- def self.#{sym.id2name}=(obj)
29
- @@#{sym.id2name} = obj
30
- end
31
-
32
- def #{sym.id2name}=(obj)
33
- self.class.#{sym.id2name}=(obj)
34
- end
35
- EOS
36
- end
37
- end
38
-
39
- def cattr_accessor(*syms)
40
- cattr_reader(*syms)
41
- cattr_writer(*syms)
42
- end
43
- end
@@ -1,37 +0,0 @@
1
- # Allows attributes to be shared within an inheritance hierarchy, but where each descentent gets a copy of
2
- # their parents' attributes, instead of just a pointer to the same. This means that the child can add elements
3
- # to, for example, an array without those additions being shared with either their parent, siblings, or
4
- # children, which is unlike the regular class-level attributes that are shared across the entire hierarchy.
5
- module ClassInheritableAttributes # :nodoc:
6
- def self.append_features(base)
7
- super
8
- base.extend(ClassMethods)
9
- end
10
-
11
- module ClassMethods # :nodoc:
12
- @@classes ||= {}
13
-
14
- def inheritable_attributes
15
- @@classes[self] ||= {}
16
- end
17
-
18
- def write_inheritable_attribute(key, value)
19
- inheritable_attributes[key] = value
20
- end
21
-
22
- def write_inheritable_array(key, elements)
23
- write_inheritable_attribute(key, []) if read_inheritable_attribute(key).nil?
24
- write_inheritable_attribute(key, read_inheritable_attribute(key) + elements)
25
- end
26
-
27
- def read_inheritable_attribute(key)
28
- inheritable_attributes[key]
29
- end
30
-
31
- private
32
- def inherited(child)
33
- @@classes[child] = inheritable_attributes.dup
34
- end
35
-
36
- end
37
- end
@@ -1,10 +0,0 @@
1
- require 'logger'
2
-
3
- class Logger #:nodoc:
4
- private
5
- remove_const "Format"
6
- Format = "%s\n"
7
- def format_message(severity, timestamp, msg, progname)
8
- Format % [msg]
9
- end
10
- end
@@ -1,70 +0,0 @@
1
- # The Inflector transforms words from singular to plural, class names to table names, modulized class names to ones without,
2
- # and class names to foreign keys.
3
- module Inflector
4
- extend self
5
-
6
- def pluralize(word)
7
- result = word.dup
8
- plural_rules.each do |(rule, replacement)|
9
- break if result.gsub!(rule, replacement)
10
- end
11
- return result
12
- end
13
-
14
- def singularize(word)
15
- result = word.dup
16
- singular_rules.each do |(rule, replacement)|
17
- break if result.gsub!(rule, replacement)
18
- end
19
- return result
20
- end
21
-
22
- def camelize(lower_case_and_underscored_word)
23
- lower_case_and_underscored_word.gsub(/(^|_)(.)/){$2.upcase}
24
- end
25
-
26
- def underscore(camel_cased_word)
27
- camel_cased_word.gsub(/([A-Z]+)([A-Z])/,'\1_\2').gsub(/([a-z])([A-Z])/,'\1_\2').downcase
28
- end
29
-
30
- def demodulize(class_name_in_module)
31
- class_name_in_module.gsub(/^.*::/, '')
32
- end
33
-
34
- def foreign_key(class_name, separate_class_name_and_id_with_underscore = true)
35
- Inflector.underscore(Inflector.demodulize(class_name)) +
36
- (separate_class_name_and_id_with_underscore ? "_id" : "id")
37
- end
38
-
39
- private
40
- def plural_rules #:doc:
41
- [
42
- [/(x|ch|ss)$/, '\1es'], # search, switch, fix, box, process, address
43
- [/([^aeiouy]|qu)y$/, '\1ies'], # query, ability, agency
44
- [/(?:([^f])fe|([lr])f)$/, '\1\2ves'], # half, safe, wife
45
- [/sis$/, 'ses'], # basis, diagnosis
46
- [/([ti])um$/, '\1a'], # datum, medium
47
- [/person$/, 'people'], # person, salesperson
48
- [/man$/, 'men'], # man, woman, spokesman
49
- [/child$/, 'children'], # child
50
- [/s$/, 's'], # no change (compatibility)
51
- [/$/, 's']
52
- ]
53
- end
54
-
55
- def singular_rules #:doc:
56
- [
57
- [/(x|ch|ss)es$/, '\1'],
58
- [/([^aeiouy]|qu)ies$/, '\1y'],
59
- [/([lr])ves$/, '\1f'],
60
- [/([^f])ves$/, '\1fe'],
61
- [/(analy|ba|diagno|parenthe|progno|synop|the)ses$/, '\1sis'],
62
- [/([ti])a$/, '\1um'],
63
- [/people$/, 'person'],
64
- [/men$/, 'man'],
65
- [/status$/, 'status'],
66
- [/children$/, 'child'],
67
- [/s$/, '']
68
- ]
69
- end
70
- end