id stringlengths 24 24 | repo stringlengths 5 58 | path stringlengths 6 168 | func_name stringlengths 8 153 | url stringlengths 94 268 | split stringclasses 3
values | language stringclasses 1
value | docstring stringlengths 1 25.7k | code stringlengths 64 124k | text stringlengths 100 124k | token_count int32 22 59k | doc_chars int32 1 25.7k | code_chars int32 64 124k | license_basis stringclasses 1
value | source stringclasses 1
value | added stringdate 2026-12-05 00:00:00 2026-12-05 00:00:00 | record_sha256 stringlengths 64 64 | license stringclasses 8
values | license_class stringclasses 1
value | license_source stringlengths 42 97 |
|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
2ffbe4a3e5d6983fad6a010b | rails/rails | activesupport/lib/active_support/current_attributes.rb | ActiveSupport.CurrentAttributes.set | https://github.com/rails/rails/blob/85a8bc644be69908f05740a5886ec19cd3679df5/activesupport/lib/active_support/current_attributes.rb#L179-L185 | train | ruby | Expose one or more attributes within a block. Old values are returned after the block concludes.
Example demonstrating the common use of needing to set Current attributes outside the request-cycle:
class Chat::PublicationJob < ApplicationJob
def perform(attributes, room_number, creator)
Current.set(per... | def set(set_attributes)
old_attributes = compute_attributes(set_attributes.keys)
assign_attributes(set_attributes)
yield
ensure
assign_attributes(old_attributes)
end | Expose one or more attributes within a block. Old values are returned after the block concludes.
Example demonstrating the common use of needing to set Current attributes outside the request-cycle:
class Chat::PublicationJob < ApplicationJob
def perform(attributes, room_number, creator)
Current.set(per... | 122 | 446 | 197 | CodeSearchNet permissive-repo filter (dataset-level) | code_search_net | 2026-12-05 | bea34488c91caf48b1a40442be185e314e60b6ee2d4c6d888a7dd18286cd6417 | MIT | permissive | https://github.com/rails/rails/blob/main/MIT-LICENSE |
0aad2c8da8b42ec68ba3dcf3 | rails/rails | actionpack/lib/action_controller/renderer.rb | ActionController.Renderer.render | https://github.com/rails/rails/blob/85a8bc644be69908f05740a5886ec19cd3679df5/actionpack/lib/action_controller/renderer.rb#L87-L97 | train | ruby | Accepts a custom Rack environment to render templates in.
It will be merged with the default Rack environment defined by
+ActionController::Renderer::DEFAULTS+.
Render templates with any options from ActionController::Base#render_to_string.
The primary options are:
* <tt>:partial</tt> - See <tt>ActionView::Partia... | def render(*args)
raise "missing controller" unless controller
request = ActionDispatch::Request.new @env
request.routes = controller._routes
instance = controller.new
instance.set_request! request
instance.set_response! controller.make_response!(request)
instance.render_to_s... | Accepts a custom Rack environment to render templates in.
It will be merged with the default Rack environment defined by
+ActionController::Renderer::DEFAULTS+.
Render templates with any options from ActionController::Base#render_to_string.
The primary options are:
* <tt>:partial</tt> - See <tt>ActionView::Partia... | 383 | 1,237 | 340 | CodeSearchNet permissive-repo filter (dataset-level) | code_search_net | 2026-12-05 | 8356bd910bfe1d403b712515342bc2f0ae368b57fb4693ab028f08b90150f5da | MIT | permissive | https://github.com/rails/rails/blob/main/MIT-LICENSE |
2cf3b1ffa88da20b1d84f961 | rails/rails | actionview/lib/action_view/renderer/renderer.rb | ActionView.Renderer.render_body | https://github.com/rails/rails/blob/85a8bc644be69908f05740a5886ec19cd3679df5/actionview/lib/action_view/renderer/renderer.rb#L38-L44 | train | ruby | Render but returns a valid Rack body. If fibers are defined, we return
a streaming body that renders the template piece by piece.
Note that partials are not supported to be rendered with streaming,
so in such cases, we just wrap them in an array. | def render_body(context, options)
if options.key?(:partial)
[render_partial(context, options)]
else
StreamingTemplateRenderer.new(@lookup_context).render(context, options)
end
end | Render but returns a valid Rack body. If fibers are defined, we return
a streaming body that renders the template piece by piece.
Note that partials are not supported to be rendered with streaming,
so in such cases, we just wrap them in an array.
def render_body(context, options)
if options.key?(:partial)
... | 97 | 250 | 217 | CodeSearchNet permissive-repo filter (dataset-level) | code_search_net | 2026-12-05 | ebcb70248fa70eddd6ec40429f070bc732c1c6db646a8431e1d46599a4358669 | MIT | permissive | https://github.com/rails/rails/blob/main/MIT-LICENSE |
667281283c37065a4bf169b2 | rails/rails | actionpack/lib/action_controller/metal/head.rb | ActionController.Head.head | https://github.com/rails/rails/blob/85a8bc644be69908f05740a5886ec19cd3679df5/actionpack/lib/action_controller/metal/head.rb#L21-L46 | train | ruby | Returns a response that has no content (merely headers). The options
argument is interpreted to be a hash of header names and values.
This allows you to easily return a response that consists only of
significant headers:
head :created, location: person_path(@person)
head :created, location: @person
It can ... | def head(status, options = {})
if status.is_a?(Hash)
raise ArgumentError, "#{status.inspect} is not a valid value for `status`."
end
status ||= :ok
location = options.delete(:location)
content_type = options.delete(:content_type)
options.each do |key, value|
header... | Returns a response that has no content (merely headers). The options
argument is interpreted to be a hash of header names and values.
This allows you to easily return a response that consists only of
significant headers:
head :created, location: person_path(@person)
head :created, location: @person
It can ... | 300 | 569 | 729 | CodeSearchNet permissive-repo filter (dataset-level) | code_search_net | 2026-12-05 | 57e5a75ad265a929bf1565e6f1be5fc53df9df0354b4ca5ae90f018d732316d1 | MIT | permissive | https://github.com/rails/rails/blob/main/MIT-LICENSE |
320ccdbffb3593733704b41c | rails/rails | actionpack/lib/action_controller/metal/redirecting.rb | ActionController.Redirecting.redirect_to | https://github.com/rails/rails/blob/85a8bc644be69908f05740a5886ec19cd3679df5/actionpack/lib/action_controller/metal/redirecting.rb#L58-L65 | train | ruby | Redirects the browser to the target specified in +options+. This parameter can be any one of:
* <tt>Hash</tt> - The URL will be generated by calling url_for with the +options+.
* <tt>Record</tt> - The URL will be generated by calling url_for with the +options+, which will reference a named URL for that record.
* <t... | def redirect_to(options = {}, response_options = {})
raise ActionControllerError.new("Cannot redirect to nil!") unless options
raise AbstractController::DoubleRenderError if response_body
self.status = _extract_redirect_to_status(options, response_options)
self.location = _compute_r... | Redirects the browser to the target specified in +options+. This parameter can be any one of:
* <tt>Hash</tt> - The URL will be generated by calling url_for with the +options+.
* <tt>Record</tt> - The URL will be generated by calling url_for with the +options+, which will reference a named URL for that record.
* <t... | 782 | 2,782 | 516 | CodeSearchNet permissive-repo filter (dataset-level) | code_search_net | 2026-12-05 | ef9cc3636434a8052a85cc5663673c1c3fe814ca383b60788ed36ea096bad63f | MIT | permissive | https://github.com/rails/rails/blob/main/MIT-LICENSE |
602238223f82f8f2e1b74609 | rails/rails | actionpack/lib/action_controller/metal/redirecting.rb | ActionController.Redirecting.redirect_back | https://github.com/rails/rails/blob/85a8bc644be69908f05740a5886ec19cd3679df5/actionpack/lib/action_controller/metal/redirecting.rb#L90-L94 | train | ruby | Redirects the browser to the page that issued the request (the referrer)
if possible, otherwise redirects to the provided default fallback
location.
The referrer information is pulled from the HTTP +Referer+ (sic) header on
the request. This is an optional header and its presence on the request is
subject to brow... | def redirect_back(fallback_location:, allow_other_host: true, **args)
referer = request.headers["Referer"]
redirect_to_referer = referer && (allow_other_host || _url_host_allowed?(referer))
redirect_to redirect_to_referer ? referer : fallback_location, **args
end | Redirects the browser to the page that issued the request (the referrer)
if possible, otherwise redirects to the provided default fallback
location.
The referrer information is pulled from the HTTP +Referer+ (sic) header on
the request. This is an optional header and its presence on the request is
subject to brow... | 339 | 1,231 | 285 | CodeSearchNet permissive-repo filter (dataset-level) | code_search_net | 2026-12-05 | f443bb9c2a64a1fc3c2c0e83fc36c55fb0d64a23de2b4e198a500f197d58d448 | MIT | permissive | https://github.com/rails/rails/blob/main/MIT-LICENSE |
5548a92dc37ba5c7cfbae559 | rails/rails | activemodel/lib/active_model/attribute_methods.rb | ActiveModel.AttributeMethods.method_missing | https://github.com/rails/rails/blob/85a8bc644be69908f05740a5886ec19cd3679df5/activemodel/lib/active_model/attribute_methods.rb#L426-L433 | train | ruby | Allows access to the object attributes, which are held in the hash
returned by <tt>attributes</tt>, as though they were first-class
methods. So a +Person+ class with a +name+ attribute can for example use
<tt>Person#name</tt> and <tt>Person#name=</tt> and never directly use
the attributes hash -- except for multipl... | def method_missing(method, *args, &block)
if respond_to_without_attributes?(method, true)
super
else
match = matched_attribute_method(method.to_s)
match ? attribute_missing(match, *args, &block) : super
end
end | Allows access to the object attributes, which are held in the hash
returned by <tt>attributes</tt>, as though they were first-class
methods. So a +Person+ class with a +name+ attribute can for example use
<tt>Person#name</tt> and <tt>Person#name=</tt> and never directly use
the attributes hash -- except for multipl... | 204 | 581 | 256 | CodeSearchNet permissive-repo filter (dataset-level) | code_search_net | 2026-12-05 | edc7ce8fff1750a22f82d717fcd2e6130c35b050e047ee5ad7bf0b697bc6590c | MIT | permissive | https://github.com/rails/rails/blob/main/MIT-LICENSE |
d4f30e19c5afd0efa5726ed5 | rails/rails | activemodel/lib/active_model/attribute_methods.rb | ActiveModel.AttributeMethods.attribute_missing | https://github.com/rails/rails/blob/85a8bc644be69908f05740a5886ec19cd3679df5/activemodel/lib/active_model/attribute_methods.rb#L439-L441 | train | ruby | +attribute_missing+ is like +method_missing+, but for attributes. When
+method_missing+ is called we check to see if there is a matching
attribute method. If so, we tell +attribute_missing+ to dispatch the
attribute. This method can be overloaded to customize the behavior. | def attribute_missing(match, *args, &block)
__send__(match.target, match.attr_name, *args, &block)
end | +attribute_missing+ is like +method_missing+, but for attributes. When
+method_missing+ is called we check to see if there is a matching
attribute method. If so, we tell +attribute_missing+ to dispatch the
attribute. This method can be overloaded to customize the behavior.
def attribute_missing(match, *args, &block... | 90 | 276 | 112 | CodeSearchNet permissive-repo filter (dataset-level) | code_search_net | 2026-12-05 | 44fa2f4b0ca0ec99bd4ebc2549e169e9a4638a8767d8937ee84c72bb7a06b98a | MIT | permissive | https://github.com/rails/rails/blob/main/MIT-LICENSE |
5a3296c3e12fec4ccd680203 | rails/rails | activemodel/lib/active_model/attribute_methods.rb | ActiveModel.AttributeMethods.matched_attribute_method | https://github.com/rails/rails/blob/85a8bc644be69908f05740a5886ec19cd3679df5/activemodel/lib/active_model/attribute_methods.rb#L466-L469 | train | ruby | Returns a struct representing the matching attribute method.
The struct's attributes are prefix, base and suffix. | def matched_attribute_method(method_name)
matches = self.class.send(:attribute_method_matchers_matching, method_name)
matches.detect { |match| attribute_method?(match.attr_name) }
end | Returns a struct representing the matching attribute method.
The struct's attributes are prefix, base and suffix.
def matched_attribute_method(method_name)
matches = self.class.send(:attribute_method_matchers_matching, method_name)
matches.detect { |match| attribute_method?(match.attr_name) }
en... | 60 | 114 | 205 | CodeSearchNet permissive-repo filter (dataset-level) | code_search_net | 2026-12-05 | 683db6777678b43ace2fc4a349c790c18151a2c706487517ee886176ae621079 | MIT | permissive | https://github.com/rails/rails/blob/main/MIT-LICENSE |
3a57f701d73ae990f87a65ea | rails/rails | activerecord/lib/active_record/connection_adapters/mysql2_adapter.rb | ActiveRecord.ConnectionHandling.mysql2_connection | https://github.com/rails/rails/blob/85a8bc644be69908f05740a5886ec19cd3679df5/activerecord/lib/active_record/connection_adapters/mysql2_adapter.rb#L12-L30 | train | ruby | :nodoc:
Establishes a connection to the database that's used by all Active Record objects. | def mysql2_connection(config)
config = config.symbolize_keys
config[:flags] ||= 0
if config[:flags].kind_of? Array
config[:flags].push "FOUND_ROWS"
else
config[:flags] |= Mysql2::Client::FOUND_ROWS
end
client = Mysql2::Client.new(config)
ConnectionAdapters::My... | :nodoc:
Establishes a connection to the database that's used by all Active Record objects.
def mysql2_connection(config)
config = config.symbolize_keys
config[:flags] ||= 0
if config[:flags].kind_of? Array
config[:flags].push "FOUND_ROWS"
else
config[:flags] |= Mysql2::Client:... | 152 | 91 | 537 | CodeSearchNet permissive-repo filter (dataset-level) | code_search_net | 2026-12-05 | fab03fd4c6984fae61e3a51abff1877fd0f590c2d8bd6af6532acfc8a9f30450 | MIT | permissive | https://github.com/rails/rails/blob/main/MIT-LICENSE |
e0f15a23cb57123d65dd1597 | rails/rails | activerecord/lib/active_record/relation/calculations.rb | ActiveRecord.Calculations.calculate | https://github.com/rails/rails/blob/85a8bc644be69908f05740a5886ec19cd3679df5/activerecord/lib/active_record/relation/calculations.rb#L127-L144 | train | ruby | This calculates aggregate values in the given column. Methods for #count, #sum, #average,
#minimum, and #maximum have been added as shortcuts.
Person.calculate(:count, :all) # The same as Person.count
Person.average(:age) # SELECT AVG(age) FROM people...
# Selects the minimum age for any family without any ... | def calculate(operation, column_name)
if has_include?(column_name)
relation = apply_join_dependency
if operation.to_s.downcase == "count"
unless distinct_value || distinct_select?(column_name || select_for_count)
relation.distinct!
relation.select_values = [ klas... | This calculates aggregate values in the given column. Methods for #count, #sum, #average,
#minimum, and #maximum have been added as shortcuts.
Person.calculate(:count, :all) # The same as Person.count
Person.average(:age) # SELECT AVG(age) FROM people...
# Selects the minimum age for any family without any ... | 388 | 1,087 | 643 | CodeSearchNet permissive-repo filter (dataset-level) | code_search_net | 2026-12-05 | eb8c0b75f627c7b9a7a5106ffea476897097a20259577b67e1181db0f25ed42d | MIT | permissive | https://github.com/rails/rails/blob/main/MIT-LICENSE |
1a5980d331fcc63232c9b34c | rails/rails | activerecord/lib/active_record/relation/calculations.rb | ActiveRecord.Calculations.pluck | https://github.com/rails/rails/blob/85a8bc644be69908f05740a5886ec19cd3679df5/activerecord/lib/active_record/relation/calculations.rb#L181-L196 | train | ruby | Use #pluck as a shortcut to select one or more attributes without
loading a bunch of records just to grab the attributes you want.
Person.pluck(:name)
instead of
Person.all.map(&:name)
Pluck returns an Array of attribute values type-casted to match
the plucked column names, if they can be deduced. Pluckin... | def pluck(*column_names)
if loaded? && (column_names.map(&:to_s) - @klass.attribute_names - @klass.attribute_aliases.keys).empty?
return records.pluck(*column_names)
end
if has_include?(column_names.first)
relation = apply_join_dependency
relation.pluck(*column_names)
el... | Use #pluck as a shortcut to select one or more attributes without
loading a bunch of records just to grab the attributes you want.
Person.pluck(:name)
instead of
Person.all.map(&:name)
Pluck returns an Array of attribute values type-casted to match
the plucked column names, if they can be deduced. Pluckin... | 401 | 985 | 606 | CodeSearchNet permissive-repo filter (dataset-level) | code_search_net | 2026-12-05 | 361de402dc2afea204e3eeb82174608752c74d570c0c24e57355512f3fcfa596 | MIT | permissive | https://github.com/rails/rails/blob/main/MIT-LICENSE |
b8c6e5175236732bbc042825 | rails/rails | activerecord/lib/active_record/relation/calculations.rb | ActiveRecord.Calculations.column_alias_for | https://github.com/rails/rails/blob/85a8bc644be69908f05740a5886ec19cd3679df5/activerecord/lib/active_record/relation/calculations.rb#L376-L386 | train | ruby | Converts the given field to the value that the database adapter returns as
a usable column name:
column_alias_for("users.id") # => "users_id"
column_alias_for("sum(id)") # => "sum_id"
column_alias_for("count(distinct users.id)") # => "count_distinct_users_id"
column_alias_... | def column_alias_for(field)
return field if field.match?(/\A\w{,#{connection.table_alias_length}}\z/)
column_alias = +field
column_alias.gsub!(/\*/, "all")
column_alias.gsub!(/\W+/, " ")
column_alias.strip!
column_alias.gsub!(/ +/, "_")
connection.table_alias_fo... | Converts the given field to the value that the database adapter returns as
a usable column name:
column_alias_for("users.id") # => "users_id"
column_alias_for("sum(id)") # => "sum_id"
column_alias_for("count(distinct users.id)") # => "count_distinct_users_id"
column_alias_... | 167 | 368 | 345 | CodeSearchNet permissive-repo filter (dataset-level) | code_search_net | 2026-12-05 | 53963246d8d0f0e561baf68627c992a8ff1dfaa9635301e2ecb64641ad8624cb | MIT | permissive | https://github.com/rails/rails/blob/main/MIT-LICENSE |
513f9802a23a8dc928eca8c1 | rails/rails | activerecord/lib/active_record/nested_attributes.rb | ActiveRecord.NestedAttributes.assign_nested_attributes_for_one_to_one_association | https://github.com/rails/rails/blob/85a8bc644be69908f05740a5886ec19cd3679df5/activerecord/lib/active_record/nested_attributes.rb#L407-L437 | train | ruby | Assigns the given attributes to the association.
If an associated record does not yet exist, one will be instantiated. If
an associated record already exists, the method's behavior depends on
the value of the update_only option. If update_only is +false+ and the
given attributes include an <tt>:id</tt> that matche... | def assign_nested_attributes_for_one_to_one_association(association_name, attributes)
options = nested_attributes_options[association_name]
if attributes.respond_to?(:permitted?)
attributes = attributes.to_h
end
attributes = attributes.with_indifferent_access
existing_r... | Assigns the given attributes to the association.
If an associated record does not yet exist, one will be instantiated. If
an associated record already exists, the method's behavior depends on
the value of the update_only option. If update_only is +false+ and the
given attributes include an <tt>:id</tt> that matche... | 462 | 780 | 1,517 | CodeSearchNet permissive-repo filter (dataset-level) | code_search_net | 2026-12-05 | 5518451b8db2cd6e72f5c0a7b3403e2d7847a9aeda491584e8bb2aa79207bbfd | MIT | permissive | https://github.com/rails/rails/blob/main/MIT-LICENSE |
be7bf30c023bd9b7557f3dc6 | rails/rails | activerecord/lib/active_record/nested_attributes.rb | ActiveRecord.NestedAttributes.assign_nested_attributes_for_collection_association | https://github.com/rails/rails/blob/85a8bc644be69908f05740a5886ec19cd3679df5/activerecord/lib/active_record/nested_attributes.rb#L466-L524 | train | ruby | Assigns the given attributes to the collection association.
Hashes with an <tt>:id</tt> value matching an existing associated record
will update that record. Hashes without an <tt>:id</tt> value will build
a new record for the association. Hashes with a matching <tt>:id</tt>
value and a <tt>:_destroy</tt> key set ... | def assign_nested_attributes_for_collection_association(association_name, attributes_collection)
options = nested_attributes_options[association_name]
if attributes_collection.respond_to?(:permitted?)
attributes_collection = attributes_collection.to_h
end
unless attributes_col... | Assigns the given attributes to the collection association.
Hashes with an <tt>:id</tt> value matching an existing associated record
will update that record. Hashes without an <tt>:id</tt> value will build
a new record for the association. Hashes with a matching <tt>:id</tt>
value and a <tt>:_destroy</tt> key set ... | 737 | 949 | 2,685 | CodeSearchNet permissive-repo filter (dataset-level) | code_search_net | 2026-12-05 | a6cffbbdcc837915dbeda63184970c2cb7b9e5443bcf80b66bd240b32d431ccf | MIT | permissive | https://github.com/rails/rails/blob/main/MIT-LICENSE |
17e64920577240c998c803d4 | rails/rails | activerecord/lib/active_record/nested_attributes.rb | ActiveRecord.NestedAttributes.check_record_limit! | https://github.com/rails/rails/blob/85a8bc644be69908f05740a5886ec19cd3679df5/activerecord/lib/active_record/nested_attributes.rb#L532-L548 | train | ruby | Takes in a limit and checks if the attributes_collection has too many
records. It accepts limit in the form of symbol, proc, or
number-like object (anything that can be compared with an integer).
Raises TooManyRecords error if the attributes_collection is
larger than the limit. | def check_record_limit!(limit, attributes_collection)
if limit
limit = \
case limit
when Symbol
send(limit)
when Proc
limit.call
else
limit
end
if limit && attributes_collection.size > limi... | Takes in a limit and checks if the attributes_collection has too many
records. It accepts limit in the form of symbol, proc, or
number-like object (anything that can be compared with an integer).
Raises TooManyRecords error if the attributes_collection is
larger than the limit.
def check_record_limit!(limit, attr... | 148 | 283 | 482 | CodeSearchNet permissive-repo filter (dataset-level) | code_search_net | 2026-12-05 | 600678f3ba5e60fc0b39cf23cb0ff5ba3fcdaa874bb127c2241eb7dc1e2514f3 | MIT | permissive | https://github.com/rails/rails/blob/main/MIT-LICENSE |
21e32d71870eb535fddb8d6e | rails/rails | activerecord/lib/active_record/nested_attributes.rb | ActiveRecord.NestedAttributes.assign_to_or_mark_for_destruction | https://github.com/rails/rails/blob/85a8bc644be69908f05740a5886ec19cd3679df5/activerecord/lib/active_record/nested_attributes.rb#L552-L555 | train | ruby | Updates a record with the +attributes+ or marks it for destruction if
+allow_destroy+ is +true+ and has_destroy_flag? returns +true+. | def assign_to_or_mark_for_destruction(record, attributes, allow_destroy)
record.assign_attributes(attributes.except(*UNASSIGNABLE_KEYS))
record.mark_for_destruction if has_destroy_flag?(attributes) && allow_destroy
end | Updates a record with the +attributes+ or marks it for destruction if
+allow_destroy+ is +true+ and has_destroy_flag? returns +true+.
def assign_to_or_mark_for_destruction(record, attributes, allow_destroy)
record.assign_attributes(attributes.except(*UNASSIGNABLE_KEYS))
record.mark_for_destruction if ... | 81 | 134 | 240 | CodeSearchNet permissive-repo filter (dataset-level) | code_search_net | 2026-12-05 | 13a14be2414e8e4a12d1a7aca849368219ea58d9319a8a07b3465fcfad47f054 | MIT | permissive | https://github.com/rails/rails/blob/main/MIT-LICENSE |
150a4261b6392370d9f59cf2 | rails/rails | activerecord/lib/active_record/translation.rb | ActiveRecord.Translation.lookup_ancestors | https://github.com/rails/rails/blob/85a8bc644be69908f05740a5886ec19cd3679df5/activerecord/lib/active_record/translation.rb#L8-L17 | train | ruby | Set the lookup ancestors for ActiveModel. | def lookup_ancestors #:nodoc:
klass = self
classes = [klass]
return classes if klass == ActiveRecord::Base
while !klass.base_class?
classes << klass = klass.superclass
end
classes
end | Set the lookup ancestors for ActiveModel.
def lookup_ancestors #:nodoc:
klass = self
classes = [klass]
return classes if klass == ActiveRecord::Base
while !klass.base_class?
classes << klass = klass.superclass
end
classes
end | 62 | 41 | 232 | CodeSearchNet permissive-repo filter (dataset-level) | code_search_net | 2026-12-05 | 2142902ebf346b53c0c23f176d1b1e1f8e6712ba7b327e2dd9e506e3ad10b3ef | MIT | permissive | https://github.com/rails/rails/blob/main/MIT-LICENSE |
725c66461bd1b83fa59357f6 | rails/rails | activesupport/lib/active_support/inflector/methods.rb | ActiveSupport.Inflector.camelize | https://github.com/rails/rails/blob/85a8bc644be69908f05740a5886ec19cd3679df5/activesupport/lib/active_support/inflector/methods.rb#L68-L78 | train | ruby | Converts strings to UpperCamelCase.
If the +uppercase_first_letter+ parameter is set to false, then produces
lowerCamelCase.
Also converts '/' to '::' which is useful for converting
paths to namespaces.
camelize('active_model') # => "ActiveModel"
camelize('active_model', false) # => "... | def camelize(term, uppercase_first_letter = true)
string = term.to_s
if uppercase_first_letter
string = string.sub(/^[a-z\d]*/) { |match| inflections.acronyms[match] || match.capitalize }
else
string = string.sub(inflections.acronyms_camelize_regex) { |match| match.downcase }
end... | Converts strings to UpperCamelCase.
If the +uppercase_first_letter+ parameter is set to false, then produces
lowerCamelCase.
Also converts '/' to '::' which is useful for converting
paths to namespaces.
camelize('active_model') # => "ActiveModel"
camelize('active_model', false) # => "... | 290 | 662 | 471 | CodeSearchNet permissive-repo filter (dataset-level) | code_search_net | 2026-12-05 | 220793215540adf21ee2ece13796d840f926607928e3f3366a517ff35d013d4a | MIT | permissive | https://github.com/rails/rails/blob/main/MIT-LICENSE |
1be59eeacd9090f0f0f0de04 | rails/rails | activesupport/lib/active_support/inflector/methods.rb | ActiveSupport.Inflector.humanize | https://github.com/rails/rails/blob/85a8bc644be69908f05740a5886ec19cd3679df5/activesupport/lib/active_support/inflector/methods.rb#L128-L148 | train | ruby | Tweaks an attribute name for display to end users.
Specifically, performs these transformations:
* Applies human inflection rules to the argument.
* Deletes leading underscores, if any.
* Removes a "_id" suffix if present.
* Replaces underscores with spaces, if any.
* Downcases all words except acronyms.
* Cap... | def humanize(lower_case_and_underscored_word, capitalize: true, keep_id_suffix: false)
result = lower_case_and_underscored_word.to_s.dup
inflections.humans.each { |(rule, replacement)| break if result.sub!(rule, replacement) }
result.sub!(/\A_+/, "")
unless keep_id_suffix
result.sub!(/... | Tweaks an attribute name for display to end users.
Specifically, performs these transformations:
* Applies human inflection rules to the argument.
* Deletes leading underscores, if any.
* Removes a "_id" suffix if present.
* Replaces underscores with spaces, if any.
* Downcases all words except acronyms.
* Cap... | 389 | 997 | 598 | CodeSearchNet permissive-repo filter (dataset-level) | code_search_net | 2026-12-05 | e5ac262293ece29100ac99dd884aa3351c619ba012e8265a55e25bfd589ed603 | MIT | permissive | https://github.com/rails/rails/blob/main/MIT-LICENSE |
13de6671ef5f4e1948e3b9e5 | rails/rails | activesupport/lib/active_support/inflector/methods.rb | ActiveSupport.Inflector.demodulize | https://github.com/rails/rails/blob/85a8bc644be69908f05740a5886ec19cd3679df5/activesupport/lib/active_support/inflector/methods.rb#L220-L227 | train | ruby | Removes the module part from the expression in the string.
demodulize('ActiveSupport::Inflector::Inflections') # => "Inflections"
demodulize('Inflections') # => "Inflections"
demodulize('::Inflections') # => "Inflections"
demodulize('') ... | def demodulize(path)
path = path.to_s
if i = path.rindex("::")
path[(i + 2)..-1]
else
path
end
end | Removes the module part from the expression in the string.
demodulize('ActiveSupport::Inflector::Inflections') # => "Inflections"
demodulize('Inflections') # => "Inflections"
demodulize('::Inflections') # => "Inflections"
demodulize('') ... | 130 | 371 | 142 | CodeSearchNet permissive-repo filter (dataset-level) | code_search_net | 2026-12-05 | dbfed9dda2e097d9d495d11cb5184293651a732049af16b803e585373df63851 | MIT | permissive | https://github.com/rails/rails/blob/main/MIT-LICENSE |
80fbccb4e502820466b188de | rails/rails | activesupport/lib/active_support/inflector/methods.rb | ActiveSupport.Inflector.constantize | https://github.com/rails/rails/blob/85a8bc644be69908f05740a5886ec19cd3679df5/activesupport/lib/active_support/inflector/methods.rb#L271-L300 | train | ruby | Tries to find a constant with the name specified in the argument string.
constantize('Module') # => Module
constantize('Foo::Bar') # => Foo::Bar
The name is assumed to be the one of a top-level constant, no matter
whether it starts with "::" or not. No lexical context is taken into
account:
C = 'outsid... | def constantize(camel_cased_word)
names = camel_cased_word.split("::")
# Trigger a built-in NameError exception including the ill-formed constant in the message.
Object.const_get(camel_cased_word) if names.empty?
# Remove the first blank element in case of '::ClassName' notation.
names.s... | Tries to find a constant with the name specified in the argument string.
constantize('Module') # => Module
constantize('Foo::Bar') # => Foo::Bar
The name is assumed to be the one of a top-level constant, no matter
whether it starts with "::" or not. No lexical context is taken into
account:
C = 'outsid... | 376 | 530 | 1,150 | CodeSearchNet permissive-repo filter (dataset-level) | code_search_net | 2026-12-05 | 2e6b5da7e2b9e46dda19354c43382f8e267113685a666948c45f8685f869b6c5 | MIT | permissive | https://github.com/rails/rails/blob/main/MIT-LICENSE |
55938c4948174462861db4f4 | rails/rails | activesupport/lib/active_support/inflector/methods.rb | ActiveSupport.Inflector.const_regexp | https://github.com/rails/rails/blob/85a8bc644be69908f05740a5886ec19cd3679df5/activesupport/lib/active_support/inflector/methods.rb#L368-L378 | train | ruby | Mounts a regular expression, returned as a string to ease interpolation,
that will match part by part the given constant.
const_regexp("Foo::Bar::Baz") # => "Foo(::Bar(::Baz)?)?"
const_regexp("::") # => "::" | def const_regexp(camel_cased_word)
parts = camel_cased_word.split("::")
return Regexp.escape(camel_cased_word) if parts.blank?
last = parts.pop
parts.reverse.inject(last) do |acc, part|
part.empty? ? acc : "#{part}(::#{acc})?"
end
end | Mounts a regular expression, returned as a string to ease interpolation,
that will match part by part the given constant.
const_regexp("Foo::Bar::Baz") # => "Foo(::Bar(::Baz)?)?"
const_regexp("::") # => "::"
def const_regexp(camel_cased_word)
parts = camel_cased_word.split("::")
ret... | 134 | 226 | 293 | CodeSearchNet permissive-repo filter (dataset-level) | code_search_net | 2026-12-05 | 47fdf8b557072d2cfc9ea70d40b0d15b821a54f01ea230e668dc2263cbd09561 | MIT | permissive | https://github.com/rails/rails/blob/main/MIT-LICENSE |
bc595624f2d20596508442f2 | rails/rails | activesupport/lib/active_support/inflector/methods.rb | ActiveSupport.Inflector.apply_inflections | https://github.com/rails/rails/blob/85a8bc644be69908f05740a5886ec19cd3679df5/activesupport/lib/active_support/inflector/methods.rb#L387-L396 | train | ruby | Applies inflection rules for +singularize+ and +pluralize+.
If passed an optional +locale+ parameter, the uncountables will be
found for that locale.
apply_inflections('post', inflections.plurals, :en) # => "posts"
apply_inflections('posts', inflections.singulars, :en) # => "post" | def apply_inflections(word, rules, locale = :en)
result = word.to_s.dup
if word.empty? || inflections(locale).uncountables.uncountable?(result)
result
else
rules.each { |(rule, replacement)| break if result.sub!(rule, replacement) }
result
end
end | Applies inflection rules for +singularize+ and +pluralize+.
If passed an optional +locale+ parameter, the uncountables will be
found for that locale.
apply_inflections('post', inflections.plurals, :en) # => "posts"
apply_inflections('posts', inflections.singulars, :en) # => "post"
def apply_inflections(word... | 155 | 292 | 316 | CodeSearchNet permissive-repo filter (dataset-level) | code_search_net | 2026-12-05 | 10701e03c6488f98f6a1e8afe863fa51a7456945f1b33f0c0f2f4842a904232b | MIT | permissive | https://github.com/rails/rails/blob/main/MIT-LICENSE |
45a8e8841c2af6f3e7fe80ae | rails/rails | activerecord/lib/active_record/associations.rb | ActiveRecord.Associations.association | https://github.com/rails/rails/blob/85a8bc644be69908f05740a5886ec19cd3679df5/activerecord/lib/active_record/associations.rb#L230-L242 | train | ruby | Returns the association instance for the given name, instantiating it if it doesn't already exist | def association(name) #:nodoc:
association = association_instance_get(name)
if association.nil?
unless reflection = self.class._reflect_on_association(name)
raise AssociationNotFoundError.new(self, name)
end
association = reflection.association_class.new(self, reflection)
... | Returns the association instance for the given name, instantiating it if it doesn't already exist
def association(name) #:nodoc:
association = association_instance_get(name)
if association.nil?
unless reflection = self.class._reflect_on_association(name)
raise AssociationNotFoundError.ne... | 92 | 97 | 408 | CodeSearchNet permissive-repo filter (dataset-level) | code_search_net | 2026-12-05 | b38064712b114e60a4e1a9141c36399c48e3d334df8bc7b502518e3f786cd93b | MIT | permissive | https://github.com/rails/rails/blob/main/MIT-LICENSE |
33563bd4c08322120e65ec51 | rails/rails | actionpack/lib/action_dispatch/middleware/request_id.rb | ActionDispatch.RequestId.call | https://github.com/rails/rails/blob/85a8bc644be69908f05740a5886ec19cd3679df5/actionpack/lib/action_dispatch/middleware/request_id.rb#L24-L28 | train | ruby | :nodoc: | def call(env)
req = ActionDispatch::Request.new env
req.request_id = make_request_id(req.x_request_id)
@app.call(env).tap { |_status, headers, _body| headers[X_REQUEST_ID] = req.request_id }
end | :nodoc:
def call(env)
req = ActionDispatch::Request.new env
req.request_id = make_request_id(req.x_request_id)
@app.call(env).tap { |_status, headers, _body| headers[X_REQUEST_ID] = req.request_id }
end | 59 | 7 | 216 | CodeSearchNet permissive-repo filter (dataset-level) | code_search_net | 2026-12-05 | 9e3fada8da275225ca84d9a3825db2fe2eb19478385630088596a46d74ffb24e | MIT | permissive | https://github.com/rails/rails/blob/main/MIT-LICENSE |
4360d0f662a31963db98cea6 | rails/rails | activesupport/lib/active_support/dependencies.rb | ActiveSupport.Dependencies.loadable_constants_for_path | https://github.com/rails/rails/blob/85a8bc644be69908f05740a5886ec19cd3679df5/activesupport/lib/active_support/dependencies.rb#L412-L430 | train | ruby | Given +path+, a filesystem path to a ruby file, return an array of
constant paths which would cause Dependencies to attempt to load this
file. | def loadable_constants_for_path(path, bases = autoload_paths)
path = path.chomp(".rb")
expanded_path = File.expand_path(path)
paths = []
bases.each do |root|
expanded_root = File.expand_path(root)
next unless expanded_path.start_with?(expanded_root)
root_size = expanded... | Given +path+, a filesystem path to a ruby file, return an array of
constant paths which would cause Dependencies to attempt to load this
file.
def loadable_constants_for_path(path, bases = autoload_paths)
path = path.chomp(".rb")
expanded_path = File.expand_path(path)
paths = []
bases.each d... | 149 | 144 | 536 | CodeSearchNet permissive-repo filter (dataset-level) | code_search_net | 2026-12-05 | f847aee56caa7e5fcafb1b9230b8454d262462c9f304403aa458bbae772533a5 | MIT | permissive | https://github.com/rails/rails/blob/main/MIT-LICENSE |
1b123cf1773a3ecd0745c5ef | rails/rails | activesupport/lib/active_support/dependencies.rb | ActiveSupport.Dependencies.autoloadable_module? | https://github.com/rails/rails/blob/85a8bc644be69908f05740a5886ec19cd3679df5/activesupport/lib/active_support/dependencies.rb#L446-L451 | train | ruby | Does the provided path_suffix correspond to an autoloadable module?
Instead of returning a boolean, the autoload base for this module is
returned. | def autoloadable_module?(path_suffix)
autoload_paths.each do |load_path|
return load_path if File.directory? File.join(load_path, path_suffix)
end
nil
end | Does the provided path_suffix correspond to an autoloadable module?
Instead of returning a boolean, the autoload base for this module is
returned.
def autoloadable_module?(path_suffix)
autoload_paths.each do |load_path|
return load_path if File.directory? File.join(load_path, path_suffix)
end
... | 69 | 148 | 184 | CodeSearchNet permissive-repo filter (dataset-level) | code_search_net | 2026-12-05 | 357c1abf35295c9123687a0a3aee296db22ed17fbd0eec200794b225ab5c24a7 | MIT | permissive | https://github.com/rails/rails/blob/main/MIT-LICENSE |
d62d01b0093a3bc1cf31d5c4 | rails/rails | activesupport/lib/active_support/dependencies.rb | ActiveSupport.Dependencies.autoload_module! | https://github.com/rails/rails/blob/85a8bc644be69908f05740a5886ec19cd3679df5/activesupport/lib/active_support/dependencies.rb#L464-L472 | train | ruby | Attempt to autoload the provided module name by searching for a directory
matching the expected path suffix. If found, the module is created and
assigned to +into+'s constants with the name +const_name+. Provided that
the directory was loaded from a reloadable base path, it is added to the
set of constants that are... | def autoload_module!(into, const_name, qualified_name, path_suffix)
return nil unless base_path = autoloadable_module?(path_suffix)
mod = Module.new
into.const_set const_name, mod
log("constant #{qualified_name} autoloaded (module autovivified from #{File.join(base_path, path_suffix)})")
a... | Attempt to autoload the provided module name by searching for a directory
matching the expected path suffix. If found, the module is created and
assigned to +into+'s constants with the name +const_name+. Provided that
the directory was loaded from a reloadable base path, it is added to the
set of constants that are... | 170 | 336 | 455 | CodeSearchNet permissive-repo filter (dataset-level) | code_search_net | 2026-12-05 | 394cc1d3a05daab9e8703c79dd66849c426b7a7e944af5bd6867ff41a8cbc82d | MIT | permissive | https://github.com/rails/rails/blob/main/MIT-LICENSE |
fb471e963fa6d23c99ac9a58 | rails/rails | activesupport/lib/active_support/dependencies.rb | ActiveSupport.Dependencies.load_file | https://github.com/rails/rails/blob/85a8bc644be69908f05740a5886ec19cd3679df5/activesupport/lib/active_support/dependencies.rb#L482-L494 | train | ruby | Load the file at the provided path. +const_paths+ is a set of qualified
constant names. When loading the file, Dependencies will watch for the
addition of these constants. Each that is defined will be marked as
autoloaded, and will be removed when Dependencies.clear is next called.
If the second parameter is left ... | def load_file(path, const_paths = loadable_constants_for_path(path))
const_paths = [const_paths].compact unless const_paths.is_a? Array
parent_paths = const_paths.collect { |const_path| const_path[/.*(?=::)/] || ::Object }
result = nil
newly_defined_paths = new_constants_in(*parent_paths) do
... | Load the file at the provided path. +const_paths+ is a set of qualified
constant names. When loading the file, Dependencies will watch for the
addition of these constants. Each that is defined will be marked as
autoloaded, and will be removed when Dependencies.clear is next called.
If the second parameter is left ... | 213 | 462 | 499 | CodeSearchNet permissive-repo filter (dataset-level) | code_search_net | 2026-12-05 | 754fb4af3f6e56bc185f68137ee037ac2bf5b06aa71c031d9a2b7e57b7801f6f | MIT | permissive | https://github.com/rails/rails/blob/main/MIT-LICENSE |
61ef30e198fc78fe4f5c9977 | rails/rails | activesupport/lib/active_support/dependencies.rb | ActiveSupport.Dependencies.load_missing_constant | https://github.com/rails/rails/blob/85a8bc644be69908f05740a5886ec19cd3679df5/activesupport/lib/active_support/dependencies.rb#L505-L568 | train | ruby | Load the constant named +const_name+ which is missing from +from_mod+. If
it is not possible to load the constant into from_mod, try its parent
module using +const_missing+. | def load_missing_constant(from_mod, const_name)
unless qualified_const_defined?(from_mod.name) && Inflector.constantize(from_mod.name).equal?(from_mod)
raise ArgumentError, "A copy of #{from_mod} has been removed from the module tree but is still active!"
end
qualified_name = qualified_name_f... | Load the constant named +const_name+ which is missing from +from_mod+. If
it is not possible to load the constant into from_mod, try its parent
module using +const_missing+.
def load_missing_constant(from_mod, const_name)
unless qualified_const_defined?(from_mod.name) && Inflector.constantize(from_mod.name).eq... | 643 | 175 | 2,712 | CodeSearchNet permissive-repo filter (dataset-level) | code_search_net | 2026-12-05 | 2e1dc8e69e05686b7d7859dd5ad335c25da2c5656947628538ab18021897c6da | MIT | permissive | https://github.com/rails/rails/blob/main/MIT-LICENSE |
0ba960aa5c9f0460734a9062 | rails/rails | activesupport/lib/active_support/dependencies.rb | ActiveSupport.Dependencies.remove_unloadable_constants! | https://github.com/rails/rails/blob/85a8bc644be69908f05740a5886ec19cd3679df5/activesupport/lib/active_support/dependencies.rb#L577-L583 | train | ruby | Remove the constants that have been autoloaded, and those that have been
marked for unloading. Before each constant is removed a callback is sent
to its class/module if it implements +before_remove_const+.
The callback implementation should be restricted to cleaning up caches, etc.
as the environment will be in an... | def remove_unloadable_constants!
log("removing unloadable constants")
autoloaded_constants.each { |const| remove_constant const }
autoloaded_constants.clear
Reference.clear!
explicitly_unloadable_constants.each { |const| remove_constant const }
end | Remove the constants that have been autoloaded, and those that have been
marked for unloading. Before each constant is removed a callback is sent
to its class/module if it implements +before_remove_const+.
The callback implementation should be restricted to cleaning up caches, etc.
as the environment will be in an... | 137 | 413 | 282 | CodeSearchNet permissive-repo filter (dataset-level) | code_search_net | 2026-12-05 | 347a2455dba4a917fa1da2aaac82aeec3f605be7dd024c207ec5e6b5234c63dd | MIT | permissive | https://github.com/rails/rails/blob/main/MIT-LICENSE |
a7c353730284db2464ce30f3 | rails/rails | activesupport/lib/active_support/dependencies.rb | ActiveSupport.Dependencies.new_constants_in | https://github.com/rails/rails/blob/85a8bc644be69908f05740a5886ec19cd3679df5/activesupport/lib/active_support/dependencies.rb#L674-L689 | train | ruby | Run the provided block and detect the new constants that were loaded during
its execution. Constants may only be regarded as 'new' once -- so if the
block calls +new_constants_in+ again, then the constants defined within the
inner call will not be reported in this one.
If the provided block does not run to complet... | def new_constants_in(*descs)
constant_watch_stack.watch_namespaces(descs)
success = false
begin
yield # Now yield to the code that is to define new constants.
success = true
ensure
new_constants = constant_watch_stack.new_constants
return new_constants if succes... | Run the provided block and detect the new constants that were loaded during
its execution. Constants may only be regarded as 'new' once -- so if the
block calls +new_constants_in+ again, then the constants defined within the
inner call will not be reported in this one.
If the provided block does not run to complet... | 183 | 455 | 439 | CodeSearchNet permissive-repo filter (dataset-level) | code_search_net | 2026-12-05 | 1e4e6e2459ed7d94ca90155bba540a4150535036e189555302616ceb4b7093f5 | MIT | permissive | https://github.com/rails/rails/blob/main/MIT-LICENSE |
04b506f9be9860e10ead97ef | rails/rails | activesupport/lib/active_support/dependencies.rb | ActiveSupport.Dependencies.to_constant_name | https://github.com/rails/rails/blob/85a8bc644be69908f05740a5886ec19cd3679df5/activesupport/lib/active_support/dependencies.rb#L693-L702 | train | ruby | Convert the provided const desc to a qualified constant name (as a string).
A module, class, symbol, or string may be provided. | def to_constant_name(desc) #:nodoc:
case desc
when String then desc.sub(/^::/, "")
when Symbol then desc.to_s
when Module
desc.name ||
raise(ArgumentError, "Anonymous modules have no name to be referenced by")
else raise TypeError, "Not a valid constant descriptor: #{desc... | Convert the provided const desc to a qualified constant name (as a string).
A module, class, symbol, or string may be provided.
def to_constant_name(desc) #:nodoc:
case desc
when String then desc.sub(/^::/, "")
when Symbol then desc.to_s
when Module
desc.name ||
raise(Argumen... | 105 | 128 | 348 | CodeSearchNet permissive-repo filter (dataset-level) | code_search_net | 2026-12-05 | 38210e93b0d972d395fbf311923822f747cdb4f4f4464e6d97e2910b76facbff | MIT | permissive | https://github.com/rails/rails/blob/main/MIT-LICENSE |
be4363ae361577f25138bcda | rails/rails | activerecord/lib/active_record/relation/query_methods.rb | ActiveRecord.QueryMethods.select | https://github.com/rails/rails/blob/85a8bc644be69908f05740a5886ec19cd3679df5/activerecord/lib/active_record/relation/query_methods.rb#L254-L265 | train | ruby | Works in two unique ways.
First: takes a block so it can be used just like <tt>Array#select</tt>.
Model.all.select { |m| m.field == value }
This will build an array of objects from the database for the scope,
converting them into an array and iterating through them using
<tt>Array#select</tt>.
Second: Modif... | def select(*fields)
if block_given?
if fields.any?
raise ArgumentError, "`select' with block doesn't take arguments."
end
return super()
end
raise ArgumentError, "Call `select' with at least one field" if fields.empty?
spawn._select!(*fields)
end | Works in two unique ways.
First: takes a block so it can be used just like <tt>Array#select</tt>.
Model.all.select { |m| m.field == value }
This will build an array of objects from the database for the scope,
converting them into an array and iterating through them using
<tt>Array#select</tt>.
Second: Modif... | 429 | 1,529 | 310 | CodeSearchNet permissive-repo filter (dataset-level) | code_search_net | 2026-12-05 | f767b4e904f8d22f4227dbc6269f212429ee98fc6133cd1488c4eb133b69d89c | MIT | permissive | https://github.com/rails/rails/blob/main/MIT-LICENSE |
4fe0d6a56c9f0f61174be5be | rails/rails | activerecord/lib/active_record/relation/query_methods.rb | ActiveRecord.QueryMethods.where | https://github.com/rails/rails/blob/85a8bc644be69908f05740a5886ec19cd3679df5/activerecord/lib/active_record/relation/query_methods.rb#L632-L640 | train | ruby | Returns a new relation, which is the result of filtering the current relation
according to the conditions in the arguments.
#where accepts conditions in one of several formats. In the examples below, the resulting
SQL is given as an illustration; the actual query generated may be different depending
on the databas... | def where(opts = :chain, *rest)
if :chain == opts
WhereChain.new(spawn)
elsif opts.blank?
self
else
spawn.where!(opts, *rest)
end
end | Returns a new relation, which is the result of filtering the current relation
according to the conditions in the arguments.
#where accepts conditions in one of several formats. In the examples below, the resulting
SQL is given as an illustration; the actual query generated may be different depending
on the databas... | 1,224 | 5,162 | 185 | CodeSearchNet permissive-repo filter (dataset-level) | code_search_net | 2026-12-05 | 386645c1013bf7b10e40f8e614f3e8174fcd5ae440854e53d0463803d6611663 | MIT | permissive | https://github.com/rails/rails/blob/main/MIT-LICENSE |
a833265825512cb6b8cdb5c8 | rails/rails | activerecord/lib/active_record/relation/query_methods.rb | ActiveRecord.QueryMethods.extending | https://github.com/rails/rails/blob/85a8bc644be69908f05740a5886ec19cd3679df5/activerecord/lib/active_record/relation/query_methods.rb#L918-L924 | train | ruby | Used to extend a scope with additional methods, either through
a module or through a block provided.
The object returned is a relation, which can be further extended.
=== Using a module
module Pagination
def page(number)
# pagination code goes here
end
end
scope = Model.all.extending(Pa... | def extending(*modules, &block)
if modules.any? || block
spawn.extending!(*modules, &block)
else
self
end
end | Used to extend a scope with additional methods, either through
a module or through a block provided.
The object returned is a relation, which can be further extended.
=== Using a module
module Pagination
def page(number)
# pagination code goes here
end
end
scope = Model.all.extending(Pa... | 218 | 783 | 147 | CodeSearchNet permissive-repo filter (dataset-level) | code_search_net | 2026-12-05 | 31ddf10629afc06d185e9960dee6e4af3df05ab0452dbcc9825fe582bfb3b37e | MIT | permissive | https://github.com/rails/rails/blob/main/MIT-LICENSE |
92ff8c752c63b7d16958d8cc | rails/rails | activerecord/lib/active_record/relation/query_methods.rb | ActiveRecord.QueryMethods.validate_order_args | https://github.com/rails/rails/blob/85a8bc644be69908f05740a5886ec19cd3679df5/activerecord/lib/active_record/relation/query_methods.rb#L1243-L1253 | train | ruby | :nodoc: | def validate_order_args(args)
args.each do |arg|
next unless arg.is_a?(Hash)
arg.each do |_key, value|
unless VALID_DIRECTIONS.include?(value)
raise ArgumentError,
"Direction \"#{value}\" is invalid. Valid directions are: #{VALID_DIRECTIONS.to_a.insp... | :nodoc:
def validate_order_args(args)
args.each do |arg|
next unless arg.is_a?(Hash)
arg.each do |_key, value|
unless VALID_DIRECTIONS.include?(value)
raise ArgumentError,
"Direction \"#{value}\" is invalid. Valid directions are: #{VALID_DIRECTIONS.... | 83 | 7 | 377 | CodeSearchNet permissive-repo filter (dataset-level) | code_search_net | 2026-12-05 | 1190d551a78dd71a568d983dd98dfc476ef363275ac9e37c11b29210574cc4bc | MIT | permissive | https://github.com/rails/rails/blob/main/MIT-LICENSE |
b93e689dff4da3c8dc699d1e | rails/rails | activesupport/lib/active_support/xml_mini/rexml.rb | ActiveSupport.XmlMini_REXML.parse | https://github.com/rails/rails/blob/85a8bc644be69908f05740a5886ec19cd3679df5/activesupport/lib/active_support/xml_mini/rexml.rb#L20-L38 | train | ruby | Parse an XML Document string or IO into a simple hash.
Same as XmlSimple::xml_in but doesn't shoot itself in the foot,
and uses the defaults from Active Support.
data::
XML Document string or IO to parse | def parse(data)
if !data.respond_to?(:read)
data = StringIO.new(data || "")
end
if data.eof?
{}
else
silence_warnings { require "rexml/document" } unless defined?(REXML::Document)
doc = REXML::Document.new(data)
if doc.root
merge_element!({}, d... | Parse an XML Document string or IO into a simple hash.
Same as XmlSimple::xml_in but doesn't shoot itself in the foot,
and uses the defaults from Active Support.
data::
XML Document string or IO to parse
def parse(data)
if !data.respond_to?(:read)
data = StringIO.new(data || "")
end
... | 164 | 211 | 499 | CodeSearchNet permissive-repo filter (dataset-level) | code_search_net | 2026-12-05 | fcc8165b180ecdda4ff553a499190ade9886adf054a5f1e644890613f01483bd | MIT | permissive | https://github.com/rails/rails/blob/main/MIT-LICENSE |
87d35c667d555349b7e60b80 | rails/rails | activesupport/lib/active_support/xml_mini/rexml.rb | ActiveSupport.XmlMini_REXML.merge_element! | https://github.com/rails/rails/blob/85a8bc644be69908f05740a5886ec19cd3679df5/activesupport/lib/active_support/xml_mini/rexml.rb#L47-L50 | train | ruby | Convert an XML element and merge into the hash
hash::
Hash to merge the converted element into.
element::
XML element to merge into hash | def merge_element!(hash, element, depth)
raise REXML::ParseException, "The document is too deep" if depth == 0
merge!(hash, element.name, collapse(element, depth))
end | Convert an XML element and merge into the hash
hash::
Hash to merge the converted element into.
element::
XML element to merge into hash
def merge_element!(hash, element, depth)
raise REXML::ParseException, "The document is too deep" if depth == 0
merge!(hash, element.name, collapse(element, d... | 77 | 145 | 189 | CodeSearchNet permissive-repo filter (dataset-level) | code_search_net | 2026-12-05 | 335cac25de74dd8dc8d6cf1aee0f5b81371bcdf7709a7f57717895695cdac4be | MIT | permissive | https://github.com/rails/rails/blob/main/MIT-LICENSE |
977b760d3dc7d6abfa5945d4 | rails/rails | activesupport/lib/active_support/xml_mini/rexml.rb | ActiveSupport.XmlMini_REXML.merge_texts! | https://github.com/rails/rails/blob/85a8bc644be69908f05740a5886ec19cd3679df5/activesupport/lib/active_support/xml_mini/rexml.rb#L74-L83 | train | ruby | Merge all the texts of an element into the hash
hash::
Hash to add the converted element to.
element::
XML element whose texts are to me merged into the hash | def merge_texts!(hash, element)
unless element.has_text?
hash
else
# must use value to prevent double-escaping
texts = +""
element.texts.each { |t| texts << t.value }
merge!(hash, CONTENT_KEY, texts)
end
end | Merge all the texts of an element into the hash
hash::
Hash to add the converted element to.
element::
XML element whose texts are to me merged into the hash
def merge_texts!(hash, element)
unless element.has_text?
hash
else
# must use value to prevent double-escaping
... | 102 | 166 | 287 | CodeSearchNet permissive-repo filter (dataset-level) | code_search_net | 2026-12-05 | a7b17422aaef170c4b5f01b660fef1bd54c97703f33b814d26099c98cca972d0 | MIT | permissive | https://github.com/rails/rails/blob/main/MIT-LICENSE |
9faad080b7cc7c3e0ff60799 | rails/rails | activesupport/lib/active_support/xml_mini/rexml.rb | ActiveSupport.XmlMini_REXML.merge! | https://github.com/rails/rails/blob/85a8bc644be69908f05740a5886ec19cd3679df5/activesupport/lib/active_support/xml_mini/rexml.rb#L96-L109 | train | ruby | Adds a new key/value pair to an existing Hash. If the key to be added
already exists and the existing value associated with key is not
an Array, it will be wrapped in an Array. Then the new value is
appended to that Array.
hash::
Hash to add key/value pair to.
key::
Key to be added.
value::
Value to be ... | def merge!(hash, key, value)
if hash.has_key?(key)
if hash[key].instance_of?(Array)
hash[key] << value
else
hash[key] = [hash[key], value]
end
elsif value.instance_of?(Array)
hash[key] = [value]
else
hash[key] = value
... | Adds a new key/value pair to an existing Hash. If the key to be added
already exists and the existing value associated with key is not
an Array, it will be wrapped in an Array. Then the new value is
appended to that Array.
hash::
Hash to add key/value pair to.
key::
Key to be added.
value::
Value to be ... | 166 | 340 | 350 | CodeSearchNet permissive-repo filter (dataset-level) | code_search_net | 2026-12-05 | 30ee7739aeba03a66a09f93345558ec3868fa0fd7b2fdc5976800b8fe45e6854 | MIT | permissive | https://github.com/rails/rails/blob/main/MIT-LICENSE |
f48cae7aa0ab667b1244c931 | rails/rails | activesupport/lib/active_support/xml_mini/rexml.rb | ActiveSupport.XmlMini_REXML.get_attributes | https://github.com/rails/rails/blob/85a8bc644be69908f05740a5886ec19cd3679df5/activesupport/lib/active_support/xml_mini/rexml.rb#L116-L120 | train | ruby | Converts the attributes array of an XML element into a hash.
Returns an empty Hash if node has no attributes.
element::
XML element to extract attributes from. | def get_attributes(element)
attributes = {}
element.attributes.each { |n, v| attributes[n] = v }
attributes
end | Converts the attributes array of an XML element into a hash.
Returns an empty Hash if node has no attributes.
element::
XML element to extract attributes from.
def get_attributes(element)
attributes = {}
element.attributes.each { |n, v| attributes[n] = v }
attributes
end | 63 | 165 | 141 | CodeSearchNet permissive-repo filter (dataset-level) | code_search_net | 2026-12-05 | 56d40db1b305e14b4fa7c55afb5d78abde04f56fae86bb2bedb10211be7c429e | MIT | permissive | https://github.com/rails/rails/blob/main/MIT-LICENSE |
60f5c6e9fc5722a8ed1b7844 | rails/rails | actionview/lib/action_view/flows.rb | ActionView.StreamingFlow.get | https://github.com/rails/rails/blob/85a8bc644be69908f05740a5886ec19cd3679df5/actionview/lib/action_view/flows.rb#L43-L60 | train | ruby | :nodoc:
Try to get stored content. If the content
is not available and we're inside the layout fiber,
then it will begin waiting for the given key and yield. | def get(key)
return super if @content.key?(key)
if inside_fiber?
view = @view
begin
@waiting_for = key
view.output_buffer, @parent = @child, view.output_buffer
Fiber.yield
ensure
@waiting_for = nil
view.output_buffer, @child = @pare... | :nodoc:
Try to get stored content. If the content
is not available and we're inside the layout fiber,
then it will begin waiting for the given key and yield.
def get(key)
return super if @content.key?(key)
if inside_fiber?
view = @view
begin
@waiting_for = key
view.... | 129 | 160 | 385 | CodeSearchNet permissive-repo filter (dataset-level) | code_search_net | 2026-12-05 | f07a6b2710a1fc026f83a7cd737a90f17858fb6445b8d13337591ab976bdb89d | MIT | permissive | https://github.com/rails/rails/blob/main/MIT-LICENSE |
a7439a528c1d5cc5d3dade93 | rails/rails | activerecord/lib/active_record/connection_handling.rb | ActiveRecord.ConnectionHandling.connects_to | https://github.com/rails/rails/blob/85a8bc644be69908f05740a5886ec19cd3679df5/activerecord/lib/active_record/connection_handling.rb#L68-L79 | train | ruby | Connects a model to the databases specified. The +database+ keyword
takes a hash consisting of a +role+ and a +database_key+.
This will create a connection handler for switching between connections,
look up the config hash using the +database_key+ and finally
establishes a connection to that config.
class Anim... | def connects_to(database: {})
connections = []
database.each do |role, database_key|
config_hash = resolve_config_for_connection(database_key)
handler = lookup_connection_handler(role.to_sym)
connections << handler.establish_connection(config_hash)
end
connections
... | Connects a model to the databases specified. The +database+ keyword
takes a hash consisting of a +role+ and a +database_key+.
This will create a connection handler for switching between connections,
look up the config hash using the +database_key+ and finally
establishes a connection to that config.
class Anim... | 164 | 511 | 323 | CodeSearchNet permissive-repo filter (dataset-level) | code_search_net | 2026-12-05 | 75b7bc7e9a5d293cec719ef0ce98a4bb5818ac9b90408599be446991b8cdbd3a | MIT | permissive | https://github.com/rails/rails/blob/main/MIT-LICENSE |
4fb51c52727307f17cfcc766 | rails/rails | activerecord/lib/active_record/connection_handling.rb | ActiveRecord.ConnectionHandling.connected_to | https://github.com/rails/rails/blob/85a8bc644be69908f05740a5886ec19cd3679df5/activerecord/lib/active_record/connection_handling.rb#L117-L137 | train | ruby | Connects to a database or role (ex writing, reading, or another
custom role) for the duration of the block.
If a role is passed, Active Record will look up the connection
based on the requested role:
ActiveRecord::Base.connected_to(role: :writing) do
Dog.create! # creates dog using dog writing connection
... | def connected_to(database: nil, role: nil, &blk)
if database && role
raise ArgumentError, "connected_to can only accept a `database` or a `role` argument, but not both arguments."
elsif database
if database.is_a?(Hash)
role, database = database.first
role = role.to_sym
... | Connects to a database or role (ex writing, reading, or another
custom role) for the duration of the block.
If a role is passed, Active Record will look up the connection
based on the requested role:
ActiveRecord::Base.connected_to(role: :writing) do
Dog.create! # creates dog using dog writing connection
... | 488 | 1,510 | 683 | CodeSearchNet permissive-repo filter (dataset-level) | code_search_net | 2026-12-05 | 818a9b17256244df0b85340216163263fd6f9d0f34bf9809d2fb71db0c7c4676 | MIT | permissive | https://github.com/rails/rails/blob/main/MIT-LICENSE |
1c99084dca9b69c2d1c0f2a8 | rails/rails | activerecord/lib/active_record/connection_handling.rb | ActiveRecord.ConnectionHandling.clear_query_caches_for_current_thread | https://github.com/rails/rails/blob/85a8bc644be69908f05740a5886ec19cd3679df5/activerecord/lib/active_record/connection_handling.rb#L187-L193 | train | ruby | Clears the query cache for all connections associated with the current thread. | def clear_query_caches_for_current_thread
ActiveRecord::Base.connection_handlers.each_value do |handler|
handler.connection_pool_list.each do |pool|
pool.connection.clear_query_cache if pool.active_connection?
end
end
end | Clears the query cache for all connections associated with the current thread.
def clear_query_caches_for_current_thread
ActiveRecord::Base.connection_handlers.each_value do |handler|
handler.connection_pool_list.each do |pool|
pool.connection.clear_query_cache if pool.active_connection?
... | 64 | 78 | 263 | CodeSearchNet permissive-repo filter (dataset-level) | code_search_net | 2026-12-05 | e9053424bad993fed6b6170a548523ce90692e24f8bfc504c8e891010fb0f371 | MIT | permissive | https://github.com/rails/rails/blob/main/MIT-LICENSE |
1bfc54c98a9c126f9dbd0ae8 | rails/rails | activerecord/lib/active_record/schema_dumper.rb | ActiveRecord.SchemaDumper.formatted_version | https://github.com/rails/rails/blob/85a8bc644be69908f05740a5886ec19cd3679df5/activerecord/lib/active_record/schema_dumper.rb#L59-L63 | train | ruby | turns 20170404131909 into "2017_04_04_131909" | def formatted_version
stringified = @version.to_s
return stringified unless stringified.length == 14
stringified.insert(4, "_").insert(7, "_").insert(10, "_")
end | turns 20170404131909 into "2017_04_04_131909"
def formatted_version
stringified = @version.to_s
return stringified unless stringified.length == 14
stringified.insert(4, "_").insert(7, "_").insert(10, "_")
end | 68 | 45 | 192 | CodeSearchNet permissive-repo filter (dataset-level) | code_search_net | 2026-12-05 | 0bf53547a9f4f94e388af72f777a2bb12043522f672336a5e7a94a8ded5e3e58 | MIT | permissive | https://github.com/rails/rails/blob/main/MIT-LICENSE |
55a74d505fed93680da60ba9 | rails/rails | activerecord/lib/active_record/schema_dumper.rb | ActiveRecord.SchemaDumper.indexes | https://github.com/rails/rails/blob/85a8bc644be69908f05740a5886ec19cd3679df5/activerecord/lib/active_record/schema_dumper.rb#L171-L181 | train | ruby | Keep it for indexing materialized views | def indexes(table, stream)
if (indexes = @connection.indexes(table)).any?
add_index_statements = indexes.map do |index|
table_name = remove_prefix_and_suffix(index.table).inspect
" add_index #{([table_name] + index_parts(index)).join(', ')}"
end
stream.put... | Keep it for indexing materialized views
def indexes(table, stream)
if (indexes = @connection.indexes(table)).any?
add_index_statements = indexes.map do |index|
table_name = remove_prefix_and_suffix(index.table).inspect
" add_index #{([table_name] + index_parts(index)).join(',... | 95 | 39 | 402 | CodeSearchNet permissive-repo filter (dataset-level) | code_search_net | 2026-12-05 | 1822813c1c0af7a8d7eadebee5578ae0a139c68eaf87f93c930d10a334012ca6 | MIT | permissive | https://github.com/rails/rails/blob/main/MIT-LICENSE |
a33fca07425b4de29b7c8af3 | rails/rails | activesupport/lib/active_support/core_ext/object/try.rb | ActiveSupport.Tryable.try | https://github.com/rails/rails/blob/85a8bc644be69908f05740a5886ec19cd3679df5/activesupport/lib/active_support/core_ext/object/try.rb#L7-L17 | train | ruby | :nodoc: | def try(method_name = nil, *args, &b)
if method_name.nil? && block_given?
if b.arity == 0
instance_eval(&b)
else
yield self
end
elsif respond_to?(method_name)
public_send(method_name, *args, &b)
end
end | :nodoc:
def try(method_name = nil, *args, &b)
if method_name.nil? && block_given?
if b.arity == 0
instance_eval(&b)
else
yield self
end
elsif respond_to?(method_name)
public_send(method_name, *args, &b)
end
end | 77 | 7 | 276 | CodeSearchNet permissive-repo filter (dataset-level) | code_search_net | 2026-12-05 | 5b2d139983142428dc1d26e2b761780c9c4d68f0d251f668a8fa7c87befc298c | MIT | permissive | https://github.com/rails/rails/blob/main/MIT-LICENSE |
6908e7d01a3aeed2a5a6f142 | rails/rails | actionview/lib/action_view/routing_url_for.rb | ActionView.RoutingUrlFor.url_for | https://github.com/rails/rails/blob/85a8bc644be69908f05740a5886ec19cd3679df5/actionview/lib/action_view/routing_url_for.rb#L79-L119 | train | ruby | Returns the URL for the set of +options+ provided. This takes the
same options as +url_for+ in Action Controller (see the
documentation for <tt>ActionController::Base#url_for</tt>). Note that by default
<tt>:only_path</tt> is <tt>true</tt> so you'll get the relative "/controller/action"
instead of the fully qualifi... | def url_for(options = nil)
case options
when String
options
when nil
super(only_path: _generate_paths_by_default)
when Hash
options = options.symbolize_keys
ensure_only_path_option(options)
super(options)
when ActionController::Parameters
en... | Returns the URL for the set of +options+ provided. This takes the
same options as +url_for+ in Action Controller (see the
documentation for <tt>ActionController::Base#url_for</tt>). Note that by default
<tt>:only_path</tt> is <tt>true</tt> so you'll get the relative "/controller/action"
instead of the fully qualifi... | 1,042 | 3,112 | 1,121 | CodeSearchNet permissive-repo filter (dataset-level) | code_search_net | 2026-12-05 | b7b09cee09c2b179f03ce20f8cbeb8c0949d0f0a604743fc30ff7b92de30f2ab | MIT | permissive | https://github.com/rails/rails/blob/main/MIT-LICENSE |
43caf44a3f8cb8542b67a13a | rails/rails | activesupport/lib/active_support/time_with_zone.rb | ActiveSupport.TimeWithZone.formatted_offset | https://github.com/rails/rails/blob/85a8bc644be69908f05740a5886ec19cd3679df5/activesupport/lib/active_support/time_with_zone.rb#L126-L128 | train | ruby | Returns a formatted string of the offset from UTC, or an alternative
string if the time zone is already UTC.
Time.zone = 'Eastern Time (US & Canada)' # => "Eastern Time (US & Canada)"
Time.zone.now.formatted_offset(true) # => "-05:00"
Time.zone.now.formatted_offset(false) # => "-0500"
Time.zo... | def formatted_offset(colon = true, alternate_utc_string = nil)
utc? && alternate_utc_string || TimeZone.seconds_to_utc_offset(utc_offset, colon)
end | Returns a formatted string of the offset from UTC, or an alternative
string if the time zone is already UTC.
Time.zone = 'Eastern Time (US & Canada)' # => "Eastern Time (US & Canada)"
Time.zone.now.formatted_offset(true) # => "-05:00"
Time.zone.now.formatted_offset(false) # => "-0500"
Time.zo... | 145 | 421 | 158 | CodeSearchNet permissive-repo filter (dataset-level) | code_search_net | 2026-12-05 | 00b08a06fdffd0e47b164c220ae8392c51e0218bbfd345878cb9e34bcae9d9af | MIT | permissive | https://github.com/rails/rails/blob/main/MIT-LICENSE |
89556e6cb910e52dfb72f64b | rails/rails | activesupport/lib/active_support/time_with_zone.rb | ActiveSupport.TimeWithZone.as_json | https://github.com/rails/rails/blob/85a8bc644be69908f05740a5886ec19cd3679df5/activesupport/lib/active_support/time_with_zone.rb#L167-L173 | train | ruby | Coerces time to a string for JSON encoding. The default format is ISO 8601.
You can get %Y/%m/%d %H:%M:%S +offset style by setting
<tt>ActiveSupport::JSON::Encoding.use_standard_json_time_format</tt>
to +false+.
# With ActiveSupport::JSON::Encoding.use_standard_json_time_format = true
Time.utc(2005,2,1,15,15,... | def as_json(options = nil)
if ActiveSupport::JSON::Encoding.use_standard_json_time_format
xmlschema(ActiveSupport::JSON::Encoding.time_precision)
else
%(#{time.strftime("%Y/%m/%d %H:%M:%S")} #{formatted_offset(false)})
end
end | Coerces time to a string for JSON encoding. The default format is ISO 8601.
You can get %Y/%m/%d %H:%M:%S +offset style by setting
<tt>ActiveSupport::JSON::Encoding.use_standard_json_time_format</tt>
to +false+.
# With ActiveSupport::JSON::Encoding.use_standard_json_time_format = true
Time.utc(2005,2,1,15,15,... | 256 | 571 | 264 | CodeSearchNet permissive-repo filter (dataset-level) | code_search_net | 2026-12-05 | 3d6aa57bbc0e7ed67ab2dd48b8fd2c029d774b15976a9e5e5d5d30c7a2ef8a75 | MIT | permissive | https://github.com/rails/rails/blob/main/MIT-LICENSE |
e4206e32343a5e4685f24b5d | rails/rails | activesupport/lib/active_support/time_with_zone.rb | ActiveSupport.TimeWithZone.to_s | https://github.com/rails/rails/blob/85a8bc644be69908f05740a5886ec19cd3679df5/activesupport/lib/active_support/time_with_zone.rb#L206-L214 | train | ruby | Returns a string of the object's date and time.
Accepts an optional <tt>format</tt>:
* <tt>:default</tt> - default value, mimics Ruby Time#to_s format.
* <tt>:db</tt> - format outputs time in UTC :db time. See Time#to_formatted_s(:db).
* Any key in <tt>Time::DATE_FORMATS</tt> can be used. See active_support/core_ex... | def to_s(format = :default)
if format == :db
utc.to_s(format)
elsif formatter = ::Time::DATE_FORMATS[format]
formatter.respond_to?(:call) ? formatter.call(self).to_s : strftime(formatter)
else
"#{time.strftime("%Y-%m-%d %H:%M:%S")} #{formatted_offset(false, 'UTC')}" # mimicking... | Returns a string of the object's date and time.
Accepts an optional <tt>format</tt>:
* <tt>:default</tt> - default value, mimics Ruby Time#to_s format.
* <tt>:db</tt> - format outputs time in UTC :db time. See Time#to_formatted_s(:db).
* Any key in <tt>Time::DATE_FORMATS</tt> can be used. See active_support/core_ex... | 196 | 342 | 360 | CodeSearchNet permissive-repo filter (dataset-level) | code_search_net | 2026-12-05 | 37ea189a90ac90625767fcd2008c921dac9d08db4a1390440524cbf5164b6204 | MIT | permissive | https://github.com/rails/rails/blob/main/MIT-LICENSE |
a05ed7fd305da26c2b861f47 | rails/rails | activesupport/lib/active_support/time_with_zone.rb | ActiveSupport.TimeWithZone.change | https://github.com/rails/rails/blob/85a8bc644be69908f05740a5886ec19cd3679df5/activesupport/lib/active_support/time_with_zone.rb#L362-L379 | train | ruby | Returns a new +ActiveSupport::TimeWithZone+ where one or more of the elements have
been changed according to the +options+ parameter. The time options (<tt>:hour</tt>,
<tt>:min</tt>, <tt>:sec</tt>, <tt>:usec</tt>, <tt>:nsec</tt>) reset cascadingly,
so if only the hour is passed, then minute, sec, usec and nsec is se... | def change(options)
if options[:zone] && options[:offset]
raise ArgumentError, "Can't change both :offset and :zone at the same time: #{options.inspect}"
end
new_time = time.change(options)
if options[:zone]
new_zone = ::Time.find_zone(options[:zone])
elsif options[:offse... | Returns a new +ActiveSupport::TimeWithZone+ where one or more of the elements have
been changed according to the +options+ parameter. The time options (<tt>:hour</tt>,
<tt>:min</tt>, <tt>:sec</tt>, <tt>:usec</tt>, <tt>:nsec</tt>) reset cascadingly,
so if only the hour is passed, then minute, sec, usec and nsec is se... | 574 | 1,183 | 568 | CodeSearchNet permissive-repo filter (dataset-level) | code_search_net | 2026-12-05 | fc10bff1bd48b4849bdd2602c77553ae426c99f9a778f19181d2e39f56c69a8b | MIT | permissive | https://github.com/rails/rails/blob/main/MIT-LICENSE |
2983f16c5697521218eeeeaf | rails/rails | activesupport/lib/active_support/time_with_zone.rb | ActiveSupport.TimeWithZone.advance | https://github.com/rails/rails/blob/85a8bc644be69908f05740a5886ec19cd3679df5/activesupport/lib/active_support/time_with_zone.rb#L402-L410 | train | ruby | Uses Date to provide precise Time calculations for years, months, and days
according to the proleptic Gregorian calendar. The result is returned as a
new TimeWithZone object.
The +options+ parameter takes a hash with any of these keys:
<tt>:years</tt>, <tt>:months</tt>, <tt>:weeks</tt>, <tt>:days</tt>,
<tt>:hours... | def advance(options)
# If we're advancing a value of variable length (i.e., years, weeks, months, days), advance from #time,
# otherwise advance from #utc, for accuracy when moving across DST boundaries
if options.values_at(:years, :weeks, :months, :days).any?
method_missing(:advance, options)... | Uses Date to provide precise Time calculations for years, months, and days
according to the proleptic Gregorian calendar. The result is returned as a
new TimeWithZone object.
The +options+ parameter takes a hash with any of these keys:
<tt>:years</tt>, <tt>:months</tt>, <tt>:weeks</tt>, <tt>:days</tt>,
<tt>:hours... | 505 | 1,181 | 402 | CodeSearchNet permissive-repo filter (dataset-level) | code_search_net | 2026-12-05 | 2432c56b84189caad795299ebf622a6f5cf98a80959c47476e6102c4b5602388 | MIT | permissive | https://github.com/rails/rails/blob/main/MIT-LICENSE |
a6cb3578b8ba2f08152d5e40 | rails/rails | activesupport/lib/active_support/time_with_zone.rb | ActiveSupport.TimeWithZone.to_a | https://github.com/rails/rails/blob/85a8bc644be69908f05740a5886ec19cd3679df5/activesupport/lib/active_support/time_with_zone.rb#L425-L427 | train | ruby | Returns Array of parts of Time in sequence of
[seconds, minutes, hours, day, month, year, weekday, yearday, dst?, zone].
now = Time.zone.now # => Tue, 18 Aug 2015 02:29:27 UTC +00:00
now.to_a # => [27, 29, 2, 18, 8, 2015, 2, 230, false, "UTC"] | def to_a
[time.sec, time.min, time.hour, time.day, time.mon, time.year, time.wday, time.yday, dst?, zone]
end | Returns Array of parts of Time in sequence of
[seconds, minutes, hours, day, month, year, weekday, yearday, dst?, zone].
now = Time.zone.now # => Tue, 18 Aug 2015 02:29:27 UTC +00:00
now.to_a # => [27, 29, 2, 18, 8, 2015, 2, 230, false, "UTC"]
def to_a
[time.sec, time.min, time.hour, t... | 137 | 270 | 119 | CodeSearchNet permissive-repo filter (dataset-level) | code_search_net | 2026-12-05 | cbd32868dc78cdc2a1eb616a3e651bc6d277e4565d03028c114e4f86261e0ee7 | MIT | permissive | https://github.com/rails/rails/blob/main/MIT-LICENSE |
05a6f4fccae491ea161f2ae6 | rails/rails | activesupport/lib/active_support/time_with_zone.rb | ActiveSupport.TimeWithZone.respond_to_missing? | https://github.com/rails/rails/blob/85a8bc644be69908f05740a5886ec19cd3679df5/activesupport/lib/active_support/time_with_zone.rb#L513-L516 | train | ruby | Ensure proxy class responds to all methods that underlying time instance
responds to. | def respond_to_missing?(sym, include_priv)
return false if sym.to_sym == :acts_like_date?
time.respond_to?(sym, include_priv)
end | Ensure proxy class responds to all methods that underlying time instance
responds to.
def respond_to_missing?(sym, include_priv)
return false if sym.to_sym == :acts_like_date?
time.respond_to?(sym, include_priv)
end | 50 | 86 | 145 | CodeSearchNet permissive-repo filter (dataset-level) | code_search_net | 2026-12-05 | d8efe13b0088dc6fe0a209c3390387761c96875ac30b04d8ce068415e6cc63b6 | MIT | permissive | https://github.com/rails/rails/blob/main/MIT-LICENSE |
af27c1fcee2d2b0df01b3e6e | rails/rails | activesupport/lib/active_support/time_with_zone.rb | ActiveSupport.TimeWithZone.method_missing | https://github.com/rails/rails/blob/85a8bc644be69908f05740a5886ec19cd3679df5/activesupport/lib/active_support/time_with_zone.rb#L520-L524 | train | ruby | Send the missing method to +time+ instance, and wrap result in a new
TimeWithZone with the existing +time_zone+. | def method_missing(sym, *args, &block)
wrap_with_time_zone time.__send__(sym, *args, &block)
rescue NoMethodError => e
raise e, e.message.sub(time.inspect, inspect), e.backtrace
end | Send the missing method to +time+ instance, and wrap result in a new
TimeWithZone with the existing +time_zone+.
def method_missing(sym, *args, &block)
wrap_with_time_zone time.__send__(sym, *args, &block)
rescue NoMethodError => e
raise e, e.message.sub(time.inspect, inspect), e.backtrace
end | 82 | 113 | 201 | CodeSearchNet permissive-repo filter (dataset-level) | code_search_net | 2026-12-05 | 68c6bc8e0a235db2ba3790ae135415f2d5524ce03be7de9de873117c7bc7cd99 | MIT | permissive | https://github.com/rails/rails/blob/main/MIT-LICENSE |
80bf55a814d50fb6c861dd99 | rails/rails | actionpack/lib/abstract_controller/base.rb | AbstractController.Base.process | https://github.com/rails/rails/blob/85a8bc644be69908f05740a5886ec19cd3679df5/actionpack/lib/abstract_controller/base.rb#L127-L137 | train | ruby | Calls the action going through the entire action dispatch stack.
The actual method that is called is determined by calling
#method_for_action. If no method can handle the action, then an
AbstractController::ActionNotFound error is raised.
==== Returns
* <tt>self</tt> | def process(action, *args)
@_action_name = action.to_s
unless action_name = _find_action_name(@_action_name)
raise ActionNotFound, "The action '#{action}' could not be found for #{self.class.name}"
end
@_response_body = nil
process_action(action_name, *args)
end | Calls the action going through the entire action dispatch stack.
The actual method that is called is determined by calling
#method_for_action. If no method can handle the action, then an
AbstractController::ActionNotFound error is raised.
==== Returns
* <tt>self</tt>
def process(action, *args)
@_action_na... | 130 | 274 | 307 | CodeSearchNet permissive-repo filter (dataset-level) | code_search_net | 2026-12-05 | d96d061ae3dcef0ec7a727557c0e45305194e8f5fdeca4aee5921e932fa4e1d3 | MIT | permissive | https://github.com/rails/rails/blob/main/MIT-LICENSE |
8ca8fcdf490a9a78c20e1782 | rails/rails | activesupport/lib/active_support/array_inquirer.rb | ActiveSupport.ArrayInquirer.any? | https://github.com/rails/rails/blob/85a8bc644be69908f05740a5886ec19cd3679df5/activesupport/lib/active_support/array_inquirer.rb#L25-L33 | train | ruby | Passes each element of +candidates+ collection to ArrayInquirer collection.
The method returns true if any element from the ArrayInquirer collection
is equal to the stringified or symbolized form of any element in the +candidates+ collection.
If +candidates+ collection is not given, method returns true.
variant... | def any?(*candidates)
if candidates.none?
super
else
candidates.any? do |candidate|
include?(candidate.to_sym) || include?(candidate.to_s)
end
end
end | Passes each element of +candidates+ collection to ArrayInquirer collection.
The method returns true if any element from the ArrayInquirer collection
is equal to the stringified or symbolized form of any element in the +candidates+ collection.
If +candidates+ collection is not given, method returns true.
variant... | 176 | 569 | 206 | CodeSearchNet permissive-repo filter (dataset-level) | code_search_net | 2026-12-05 | 534bc5e155814925ee93202b9cd859a9ad5ed986e322099eeea0fa87ce249fb3 | MIT | permissive | https://github.com/rails/rails/blob/main/MIT-LICENSE |
a04bf6d1c7167d44078058f1 | rails/rails | activerecord/lib/active_record/integration.rb | ActiveRecord.Integration.cache_key | https://github.com/rails/rails/blob/85a8bc644be69908f05740a5886ec19cd3679df5/activerecord/lib/active_record/integration.rb#L72-L89 | train | ruby | Returns a stable cache key that can be used to identify this record.
Product.new.cache_key # => "products/new"
Product.find(5).cache_key # => "products/5"
If ActiveRecord::Base.cache_versioning is turned off, as it was in Rails 5.1 and earlier,
the cache key will also include a version.
Product.cache_... | def cache_key
if new_record?
"#{model_name.cache_key}/new"
else
if cache_version
"#{model_name.cache_key}/#{id}"
else
timestamp = max_updated_column_timestamp
if timestamp
timestamp = timestamp.utc.to_s(cache_timestamp_format)
"#... | Returns a stable cache key that can be used to identify this record.
Product.new.cache_key # => "products/new"
Product.find(5).cache_key # => "products/5"
If ActiveRecord::Base.cache_versioning is turned off, as it was in Rails 5.1 and earlier,
the cache key will also include a version.
Product.cache_... | 204 | 424 | 465 | CodeSearchNet permissive-repo filter (dataset-level) | code_search_net | 2026-12-05 | 267430e63a754a421717c67a4b84e447ee027eb5ea22c69be5ff486551139c3e | MIT | permissive | https://github.com/rails/rails/blob/main/MIT-LICENSE |
4e21df07a07a6d0a9cd376a3 | rails/rails | activerecord/lib/active_record/integration.rb | ActiveRecord.Integration.cache_version | https://github.com/rails/rails/blob/85a8bc644be69908f05740a5886ec19cd3679df5/activerecord/lib/active_record/integration.rb#L97-L112 | train | ruby | Returns a cache version that can be used together with the cache key to form
a recyclable caching scheme. By default, the #updated_at column is used for the
cache_version, but this method can be overwritten to return something else.
Note, this method will return nil if ActiveRecord::Base.cache_versioning is set to
... | def cache_version
return unless cache_versioning
if has_attribute?("updated_at")
timestamp = updated_at_before_type_cast
if can_use_fast_cache_version?(timestamp)
raw_timestamp_to_cache_version(timestamp)
elsif timestamp = updated_at
timestamp.utc.to_s(cache_time... | Returns a cache version that can be used together with the cache key to form
a recyclable caching scheme. By default, the #updated_at column is used for the
cache_version, but this method can be overwritten to return something else.
Note, this method will return nil if ActiveRecord::Base.cache_versioning is set to
... | 185 | 370 | 521 | CodeSearchNet permissive-repo filter (dataset-level) | code_search_net | 2026-12-05 | d1aa20781aaf519f772f6cacebf6883893eaad85198c084e69145bb6fc82771a | MIT | permissive | https://github.com/rails/rails/blob/main/MIT-LICENSE |
406f38e1a9ba4f369dbe0273 | rails/rails | activerecord/lib/active_record/integration.rb | ActiveRecord.Integration.raw_timestamp_to_cache_version | https://github.com/rails/rails/blob/85a8bc644be69908f05740a5886ec19cd3679df5/activerecord/lib/active_record/integration.rb#L198-L205 | train | ruby | Converts a raw database string to `:usec`
format.
Example:
timestamp = "2018-10-15 20:02:15.266505"
raw_timestamp_to_cache_version(timestamp)
# => "20181015200215266505"
PostgreSQL truncates trailing zeros,
https://github.com/postgres/postgres/commit/3e1beda2cde3495f41290e1ece5d544525810214
to account ... | def raw_timestamp_to_cache_version(timestamp)
key = timestamp.delete("- :.")
if key.length < 20
key.ljust(20, "0")
else
key
end
end | Converts a raw database string to `:usec`
format.
Example:
timestamp = "2018-10-15 20:02:15.266505"
raw_timestamp_to_cache_version(timestamp)
# => "20181015200215266505"
PostgreSQL truncates trailing zeros,
https://github.com/postgres/postgres/commit/3e1beda2cde3495f41290e1ece5d544525810214
to account ... | 152 | 357 | 189 | CodeSearchNet permissive-repo filter (dataset-level) | code_search_net | 2026-12-05 | 99a2e061e2cb623907eaeee8521c770d33f426890f3bc57fb491b34c3f8f04ad | MIT | permissive | https://github.com/rails/rails/blob/main/MIT-LICENSE |
14e5e7b4ff61d47dcd27a3ab | rails/rails | actionmailer/lib/action_mailer/mail_helper.rb | ActionMailer.MailHelper.block_format | https://github.com/rails/rails/blob/85a8bc644be69908f05740a5886ec19cd3679df5/actionmailer/lib/action_mailer/mail_helper.rb#L20-L30 | train | ruby | Take the text and format it, indented two spaces for each line, and
wrapped at 72 columns:
text = <<-TEXT
This is
the paragraph.
* item1 * item2
TEXT
block_format text
# => " This is the paragraph.\n\n * item1\n * item2\n" | def block_format(text)
formatted = text.split(/\n\r?\n/).collect { |paragraph|
format_paragraph(paragraph)
}.join("\n\n")
# Make list points stand on their own line
formatted.gsub!(/[ ]*([*]+) ([^*]*)/) { " #{$1} #{$2.strip}\n" }
formatted.gsub!(/[ ]*([#]+) ([^#]*)/) { " #{$1} #... | Take the text and format it, indented two spaces for each line, and
wrapped at 72 columns:
text = <<-TEXT
This is
the paragraph.
* item1 * item2
TEXT
block_format text
# => " This is the paragraph.\n\n * item1\n * item2\n"
def block_format(text)
formatted = text.split(/\n\r... | 190 | 261 | 360 | CodeSearchNet permissive-repo filter (dataset-level) | code_search_net | 2026-12-05 | cb42ddaa23745f7d5359fb9a501c1707985815e7eb1a1e446fb49c4639b68cbc | MIT | permissive | https://github.com/rails/rails/blob/main/MIT-LICENSE |
2f68ccb23e4ce90d4995b990 | rails/rails | actionmailer/lib/action_mailer/mail_helper.rb | ActionMailer.MailHelper.format_paragraph | https://github.com/rails/rails/blob/85a8bc644be69908f05740a5886ec19cd3679df5/actionmailer/lib/action_mailer/mail_helper.rb#L55-L70 | train | ruby | Returns +text+ wrapped at +len+ columns and indented +indent+ spaces.
By default column length +len+ equals 72 characters and indent
+indent+ equal two spaces.
my_text = 'Here is a sample text with more than 40 characters'
format_paragraph(my_text, 25, 4)
# => " Here is a sample text with\n more than... | def format_paragraph(text, len = 72, indent = 2)
sentences = [[]]
text.split.each do |word|
if sentences.first.present? && (sentences.last + [word]).join(" ").length > len
sentences << [word]
else
sentences.last << word
end
end
indentation = " " * in... | Returns +text+ wrapped at +len+ columns and indented +indent+ spaces.
By default column length +len+ equals 72 characters and indent
+indent+ equal two spaces.
my_text = 'Here is a sample text with more than 40 characters'
format_paragraph(my_text, 25, 4)
# => " Here is a sample text with\n more than... | 193 | 335 | 430 | CodeSearchNet permissive-repo filter (dataset-level) | code_search_net | 2026-12-05 | f46f7f36424d3bdeba4c2e83cde9802b9898a5643c233ea5e1d2f889101a86df | MIT | permissive | https://github.com/rails/rails/blob/main/MIT-LICENSE |
2ba420ca7450673e3a11cee5 | rails/rails | activerecord/lib/active_record/relation/batches.rb | ActiveRecord.Batches.find_each | https://github.com/rails/rails/blob/85a8bc644be69908f05740a5886ec19cd3679df5/activerecord/lib/active_record/relation/batches.rb#L67-L78 | train | ruby | Looping through a collection of records from the database
(using the Scoping::Named::ClassMethods.all method, for example)
is very inefficient since it will try to instantiate all the objects at once.
In that case, batch processing methods allow you to work
with the records in batches, thereby greatly reducing mem... | def find_each(start: nil, finish: nil, batch_size: 1000, error_on_ignore: nil)
if block_given?
find_in_batches(start: start, finish: finish, batch_size: batch_size, error_on_ignore: error_on_ignore) do |records|
records.each { |record| yield record }
end
else
enum_for(:find... | Looping through a collection of records from the database
(using the Scoping::Named::ClassMethods.all method, for example)
is very inefficient since it will try to instantiate all the objects at once.
In that case, batch processing methods allow you to work
with the records in batches, thereby greatly reducing mem... | 700 | 2,336 | 526 | CodeSearchNet permissive-repo filter (dataset-level) | code_search_net | 2026-12-05 | 593720aa849eaaa230f466201d2a47daa75cda8258be548a8f5743d9ddbf4a6b | MIT | permissive | https://github.com/rails/rails/blob/main/MIT-LICENSE |
e4a2526933d208bd3bbe4468 | rails/rails | activerecord/lib/active_record/relation/batches.rb | ActiveRecord.Batches.find_in_batches | https://github.com/rails/rails/blob/85a8bc644be69908f05740a5886ec19cd3679df5/activerecord/lib/active_record/relation/batches.rb#L126-L138 | train | ruby | Yields each batch of records that was found by the find options as
an array.
Person.where("age > 21").find_in_batches do |group|
sleep(50) # Make sure it doesn't get too crowded in there!
group.each { |person| person.party_all_night! }
end
If you do not provide a block to #find_in_batches, it will r... | def find_in_batches(start: nil, finish: nil, batch_size: 1000, error_on_ignore: nil)
relation = self
unless block_given?
return to_enum(:find_in_batches, start: start, finish: finish, batch_size: batch_size, error_on_ignore: error_on_ignore) do
total = apply_limits(relation, start, finish)... | Yields each batch of records that was found by the find options as
an array.
Person.where("age > 21").find_in_batches do |group|
sleep(50) # Make sure it doesn't get too crowded in there!
group.each { |person| person.party_all_night! }
end
If you do not provide a block to #find_in_batches, it will r... | 627 | 1,974 | 553 | CodeSearchNet permissive-repo filter (dataset-level) | code_search_net | 2026-12-05 | df5bbb465a62f2c091d4aa34bda379b59d09e5daa0e0191cbbfaa56783193646 | MIT | permissive | https://github.com/rails/rails/blob/main/MIT-LICENSE |
342b91c6e2c2ed43f704683b | rails/rails | activerecord/lib/active_record/relation/batches.rb | ActiveRecord.Batches.in_batches | https://github.com/rails/rails/blob/85a8bc644be69908f05740a5886ec19cd3679df5/activerecord/lib/active_record/relation/batches.rb#L201-L258 | train | ruby | Yields ActiveRecord::Relation objects to work with a batch of records.
Person.where("age > 21").in_batches do |relation|
relation.delete_all
sleep(10) # Throttle the delete queries
end
If you do not provide a block to #in_batches, it will return a
BatchEnumerator which is enumerable.
Person.in_b... | def in_batches(of: 1000, start: nil, finish: nil, load: false, error_on_ignore: nil)
relation = self
unless block_given?
return BatchEnumerator.new(of: of, start: start, finish: finish, relation: self)
end
if arel.orders.present?
act_on_ignored_order(error_on_ignore)
end
... | Yields ActiveRecord::Relation objects to work with a batch of records.
Person.where("age > 21").in_batches do |relation|
relation.delete_all
sleep(10) # Throttle the delete queries
end
If you do not provide a block to #in_batches, it will return a
BatchEnumerator which is enumerable.
Person.in_b... | 959 | 2,468 | 1,814 | CodeSearchNet permissive-repo filter (dataset-level) | code_search_net | 2026-12-05 | 38e481a3cd5e91fc93baa6a0b28f6592d899632d0906f509c8e4f32710640a08 | MIT | permissive | https://github.com/rails/rails/blob/main/MIT-LICENSE |
f4b6c700a012d816cfb4c83c | rails/rails | actionpack/lib/action_controller/metal/data_streaming.rb | ActionController.DataStreaming.send_file | https://github.com/rails/rails/blob/85a8bc644be69908f05740a5886ec19cd3679df5/actionpack/lib/action_controller/metal/data_streaming.rb#L69-L78 | train | ruby | Sends the file. This uses a server-appropriate method (such as X-Sendfile)
via the Rack::Sendfile middleware. The header to use is set via
+config.action_dispatch.x_sendfile_header+.
Your server can also configure this for you by setting the X-Sendfile-Type header.
Be careful to sanitize the path parameter if it i... | def send_file(path, options = {}) #:doc:
raise MissingFile, "Cannot read file #{path}" unless File.file?(path) && File.readable?(path)
options[:filename] ||= File.basename(path) unless options[:url_based_filename]
send_file_headers! options
self.status = options[:status] || 200
... | Sends the file. This uses a server-appropriate method (such as X-Sendfile)
via the Rack::Sendfile middleware. The header to use is set via
+config.action_dispatch.x_sendfile_header+.
Your server can also configure this for you by setting the X-Sendfile-Type header.
Be careful to sanitize the path parameter if it i... | 725 | 2,569 | 436 | CodeSearchNet permissive-repo filter (dataset-level) | code_search_net | 2026-12-05 | ce98d88c75a9983184397296b46957cb2e7555ee27251328d2302cdd22b65fba | MIT | permissive | https://github.com/rails/rails/blob/main/MIT-LICENSE |
2b46b1952edb0c037e274753 | rails/rails | actionpack/lib/action_controller/metal/data_streaming.rb | ActionController.DataStreaming.send_data | https://github.com/rails/rails/blob/85a8bc644be69908f05740a5886ec19cd3679df5/actionpack/lib/action_controller/metal/data_streaming.rb#L109-L112 | train | ruby | Sends the given binary data to the browser. This method is similar to
<tt>render plain: data</tt>, but also allows you to specify whether
the browser should display the response as a file attachment (i.e. in a
download dialog) or as inline data. You may also set the content type,
the file name, and other things.
... | def send_data(data, options = {}) #:doc:
send_file_headers! options
render options.slice(:status, :content_type).merge(body: data)
end | Sends the given binary data to the browser. This method is similar to
<tt>render plain: data</tt>, but also allows you to specify whether
the browser should display the response as a file attachment (i.e. in a
download dialog) or as inline data. You may also set the content type,
the file name, and other things.
... | 360 | 1,403 | 156 | CodeSearchNet permissive-repo filter (dataset-level) | code_search_net | 2026-12-05 | c636ae97232912cbb8a015b6e06f411933b9dff532e578813ef06fe3b980c861 | MIT | permissive | https://github.com/rails/rails/blob/main/MIT-LICENSE |
2313dc208adfe081e5cb3db3 | rails/rails | activemodel/lib/active_model/dirty.rb | ActiveModel.Dirty.restore_attribute! | https://github.com/rails/rails/blob/85a8bc644be69908f05740a5886ec19cd3679df5/activemodel/lib/active_model/dirty.rb#L272-L278 | train | ruby | Dispatch target for <tt>restore_*!</tt> attribute methods. | def restore_attribute!(attr_name)
attr_name = attr_name.to_s
if attribute_changed?(attr_name)
__send__("#{attr_name}=", attribute_was(attr_name))
clear_attribute_change(attr_name)
end
end | Dispatch target for <tt>restore_*!</tt> attribute methods.
def restore_attribute!(attr_name)
attr_name = attr_name.to_s
if attribute_changed?(attr_name)
__send__("#{attr_name}=", attribute_was(attr_name))
clear_attribute_change(attr_name)
end
end | 64 | 58 | 237 | CodeSearchNet permissive-repo filter (dataset-level) | code_search_net | 2026-12-05 | e7b9659a7e7d6e3f883b80738fc11d45e80e255dd219ceb5e0dfeaaaf2d0a39f | MIT | permissive | https://github.com/rails/rails/blob/main/MIT-LICENSE |
a5d118c068a0eddba43d4bc4 | rails/rails | activemodel/lib/active_model/error.rb | ActiveModel.Error.match? | https://github.com/rails/rails/blob/85a8bc644be69908f05740a5886ec19cd3679df5/activemodel/lib/active_model/error.rb#L46-L58 | train | ruby | See if error matches provided +attribute+, +type+ and +options+. | def match?(attribute, type = nil, **options)
if @attribute != attribute || (type && @type != type)
return false
end
options.each do |key, value|
if @options[key] != value
return false
end
end
true
end | See if error matches provided +attribute+, +type+ and +options+.
def match?(attribute, type = nil, **options)
if @attribute != attribute || (type && @type != type)
return false
end
options.each do |key, value|
if @options[key] != value
return false
end
end
... | 83 | 64 | 270 | CodeSearchNet permissive-repo filter (dataset-level) | code_search_net | 2026-12-05 | 56a5740c42ae547b37e5e800b7254648d87af61a331dc74bc51896ab236f58dd | MIT | permissive | https://github.com/rails/rails/blob/main/MIT-LICENSE |
44af9cbb0d7a41011b2e6e5d | rails/rails | activesupport/lib/active_support/xml_mini/nokogiri.rb | ActiveSupport.XmlMini_Nokogiri.parse | https://github.com/rails/rails/blob/85a8bc644be69908f05740a5886ec19cd3679df5/activesupport/lib/active_support/xml_mini/nokogiri.rb#L19-L31 | train | ruby | Parse an XML Document string or IO into a simple hash using libxml / nokogiri.
data::
XML Document string or IO to parse | def parse(data)
if !data.respond_to?(:read)
data = StringIO.new(data || "")
end
if data.eof?
{}
else
doc = Nokogiri::XML(data)
raise doc.errors.first if doc.errors.length > 0
doc.to_hash
end
end | Parse an XML Document string or IO into a simple hash using libxml / nokogiri.
data::
XML Document string or IO to parse
def parse(data)
if !data.respond_to?(:read)
data = StringIO.new(data || "")
end
if data.eof?
{}
else
doc = Nokogiri::XML(data)
raise doc.... | 98 | 124 | 269 | CodeSearchNet permissive-repo filter (dataset-level) | code_search_net | 2026-12-05 | b5709ca54129e34fa191721aee9aa5680798ffe1fe196e141c91dda298f12c97 | MIT | permissive | https://github.com/rails/rails/blob/main/MIT-LICENSE |
83b196c4176e2eadb6194be8 | rails/rails | activerecord/lib/active_record/connection_adapters/sqlite3_adapter.rb | ActiveRecord.ConnectionHandling.sqlite3_connection | https://github.com/rails/rails/blob/85a8bc644be69908f05740a5886ec19cd3679df5/activerecord/lib/active_record/connection_adapters/sqlite3_adapter.rb#L18-L47 | train | ruby | :nodoc: | def sqlite3_connection(config)
config = config.symbolize_keys
# Require database.
unless config[:database]
raise ArgumentError, "No database file specified. Missing argument: database"
end
# Allow database path relative to Rails.root, but only if the database
# path is not ... | :nodoc:
def sqlite3_connection(config)
config = config.symbolize_keys
# Require database.
unless config[:database]
raise ArgumentError, "No database file specified. Missing argument: database"
end
# Allow database path relative to Rails.root, but only if the database
# pat... | 226 | 7 | 1,030 | CodeSearchNet permissive-repo filter (dataset-level) | code_search_net | 2026-12-05 | 998dccd0ff1dcb27a9c368fcd184cf0211d5716a53a31b2611ca40c9685eb23b | MIT | permissive | https://github.com/rails/rails/blob/main/MIT-LICENSE |
cbcd8d1fa43af18500d60af3 | rails/rails | activesupport/lib/active_support/hash_with_indifferent_access.rb | ActiveSupport.HashWithIndifferentAccess.update | https://github.com/rails/rails/blob/85a8bc644be69908f05740a5886ec19cd3679df5/activesupport/lib/active_support/hash_with_indifferent_access.rb#L124-L136 | train | ruby | Updates the receiver in-place, merging in the hash passed as argument:
hash_1 = ActiveSupport::HashWithIndifferentAccess.new
hash_1[:key] = 'value'
hash_2 = ActiveSupport::HashWithIndifferentAccess.new
hash_2[:key] = 'New Value!'
hash_1.update(hash_2) # => {"key"=>"New Value!"}
The argument can be e... | def update(other_hash)
if other_hash.is_a? HashWithIndifferentAccess
super(other_hash)
else
other_hash.to_hash.each_pair do |key, value|
if block_given? && key?(key)
value = yield(convert_key(key), self[key], value)
end
regular_writer(convert_key(key... | Updates the receiver in-place, merging in the hash passed as argument:
hash_1 = ActiveSupport::HashWithIndifferentAccess.new
hash_1[:key] = 'value'
hash_2 = ActiveSupport::HashWithIndifferentAccess.new
hash_2[:key] = 'New Value!'
hash_1.update(hash_2) # => {"key"=>"New Value!"}
The argument can be e... | 350 | 998 | 387 | CodeSearchNet permissive-repo filter (dataset-level) | code_search_net | 2026-12-05 | 0fb314920d1e49f80d6a875287b65eb896ef261e79b6646e24145061cfa2f746 | MIT | permissive | https://github.com/rails/rails/blob/main/MIT-LICENSE |
f2d5de62ec148a7ab22a0bf2 | rails/rails | actionview/lib/action_view/renderer/partial_renderer/collection_caching.rb | ActionView.CollectionCaching.fetch_or_cache_partial | https://github.com/rails/rails/blob/85a8bc644be69908f05740a5886ec19cd3679df5/actionview/lib/action_view/renderer/partial_renderer/collection_caching.rb#L90-L101 | train | ruby | `order_by` is an enumerable object containing keys of the cache,
all keys are passed in whether found already or not.
`cached_partials` is a hash. If the value exists
it represents the rendered partial from the cache
otherwise `Hash#fetch` will take the value of its block.
This method expects a block that will ... | def fetch_or_cache_partial(cached_partials, template, order_by:)
order_by.each_with_object({}) do |cache_key, hash|
hash[cache_key] =
if content = cached_partials[cache_key]
build_rendered_template(content, template)
else
yield.tap do |rend... | `order_by` is an enumerable object containing keys of the cache,
all keys are passed in whether found already or not.
`cached_partials` is a hash. If the value exists
it represents the rendered partial from the cache
otherwise `Hash#fetch` will take the value of its block.
This method expects a block that will ... | 239 | 688 | 470 | CodeSearchNet permissive-repo filter (dataset-level) | code_search_net | 2026-12-05 | 067c60f2e438a6ce456941e74db543e4e7a176d657d92e01b57f1b4834c622e8 | MIT | permissive | https://github.com/rails/rails/blob/main/MIT-LICENSE |
d0f2f01191e63d1b5b9a96ce | rails/rails | activesupport/lib/active_support/callbacks.rb | ActiveSupport.Callbacks.run_callbacks | https://github.com/rails/rails/blob/85a8bc644be69908f05740a5886ec19cd3679df5/activesupport/lib/active_support/callbacks.rb#L97-L142 | train | ruby | Runs the callbacks for the given event.
Calls the before and around callbacks in the order they were set, yields
the block (if given one), and then runs the after callbacks in reverse
order.
If the callback chain was halted, returns +false+. Otherwise returns the
result of the block, +nil+ if no callbacks have b... | def run_callbacks(kind)
callbacks = __callbacks[kind.to_sym]
if callbacks.empty?
yield if block_given?
else
env = Filters::Environment.new(self, false, nil)
next_sequence = callbacks.compile
invoke_sequence = Proc.new do
skipped = nil
while true
... | Runs the callbacks for the given event.
Calls the before and around callbacks in the order they were set, yields
the block (if given one), and then runs the after callbacks in reverse
order.
If the callback chain was halted, returns +false+. Otherwise returns the
result of the block, +nil+ if no callbacks have b... | 468 | 830 | 1,471 | CodeSearchNet permissive-repo filter (dataset-level) | code_search_net | 2026-12-05 | debae32c987a9d2f4eb9a58d0937edbf8b245e0defcad37cc543abc1214e7857 | MIT | permissive | https://github.com/rails/rails/blob/main/MIT-LICENSE |
2629c205990e0c847714990e | rails/rails | railties/lib/rails/source_annotation_extractor.rb | Rails.SourceAnnotationExtractor.find | https://github.com/rails/rails/blob/85a8bc644be69908f05740a5886ec19cd3679df5/railties/lib/rails/source_annotation_extractor.rb#L105-L107 | train | ruby | Returns a hash that maps filenames under +dirs+ (recursively) to arrays
with their annotations. | def find(dirs)
dirs.inject({}) { |h, dir| h.update(find_in(dir)) }
end | Returns a hash that maps filenames under +dirs+ (recursively) to arrays
with their annotations.
def find(dirs)
dirs.inject({}) { |h, dir| h.update(find_in(dir)) }
end | 46 | 96 | 80 | CodeSearchNet permissive-repo filter (dataset-level) | code_search_net | 2026-12-05 | 740ede1fb3f90c2b5bc30218afdeff6730786aac426ad73a93e31dbdb1a88812 | MIT | permissive | https://github.com/rails/rails/blob/main/MIT-LICENSE |
fadfbc9ee6d58fe14435df9d | rails/rails | railties/lib/rails/source_annotation_extractor.rb | Rails.SourceAnnotationExtractor.find_in | https://github.com/rails/rails/blob/85a8bc644be69908f05740a5886ec19cd3679df5/railties/lib/rails/source_annotation_extractor.rb#L113-L134 | train | ruby | Returns a hash that maps filenames under +dir+ (recursively) to arrays
with their annotations. Files with extensions registered in
<tt>Rails::SourceAnnotationExtractor::Annotation.extensions</tt> are
taken into account. Only files with annotations are included. | def find_in(dir)
results = {}
Dir.glob("#{dir}/*") do |item|
next if File.basename(item)[0] == ?.
if File.directory?(item)
results.update(find_in(item))
else
extension = Annotation.extensions.detect do |regexp, _block|
regexp.match(item)
en... | Returns a hash that maps filenames under +dir+ (recursively) to arrays
with their annotations. Files with extensions registered in
<tt>Rails::SourceAnnotationExtractor::Annotation.extensions</tt> are
taken into account. Only files with annotations are included.
def find_in(dir)
results = {}
Dir.glob("#... | 165 | 264 | 530 | CodeSearchNet permissive-repo filter (dataset-level) | code_search_net | 2026-12-05 | 5ade759d878fb2652d6f95a0a65aadb1e824c83aa9f716ddbd9289512b5e715b | MIT | permissive | https://github.com/rails/rails/blob/main/MIT-LICENSE |
0b95bfc6f89b10aee7447179 | rails/rails | railties/lib/rails/source_annotation_extractor.rb | Rails.SourceAnnotationExtractor.extract_annotations_from | https://github.com/rails/rails/blob/85a8bc644be69908f05740a5886ec19cd3679df5/railties/lib/rails/source_annotation_extractor.rb#L139-L147 | train | ruby | If +file+ is the filename of a file that contains annotations this method returns
a hash with a single entry that maps +file+ to an array of its annotations.
Otherwise it returns an empty hash. | def extract_annotations_from(file, pattern)
lineno = 0
result = File.readlines(file, encoding: Encoding::BINARY).inject([]) do |list, line|
lineno += 1
next list unless line =~ pattern
list << Annotation.new(lineno, $1, $2)
end
result.empty? ? {} : { file => result }
... | If +file+ is the filename of a file that contains annotations this method returns
a hash with a single entry that maps +file+ to an array of its annotations.
Otherwise it returns an empty hash.
def extract_annotations_from(file, pattern)
lineno = 0
result = File.readlines(file, encoding: Encoding::BINARY... | 125 | 195 | 323 | CodeSearchNet permissive-repo filter (dataset-level) | code_search_net | 2026-12-05 | 823be9be5241e27c2e6ec57a3cbc37ae8ab8b5ab0bd0377a38f1e7f31b20aa23 | MIT | permissive | https://github.com/rails/rails/blob/main/MIT-LICENSE |
794b20e5fc67c705d769fda2 | rails/rails | actionpack/lib/action_controller/metal/params_wrapper.rb | ActionController.ParamsWrapper._wrapper_enabled? | https://github.com/rails/rails/blob/85a8bc644be69908f05740a5886ec19cd3679df5/actionpack/lib/action_controller/metal/params_wrapper.rb#L275-L280 | train | ruby | Checks if we should perform parameters wrapping. | def _wrapper_enabled?
return false unless request.has_content_type?
ref = request.content_mime_type.ref
_wrapper_formats.include?(ref) && _wrapper_key && !request.parameters.key?(_wrapper_key)
end | Checks if we should perform parameters wrapping.
def _wrapper_enabled?
return false unless request.has_content_type?
ref = request.content_mime_type.ref
_wrapper_formats.include?(ref) && _wrapper_key && !request.parameters.key?(_wrapper_key)
end | 55 | 48 | 227 | CodeSearchNet permissive-repo filter (dataset-level) | code_search_net | 2026-12-05 | 90bded890312320224a209d188c05ce23395cbcd3a9832e0ef39a56c411db281 | MIT | permissive | https://github.com/rails/rails/blob/main/MIT-LICENSE |
485fba614cf79b99a5a7d8f9 | rails/rails | railties/lib/rails/console/app.rb | Rails.ConsoleMethods.new_session | https://github.com/rails/rails/blob/85a8bc644be69908f05740a5886ec19cd3679df5/railties/lib/rails/console/app.rb#L19-L29 | train | ruby | create a new session. If a block is given, the new session will be yielded
to the block before being returned. | def new_session
app = Rails.application
session = ActionDispatch::Integration::Session.new(app)
yield session if block_given?
# This makes app.url_for and app.foo_path available in the console
session.extend(app.routes.url_helpers)
session.extend(app.routes.mounted_helpers)
s... | create a new session. If a block is given, the new session will be yielded
to the block before being returned.
def new_session
app = Rails.application
session = ActionDispatch::Integration::Session.new(app)
yield session if block_given?
# This makes app.url_for and app.foo_path available in t... | 92 | 111 | 334 | CodeSearchNet permissive-repo filter (dataset-level) | code_search_net | 2026-12-05 | ad0e819ad5ff982f837562c2f7988112db46b9008ca996b70f07df4a044806af | MIT | permissive | https://github.com/rails/rails/blob/main/MIT-LICENSE |
d719b7668e6472c429f5a5b8 | rails/rails | railties/lib/rails/console/app.rb | Rails.ConsoleMethods.reload! | https://github.com/rails/rails/blob/85a8bc644be69908f05740a5886ec19cd3679df5/railties/lib/rails/console/app.rb#L32-L36 | train | ruby | reloads the environment | def reload!(print = true)
puts "Reloading..." if print
Rails.application.reloader.reload!
true
end | reloads the environment
def reload!(print = true)
puts "Reloading..." if print
Rails.application.reloader.reload!
true
end | 34 | 23 | 120 | CodeSearchNet permissive-repo filter (dataset-level) | code_search_net | 2026-12-05 | aad52685cca48605b84a0a530c40dc2a49e8b655e551b1f931f9df3f68816a6b | MIT | permissive | https://github.com/rails/rails/blob/main/MIT-LICENSE |
1c232c0f56ab348795615a10 | rails/rails | actionview/lib/action_view/record_identifier.rb | ActionView.RecordIdentifier.dom_id | https://github.com/rails/rails/blob/85a8bc644be69908f05740a5886ec19cd3679df5/actionview/lib/action_view/record_identifier.rb#L89-L95 | train | ruby | The DOM id convention is to use the singular form of an object or class with the id following an underscore.
If no id is found, prefix with "new_" instead.
dom_id(Post.find(45)) # => "post_45"
dom_id(Post.new) # => "new_post"
If you need to address multiple instances of the same class in the ... | def dom_id(record, prefix = nil)
if record_id = record_key_for_dom_id(record)
"#{dom_class(record, prefix)}#{JOIN}#{record_id}"
else
dom_class(record, prefix || NEW)
end
end | The DOM id convention is to use the singular form of an object or class with the id following an underscore.
If no id is found, prefix with "new_" instead.
dom_id(Post.find(45)) # => "post_45"
dom_id(Post.new) # => "new_post"
If you need to address multiple instances of the same class in the ... | 175 | 461 | 211 | CodeSearchNet permissive-repo filter (dataset-level) | code_search_net | 2026-12-05 | 9b8ccbdc89e1de4ea397cf841e4da30c6aea6c18abd3b19a90ca00ba1410ecbd | MIT | permissive | https://github.com/rails/rails/blob/main/MIT-LICENSE |
75f0a60b2e8b83afa38320fa | rails/rails | actionview/lib/action_view/record_identifier.rb | ActionView.RecordIdentifier.record_key_for_dom_id | https://github.com/rails/rails/blob/85a8bc644be69908f05740a5886ec19cd3679df5/actionview/lib/action_view/record_identifier.rb#L107-L110 | train | ruby | Returns a string representation of the key attribute(s) that is suitable for use in an HTML DOM id.
This can be overwritten to customize the default generated string representation if desired.
If you need to read back a key from a dom_id in order to query for the underlying database record,
you should write a helper... | def record_key_for_dom_id(record) # :doc:
key = convert_to_model(record).to_key
key ? key.join(JOIN) : key
end | Returns a string representation of the key attribute(s) that is suitable for use in an HTML DOM id.
This can be overwritten to customize the default generated string representation if desired.
If you need to read back a key from a dom_id in order to query for the underlying database record,
you should write a helper... | 189 | 768 | 126 | CodeSearchNet permissive-repo filter (dataset-level) | code_search_net | 2026-12-05 | d0f133582d578905427c6ecbfd932b17777c79b8f426ab4371f08a6fd1db408e | MIT | permissive | https://github.com/rails/rails/blob/main/MIT-LICENSE |
80be705f324d22ea875b6a82 | rails/rails | activesupport/lib/active_support/concern.rb | ActiveSupport.Concern.included | https://github.com/rails/rails/blob/85a8bc644be69908f05740a5886ec19cd3679df5/activesupport/lib/active_support/concern.rb#L129-L141 | train | ruby | Evaluate given block in context of base class,
so that you can write class macros here.
When you define more than one +included+ block, it raises an exception. | def included(base = nil, &block)
if base.nil?
if instance_variable_defined?(:@_included_block)
if @_included_block.source_location != block.source_location
raise MultipleIncludedBlocks
end
else
@_included_block = block
end
else
super
... | Evaluate given block in context of base class,
so that you can write class macros here.
When you define more than one +included+ block, it raises an exception.
def included(base = nil, &block)
if base.nil?
if instance_variable_defined?(:@_included_block)
if @_included_block.source_location !=... | 104 | 161 | 337 | CodeSearchNet permissive-repo filter (dataset-level) | code_search_net | 2026-12-05 | bf4d4dbe67218e27912770f2b1b9fd28f8be6196beae06bf2c5aacc3df63391a | MIT | permissive | https://github.com/rails/rails/blob/main/MIT-LICENSE |
2da591da467ab6900a682fe9 | rails/rails | activesupport/lib/active_support/concern.rb | ActiveSupport.Concern.class_methods | https://github.com/rails/rails/blob/85a8bc644be69908f05740a5886ec19cd3679df5/activesupport/lib/active_support/concern.rb#L163-L169 | train | ruby | Define class methods from given block.
You can define private class methods as well.
module Example
extend ActiveSupport::Concern
class_methods do
def foo; puts 'foo'; end
private
def bar; puts 'bar'; end
end
end
class Buzz
include Example
end
Buzz.foo # =... | def class_methods(&class_methods_module_definition)
mod = const_defined?(:ClassMethods, false) ?
const_get(:ClassMethods) :
const_set(:ClassMethods, Module.new)
mod.module_eval(&class_methods_module_definition)
end | Define class methods from given block.
You can define private class methods as well.
module Example
extend ActiveSupport::Concern
class_methods do
def foo; puts 'foo'; end
private
def bar; puts 'bar'; end
end
end
class Buzz
include Example
end
Buzz.foo # =... | 150 | 402 | 247 | CodeSearchNet permissive-repo filter (dataset-level) | code_search_net | 2026-12-05 | 8bdeaefe6a339976a1fbd4a545fbe4b6a8d367ffc642ba835658ae7f2f6eef4a | MIT | permissive | https://github.com/rails/rails/blob/main/MIT-LICENSE |
19446f1e1383be3af76d93da | rails/rails | actionpack/lib/abstract_controller/caching.rb | AbstractController.Caching.cache | https://github.com/rails/rails/blob/85a8bc644be69908f05740a5886ec19cd3679df5/actionpack/lib/abstract_controller/caching.rb#L58-L64 | train | ruby | Convenience accessor. | def cache(key, options = {}, &block) # :doc:
if cache_configured?
cache_store.fetch(ActiveSupport::Cache.expand_cache_key(key, :controller), options, &block)
else
yield
end
end | Convenience accessor.
def cache(key, options = {}, &block) # :doc:
if cache_configured?
cache_store.fetch(ActiveSupport::Cache.expand_cache_key(key, :controller), options, &block)
else
yield
end
end | 57 | 21 | 226 | CodeSearchNet permissive-repo filter (dataset-level) | code_search_net | 2026-12-05 | 8c0a072c680aeddad4a670c61a75ecaa6986336cffee214c4a65f517f4c665b7 | MIT | permissive | https://github.com/rails/rails/blob/main/MIT-LICENSE |
7e89e5f9d8dfc837d345fbdf | rails/rails | activesupport/lib/active_support/message_verifier.rb | ActiveSupport.MessageVerifier.valid_message? | https://github.com/rails/rails/blob/85a8bc644be69908f05740a5886ec19cd3679df5/activesupport/lib/active_support/message_verifier.rb#L122-L127 | train | ruby | Checks if a signed message could have been generated by signing an object
with the +MessageVerifier+'s secret.
verifier = ActiveSupport::MessageVerifier.new 's3Krit'
signed_message = verifier.generate 'a private message'
verifier.valid_message?(signed_message) # => true
tampered_message = signed_message.... | def valid_message?(signed_message)
return if signed_message.nil? || !signed_message.valid_encoding? || signed_message.blank?
data, digest = signed_message.split("--")
data.present? && digest.present? && ActiveSupport::SecurityUtils.secure_compare(digest, generate_digest(data))
end | Checks if a signed message could have been generated by signing an object
with the +MessageVerifier+'s secret.
verifier = ActiveSupport::MessageVerifier.new 's3Krit'
signed_message = verifier.generate 'a private message'
verifier.valid_message?(signed_message) # => true
tampered_message = signed_message.... | 152 | 428 | 304 | CodeSearchNet permissive-repo filter (dataset-level) | code_search_net | 2026-12-05 | 33fa23f1dc85af3610112d1dfa223b8f09f34b877b29a884dd11459d1c747f9b | MIT | permissive | https://github.com/rails/rails/blob/main/MIT-LICENSE |
1c9ec901283254d343b55554 | rails/rails | activesupport/lib/active_support/message_verifier.rb | ActiveSupport.MessageVerifier.verified | https://github.com/rails/rails/blob/85a8bc644be69908f05740a5886ec19cd3679df5/activesupport/lib/active_support/message_verifier.rb#L150-L161 | train | ruby | Decodes the signed message using the +MessageVerifier+'s secret.
verifier = ActiveSupport::MessageVerifier.new 's3Krit'
signed_message = verifier.generate 'a private message'
verifier.verified(signed_message) # => 'a private message'
Returns +nil+ if the message was not signed with the same secret.
oth... | def verified(signed_message, purpose: nil, **)
if valid_message?(signed_message)
begin
data = signed_message.split("--")[0]
message = Messages::Metadata.verify(decode(data), purpose)
@serializer.load(message) if message
rescue ArgumentError => argument_error
... | Decodes the signed message using the +MessageVerifier+'s secret.
verifier = ActiveSupport::MessageVerifier.new 's3Krit'
signed_message = verifier.generate 'a private message'
verifier.verified(signed_message) # => 'a private message'
Returns +nil+ if the message was not signed with the same secret.
oth... | 305 | 837 | 426 | CodeSearchNet permissive-repo filter (dataset-level) | code_search_net | 2026-12-05 | 13198167c3b376d264b27bbf52738d39abb4f7a75c19a8b1d51837af7dfbe6b5 | MIT | permissive | https://github.com/rails/rails/blob/main/MIT-LICENSE |
5fe0efe2db5a7fef4ae16160 | rails/rails | activesupport/lib/active_support/message_verifier.rb | ActiveSupport.MessageVerifier.generate | https://github.com/rails/rails/blob/85a8bc644be69908f05740a5886ec19cd3679df5/activesupport/lib/active_support/message_verifier.rb#L186-L189 | train | ruby | Generates a signed message for the provided value.
The message is signed with the +MessageVerifier+'s secret. Without knowing
the secret, the original value cannot be extracted from the message.
verifier = ActiveSupport::MessageVerifier.new 's3Krit'
verifier.generate 'a private message' # => "BAhJIhRwcml2YXRl... | def generate(value, expires_at: nil, expires_in: nil, purpose: nil)
data = encode(Messages::Metadata.wrap(@serializer.dump(value), expires_at: expires_at, expires_in: expires_in, purpose: purpose))
"#{data}--#{generate_digest(data)}"
end | Generates a signed message for the provided value.
The message is signed with the +MessageVerifier+'s secret. Without knowing
the secret, the original value cannot be extracted from the message.
verifier = ActiveSupport::MessageVerifier.new 's3Krit'
verifier.generate 'a private message' # => "BAhJIhRwcml2YXRl... | 171 | 383 | 253 | CodeSearchNet permissive-repo filter (dataset-level) | code_search_net | 2026-12-05 | be35b5cab654bc9c2258c31360b98025daff9278c19e3ee4c7b4900d0a8a87d0 | MIT | permissive | https://github.com/rails/rails/blob/main/MIT-LICENSE |
1362c0cd1f851bafc1f68ae5 | rails/rails | activejob/lib/active_job/core.rb | ActiveJob.Core.serialize | https://github.com/rails/rails/blob/85a8bc644be69908f05740a5886ec19cd3679df5/activejob/lib/active_job/core.rb#L92-L106 | train | ruby | Creates a new job instance. Takes the arguments that will be
passed to the perform method.
Returns a hash with the job data that can safely be passed to the
queuing adapter. | def serialize
{
"job_class" => self.class.name,
"job_id" => job_id,
"provider_job_id" => provider_job_id,
"queue_name" => queue_name,
"priority" => priority,
"arguments" => serialize_arguments_if_needed(arguments),
"executions" => executions,
... | Creates a new job instance. Takes the arguments that will be
passed to the perform method.
Returns a hash with the job data that can safely be passed to the
queuing adapter.
def serialize
{
"job_class" => self.class.name,
"job_id" => job_id,
"provider_job_id" => provider_job_id,
... | 166 | 176 | 518 | CodeSearchNet permissive-repo filter (dataset-level) | code_search_net | 2026-12-05 | e830fae56ae58e1bc10fe7cebe578c4d0e4a3059d10d62f78c2a8b1eb8f6880d | MIT | permissive | https://github.com/rails/rails/blob/main/MIT-LICENSE |
babc3f5eaa123436f4fa3db6 | rails/rails | activejob/lib/active_job/core.rb | ActiveJob.Core.deserialize | https://github.com/rails/rails/blob/85a8bc644be69908f05740a5886ec19cd3679df5/activejob/lib/active_job/core.rb#L134-L145 | train | ruby | Attaches the stored job data to the current instance. Receives a hash
returned from +serialize+
==== Examples
class DeliverWebhookJob < ActiveJob::Base
attr_writer :attempt_number
def attempt_number
@attempt_number ||= 0
end
def serialize
super.merge('attempt_number' =>... | def deserialize(job_data)
self.job_id = job_data["job_id"]
self.provider_job_id = job_data["provider_job_id"]
self.queue_name = job_data["queue_name"]
self.priority = job_data["priority"]
self.serialized_arguments = job_data["arguments"]
self.... | Attaches the stored job data to the current instance. Receives a hash
returned from +serialize+
==== Examples
class DeliverWebhookJob < ActiveJob::Base
attr_writer :attempt_number
def attempt_number
@attempt_number ||= 0
end
def serialize
super.merge('attempt_number' =>... | 280 | 606 | 650 | CodeSearchNet permissive-repo filter (dataset-level) | code_search_net | 2026-12-05 | 8c324b60ef7c51236cacf949cecf728911250eea45f57cff2291c19db4b7a3f3 | MIT | permissive | https://github.com/rails/rails/blob/main/MIT-LICENSE |
4a5d4a052d2a11974f74ecc6 | rails/rails | activesupport/lib/active_support/evented_file_update_checker.rb | ActiveSupport.EventedFileUpdateChecker.updated? | https://github.com/rails/rails/blob/85a8bc644be69908f05740a5886ec19cd3679df5/activesupport/lib/active_support/evented_file_update_checker.rb#L71-L93 | train | ruby | :nodoc: all | def updated?
@boot_mutex.synchronize do
if @pid != Process.pid
boot!
@pid = Process.pid
@updated.make_true
end
end
if @missing.any?(&:exist?)
@boot_mutex.synchronize do
appeared, @missing = @missing.partition(&:exist?)
shutdown... | :nodoc: all
def updated?
@boot_mutex.synchronize do
if @pid != Process.pid
boot!
@pid = Process.pid
@updated.make_true
end
end
if @missing.any?(&:exist?)
@boot_mutex.synchronize do
appeared, @missing = @missing.partition(&:exist?)
... | 108 | 11 | 447 | CodeSearchNet permissive-repo filter (dataset-level) | code_search_net | 2026-12-05 | e6014b0cdc1f8829e2ab851e093cfbfb9e4926a634363016b91fbba03a39fbc5 | MIT | permissive | https://github.com/rails/rails/blob/main/MIT-LICENSE |
7809d5395cf1bc4f52640c93 | rails/rails | actionpack/lib/action_dispatch/middleware/static.rb | ActionDispatch.FileHandler.match? | https://github.com/rails/rails/blob/85a8bc644be69908f05740a5886ec19cd3679df5/actionpack/lib/action_dispatch/middleware/static.rb#L30-L47 | train | ruby | Takes a path to a file. If the file is found, has valid encoding, and has
correct read permissions, the return value is a URI-escaped string
representing the filename. Otherwise, false is returned.
Used by the +Static+ class to check the existence of a valid file
in the server's +public/+ directory (see Static#cal... | def match?(path)
path = ::Rack::Utils.unescape_path path
return false unless ::Rack::Utils.valid_path? path
path = ::Rack::Utils.clean_path_info path
paths = [path, "#{path}#{ext}", "#{path}/#{@index}#{ext}"]
if match = paths.detect { |p|
path = File.join(@root, p.b)
begi... | Takes a path to a file. If the file is found, has valid encoding, and has
correct read permissions, the return value is a URI-escaped string
representing the filename. Otherwise, false is returned.
Used by the +Static+ class to check the existence of a valid file
in the server's +public/+ directory (see Static#cal... | 211 | 323 | 507 | CodeSearchNet permissive-repo filter (dataset-level) | code_search_net | 2026-12-05 | 83224ca879dc79ab1423f8f9083abbfa2b43c0c1229d602e24d2f961313c7caa | MIT | permissive | https://github.com/rails/rails/blob/main/MIT-LICENSE |
30bd30bba08b292f55d15475 | rails/rails | activesupport/lib/active_support/duration.rb | ActiveSupport.Duration.+ | https://github.com/rails/rails/blob/85a8bc644be69908f05740a5886ec19cd3679df5/activesupport/lib/active_support/duration.rb#L238-L249 | train | ruby | Compares one Duration with another or a Numeric to this Duration.
Numeric values are treated as seconds.
Adds another Duration or a Numeric to this Duration. Numeric values
are treated as seconds. | def +(other)
if Duration === other
parts = @parts.dup
other.parts.each do |(key, value)|
parts[key] += value
end
Duration.new(value + other.value, parts)
else
seconds = @parts[:seconds] + other
Duration.new(value + other, @parts.merge(seconds: second... | Compares one Duration with another or a Numeric to this Duration.
Numeric values are treated as seconds.
Adds another Duration or a Numeric to this Duration. Numeric values
are treated as seconds.
def +(other)
if Duration === other
parts = @parts.dup
other.parts.each do |(key, value)|
... | 120 | 199 | 341 | CodeSearchNet permissive-repo filter (dataset-level) | code_search_net | 2026-12-05 | f4b939d322f82079a28215acf736eba16aad48a6c880a3e7683cefb92e25fd72 | MIT | permissive | https://github.com/rails/rails/blob/main/MIT-LICENSE |
3dc88e9073397c01fd2d6ca4 | rails/rails | activesupport/lib/active_support/duration.rb | ActiveSupport.Duration.* | https://github.com/rails/rails/blob/85a8bc644be69908f05740a5886ec19cd3679df5/activesupport/lib/active_support/duration.rb#L258-L266 | train | ruby | Multiplies this Duration by a Numeric and returns a new Duration. | def *(other)
if Scalar === other || Duration === other
Duration.new(value * other.value, parts.map { |type, number| [type, number * other.value] })
elsif Numeric === other
Duration.new(value * other, parts.map { |type, number| [type, number * other] })
else
raise_type_error(oth... | Multiplies this Duration by a Numeric and returns a new Duration.
def *(other)
if Scalar === other || Duration === other
Duration.new(value * other.value, parts.map { |type, number| [type, number * other.value] })
elsif Numeric === other
Duration.new(value * other, parts.map { |type, number... | 95 | 65 | 341 | CodeSearchNet permissive-repo filter (dataset-level) | code_search_net | 2026-12-05 | d6d52bbcf93206960bd1995a671a2c54d0170e9f96f1506e8fae33de0c228861 | MIT | permissive | https://github.com/rails/rails/blob/main/MIT-LICENSE |
102c7ace9954e690e88bfe3b | rails/rails | activesupport/lib/active_support/duration.rb | ActiveSupport.Duration.% | https://github.com/rails/rails/blob/85a8bc644be69908f05740a5886ec19cd3679df5/activesupport/lib/active_support/duration.rb#L283-L291 | train | ruby | Returns the modulo of this Duration by another Duration or Numeric.
Numeric values are treated as seconds. | def %(other)
if Duration === other || Scalar === other
Duration.build(value % other.value)
elsif Numeric === other
Duration.build(value % other)
else
raise_type_error(other)
end
end | Returns the modulo of this Duration by another Duration or Numeric.
Numeric values are treated as seconds.
def %(other)
if Duration === other || Scalar === other
Duration.build(value % other.value)
elsif Numeric === other
Duration.build(value % other)
else
raise_type_error(ot... | 68 | 107 | 233 | CodeSearchNet permissive-repo filter (dataset-level) | code_search_net | 2026-12-05 | ffc6c736d85ea362f0888496e8442b88590375f4ed9e7183ab1b38ebbb451f76 | MIT | permissive | https://github.com/rails/rails/blob/main/MIT-LICENSE |
21201086d45b47227125e3f2 | rails/rails | actionview/lib/action_view/lookup_context.rb | ActionView.LookupContext.formats= | https://github.com/rails/rails/blob/85a8bc644be69908f05740a5886ec19cd3679df5/actionview/lib/action_view/lookup_context.rb#L280-L297 | train | ruby | Override formats= to expand ["*/*"] values and automatically
add :html as fallback to :js. | def formats=(values)
if values
values = values.dup
values.concat(default_formats) if values.delete "*/*"
values.uniq!
invalid_values = (values - Template::Types.symbols)
unless invalid_values.empty?
raise ArgumentError, "Invalid formats: #{invalid_values.map(&:in... | Override formats= to expand ["*/*"] values and automatically
add :html as fallback to :js.
def formats=(values)
if values
values = values.dup
values.concat(default_formats) if values.delete "*/*"
values.uniq!
invalid_values = (values - Template::Types.symbols)
unless inv... | 130 | 91 | 494 | CodeSearchNet permissive-repo filter (dataset-level) | code_search_net | 2026-12-05 | 2b6f6a94ce25c462303aa30ddeac837c0153343712bf5c663c430d3e64e94c01 | MIT | permissive | https://github.com/rails/rails/blob/main/MIT-LICENSE |
Subsets and Splits
No community queries yet
The top public SQL queries from the community will appear here once available.