edge badge
Methods
C
I
N
Class Public methods
configurations()

Returns fully resolved configurations hash

# File activerecord/lib/active_record/core.rb, line 59
def self.configurations
  @@configurations
end
configurations=(config)

Contains the database configuration - as is typically stored in config/database.yml - as a Hash.

For example, the following database.yml…

development:
  adapter: sqlite3
  database: db/development.sqlite3

production:
  adapter: sqlite3
  database: db/production.sqlite3

…would result in ::configurations to look like this:

{
   'development' => {
      'adapter'  => 'sqlite3',
      'database' => 'db/development.sqlite3'
   },
   'production' => {
      'adapter'  => 'sqlite3',
      'database' => 'db/production.sqlite3'
   }
}
# File activerecord/lib/active_record/core.rb, line 53
def self.configurations=(config)
  @@configurations = ActiveRecord::ConnectionHandling::MergeAndResolveDefaultUrlConfig.new(config).resolve
end
connection_handler()
# File activerecord/lib/active_record/core.rb, line 130
def self.connection_handler
  ActiveRecord::RuntimeRegistry.connection_handler || default_connection_handler
end
connection_handler=(handler)
# File activerecord/lib/active_record/core.rb, line 134
def self.connection_handler=(handler)
  ActiveRecord::RuntimeRegistry.connection_handler = handler
end
new(attributes = nil)

New objects can be instantiated as either empty (pass no construction parameter) or pre-set with attributes but not yet saved (pass a hash with key names matching the associated table column names). In both instances, valid attribute keys are determined by the column names of the associated table – hence you can't have attributes that aren't part of the table columns.

Example:

# Instantiates a single new object
User.new(first_name: 'Jamie')
# File activerecord/lib/active_record/core.rb, line 302
def initialize(attributes = nil)
  self.class.define_attribute_methods
  @attributes = self.class._default_attributes.deep_dup

  init_internals
  initialize_internals_callback

  assign_attributes(attributes) if attributes

  yield self if block_given?
  _run_initialize_callbacks
end
Instance Public methods
init_with(coder)

Initialize an empty model object from coder. coder should be the result of previously encoding an Active Record model, using encode_with.

class Post < ActiveRecord::Base
end

old_post = Post.new(title: "hello world")
coder = {}
old_post.encode_with(coder)

post = Post.allocate
post.init_with(coder)
post.title # => 'hello world'
# File activerecord/lib/active_record/core.rb, line 329
def init_with(coder)
  coder = LegacyYamlAdapter.convert(self.class, coder)
  @attributes = self.class.yaml_encoder.decode(coder)

  init_internals

  @new_record = coder["new_record"]

  self.class.define_attribute_methods

  yield self if block_given?

  _run_find_callbacks
  _run_initialize_callbacks

  self
end