active_record.rb 4.7 KB
Newer Older
D
Initial  
David Heinemeier Hansson 已提交
1
#--
J
Jon Moss 已提交
2
# Copyright (c) 2004-2017 David Heinemeier Hansson
D
Initial  
David Heinemeier Hansson 已提交
3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23
#
# Permission is hereby granted, free of charge, to any person obtaining
# a copy of this software and associated documentation files (the
# "Software"), to deal in the Software without restriction, including
# without limitation the rights to use, copy, modify, merge, publish,
# distribute, sublicense, and/or sell copies of the Software, and to
# permit persons to whom the Software is furnished to do so, subject to
# the following conditions:
#
# The above copyright notice and this permission notice shall be
# included in all copies or substantial portions of the Software.
#
# THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
# EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
# MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
# NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
# LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
# OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
# WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
#++

24 25 26 27
require "active_support"
require "active_support/rails"
require "active_model"
require "arel"
J
Jeremy Kemper 已提交
28

29 30
require "active_record/version"
require "active_record/attribute_set"
31

J
Joshua Peek 已提交
32
module ActiveRecord
C
Carlhuda 已提交
33
  extend ActiveSupport::Autoload
D
Initial  
David Heinemeier Hansson 已提交
34

35
  autoload :Attribute
S
Santiago Pastorino 已提交
36 37 38 39
  autoload :Base
  autoload :Callbacks
  autoload :Core
  autoload :ConnectionHandling
40
  autoload :CounterCache
S
Santiago Pastorino 已提交
41
  autoload :DynamicMatchers
42
  autoload :Enum
43
  autoload :InternalMetadata
S
Santiago Pastorino 已提交
44 45 46 47
  autoload :Explain
  autoload :Inheritance
  autoload :Integration
  autoload :Migration
48
  autoload :Migrator, "active_record/migration"
S
Santiago Pastorino 已提交
49 50
  autoload :ModelSchema
  autoload :NestedAttributes
51
  autoload :NoTouching
A
Arthur Neves 已提交
52
  autoload :TouchLater
S
Santiago Pastorino 已提交
53 54 55
  autoload :Persistence
  autoload :QueryCache
  autoload :Querying
56
  autoload :CollectionCacheKey
S
Santiago Pastorino 已提交
57
  autoload :ReadonlyAttributes
58
  autoload :RecordInvalid, "active_record/validations"
S
Santiago Pastorino 已提交
59
  autoload :Reflection
60
  autoload :RuntimeRegistry
S
Santiago Pastorino 已提交
61 62 63 64 65 66
  autoload :Sanitization
  autoload :Schema
  autoload :SchemaDumper
  autoload :SchemaMigration
  autoload :Scoping
  autoload :Serialization
N
Noemj 已提交
67
  autoload :StatementCache
S
Santiago Pastorino 已提交
68
  autoload :Store
M
Michael Ryan 已提交
69
  autoload :Suppressor
S
Santiago Pastorino 已提交
70 71 72 73
  autoload :Timestamp
  autoload :Transactions
  autoload :Translation
  autoload :Validations
74
  autoload :SecureToken
S
Santiago Pastorino 已提交
75

J
Joshua Peek 已提交
76
  eager_autoload do
77 78 79
    autoload :ActiveRecordError, "active_record/errors"
    autoload :ConnectionNotEstablished, "active_record/errors"
    autoload :ConnectionAdapters, "active_record/connection_adapters/abstract_adapter"
80

81
    autoload :Aggregations
J
Joshua Peek 已提交
82
    autoload :Associations
83
    autoload :AttributeAssignment
84
    autoload :AttributeMethods
J
Joshua Peek 已提交
85
    autoload :AutosaveAssociation
86

87 88
    autoload :LegacyYamlAdapter

J
Joshua Peek 已提交
89
    autoload :Relation
90
    autoload :AssociationRelation
91
    autoload :NullRelation
92

93
    autoload_under "relation" do
94 95
      autoload :QueryMethods
      autoload :FinderMethods
96
      autoload :Calculations
97
      autoload :PredicateBuilder
98
      autoload :SpawnMethods
P
Pratik Naik 已提交
99
      autoload :Batches
100
      autoload :Delegation
101 102
    end

103
    autoload :Result
104
    autoload :TableMetadata
J
Joshua Peek 已提交
105
  end
D
Initial  
David Heinemeier Hansson 已提交
106

107
  module Coders
108 109
    autoload :YAMLColumn, "active_record/coders/yaml_column"
    autoload :JSON, "active_record/coders/json"
110 111
  end

J
Joshua Peek 已提交
112
  module AttributeMethods
C
Carlhuda 已提交
113 114
    extend ActiveSupport::Autoload

J
Joshua Peek 已提交
115 116 117 118 119 120 121 122
    eager_autoload do
      autoload :BeforeTypeCast
      autoload :Dirty
      autoload :PrimaryKey
      autoload :Query
      autoload :Read
      autoload :TimeZoneConversion
      autoload :Write
123
      autoload :Serialization
J
Joshua Peek 已提交
124
    end
J
Joshua Peek 已提交
125 126
  end

J
Joshua Peek 已提交
127
  module Locking
C
Carlhuda 已提交
128
    extend ActiveSupport::Autoload
129

J
Joshua Peek 已提交
130 131 132 133
    eager_autoload do
      autoload :Optimistic
      autoload :Pessimistic
    end
J
Joshua Peek 已提交
134
  end
135

J
Joshua Peek 已提交
136
  module ConnectionAdapters
C
Carlhuda 已提交
137
    extend ActiveSupport::Autoload
138

J
Joshua Peek 已提交
139 140 141
    eager_autoload do
      autoload :AbstractAdapter
    end
J
Joshua Peek 已提交
142
  end
J
Joshua Peek 已提交
143

144 145 146 147 148 149 150 151 152
  module Scoping
    extend ActiveSupport::Autoload

    eager_autoload do
      autoload :Named
      autoload :Default
    end
  end

P
Pat Allan 已提交
153 154 155 156
  module Tasks
    extend ActiveSupport::Autoload

    autoload :DatabaseTasks
157 158
    autoload :SQLiteDatabaseTasks, "active_record/tasks/sqlite_database_tasks"
    autoload :MySQLDatabaseTasks,  "active_record/tasks/mysql_database_tasks"
159
    autoload :PostgreSQLDatabaseTasks,
160
      "active_record/tasks/postgresql_database_tasks"
P
Pat Allan 已提交
161 162
  end

163
  autoload :TestFixtures, "active_record/fixtures"
164 165 166 167 168 169 170 171 172

  def self.eager_load!
    super
    ActiveRecord::Locking.eager_load!
    ActiveRecord::Scoping.eager_load!
    ActiveRecord::Associations.eager_load!
    ActiveRecord::AttributeMethods.eager_load!
    ActiveRecord::ConnectionAdapters.eager_load!
  end
173
end
174

175
ActiveSupport.on_load(:active_record) do
176
  Arel::Table.engine = self
J
Joshua Peek 已提交
177
end
S
Sven Fuchs 已提交
178

S
Santiago Pastorino 已提交
179
ActiveSupport.on_load(:i18n) do
B
bogdanvlviv 已提交
180
  I18n.load_path << File.expand_path("active_record/locale/en.yml", __dir__)
S
Santiago Pastorino 已提交
181
end