repo stringlengths 5 92 | file_url stringlengths 80 287 | file_path stringlengths 5 197 | content stringlengths 0 32.8k | language stringclasses 1
value | license stringclasses 7
values | commit_sha stringlengths 40 40 | retrieved_at stringdate 2026-01-04 15:37:27 2026-01-04 17:58:21 | truncated bool 2
classes |
|---|---|---|---|---|---|---|---|---|
rails/rails | https://github.com/rails/rails/blob/ba0d6f09e991d0621cc30f19c9d189cd21dbf76e/activerecord/lib/active_record/enum.rb | activerecord/lib/active_record/enum.rb | # frozen_string_literal: true
require "active_support/core_ext/object/deep_dup"
module ActiveRecord
# Declare an enum attribute where the values map to integers in the database,
# but can be queried by name. Example:
#
# class Conversation < ActiveRecord::Base
# enum :status, [ :active, :archived ]
... | ruby | MIT | ba0d6f09e991d0621cc30f19c9d189cd21dbf76e | 2026-01-04T15:37:27.222351Z | false |
rails/rails | https://github.com/rails/rails/blob/ba0d6f09e991d0621cc30f19c9d189cd21dbf76e/activerecord/lib/active_record/querying.rb | activerecord/lib/active_record/querying.rb | # frozen_string_literal: true
module ActiveRecord
module Querying
QUERYING_METHODS = [
:find, :find_by, :find_by!, :take, :take!, :sole, :find_sole_by, :first, :first!, :last, :last!,
:second, :second!, :third, :third!, :fourth, :fourth!, :fifth, :fifth!,
:forty_two, :forty_two!, :third_to_last... | ruby | MIT | ba0d6f09e991d0621cc30f19c9d189cd21dbf76e | 2026-01-04T15:37:27.222351Z | false |
rails/rails | https://github.com/rails/rails/blob/ba0d6f09e991d0621cc30f19c9d189cd21dbf76e/activerecord/lib/active_record/future_result.rb | activerecord/lib/active_record/future_result.rb | # frozen_string_literal: true
require "active_record/connection_adapters/query_intent"
module ActiveRecord
class FutureResult # :nodoc:
class Complete
attr_reader :result
delegate :empty?, :to_a, to: :result
def initialize(result)
@result = result
end
def pending?
... | ruby | MIT | ba0d6f09e991d0621cc30f19c9d189cd21dbf76e | 2026-01-04T15:37:27.222351Z | false |
rails/rails | https://github.com/rails/rails/blob/ba0d6f09e991d0621cc30f19c9d189cd21dbf76e/activerecord/lib/active_record/associations.rb | activerecord/lib/active_record/associations.rb | # frozen_string_literal: true
module ActiveRecord
# See ActiveRecord::Associations::ClassMethods for documentation.
module Associations # :nodoc:
extend ActiveSupport::Autoload
extend ActiveSupport::Concern
# These classes will be loaded when associations are created.
# So there is no need to eage... | ruby | MIT | ba0d6f09e991d0621cc30f19c9d189cd21dbf76e | 2026-01-04T15:37:27.222351Z | true |
rails/rails | https://github.com/rails/rails/blob/ba0d6f09e991d0621cc30f19c9d189cd21dbf76e/activerecord/lib/active_record/explain_registry.rb | activerecord/lib/active_record/explain_registry.rb | # frozen_string_literal: true
module ActiveRecord
# This is a thread locals registry for EXPLAIN. For example
#
# ActiveRecord::ExplainRegistry.queries
#
# returns the collected queries local to the current thread.
class ExplainRegistry # :nodoc:
class Subscriber
MUTEX = Mutex.new
@subsc... | ruby | MIT | ba0d6f09e991d0621cc30f19c9d189cd21dbf76e | 2026-01-04T15:37:27.222351Z | false |
rails/rails | https://github.com/rails/rails/blob/ba0d6f09e991d0621cc30f19c9d189cd21dbf76e/activerecord/lib/active_record/deprecator.rb | activerecord/lib/active_record/deprecator.rb | # frozen_string_literal: true
module ActiveRecord
def self.deprecator # :nodoc:
@deprecator ||= ActiveSupport::Deprecation.new
end
end
| ruby | MIT | ba0d6f09e991d0621cc30f19c9d189cd21dbf76e | 2026-01-04T15:37:27.222351Z | false |
rails/rails | https://github.com/rails/rails/blob/ba0d6f09e991d0621cc30f19c9d189cd21dbf76e/activerecord/lib/active_record/runtime_registry.rb | activerecord/lib/active_record/runtime_registry.rb | # frozen_string_literal: true
module ActiveRecord
# This is a thread locals registry for Active Record. For example:
#
# ActiveRecord::RuntimeRegistry.stats.sql_runtime
#
# returns the connection handler local to the current unit of execution (either thread of fiber).
module RuntimeRegistry # :nodoc:
... | ruby | MIT | ba0d6f09e991d0621cc30f19c9d189cd21dbf76e | 2026-01-04T15:37:27.222351Z | false |
rails/rails | https://github.com/rails/rails/blob/ba0d6f09e991d0621cc30f19c9d189cd21dbf76e/activerecord/lib/active_record/promise.rb | activerecord/lib/active_record/promise.rb | # frozen_string_literal: true
module ActiveRecord
class Promise < BasicObject
undef_method :==, :!, :!=
def initialize(future_result, block) # :nodoc:
@future_result = future_result
@block = block
end
# Returns whether the associated query is still being executed or not.
def pending... | ruby | MIT | ba0d6f09e991d0621cc30f19c9d189cd21dbf76e | 2026-01-04T15:37:27.222351Z | false |
rails/rails | https://github.com/rails/rails/blob/ba0d6f09e991d0621cc30f19c9d189cd21dbf76e/activerecord/lib/active_record/disable_joins_association_relation.rb | activerecord/lib/active_record/disable_joins_association_relation.rb | # frozen_string_literal: true
module ActiveRecord
class DisableJoinsAssociationRelation < Relation # :nodoc:
attr_reader :ids, :key
def initialize(klass, key, ids)
@ids = ids.uniq
@key = key
super(klass)
end
def limit(value)
records.take(value)
end
def first(limit =... | ruby | MIT | ba0d6f09e991d0621cc30f19c9d189cd21dbf76e | 2026-01-04T15:37:27.222351Z | false |
rails/rails | https://github.com/rails/rails/blob/ba0d6f09e991d0621cc30f19c9d189cd21dbf76e/activerecord/lib/active_record/migration.rb | activerecord/lib/active_record/migration.rb | # frozen_string_literal: true
require "active_support/core_ext/array/access"
require "active_support/core_ext/enumerable"
require "active_support/core_ext/module/attribute_accessors"
require "active_support/actionable_error"
require "active_record/migration/pending_migration_connection"
module ActiveRecord
class Mi... | ruby | MIT | ba0d6f09e991d0621cc30f19c9d189cd21dbf76e | 2026-01-04T15:37:27.222351Z | true |
rails/rails | https://github.com/rails/rails/blob/ba0d6f09e991d0621cc30f19c9d189cd21dbf76e/activerecord/lib/active_record/signed_id.rb | activerecord/lib/active_record/signed_id.rb | # frozen_string_literal: true
module ActiveRecord
# = Active Record Signed Id
module SignedId
extend ActiveSupport::Concern
included do
class_attribute :_signed_id_verifier, instance_accessor: false, instance_predicate: false
##
# :singleton-method:
# Set the secret used for the s... | ruby | MIT | ba0d6f09e991d0621cc30f19c9d189cd21dbf76e | 2026-01-04T15:37:27.222351Z | false |
rails/rails | https://github.com/rails/rails/blob/ba0d6f09e991d0621cc30f19c9d189cd21dbf76e/activerecord/lib/active_record/filter_attribute_handler.rb | activerecord/lib/active_record/filter_attribute_handler.rb | # frozen_string_literal: true
module ActiveRecord
class FilterAttributeHandler # :nodoc:
class << self
def on_sensitive_attribute_declared(&block)
@sensitive_attribute_declaration_listeners ||= Concurrent::Array.new
@sensitive_attribute_declaration_listeners << block
end
def se... | ruby | MIT | ba0d6f09e991d0621cc30f19c9d189cd21dbf76e | 2026-01-04T15:37:27.222351Z | false |
rails/rails | https://github.com/rails/rails/blob/ba0d6f09e991d0621cc30f19c9d189cd21dbf76e/activerecord/lib/active_record/attribute_assignment.rb | activerecord/lib/active_record/attribute_assignment.rb | # frozen_string_literal: true
module ActiveRecord
module AttributeAssignment
private
def _assign_attributes(attributes)
multi_parameter_attributes = nested_parameter_attributes = nil
attributes.each do |k, v|
key = k.to_s
if key.include?("(")
(multi_paramet... | ruby | MIT | ba0d6f09e991d0621cc30f19c9d189cd21dbf76e | 2026-01-04T15:37:27.222351Z | false |
rails/rails | https://github.com/rails/rails/blob/ba0d6f09e991d0621cc30f19c9d189cd21dbf76e/activerecord/lib/active_record/gem_version.rb | activerecord/lib/active_record/gem_version.rb | # frozen_string_literal: true
module ActiveRecord
# Returns the currently loaded version of Active Record as a +Gem::Version+.
def self.gem_version
Gem::Version.new VERSION::STRING
end
module VERSION
MAJOR = 8
MINOR = 2
TINY = 0
PRE = "alpha"
STRING = [MAJOR, MINOR, TINY, PRE].comp... | ruby | MIT | ba0d6f09e991d0621cc30f19c9d189cd21dbf76e | 2026-01-04T15:37:27.222351Z | false |
rails/rails | https://github.com/rails/rails/blob/ba0d6f09e991d0621cc30f19c9d189cd21dbf76e/activerecord/lib/active_record/transactions.rb | activerecord/lib/active_record/transactions.rb | # frozen_string_literal: true
module ActiveRecord
# See ActiveRecord::Transactions::ClassMethods for documentation.
module Transactions
extend ActiveSupport::Concern
ACTIONS = [:create, :destroy, :update] # :nodoc:
included do
define_callbacks :commit, :rollback,
:before_c... | ruby | MIT | ba0d6f09e991d0621cc30f19c9d189cd21dbf76e | 2026-01-04T15:37:27.222351Z | false |
rails/rails | https://github.com/rails/rails/blob/ba0d6f09e991d0621cc30f19c9d189cd21dbf76e/activerecord/lib/active_record/schema.rb | activerecord/lib/active_record/schema.rb | # frozen_string_literal: true
module ActiveRecord
# = Active Record \Schema
#
# Allows programmers to programmatically define a schema in a portable
# DSL. This means you can define tables, indexes, etc. without using SQL
# directly, so your applications can more easily support multiple
# databases.
#
... | ruby | MIT | ba0d6f09e991d0621cc30f19c9d189cd21dbf76e | 2026-01-04T15:37:27.222351Z | false |
rails/rails | https://github.com/rails/rails/blob/ba0d6f09e991d0621cc30f19c9d189cd21dbf76e/activerecord/lib/active_record/test_fixtures.rb | activerecord/lib/active_record/test_fixtures.rb | # frozen_string_literal: true
require "active_support/core_ext/enumerable"
module ActiveRecord
module TestFixtures
extend ActiveSupport::Concern
def before_setup # :nodoc:
setup_fixtures
super
end
def after_teardown # :nodoc:
super
ensure
teardown_fixtures
end
... | ruby | MIT | ba0d6f09e991d0621cc30f19c9d189cd21dbf76e | 2026-01-04T15:37:27.222351Z | false |
rails/rails | https://github.com/rails/rails/blob/ba0d6f09e991d0621cc30f19c9d189cd21dbf76e/activerecord/lib/active_record/timestamp.rb | activerecord/lib/active_record/timestamp.rb | # frozen_string_literal: true
module ActiveRecord
# = Active Record \Timestamp
#
# Active Record automatically timestamps create and update operations if the
# table has fields named <tt>created_at/created_on</tt> or
# <tt>updated_at/updated_on</tt>.
#
# Timestamping can be turned off by setting:
#
#... | ruby | MIT | ba0d6f09e991d0621cc30f19c9d189cd21dbf76e | 2026-01-04T15:37:27.222351Z | false |
rails/rails | https://github.com/rails/rails/blob/ba0d6f09e991d0621cc30f19c9d189cd21dbf76e/activerecord/lib/active_record/connection_adapters.rb | activerecord/lib/active_record/connection_adapters.rb | # frozen_string_literal: true
require "active_support/core_ext/string/filters"
module ActiveRecord
module ConnectionAdapters
extend ActiveSupport::Autoload
@adapters = {}
class << self
# Registers a custom database adapter.
#
# Can also be used to define aliases.
#
# == E... | ruby | MIT | ba0d6f09e991d0621cc30f19c9d189cd21dbf76e | 2026-01-04T15:37:27.222351Z | false |
rails/rails | https://github.com/rails/rails/blob/ba0d6f09e991d0621cc30f19c9d189cd21dbf76e/activerecord/lib/active_record/query_cache.rb | activerecord/lib/active_record/query_cache.rb | # frozen_string_literal: true
module ActiveRecord
# = Active Record Query Cache
class QueryCache
# ActiveRecord::Base extends this module, so these methods are available in models.
module ClassMethods
# Enable the query cache within the block if Active Record is configured.
# If it's not, it wi... | ruby | MIT | ba0d6f09e991d0621cc30f19c9d189cd21dbf76e | 2026-01-04T15:37:27.222351Z | false |
rails/rails | https://github.com/rails/rails/blob/ba0d6f09e991d0621cc30f19c9d189cd21dbf76e/activerecord/lib/active_record/tasks/database_tasks.rb | activerecord/lib/active_record/tasks/database_tasks.rb | # frozen_string_literal: true
require "active_record/database_configurations"
module ActiveRecord
module Tasks # :nodoc:
class DatabaseNotSupported < StandardError; end # :nodoc:
# = Active Record \DatabaseTasks
#
# ActiveRecord::Tasks::DatabaseTasks is a utility class, which encapsulates
# log... | ruby | MIT | ba0d6f09e991d0621cc30f19c9d189cd21dbf76e | 2026-01-04T15:37:27.222351Z | false |
rails/rails | https://github.com/rails/rails/blob/ba0d6f09e991d0621cc30f19c9d189cd21dbf76e/activerecord/lib/active_record/tasks/abstract_tasks.rb | activerecord/lib/active_record/tasks/abstract_tasks.rb | # frozen_string_literal: true
module ActiveRecord
module Tasks # :nodoc:
class AbstractTasks # :nodoc:
def self.using_database_configurations?
true
end
def initialize(db_config)
@db_config = db_config
@configuration_hash = db_config.configuration_hash
end
d... | ruby | MIT | ba0d6f09e991d0621cc30f19c9d189cd21dbf76e | 2026-01-04T15:37:27.222351Z | false |
rails/rails | https://github.com/rails/rails/blob/ba0d6f09e991d0621cc30f19c9d189cd21dbf76e/activerecord/lib/active_record/tasks/postgresql_database_tasks.rb | activerecord/lib/active_record/tasks/postgresql_database_tasks.rb | # frozen_string_literal: true
require "tempfile"
module ActiveRecord
module Tasks # :nodoc:
class PostgreSQLDatabaseTasks < AbstractTasks # :nodoc:
DEFAULT_ENCODING = ENV["CHARSET"] || "utf8"
ON_ERROR_STOP_1 = "ON_ERROR_STOP=1"
SQL_COMMENT_BEGIN = "--"
def create(connection_already_esta... | ruby | MIT | ba0d6f09e991d0621cc30f19c9d189cd21dbf76e | 2026-01-04T15:37:27.222351Z | false |
rails/rails | https://github.com/rails/rails/blob/ba0d6f09e991d0621cc30f19c9d189cd21dbf76e/activerecord/lib/active_record/tasks/sqlite_database_tasks.rb | activerecord/lib/active_record/tasks/sqlite_database_tasks.rb | # frozen_string_literal: true
module ActiveRecord
module Tasks # :nodoc:
class SQLiteDatabaseTasks < AbstractTasks # :nodoc:
def initialize(db_config, root = ActiveRecord::Tasks::DatabaseTasks.root)
@db_config = db_config
@root = root
end
def create
file = ConnectionAda... | ruby | MIT | ba0d6f09e991d0621cc30f19c9d189cd21dbf76e | 2026-01-04T15:37:27.222351Z | false |
rails/rails | https://github.com/rails/rails/blob/ba0d6f09e991d0621cc30f19c9d189cd21dbf76e/activerecord/lib/active_record/tasks/mysql_database_tasks.rb | activerecord/lib/active_record/tasks/mysql_database_tasks.rb | # frozen_string_literal: true
module ActiveRecord
module Tasks # :nodoc:
class MySQLDatabaseTasks < AbstractTasks # :nodoc:
def create
establish_connection(configuration_hash_without_database)
connection.create_database(db_config.database, creation_options)
establish_connection
... | ruby | MIT | ba0d6f09e991d0621cc30f19c9d189cd21dbf76e | 2026-01-04T15:37:27.222351Z | false |
rails/rails | https://github.com/rails/rails/blob/ba0d6f09e991d0621cc30f19c9d189cd21dbf76e/activerecord/lib/active_record/type/text.rb | activerecord/lib/active_record/type/text.rb | # frozen_string_literal: true
module ActiveRecord
module Type
class Text < ActiveModel::Type::String # :nodoc:
def type
:text
end
end
end
end
| ruby | MIT | ba0d6f09e991d0621cc30f19c9d189cd21dbf76e | 2026-01-04T15:37:27.222351Z | false |
rails/rails | https://github.com/rails/rails/blob/ba0d6f09e991d0621cc30f19c9d189cd21dbf76e/activerecord/lib/active_record/type/unsigned_integer.rb | activerecord/lib/active_record/type/unsigned_integer.rb | # frozen_string_literal: true
module ActiveRecord
module Type
class UnsignedInteger < ActiveModel::Type::Integer # :nodoc:
private
def max_value
super * 2
end
def min_value
0
end
end
end
end
| ruby | MIT | ba0d6f09e991d0621cc30f19c9d189cd21dbf76e | 2026-01-04T15:37:27.222351Z | false |
rails/rails | https://github.com/rails/rails/blob/ba0d6f09e991d0621cc30f19c9d189cd21dbf76e/activerecord/lib/active_record/type/time.rb | activerecord/lib/active_record/type/time.rb | # frozen_string_literal: true
module ActiveRecord
module Type
class Time < ActiveModel::Type::Time
include Internal::Timezone
Value = ActiveSupport::Delegation::DelegateClass(::Time) # :nodoc:
def serialize(value)
case value = super
when ::Time
Value.new(value)
... | ruby | MIT | ba0d6f09e991d0621cc30f19c9d189cd21dbf76e | 2026-01-04T15:37:27.222351Z | false |
rails/rails | https://github.com/rails/rails/blob/ba0d6f09e991d0621cc30f19c9d189cd21dbf76e/activerecord/lib/active_record/type/serialized.rb | activerecord/lib/active_record/type/serialized.rb | # frozen_string_literal: true
module ActiveRecord
module Type
class Serialized < ActiveSupport::Delegation::DelegateClass(ActiveModel::Type::Value) # :nodoc:
undef to_yaml if method_defined?(:to_yaml)
include ActiveModel::Type::Helpers::Mutable
attr_reader :subtype, :coder
def initiali... | ruby | MIT | ba0d6f09e991d0621cc30f19c9d189cd21dbf76e | 2026-01-04T15:37:27.222351Z | false |
rails/rails | https://github.com/rails/rails/blob/ba0d6f09e991d0621cc30f19c9d189cd21dbf76e/activerecord/lib/active_record/type/json.rb | activerecord/lib/active_record/type/json.rb | # frozen_string_literal: true
require "active_support/json"
module ActiveRecord
module Type
class Json < ActiveModel::Type::Value
include ActiveModel::Type::Helpers::Mutable
def type
:json
end
def deserialize(value)
return value unless value.is_a?(::String)
begi... | ruby | MIT | ba0d6f09e991d0621cc30f19c9d189cd21dbf76e | 2026-01-04T15:37:27.222351Z | false |
rails/rails | https://github.com/rails/rails/blob/ba0d6f09e991d0621cc30f19c9d189cd21dbf76e/activerecord/lib/active_record/type/decimal_without_scale.rb | activerecord/lib/active_record/type/decimal_without_scale.rb | # frozen_string_literal: true
module ActiveRecord
module Type
class DecimalWithoutScale < ActiveModel::Type::BigInteger # :nodoc:
def type
:decimal
end
def type_cast_for_schema(value)
value.to_s.inspect
end
end
end
end
| ruby | MIT | ba0d6f09e991d0621cc30f19c9d189cd21dbf76e | 2026-01-04T15:37:27.222351Z | false |
rails/rails | https://github.com/rails/rails/blob/ba0d6f09e991d0621cc30f19c9d189cd21dbf76e/activerecord/lib/active_record/type/adapter_specific_registry.rb | activerecord/lib/active_record/type/adapter_specific_registry.rb | # frozen_string_literal: true
module ActiveRecord
# :stopdoc:
module Type
class AdapterSpecificRegistry # :nodoc:
def initialize
@registrations = []
end
def initialize_copy(other)
@registrations = @registrations.dup
end
def add_modifier(options, klass, **args)
... | ruby | MIT | ba0d6f09e991d0621cc30f19c9d189cd21dbf76e | 2026-01-04T15:37:27.222351Z | false |
rails/rails | https://github.com/rails/rails/blob/ba0d6f09e991d0621cc30f19c9d189cd21dbf76e/activerecord/lib/active_record/type/type_map.rb | activerecord/lib/active_record/type/type_map.rb | # frozen_string_literal: true
require "concurrent/map"
module ActiveRecord
module Type
class TypeMap # :nodoc:
def initialize(parent = nil)
@mapping = {}
@parent = parent
@cache = Concurrent::Map.new
end
def lookup(lookup_key)
fetch(lookup_key) { Type.default_v... | ruby | MIT | ba0d6f09e991d0621cc30f19c9d189cd21dbf76e | 2026-01-04T15:37:27.222351Z | false |
rails/rails | https://github.com/rails/rails/blob/ba0d6f09e991d0621cc30f19c9d189cd21dbf76e/activerecord/lib/active_record/type/hash_lookup_type_map.rb | activerecord/lib/active_record/type/hash_lookup_type_map.rb | # frozen_string_literal: true
module ActiveRecord
module Type
class HashLookupTypeMap # :nodoc:
def initialize(parent = nil)
@mapping = {}
@cache = Concurrent::Map.new do |h, key|
h.fetch_or_store(key, Concurrent::Map.new)
end
end
def lookup(lookup_key, *args)... | ruby | MIT | ba0d6f09e991d0621cc30f19c9d189cd21dbf76e | 2026-01-04T15:37:27.222351Z | false |
rails/rails | https://github.com/rails/rails/blob/ba0d6f09e991d0621cc30f19c9d189cd21dbf76e/activerecord/lib/active_record/type/date_time.rb | activerecord/lib/active_record/type/date_time.rb | # frozen_string_literal: true
module ActiveRecord
module Type
class DateTime < ActiveModel::Type::DateTime
include Internal::Timezone
end
end
end
| ruby | MIT | ba0d6f09e991d0621cc30f19c9d189cd21dbf76e | 2026-01-04T15:37:27.222351Z | false |
rails/rails | https://github.com/rails/rails/blob/ba0d6f09e991d0621cc30f19c9d189cd21dbf76e/activerecord/lib/active_record/type/date.rb | activerecord/lib/active_record/type/date.rb | # frozen_string_literal: true
module ActiveRecord
module Type
class Date < ActiveModel::Type::Date
include Internal::Timezone
end
end
end
| ruby | MIT | ba0d6f09e991d0621cc30f19c9d189cd21dbf76e | 2026-01-04T15:37:27.222351Z | false |
rails/rails | https://github.com/rails/rails/blob/ba0d6f09e991d0621cc30f19c9d189cd21dbf76e/activerecord/lib/active_record/type/internal/timezone.rb | activerecord/lib/active_record/type/internal/timezone.rb | # frozen_string_literal: true
module ActiveRecord
module Type
module Internal
module Timezone
def initialize(timezone: nil, **kwargs)
super(**kwargs)
@timezone = timezone
end
def is_utc?
default_timezone == :utc
end
def default_timezon... | ruby | MIT | ba0d6f09e991d0621cc30f19c9d189cd21dbf76e | 2026-01-04T15:37:27.222351Z | false |
rails/rails | https://github.com/rails/rails/blob/ba0d6f09e991d0621cc30f19c9d189cd21dbf76e/activerecord/lib/active_record/encryption/encryptable_record.rb | activerecord/lib/active_record/encryption/encryptable_record.rb | # frozen_string_literal: true
module ActiveRecord
module Encryption
# This is the concern mixed in Active Record models to make them encryptable. It adds the +encrypts+
# attribute declaration, as well as the API to encrypt and decrypt records.
module EncryptableRecord
extend ActiveSupport::Concern... | ruby | MIT | ba0d6f09e991d0621cc30f19c9d189cd21dbf76e | 2026-01-04T15:37:27.222351Z | false |
rails/rails | https://github.com/rails/rails/blob/ba0d6f09e991d0621cc30f19c9d189cd21dbf76e/activerecord/lib/active_record/encryption/key_provider.rb | activerecord/lib/active_record/encryption/key_provider.rb | # frozen_string_literal: true
module ActiveRecord
module Encryption
# A +KeyProvider+ serves keys:
#
# * An encryption key
# * A list of potential decryption keys. Serving multiple decryption keys supports rotation-schemes
# where new keys are added but old keys need to continue working
cla... | ruby | MIT | ba0d6f09e991d0621cc30f19c9d189cd21dbf76e | 2026-01-04T15:37:27.222351Z | false |
rails/rails | https://github.com/rails/rails/blob/ba0d6f09e991d0621cc30f19c9d189cd21dbf76e/activerecord/lib/active_record/encryption/key_generator.rb | activerecord/lib/active_record/encryption/key_generator.rb | # frozen_string_literal: true
require "securerandom"
module ActiveRecord
module Encryption
# Utility for generating and deriving random keys.
class KeyGenerator
attr_reader :hash_digest_class
def initialize(hash_digest_class: ActiveRecord::Encryption.config.hash_digest_class)
@hash_dige... | ruby | MIT | ba0d6f09e991d0621cc30f19c9d189cd21dbf76e | 2026-01-04T15:37:27.222351Z | false |
rails/rails | https://github.com/rails/rails/blob/ba0d6f09e991d0621cc30f19c9d189cd21dbf76e/activerecord/lib/active_record/encryption/message_pack_message_serializer.rb | activerecord/lib/active_record/encryption/message_pack_message_serializer.rb | # frozen_string_literal: true
require "active_support/message_pack"
module ActiveRecord
module Encryption
# A message serializer that serializes +Messages+ with MessagePack.
#
# The message is converted to a hash with this structure:
#
# {
# p: <payload>,
# h: {
# hea... | ruby | MIT | ba0d6f09e991d0621cc30f19c9d189cd21dbf76e | 2026-01-04T15:37:27.222351Z | false |
rails/rails | https://github.com/rails/rails/blob/ba0d6f09e991d0621cc30f19c9d189cd21dbf76e/activerecord/lib/active_record/encryption/errors.rb | activerecord/lib/active_record/encryption/errors.rb | # frozen_string_literal: true
module ActiveRecord
module Encryption
module Errors
class Base < StandardError; end
class Encoding < Base; end
class Decryption < Base; end
class Encryption < Base; end
class Configuration < Base; end
class ForbiddenClass < Base; end
class E... | ruby | MIT | ba0d6f09e991d0621cc30f19c9d189cd21dbf76e | 2026-01-04T15:37:27.222351Z | false |
rails/rails | https://github.com/rails/rails/blob/ba0d6f09e991d0621cc30f19c9d189cd21dbf76e/activerecord/lib/active_record/encryption/encrypting_only_encryptor.rb | activerecord/lib/active_record/encryption/encrypting_only_encryptor.rb | # frozen_string_literal: true
module ActiveRecord
module Encryption
# An encryptor that can encrypt data but can't decrypt it.
class EncryptingOnlyEncryptor < Encryptor
def decrypt(encrypted_text, key_provider: nil, cipher_options: {})
encrypted_text
end
end
end
end
| ruby | MIT | ba0d6f09e991d0621cc30f19c9d189cd21dbf76e | 2026-01-04T15:37:27.222351Z | false |
rails/rails | https://github.com/rails/rails/blob/ba0d6f09e991d0621cc30f19c9d189cd21dbf76e/activerecord/lib/active_record/encryption/auto_filtered_parameters.rb | activerecord/lib/active_record/encryption/auto_filtered_parameters.rb | # frozen_string_literal: true
module ActiveRecord
module Encryption
class AutoFilteredParameters
def initialize(app)
@app = app
@attributes_by_class = Concurrent::Map.new
@collecting = true
install_collecting_hook
end
def enable
apply_collected_attribut... | ruby | MIT | ba0d6f09e991d0621cc30f19c9d189cd21dbf76e | 2026-01-04T15:37:27.222351Z | false |
rails/rails | https://github.com/rails/rails/blob/ba0d6f09e991d0621cc30f19c9d189cd21dbf76e/activerecord/lib/active_record/encryption/extended_deterministic_uniqueness_validator.rb | activerecord/lib/active_record/encryption/extended_deterministic_uniqueness_validator.rb | # frozen_string_literal: true
module ActiveRecord
module Encryption
module ExtendedDeterministicUniquenessValidator
def self.install_support
ActiveRecord::Validations::UniquenessValidator.prepend(EncryptedUniquenessValidator)
end
module EncryptedUniquenessValidator
def validate... | ruby | MIT | ba0d6f09e991d0621cc30f19c9d189cd21dbf76e | 2026-01-04T15:37:27.222351Z | false |
rails/rails | https://github.com/rails/rails/blob/ba0d6f09e991d0621cc30f19c9d189cd21dbf76e/activerecord/lib/active_record/encryption/encryptor.rb | activerecord/lib/active_record/encryption/encryptor.rb | # frozen_string_literal: true
require "openssl"
require "active_support/core_ext/numeric"
module ActiveRecord
module Encryption
# An encryptor exposes the encryption API that ActiveRecord::Encryption::EncryptedAttributeType
# uses for encrypting and decrypting attribute values.
#
# It interacts with... | ruby | MIT | ba0d6f09e991d0621cc30f19c9d189cd21dbf76e | 2026-01-04T15:37:27.222351Z | false |
rails/rails | https://github.com/rails/rails/blob/ba0d6f09e991d0621cc30f19c9d189cd21dbf76e/activerecord/lib/active_record/encryption/key.rb | activerecord/lib/active_record/encryption/key.rb | # frozen_string_literal: true
module ActiveRecord
module Encryption
# A key is a container for a given +secret+
#
# Optionally, it can include +public_tags+. These tags are meant to be stored
# in clean (public) and can be used, for example, to include information that
# references the key for a ... | ruby | MIT | ba0d6f09e991d0621cc30f19c9d189cd21dbf76e | 2026-01-04T15:37:27.222351Z | false |
rails/rails | https://github.com/rails/rails/blob/ba0d6f09e991d0621cc30f19c9d189cd21dbf76e/activerecord/lib/active_record/encryption/null_encryptor.rb | activerecord/lib/active_record/encryption/null_encryptor.rb | # frozen_string_literal: true
module ActiveRecord
module Encryption
# An encryptor that won't decrypt or encrypt. It will just return the passed
# values
class NullEncryptor
def encrypt(clean_text, key_provider: nil, cipher_options: {})
clean_text
end
def decrypt(encrypted_text... | ruby | MIT | ba0d6f09e991d0621cc30f19c9d189cd21dbf76e | 2026-01-04T15:37:27.222351Z | false |
rails/rails | https://github.com/rails/rails/blob/ba0d6f09e991d0621cc30f19c9d189cd21dbf76e/activerecord/lib/active_record/encryption/deterministic_key_provider.rb | activerecord/lib/active_record/encryption/deterministic_key_provider.rb | # frozen_string_literal: true
module ActiveRecord
module Encryption
# A KeyProvider that derives keys from passwords.
class DeterministicKeyProvider < DerivedSecretKeyProvider
def initialize(password)
passwords = Array(password)
raise ActiveRecord::Encryption::Errors::Configuration, "De... | ruby | MIT | ba0d6f09e991d0621cc30f19c9d189cd21dbf76e | 2026-01-04T15:37:27.222351Z | false |
rails/rails | https://github.com/rails/rails/blob/ba0d6f09e991d0621cc30f19c9d189cd21dbf76e/activerecord/lib/active_record/encryption/encrypted_attribute_type.rb | activerecord/lib/active_record/encryption/encrypted_attribute_type.rb | # frozen_string_literal: true
module ActiveRecord
module Encryption
# An ActiveModel::Type::Value that encrypts/decrypts strings of text.
#
# This is the central piece that connects the encryption system with +encrypts+ declarations in the
# model classes. Whenever you declare an attribute as encrypt... | ruby | MIT | ba0d6f09e991d0621cc30f19c9d189cd21dbf76e | 2026-01-04T15:37:27.222351Z | false |
rails/rails | https://github.com/rails/rails/blob/ba0d6f09e991d0621cc30f19c9d189cd21dbf76e/activerecord/lib/active_record/encryption/properties.rb | activerecord/lib/active_record/encryption/properties.rb | # frozen_string_literal: true
module ActiveRecord
module Encryption
# This is a wrapper for a hash of encryption properties. It is used by
# +Key+ (public tags) and +Message+ (headers).
#
# Since properties are serialized in messages, it is important for storage
# efficiency to keep their keys as... | ruby | MIT | ba0d6f09e991d0621cc30f19c9d189cd21dbf76e | 2026-01-04T15:37:27.222351Z | false |
rails/rails | https://github.com/rails/rails/blob/ba0d6f09e991d0621cc30f19c9d189cd21dbf76e/activerecord/lib/active_record/encryption/message.rb | activerecord/lib/active_record/encryption/message.rb | # frozen_string_literal: true
module ActiveRecord
module Encryption
# A message defines the structure of the data we store in encrypted attributes. It contains:
#
# * An encrypted payload
# * A list of unencrypted headers
#
# See Encryptor#encrypt
class Message
attr_accessor :payloa... | ruby | MIT | ba0d6f09e991d0621cc30f19c9d189cd21dbf76e | 2026-01-04T15:37:27.222351Z | false |
rails/rails | https://github.com/rails/rails/blob/ba0d6f09e991d0621cc30f19c9d189cd21dbf76e/activerecord/lib/active_record/encryption/scheme.rb | activerecord/lib/active_record/encryption/scheme.rb | # frozen_string_literal: true
module ActiveRecord
module Encryption
# A container of attribute encryption options.
#
# It validates and serves attribute encryption options.
#
# See EncryptedAttributeType, Context
class Scheme
attr_accessor :previous_schemes
def initialize(key_pro... | ruby | MIT | ba0d6f09e991d0621cc30f19c9d189cd21dbf76e | 2026-01-04T15:37:27.222351Z | false |
rails/rails | https://github.com/rails/rails/blob/ba0d6f09e991d0621cc30f19c9d189cd21dbf76e/activerecord/lib/active_record/encryption/encrypted_fixtures.rb | activerecord/lib/active_record/encryption/encrypted_fixtures.rb | # frozen_string_literal: true
module ActiveRecord
module Encryption
module EncryptedFixtures
def initialize(fixture, model_class)
@clean_values = {}
encrypt_fixture_data(fixture, model_class)
process_preserved_original_columns(fixture, model_class)
super
end
pri... | ruby | MIT | ba0d6f09e991d0621cc30f19c9d189cd21dbf76e | 2026-01-04T15:37:27.222351Z | false |
rails/rails | https://github.com/rails/rails/blob/ba0d6f09e991d0621cc30f19c9d189cd21dbf76e/activerecord/lib/active_record/encryption/message_serializer.rb | activerecord/lib/active_record/encryption/message_serializer.rb | # frozen_string_literal: true
require "base64"
module ActiveRecord
module Encryption
# A message serializer that serializes +Messages+ with JSON.
#
# The generated structure is pretty simple:
#
# {
# p: <payload>,
# h: {
# header1: value1,
# header2: value2,... | ruby | MIT | ba0d6f09e991d0621cc30f19c9d189cd21dbf76e | 2026-01-04T15:37:27.222351Z | false |
rails/rails | https://github.com/rails/rails/blob/ba0d6f09e991d0621cc30f19c9d189cd21dbf76e/activerecord/lib/active_record/encryption/derived_secret_key_provider.rb | activerecord/lib/active_record/encryption/derived_secret_key_provider.rb | # frozen_string_literal: true
module ActiveRecord
module Encryption
# A KeyProvider that derives keys from passwords.
class DerivedSecretKeyProvider < KeyProvider
def initialize(passwords, key_generator: ActiveRecord::Encryption.key_generator)
super(Array(passwords).collect { |password| derive_... | ruby | MIT | ba0d6f09e991d0621cc30f19c9d189cd21dbf76e | 2026-01-04T15:37:27.222351Z | false |
rails/rails | https://github.com/rails/rails/blob/ba0d6f09e991d0621cc30f19c9d189cd21dbf76e/activerecord/lib/active_record/encryption/extended_deterministic_queries.rb | activerecord/lib/active_record/encryption/extended_deterministic_queries.rb | # frozen_string_literal: true
module ActiveRecord
module Encryption
# Automatically expand encrypted arguments to support querying both encrypted and unencrypted data
#
# Active Record \Encryption supports querying the db using deterministic attributes. For example:
#
# Contact.find_by(email_ad... | ruby | MIT | ba0d6f09e991d0621cc30f19c9d189cd21dbf76e | 2026-01-04T15:37:27.222351Z | false |
rails/rails | https://github.com/rails/rails/blob/ba0d6f09e991d0621cc30f19c9d189cd21dbf76e/activerecord/lib/active_record/encryption/config.rb | activerecord/lib/active_record/encryption/config.rb | # frozen_string_literal: true
require "openssl"
module ActiveRecord
module Encryption
# Container of configuration options
class Config
attr_accessor :primary_key, :deterministic_key, :store_key_references, :key_derivation_salt, :hash_digest_class,
:support_unencrypted_data, :encry... | ruby | MIT | ba0d6f09e991d0621cc30f19c9d189cd21dbf76e | 2026-01-04T15:37:27.222351Z | false |
rails/rails | https://github.com/rails/rails/blob/ba0d6f09e991d0621cc30f19c9d189cd21dbf76e/activerecord/lib/active_record/encryption/context.rb | activerecord/lib/active_record/encryption/context.rb | # frozen_string_literal: true
module ActiveRecord
module Encryption
# An encryption context configures the different entities used to perform encryption:
#
# * A key provider
# * A key generator
# * An encryptor, the facade to encrypt data
# * A cipher, the encryption algorithm
# * A mess... | ruby | MIT | ba0d6f09e991d0621cc30f19c9d189cd21dbf76e | 2026-01-04T15:37:27.222351Z | false |
rails/rails | https://github.com/rails/rails/blob/ba0d6f09e991d0621cc30f19c9d189cd21dbf76e/activerecord/lib/active_record/encryption/contexts.rb | activerecord/lib/active_record/encryption/contexts.rb | # frozen_string_literal: true
module ActiveRecord
module Encryption
# ActiveRecord::Encryption uses encryption contexts to configure the different entities used to
# encrypt/decrypt at a given moment in time.
#
# By default, the library uses a default encryption context. This is the Context that gets... | ruby | MIT | ba0d6f09e991d0621cc30f19c9d189cd21dbf76e | 2026-01-04T15:37:27.222351Z | false |
rails/rails | https://github.com/rails/rails/blob/ba0d6f09e991d0621cc30f19c9d189cd21dbf76e/activerecord/lib/active_record/encryption/envelope_encryption_key_provider.rb | activerecord/lib/active_record/encryption/envelope_encryption_key_provider.rb | # frozen_string_literal: true
module ActiveRecord
module Encryption
# Implements a simple envelope encryption approach where:
#
# * It generates a random data-encryption key for each encryption operation.
# * It stores the generated key along with the encrypted payload. It encrypts this key
# w... | ruby | MIT | ba0d6f09e991d0621cc30f19c9d189cd21dbf76e | 2026-01-04T15:37:27.222351Z | false |
rails/rails | https://github.com/rails/rails/blob/ba0d6f09e991d0621cc30f19c9d189cd21dbf76e/activerecord/lib/active_record/encryption/configurable.rb | activerecord/lib/active_record/encryption/configurable.rb | # frozen_string_literal: true
module ActiveRecord
module Encryption
# Configuration API for ActiveRecord::Encryption
module Configurable
extend ActiveSupport::Concern
included do
mattr_reader :config, default: Config.new
mattr_accessor :encrypted_attribute_declaration_listeners
... | ruby | MIT | ba0d6f09e991d0621cc30f19c9d189cd21dbf76e | 2026-01-04T15:37:27.222351Z | false |
rails/rails | https://github.com/rails/rails/blob/ba0d6f09e991d0621cc30f19c9d189cd21dbf76e/activerecord/lib/active_record/encryption/cipher.rb | activerecord/lib/active_record/encryption/cipher.rb | # frozen_string_literal: true
module ActiveRecord
module Encryption
# The algorithm used for encrypting and decrypting +Message+ objects.
#
# It uses AES-256-GCM. It will generate a random IV for non deterministic encryption (default)
# or derive an initialization vector from the encrypted content fo... | ruby | MIT | ba0d6f09e991d0621cc30f19c9d189cd21dbf76e | 2026-01-04T15:37:27.222351Z | false |
rails/rails | https://github.com/rails/rails/blob/ba0d6f09e991d0621cc30f19c9d189cd21dbf76e/activerecord/lib/active_record/encryption/read_only_null_encryptor.rb | activerecord/lib/active_record/encryption/read_only_null_encryptor.rb | # frozen_string_literal: true
module ActiveRecord
module Encryption
# A +NullEncryptor+ that will raise an error when trying to encrypt data
#
# This is useful when you want to reveal ciphertexts for debugging purposes
# and you want to make sure you won't overwrite any encryptable attribute with
... | ruby | MIT | ba0d6f09e991d0621cc30f19c9d189cd21dbf76e | 2026-01-04T15:37:27.222351Z | false |
rails/rails | https://github.com/rails/rails/blob/ba0d6f09e991d0621cc30f19c9d189cd21dbf76e/activerecord/lib/active_record/encryption/cipher/aes256_gcm.rb | activerecord/lib/active_record/encryption/cipher/aes256_gcm.rb | # frozen_string_literal: true
require "openssl"
module ActiveRecord
module Encryption
class Cipher
# A 256-GCM cipher.
#
# By default it will use random initialization vectors. For deterministic encryption, it will use a SHA-256 hash of
# the text to encrypt and the secret.
#
... | ruby | MIT | ba0d6f09e991d0621cc30f19c9d189cd21dbf76e | 2026-01-04T15:37:27.222351Z | false |
rails/rails | https://github.com/rails/rails/blob/ba0d6f09e991d0621cc30f19c9d189cd21dbf76e/activerecord/lib/active_record/fixture_set/table_rows.rb | activerecord/lib/active_record/fixture_set/table_rows.rb | # frozen_string_literal: true
require "active_record/fixture_set/table_row"
require "active_record/fixture_set/model_metadata"
module ActiveRecord
class FixtureSet
class TableRows # :nodoc:
def initialize(table_name, model_class:, fixtures:)
@model_class = model_class
# track any join tab... | ruby | MIT | ba0d6f09e991d0621cc30f19c9d189cd21dbf76e | 2026-01-04T15:37:27.222351Z | false |
rails/rails | https://github.com/rails/rails/blob/ba0d6f09e991d0621cc30f19c9d189cd21dbf76e/activerecord/lib/active_record/fixture_set/file.rb | activerecord/lib/active_record/fixture_set/file.rb | # frozen_string_literal: true
require "active_support/configuration_file"
module ActiveRecord
class FixtureSet
class File # :nodoc:
include Enumerable
##
# Open a fixture file named +file+. When called with a block, the block
# is called with the filehandle and the filehandle is automa... | ruby | MIT | ba0d6f09e991d0621cc30f19c9d189cd21dbf76e | 2026-01-04T15:37:27.222351Z | false |
rails/rails | https://github.com/rails/rails/blob/ba0d6f09e991d0621cc30f19c9d189cd21dbf76e/activerecord/lib/active_record/fixture_set/table_row.rb | activerecord/lib/active_record/fixture_set/table_row.rb | # frozen_string_literal: true
module ActiveRecord
class FixtureSet
class TableRow # :nodoc:
class ReflectionProxy # :nodoc:
def initialize(association)
@association = association
end
def join_table
@association.join_table
end
def name
... | ruby | MIT | ba0d6f09e991d0621cc30f19c9d189cd21dbf76e | 2026-01-04T15:37:27.222351Z | false |
rails/rails | https://github.com/rails/rails/blob/ba0d6f09e991d0621cc30f19c9d189cd21dbf76e/activerecord/lib/active_record/fixture_set/model_metadata.rb | activerecord/lib/active_record/fixture_set/model_metadata.rb | # frozen_string_literal: true
module ActiveRecord
class FixtureSet
class ModelMetadata # :nodoc:
def initialize(model_class)
@model_class = model_class
end
def primary_key_name
@primary_key_name ||= @model_class && @model_class.primary_key
end
def primary_key_type
... | ruby | MIT | ba0d6f09e991d0621cc30f19c9d189cd21dbf76e | 2026-01-04T15:37:27.222351Z | false |
rails/rails | https://github.com/rails/rails/blob/ba0d6f09e991d0621cc30f19c9d189cd21dbf76e/activerecord/lib/active_record/fixture_set/render_context.rb | activerecord/lib/active_record/fixture_set/render_context.rb | # frozen_string_literal: true
require "base64"
# NOTE: This class has to be defined in compact style in
# order for rendering context subclassing to work correctly.
class ActiveRecord::FixtureSet::RenderContext # :nodoc:
def self.create_subclass
Class.new(ActiveRecord::FixtureSet.context_class) do
def get... | ruby | MIT | ba0d6f09e991d0621cc30f19c9d189cd21dbf76e | 2026-01-04T15:37:27.222351Z | false |
rails/rails | https://github.com/rails/rails/blob/ba0d6f09e991d0621cc30f19c9d189cd21dbf76e/activerecord/lib/active_record/middleware/database_selector.rb | activerecord/lib/active_record/middleware/database_selector.rb | # frozen_string_literal: true
require "active_record/middleware/database_selector/resolver"
module ActiveRecord
module Middleware
# = Database Selector \Middleware
#
# The DatabaseSelector Middleware provides a framework for automatically
# swapping from the primary to the replica database connectio... | ruby | MIT | ba0d6f09e991d0621cc30f19c9d189cd21dbf76e | 2026-01-04T15:37:27.222351Z | false |
rails/rails | https://github.com/rails/rails/blob/ba0d6f09e991d0621cc30f19c9d189cd21dbf76e/activerecord/lib/active_record/middleware/shard_selector.rb | activerecord/lib/active_record/middleware/shard_selector.rb | # frozen_string_literal: true
module ActiveRecord
module Middleware
# = Shard Selector \Middleware
#
# The ShardSelector Middleware provides a framework for automatically
# swapping shards. \Rails provides a basic framework to determine which
# shard to switch to and allows for applications to wr... | ruby | MIT | ba0d6f09e991d0621cc30f19c9d189cd21dbf76e | 2026-01-04T15:37:27.222351Z | false |
rails/rails | https://github.com/rails/rails/blob/ba0d6f09e991d0621cc30f19c9d189cd21dbf76e/activerecord/lib/active_record/middleware/database_selector/resolver.rb | activerecord/lib/active_record/middleware/database_selector/resolver.rb | # frozen_string_literal: true
require "active_record/middleware/database_selector/resolver/session"
require "active_support/core_ext/numeric/time"
module ActiveRecord
module Middleware
class DatabaseSelector
# The Resolver class is used by the DatabaseSelector middleware to
# determine which databas... | ruby | MIT | ba0d6f09e991d0621cc30f19c9d189cd21dbf76e | 2026-01-04T15:37:27.222351Z | false |
rails/rails | https://github.com/rails/rails/blob/ba0d6f09e991d0621cc30f19c9d189cd21dbf76e/activerecord/lib/active_record/middleware/database_selector/resolver/session.rb | activerecord/lib/active_record/middleware/database_selector/resolver/session.rb | # frozen_string_literal: true
module ActiveRecord
module Middleware
class DatabaseSelector
class Resolver
# The session class is used by the DatabaseSelector::Resolver to save
# timestamps of the last write in the session.
#
# The last_write is used to determine whether it's... | ruby | MIT | ba0d6f09e991d0621cc30f19c9d189cd21dbf76e | 2026-01-04T15:37:27.222351Z | false |
rails/rails | https://github.com/rails/rails/blob/ba0d6f09e991d0621cc30f19c9d189cd21dbf76e/activerecord/lib/active_record/type_caster/connection.rb | activerecord/lib/active_record/type_caster/connection.rb | # frozen_string_literal: true
module ActiveRecord
module TypeCaster
class Connection # :nodoc:
def initialize(klass, table_name)
@klass = klass
@table_name = table_name
end
def type_cast_for_database(attr_name, value)
type = type_for_attribute(attr_name)
type.se... | ruby | MIT | ba0d6f09e991d0621cc30f19c9d189cd21dbf76e | 2026-01-04T15:37:27.222351Z | false |
rails/rails | https://github.com/rails/rails/blob/ba0d6f09e991d0621cc30f19c9d189cd21dbf76e/activerecord/lib/active_record/type_caster/map.rb | activerecord/lib/active_record/type_caster/map.rb | # frozen_string_literal: true
module ActiveRecord
module TypeCaster
class Map # :nodoc:
def initialize(klass)
@klass = klass
end
def type_cast_for_database(attr_name, value)
type = type_for_attribute(attr_name)
type.serialize(value)
end
def type_for_attribu... | ruby | MIT | ba0d6f09e991d0621cc30f19c9d189cd21dbf76e | 2026-01-04T15:37:27.222351Z | false |
rails/rails | https://github.com/rails/rails/blob/ba0d6f09e991d0621cc30f19c9d189cd21dbf76e/activerecord/lib/active_record/coders/column_serializer.rb | activerecord/lib/active_record/coders/column_serializer.rb | # frozen_string_literal: true
module ActiveRecord
module Coders # :nodoc:
class ColumnSerializer # :nodoc:
attr_reader :object_class
attr_reader :coder
def initialize(attr_name, coder, object_class = Object)
@attr_name = attr_name
@object_class = object_class
@coder = c... | ruby | MIT | ba0d6f09e991d0621cc30f19c9d189cd21dbf76e | 2026-01-04T15:37:27.222351Z | false |
rails/rails | https://github.com/rails/rails/blob/ba0d6f09e991d0621cc30f19c9d189cd21dbf76e/activerecord/lib/active_record/coders/json.rb | activerecord/lib/active_record/coders/json.rb | # frozen_string_literal: true
require "active_support/json"
module ActiveRecord
module Coders # :nodoc:
class JSON # :nodoc:
DEFAULT_OPTIONS = { escape: false }.freeze
def initialize(options = nil)
@options = options ? DEFAULT_OPTIONS.merge(options) : DEFAULT_OPTIONS
@encoder = Acti... | ruby | MIT | ba0d6f09e991d0621cc30f19c9d189cd21dbf76e | 2026-01-04T15:37:27.222351Z | false |
rails/rails | https://github.com/rails/rails/blob/ba0d6f09e991d0621cc30f19c9d189cd21dbf76e/activerecord/lib/active_record/coders/yaml_column.rb | activerecord/lib/active_record/coders/yaml_column.rb | # frozen_string_literal: true
require "yaml"
module ActiveRecord
module Coders # :nodoc:
class YAMLColumn < ColumnSerializer # :nodoc:
class SafeCoder
def initialize(permitted_classes: [], unsafe_load: nil)
@permitted_classes = permitted_classes
@unsafe_load = unsafe_load
... | ruby | MIT | ba0d6f09e991d0621cc30f19c9d189cd21dbf76e | 2026-01-04T15:37:27.222351Z | false |
rails/rails | https://github.com/rails/rails/blob/ba0d6f09e991d0621cc30f19c9d189cd21dbf76e/activerecord/lib/active_record/scoping/default.rb | activerecord/lib/active_record/scoping/default.rb | # frozen_string_literal: true
module ActiveRecord
module Scoping
class DefaultScope # :nodoc:
attr_reader :scope, :all_queries
def initialize(scope, all_queries = nil)
@scope = scope
@all_queries = all_queries
end
end
module Default
extend ActiveSupport::Concern
... | ruby | MIT | ba0d6f09e991d0621cc30f19c9d189cd21dbf76e | 2026-01-04T15:37:27.222351Z | false |
rails/rails | https://github.com/rails/rails/blob/ba0d6f09e991d0621cc30f19c9d189cd21dbf76e/activerecord/lib/active_record/scoping/named.rb | activerecord/lib/active_record/scoping/named.rb | # frozen_string_literal: true
module ActiveRecord
# = Active Record \Named \Scopes
module Scoping
module Named
extend ActiveSupport::Concern
module ClassMethods
# Returns an ActiveRecord::Relation scope object.
#
# posts = Post.all
# posts.size # Fires "select c... | ruby | MIT | ba0d6f09e991d0621cc30f19c9d189cd21dbf76e | 2026-01-04T15:37:27.222351Z | false |
rails/rails | https://github.com/rails/rails/blob/ba0d6f09e991d0621cc30f19c9d189cd21dbf76e/activerecord/lib/active_record/attribute_methods/before_type_cast.rb | activerecord/lib/active_record/attribute_methods/before_type_cast.rb | # frozen_string_literal: true
module ActiveRecord
module AttributeMethods
# = Active Record Attribute Methods Before Type Cast
#
# ActiveRecord::AttributeMethods::BeforeTypeCast provides a way to
# read the value of the attributes before typecasting and deserialization.
#
# class Task < Act... | ruby | MIT | ba0d6f09e991d0621cc30f19c9d189cd21dbf76e | 2026-01-04T15:37:27.222351Z | false |
rails/rails | https://github.com/rails/rails/blob/ba0d6f09e991d0621cc30f19c9d189cd21dbf76e/activerecord/lib/active_record/attribute_methods/write.rb | activerecord/lib/active_record/attribute_methods/write.rb | # frozen_string_literal: true
module ActiveRecord
module AttributeMethods
# = Active Record Attribute Methods \Write
module Write
extend ActiveSupport::Concern
included do
attribute_method_suffix "=", parameters: "value"
end
module ClassMethods # :nodoc:
private
... | ruby | MIT | ba0d6f09e991d0621cc30f19c9d189cd21dbf76e | 2026-01-04T15:37:27.222351Z | false |
rails/rails | https://github.com/rails/rails/blob/ba0d6f09e991d0621cc30f19c9d189cd21dbf76e/activerecord/lib/active_record/attribute_methods/serialization.rb | activerecord/lib/active_record/attribute_methods/serialization.rb | # frozen_string_literal: true
module ActiveRecord
module AttributeMethods
# = Active Record Attribute Methods \Serialization
module Serialization
extend ActiveSupport::Concern
class ColumnNotSerializableError < StandardError
def initialize(name, type)
super <<~EOS
C... | ruby | MIT | ba0d6f09e991d0621cc30f19c9d189cd21dbf76e | 2026-01-04T15:37:27.222351Z | false |
rails/rails | https://github.com/rails/rails/blob/ba0d6f09e991d0621cc30f19c9d189cd21dbf76e/activerecord/lib/active_record/attribute_methods/query.rb | activerecord/lib/active_record/attribute_methods/query.rb | # frozen_string_literal: true
module ActiveRecord
module AttributeMethods
# = Active Record Attribute Methods \Query
#
# Adds query methods for attributes that return either +true+ or +false+
# depending on the attribute type and value.
#
# For Boolean attributes this will return +true+ if th... | ruby | MIT | ba0d6f09e991d0621cc30f19c9d189cd21dbf76e | 2026-01-04T15:37:27.222351Z | false |
rails/rails | https://github.com/rails/rails/blob/ba0d6f09e991d0621cc30f19c9d189cd21dbf76e/activerecord/lib/active_record/attribute_methods/read.rb | activerecord/lib/active_record/attribute_methods/read.rb | # frozen_string_literal: true
module ActiveRecord
module AttributeMethods
# = Active Record Attribute Methods \Read
module Read
extend ActiveSupport::Concern
module ClassMethods # :nodoc:
private
def define_method_attribute(canonical_name, owner:, as: canonical_name)
... | ruby | MIT | ba0d6f09e991d0621cc30f19c9d189cd21dbf76e | 2026-01-04T15:37:27.222351Z | false |
rails/rails | https://github.com/rails/rails/blob/ba0d6f09e991d0621cc30f19c9d189cd21dbf76e/activerecord/lib/active_record/attribute_methods/composite_primary_key.rb | activerecord/lib/active_record/attribute_methods/composite_primary_key.rb | # frozen_string_literal: true
module ActiveRecord
module AttributeMethods
module CompositePrimaryKey # :nodoc:
# Returns the primary key column's value. If the primary key is composite,
# returns an array of the primary key column values.
def id
if self.class.composite_primary_key?
... | ruby | MIT | ba0d6f09e991d0621cc30f19c9d189cd21dbf76e | 2026-01-04T15:37:27.222351Z | false |
rails/rails | https://github.com/rails/rails/blob/ba0d6f09e991d0621cc30f19c9d189cd21dbf76e/activerecord/lib/active_record/attribute_methods/primary_key.rb | activerecord/lib/active_record/attribute_methods/primary_key.rb | # frozen_string_literal: true
module ActiveRecord
module AttributeMethods
# = Active Record Attribute Methods Primary Key
module PrimaryKey
extend ActiveSupport::Concern
# Returns this record's primary key value wrapped in an array if one is
# available.
def to_key
key = id
... | ruby | MIT | ba0d6f09e991d0621cc30f19c9d189cd21dbf76e | 2026-01-04T15:37:27.222351Z | false |
rails/rails | https://github.com/rails/rails/blob/ba0d6f09e991d0621cc30f19c9d189cd21dbf76e/activerecord/lib/active_record/attribute_methods/time_zone_conversion.rb | activerecord/lib/active_record/attribute_methods/time_zone_conversion.rb | # frozen_string_literal: true
require "active_support/core_ext/object/try"
module ActiveRecord
module AttributeMethods
module TimeZoneConversion
class TimeZoneConverter < ActiveSupport::Delegation::DelegateClass(Type::Value) # :nodoc:
def self.new(subtype)
self === subtype ? subtype : su... | ruby | MIT | ba0d6f09e991d0621cc30f19c9d189cd21dbf76e | 2026-01-04T15:37:27.222351Z | false |
rails/rails | https://github.com/rails/rails/blob/ba0d6f09e991d0621cc30f19c9d189cd21dbf76e/activerecord/lib/active_record/attribute_methods/dirty.rb | activerecord/lib/active_record/attribute_methods/dirty.rb | # frozen_string_literal: true
require "active_support/core_ext/module/attribute_accessors"
module ActiveRecord
module AttributeMethods
# = Active Record Attribute Methods \Dirty
#
# Provides a way to track changes in your Active Record models. It adds all
# methods from ActiveModel::Dirty and adds d... | ruby | MIT | ba0d6f09e991d0621cc30f19c9d189cd21dbf76e | 2026-01-04T15:37:27.222351Z | false |
rails/rails | https://github.com/rails/rails/blob/ba0d6f09e991d0621cc30f19c9d189cd21dbf76e/activerecord/lib/active_record/validations/associated.rb | activerecord/lib/active_record/validations/associated.rb | # frozen_string_literal: true
module ActiveRecord
module Validations
class AssociatedValidator < ActiveModel::EachValidator # :nodoc:
def validate_each(record, attribute, value)
context = record_validation_context_for_association(record)
if Array(value).reject { |association| valid_object?... | ruby | MIT | ba0d6f09e991d0621cc30f19c9d189cd21dbf76e | 2026-01-04T15:37:27.222351Z | false |
rails/rails | https://github.com/rails/rails/blob/ba0d6f09e991d0621cc30f19c9d189cd21dbf76e/activerecord/lib/active_record/validations/absence.rb | activerecord/lib/active_record/validations/absence.rb | # frozen_string_literal: true
module ActiveRecord
module Validations
class AbsenceValidator < ActiveModel::Validations::AbsenceValidator # :nodoc:
def validate_each(record, attribute, association_or_value)
if record.class._reflect_on_association(attribute)
association_or_value = Array.wra... | ruby | MIT | ba0d6f09e991d0621cc30f19c9d189cd21dbf76e | 2026-01-04T15:37:27.222351Z | false |
rails/rails | https://github.com/rails/rails/blob/ba0d6f09e991d0621cc30f19c9d189cd21dbf76e/activerecord/lib/active_record/validations/presence.rb | activerecord/lib/active_record/validations/presence.rb | # frozen_string_literal: true
module ActiveRecord
module Validations
class PresenceValidator < ActiveModel::Validations::PresenceValidator # :nodoc:
def validate_each(record, attribute, association_or_value)
if record.class._reflect_on_association(attribute)
association_or_value = Array.w... | ruby | MIT | ba0d6f09e991d0621cc30f19c9d189cd21dbf76e | 2026-01-04T15:37:27.222351Z | false |
rails/rails | https://github.com/rails/rails/blob/ba0d6f09e991d0621cc30f19c9d189cd21dbf76e/activerecord/lib/active_record/validations/length.rb | activerecord/lib/active_record/validations/length.rb | # frozen_string_literal: true
module ActiveRecord
module Validations
class LengthValidator < ActiveModel::Validations::LengthValidator # :nodoc:
def validate_each(record, attribute, association_or_value)
if association_or_value.respond_to?(:loaded?) && association_or_value.loaded?
associa... | ruby | MIT | ba0d6f09e991d0621cc30f19c9d189cd21dbf76e | 2026-01-04T15:37:27.222351Z | false |
rails/rails | https://github.com/rails/rails/blob/ba0d6f09e991d0621cc30f19c9d189cd21dbf76e/activerecord/lib/active_record/validations/numericality.rb | activerecord/lib/active_record/validations/numericality.rb | # frozen_string_literal: true
module ActiveRecord
module Validations
class NumericalityValidator < ActiveModel::Validations::NumericalityValidator # :nodoc:
def validate_each(record, attribute, value, precision: nil, scale: nil)
precision = [column_precision_for(record, attribute) || Float::DIG, Fl... | ruby | MIT | ba0d6f09e991d0621cc30f19c9d189cd21dbf76e | 2026-01-04T15:37:27.222351Z | false |
rails/rails | https://github.com/rails/rails/blob/ba0d6f09e991d0621cc30f19c9d189cd21dbf76e/activerecord/lib/active_record/validations/uniqueness.rb | activerecord/lib/active_record/validations/uniqueness.rb | # frozen_string_literal: true
module ActiveRecord
module Validations
class UniquenessValidator < ActiveModel::EachValidator # :nodoc:
def initialize(options)
if options[:conditions] && !options[:conditions].respond_to?(:call)
raise ArgumentError, "#{options[:conditions]} was passed as :co... | ruby | MIT | ba0d6f09e991d0621cc30f19c9d189cd21dbf76e | 2026-01-04T15:37:27.222351Z | false |
rails/rails | https://github.com/rails/rails/blob/ba0d6f09e991d0621cc30f19c9d189cd21dbf76e/activerecord/lib/active_record/connection_adapters/sqlite3_adapter.rb | activerecord/lib/active_record/connection_adapters/sqlite3_adapter.rb | # frozen_string_literal: true
require "active_record/connection_adapters/abstract_adapter"
require "active_record/connection_adapters/statement_pool"
require "active_record/connection_adapters/sqlite3/column"
require "active_record/connection_adapters/sqlite3/explain_pretty_printer"
require "active_record/connection_a... | ruby | MIT | ba0d6f09e991d0621cc30f19c9d189cd21dbf76e | 2026-01-04T15:37:27.222351Z | false |
rails/rails | https://github.com/rails/rails/blob/ba0d6f09e991d0621cc30f19c9d189cd21dbf76e/activerecord/lib/active_record/connection_adapters/mysql2_adapter.rb | activerecord/lib/active_record/connection_adapters/mysql2_adapter.rb | # frozen_string_literal: true
require "active_record/connection_adapters/abstract_mysql_adapter"
require "active_record/connection_adapters/mysql2/database_statements"
gem "mysql2", "~> 0.5"
require "mysql2"
module ActiveRecord
module ConnectionAdapters
# = Active Record MySQL2 Adapter
class Mysql2Adapter ... | ruby | MIT | ba0d6f09e991d0621cc30f19c9d189cd21dbf76e | 2026-01-04T15:37:27.222351Z | false |
rails/rails | https://github.com/rails/rails/blob/ba0d6f09e991d0621cc30f19c9d189cd21dbf76e/activerecord/lib/active_record/connection_adapters/pool_manager.rb | activerecord/lib/active_record/connection_adapters/pool_manager.rb | # frozen_string_literal: true
module ActiveRecord
module ConnectionAdapters
class PoolManager # :nodoc:
def initialize
@role_to_shard_mapping = Hash.new { |h, k| h[k] = {} }
end
def shard_names
@role_to_shard_mapping.values.flat_map { |shard_map| shard_map.keys }.uniq
end... | ruby | MIT | ba0d6f09e991d0621cc30f19c9d189cd21dbf76e | 2026-01-04T15:37:27.222351Z | false |
rails/rails | https://github.com/rails/rails/blob/ba0d6f09e991d0621cc30f19c9d189cd21dbf76e/activerecord/lib/active_record/connection_adapters/schema_cache.rb | activerecord/lib/active_record/connection_adapters/schema_cache.rb | # frozen_string_literal: true
require "active_support/core_ext/file/atomic"
module ActiveRecord
module ConnectionAdapters
class SchemaReflection
class << self
attr_accessor :use_schema_cache_dump
attr_accessor :check_schema_cache_dump_version
end
self.use_schema_cache_dump = t... | ruby | MIT | ba0d6f09e991d0621cc30f19c9d189cd21dbf76e | 2026-01-04T15:37:27.222351Z | false |
Subsets and Splits
No community queries yet
The top public SQL queries from the community will appear here once available.