_id
stringlengths
2
6
title
stringlengths
9
130
partition
stringclasses
3 values
text
stringlengths
30
4.3k
language
stringclasses
1 value
meta_information
dict
q10300
ActionView.RecordIdentifier.dom_id
train
def dom_id(record, prefix = nil) if record_id = record_key_for_dom_id(record)
ruby
{ "resource": "" }
q10301
ActiveSupport.Concern.included
train
def included(base = nil, &block) if base.nil? if instance_variable_defined?(:@_included_block) if @_included_block.source_location != block.source_location raise MultipleIncludedBlocks
ruby
{ "resource": "" }
q10302
ActiveSupport.Concern.class_methods
train
def class_methods(&class_methods_module_definition) mod = const_defined?(:ClassMethods, false) ? const_get(:ClassMethods) :
ruby
{ "resource": "" }
q10303
AbstractController.Caching.cache
train
def cache(key, options = {}, &block) # :doc: if cache_configured? cache_store.fetch(ActiveSupport::Cache.expand_cache_key(key,
ruby
{ "resource": "" }
q10304
ActiveSupport.MessageVerifier.valid_message?
train
def valid_message?(signed_message) return if signed_message.nil? || !signed_message.valid_encoding? || signed_message.blank? data, digest = signed_message.split("--") data.present?
ruby
{ "resource": "" }
q10305
ActiveSupport.MessageVerifier.verified
train
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
ruby
{ "resource": "" }
q10306
ActiveSupport.MessageVerifier.generate
train
def generate(value, expires_at: nil, expires_in: nil, purpose: nil) data = encode(Messages::Metadata.wrap(@serializer.dump(value),
ruby
{ "resource": "" }
q10307
ActiveJob.Core.serialize
train
def serialize { "job_class" => self.class.name, "job_id" => job_id, "provider_job_id" => provider_job_id, "queue_name" => queue_name, "priority" => priority,
ruby
{ "resource": "" }
q10308
ActiveJob.Core.deserialize
train
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....
ruby
{ "resource": "" }
q10309
ActionDispatch.FileHandler.match?
train
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...
ruby
{ "resource": "" }
q10310
ActiveSupport.Duration.+
train
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
ruby
{ "resource": "" }
q10311
ActiveSupport.Duration.*
train
def *(other) if Scalar === other || Duration === other Duration.new(value * other.value, parts.map { |type, number| [type, number * other.value] }) elsif Numeric === other
ruby
{ "resource": "" }
q10312
ActiveSupport.Duration.%
train
def %(other) if Duration === other || Scalar === other Duration.build(value % other.value) elsif Numeric === other
ruby
{ "resource": "" }
q10313
ActionView.LookupContext.locale=
train
def locale=(value) if value config = I18n.config.respond_to?(:original_config) ? I18n.config.original_config : I18n.config
ruby
{ "resource": "" }
q10314
ActionView.Resolver.find_all
train
def find_all(name, prefix = nil, partial = false, details = {}, key = nil, locals = []) locals = locals.map(&:to_s).sort!.freeze cached(key, [name,
ruby
{ "resource": "" }
q10315
ActionView.Resolver.cached
train
def cached(key, path_info, details, locals) name, prefix, partial = path_info if key
ruby
{ "resource": "" }
q10316
ActionView.PathResolver.extract_handler_and_format_and_variant
train
def extract_handler_and_format_and_variant(path) pieces = File.basename(path).split(".") pieces.shift extension = pieces.pop handler = Template.handler_for_extension(extension) format, variant = pieces.last.split(EXTENSIONS[:variants], 2) if pieces.last
ruby
{ "resource": "" }
q10317
ActionView.StreamingTemplateRenderer.render_template
train
def render_template(view, template, layout_name = nil, locals = {}) #:nodoc: return [super.body] unless layout_name && template.supports_streaming? locals ||= {} layout
ruby
{ "resource": "" }
q10318
ActiveRecord.AutosaveAssociation.record_changed?
train
def record_changed?(reflection, record, key) record.new_record? || association_foreign_key_changed?(reflection, record, key) ||
ruby
{ "resource": "" }
q10319
ActiveSupport.Inflector.transliterate
train
def transliterate(string, replacement = "?", locale: nil) raise ArgumentError, "Can only transliterate strings. Received #{string.class.name}" unless string.is_a?(String) I18n.transliterate(
ruby
{ "resource": "" }
q10320
ActiveModel.Errors.import
train
def import(error, override_options = {}) [:attribute, :type].each do |key| if override_options.key?(key) override_options[key] = override_options[key].to_sym
ruby
{ "resource": "" }
q10321
ActiveModel.Errors.slice!
train
def slice!(*keys) deprecation_removal_warning(:slice!) keys = keys.map(&:to_sym)
ruby
{ "resource": "" }
q10322
ActiveModel.Errors.where
train
def where(attribute, type = nil, **options) attribute, type, options = normalize_arguments(attribute, type, options) @errors.select
ruby
{ "resource": "" }
q10323
ActiveModel.Errors.delete
train
def delete(attribute, type = nil, **options) attribute, type, options = normalize_arguments(attribute, type, options) matches = where(attribute, type, options)
ruby
{ "resource": "" }
q10324
ActiveModel.Errors.each
train
def each(&block) if block.arity == 1 @errors.each(&block) else ActiveSupport::Deprecation.warn(<<~MSG) Enumerating ActiveModel::Errors as a hash has been deprecated. In Rails 6.1, `errors` is an array of Error objects, therefore it should be accessed by a block ...
ruby
{ "resource": "" }
q10325
ActiveModel.Errors.to_xml
train
def to_xml(options = {}) deprecation_removal_warning(:to_xml)
ruby
{ "resource": "" }
q10326
ActiveRecord.Migration.revert
train
def revert(*migration_classes) run(*migration_classes.reverse, revert: true) unless migration_classes.empty? if block_given? if connection.respond_to? :revert connection.revert { yield } else recorder = command_recorder @connection
ruby
{ "resource": "" }
q10327
ActiveRecord.Migration.say_with_time
train
def say_with_time(message) say(message) result = nil time = Benchmark.measure { result = yield } say "%.4fs" % time.real, :subitem
ruby
{ "resource": "" }
q10328
ActiveRecord.Migration.next_migration_number
train
def next_migration_number(number) if ActiveRecord::Base.timestamped_migrations [Time.now.utc.strftime("%Y%m%d%H%M%S"), "%.14d" % number].max
ruby
{ "resource": "" }
q10329
ActiveRecord.Migrator.run_without_lock
train
def run_without_lock migration = migrations.detect { |m| m.version == @target_version } raise UnknownMigrationVersionError.new(@target_version) if migration.nil?
ruby
{ "resource": "" }
q10330
ActiveRecord.Migrator.migrate_without_lock
train
def migrate_without_lock if invalid_target? raise UnknownMigrationVersionError.new(@target_version) end result = runnable.each do |migration|
ruby
{ "resource": "" }
q10331
ActionController.Parameters.permit!
train
def permit! each_pair do |key, value| Array.wrap(value).flatten.each do |v| v.permit! if v.respond_to? :permit!
ruby
{ "resource": "" }
q10332
ActionController.Parameters.require
train
def require(key) return key.map { |k| require(k) } if key.is_a?(Array) value = self[key] if value.present? || value == false
ruby
{ "resource": "" }
q10333
ActionController.Parameters.permitted_scalar_filter
train
def permitted_scalar_filter(params, permitted_key) permitted_key = permitted_key.to_s if has_key?(permitted_key) && permitted_scalar?(self[permitted_key]) params[permitted_key] = self[permitted_key] end each_key do |key| next
ruby
{ "resource": "" }
q10334
ActionView.Rendering.process
train
def process(*) #:nodoc: old_config, I18n.config = I18n.config, I18nProxy.new(I18n.config,
ruby
{ "resource": "" }
q10335
ActionView.Rendering._render_template
train
def _render_template(options) variant = options.delete(:variant) assigns = options.delete(:assigns) context = view_context context.assign assigns if assigns lookup_context.variants = variant if variant rendered_template = context.in_rendering_context(options) do |render...
ruby
{ "resource": "" }
q10336
ActionView.Rendering._normalize_options
train
def _normalize_options(options) options = super(options) if options[:partial] == true options[:partial] = action_name
ruby
{ "resource": "" }
q10337
ActiveJob.Enqueuing.enqueue
train
def enqueue(options = {}) self.scheduled_at = options[:wait].seconds.from_now.to_f if options[:wait] self.scheduled_at = options[:wait_until].to_f if options[:wait_until] self.queue_name = self.class.queue_name_from_part(options[:queue]) if options[:queue] self.priority = options[:priority...
ruby
{ "resource": "" }
q10338
ActiveRecord.FixtureSet.table_rows
train
def table_rows # allow a standard key to be used for doing defaults in YAML fixtures.delete("DEFAULTS") TableRows.new( table_name,
ruby
{ "resource": "" }
q10339
ActiveRecord.FixtureSet.read_fixture_files
train
def read_fixture_files(path) yaml_files = Dir["#{path}/{**,*}/*.yml"].select { |f| ::File.file?(f) } + [yaml_file_path(path)] yaml_files.each_with_object({}) do |file, fixtures| FixtureSet::File.open(file) do |fh| self.model_class ||= fh.model_class if fh.model_c...
ruby
{ "resource": "" }
q10340
ActiveStorage.Downloading.download_blob_to
train
def download_blob_to(file) #:doc: file.binmode
ruby
{ "resource": "" }
q10341
ActionController.ConditionalGet.expires_in
train
def expires_in(seconds, options = {}) response.cache_control.merge!( max_age: seconds, public: options.delete(:public), must_revalidate: options.delete(:must_revalidate),
ruby
{ "resource": "" }
q10342
ActionController.ConditionalGet.http_cache_forever
train
def http_cache_forever(public: false) expires_in 100.years, public: public yield if stale?(etag: request.fullpath,
ruby
{ "resource": "" }
q10343
ActiveStorage.Previewer.draw
train
def draw(*argv) #:doc: open_tempfile do |file| instrument :preview, key:
ruby
{ "resource": "" }
q10344
ActionController.Rendering.render_to_string
train
def render_to_string(*) result = super if result.respond_to?(:each) string = +""
ruby
{ "resource": "" }
q10345
ActionController.Rendering._normalize_options
train
def _normalize_options(options) _normalize_text(options) if options[:html] options[:html] = ERB::Util.html_escape(options[:html]) end
ruby
{ "resource": "" }
q10346
ActionController.Rendering._process_options
train
def _process_options(options) status, content_type, location = options.values_at(:status, :content_type, :location) self.status = status if status
ruby
{ "resource": "" }
q10347
ActionDispatch.RemoteIp.call
train
def call(env) req = ActionDispatch::Request.new env
ruby
{ "resource": "" }
q10348
ActiveModel.Validations.validates_with
train
def validates_with(*args, &block) options = args.extract_options! options[:class] = self.class args.each do |klass|
ruby
{ "resource": "" }
q10349
ActionView.Template.render
train
def render(view, locals, buffer = ActionView::OutputBuffer.new, &block) instrument_render_template do compile!(view)
ruby
{ "resource": "" }
q10350
ActionView.Template.compile!
train
def compile!(view) return if @compiled # Templates can be used concurrently in threaded environments # so compilation and any instance variable modification must # be synchronized @compile_mutex.synchronize do # Any thread holding this lock will be compiling the templa...
ruby
{ "resource": "" }
q10351
ActiveRecord.Persistence.reload
train
def reload(options = nil) self.class.connection.clear_query_cache fresh_object = if options && options[:lock] self.class.unscoped { self.class.lock(options[:lock]).find(id)
ruby
{ "resource": "" }
q10352
ActionController.RequestForgeryProtection.masked_authenticity_token
train
def masked_authenticity_token(session, form_options: {}) # :doc: action, method = form_options.values_at(:action, :method) raw_token = if per_form_csrf_tokens && action && method action_path = normalize_action_path(action) per_form_csrf_token(session, action_path, method) el...
ruby
{ "resource": "" }
q10353
ActionController.RequestForgeryProtection.valid_authenticity_token?
train
def valid_authenticity_token?(session, encoded_masked_token) # :doc: if encoded_masked_token.nil? || encoded_masked_token.empty? || !encoded_masked_token.is_a?(String) return false end begin masked_token = Base64.strict_decode64(encoded_masked_token) rescue ArgumentE...
ruby
{ "resource": "" }
q10354
ActionController.RequestForgeryProtection.valid_request_origin?
train
def valid_request_origin? # :doc: if forgery_protection_origin_check # We accept blank origin headers because some user agents don't send it. raise InvalidAuthenticityToken, NULL_ORIGIN_MESSAGE if request.origin ==
ruby
{ "resource": "" }
q10355
ActiveRecord.Transactions.remember_transaction_record_state
train
def remember_transaction_record_state @_start_transaction_state ||= { id: id, new_record: @new_record, destroyed: @destroyed, attributes: @attributes, frozen?: frozen?, level:
ruby
{ "resource": "" }
q10356
ActiveRecord.Transactions.sync_with_transaction_state
train
def sync_with_transaction_state if transaction_state = @transaction_state if transaction_state.fully_committed? force_clear_transaction_record_state elsif transaction_state.committed? clear_transaction_record_state elsif transaction_state.rolledback? ...
ruby
{ "resource": "" }
q10357
ActiveSupport.SecurityUtils.fixed_length_secure_compare
train
def fixed_length_secure_compare(a, b) raise ArgumentError, "string length mismatch." unless a.bytesize == b.bytesize l = a.unpack "C#{a.bytesize}"
ruby
{ "resource": "" }
q10358
ActiveSupport.SecurityUtils.secure_compare
train
def secure_compare(a, b) fixed_length_secure_compare(::Digest::SHA256.digest(a),
ruby
{ "resource": "" }
q10359
ActiveSupport.LazyLoadHooks.on_load
train
def on_load(name, options = {}, &block) @loaded[name].each do |base| execute_hook(name, base, options, block)
ruby
{ "resource": "" }
q10360
AbstractController.Rendering.view_assigns
train
def view_assigns protected_vars = _protected_ivars variables = instance_variables variables.reject! { |s| protected_vars.include? s }
ruby
{ "resource": "" }
q10361
AbstractController.Rendering._normalize_render
train
def _normalize_render(*args, &block) # :nodoc: options = _normalize_args(*args, &block) _process_variant(options)
ruby
{ "resource": "" }
q10362
ActiveSupport.NumericWithFormat.to_s
train
def to_s(format = nil, options = nil) case format when nil super() when Integer, String super(format) when :phone ActiveSupport::NumberHelper.number_to_phone(self, options || {}) when :currency ActiveSupport::NumberHelper.number_to_currency(self, options || ...
ruby
{ "resource": "" }
q10363
ActiveRecord.DatabaseConfigurations.default_hash
train
def default_hash(env = ActiveRecord::ConnectionHandling::DEFAULT_ENV.call.to_s)
ruby
{ "resource": "" }
q10364
ActiveRecord.DatabaseConfigurations.find_db_config
train
def find_db_config(env) configurations.find do |db_config| db_config.env_name == env.to_s ||
ruby
{ "resource": "" }
q10365
ActiveRecord.DatabaseConfigurations.to_h
train
def to_h configs = configurations.reverse.inject({}) do |memo, db_config|
ruby
{ "resource": "" }
q10366
ActionMailer.LogSubscriber.deliver
train
def deliver(event) info do perform_deliveries = event.payload[:perform_deliveries] if perform_deliveries "Delivered mail #{event.payload[:message_id]} (#{event.duration.round(1)}ms)" else
ruby
{ "resource": "" }
q10367
ActiveSupport.BacktraceCleaner.clean
train
def clean(backtrace, kind = :silent) filtered = filter_backtrace(backtrace) case kind when :silent silence(filtered)
ruby
{ "resource": "" }
q10368
ActionView.TemplateRenderer.determine_template
train
def determine_template(options) keys = options.has_key?(:locals) ? options[:locals].keys : [] if options.key?(:body) Template::Text.new(options[:body]) elsif options.key?(:plain) Template::Text.new(options[:plain]) elsif options.key?(:html) Template::HTML.n...
ruby
{ "resource": "" }
q10369
ActionView.TemplateRenderer.render_template
train
def render_template(view, template, layout_name, locals) render_with_layout(view, template, layout_name, locals) do |layout| instrument(:template, identifier: template.identifier, layout: layout.try(:virtual_path)) do
ruby
{ "resource": "" }
q10370
ActionController.Streaming._process_options
train
def _process_options(options) super if options[:stream] if request.version == "HTTP/1.0" options.delete(:stream) else headers["Cache-Control"] ||= "no-cache"
ruby
{ "resource": "" }
q10371
ActionController.Streaming._render_template
train
def _render_template(options) if options.delete(:stream) Rack::Chunked::Body.new
ruby
{ "resource": "" }
q10372
ActionView.Layouts._layout_for_option
train
def _layout_for_option(name) case name when String then _normalize_layout(name) when Proc then name when true then Proc.new { |lookup_context, formats| _default_layout(lookup_context, formats, true)
ruby
{ "resource": "" }
q10373
ActionView.Layouts._default_layout
train
def _default_layout(lookup_context, formats, require_layout = false) begin value = _layout(lookup_context, formats) if action_has_layout? rescue NameError => e raise e, "Could not render layout: #{e.message}" end if require_layout && action_has_layout? && !value
ruby
{ "resource": "" }
q10374
ActiveModel.Validations.valid?
train
def valid?(context = nil) current_context, self.validation_context = validation_context, context errors.clear run_validations!
ruby
{ "resource": "" }
q10375
Rails.Application.message_verifier
train
def message_verifier(verifier_name) @message_verifiers[verifier_name] ||= begin secret = key_generator.generate_key(verifier_name.to_s)
ruby
{ "resource": "" }
q10376
Rails.Application.env_config
train
def env_config @app_env_config ||= begin super.merge( "action_dispatch.parameter_filter" => config.filter_parameters, "action_dispatch.redirect_filter" => config.filter_redirect, "action_dispatch.secret_key_base" => secret_key_base, "action_dispatch.show_exceptions"...
ruby
{ "resource": "" }
q10377
Rails.Application.encrypted
train
def encrypted(path, key_path: "config/master.key", env_key: "RAILS_MASTER_KEY") ActiveSupport::EncryptedConfiguration.new( config_path: Rails.root.join(path),
ruby
{ "resource": "" }
q10378
Rails.Application.ordered_railties
train
def ordered_railties #:nodoc: @ordered_railties ||= begin order = config.railties_order.map do |railtie| if railtie == :main_app self elsif railtie.respond_to?(:instance) railtie.instance else railtie end end all ...
ruby
{ "resource": "" }
q10379
ActionDispatch.Request.raw_post
train
def raw_post unless has_header? "RAW_POST_DATA" raw_post_body = body set_header("RAW_POST_DATA", raw_post_body.read(content_length))
ruby
{ "resource": "" }
q10380
ActionDispatch.Request.body
train
def body if raw_post = get_header("RAW_POST_DATA") raw_post = raw_post.dup.force_encoding(Encoding::BINARY)
ruby
{ "resource": "" }
q10381
ActionDispatch.Request.GET
train
def GET fetch_header("action_dispatch.request.query_parameters") do |k| rack_query_params = super || {} # Check for non UTF-8 parameter values, which would cause errors later Request::Utils.check_param_encoding(rack_query_params) set_header k, Request::Utils.normalize_encode_params...
ruby
{ "resource": "" }
q10382
ActionDispatch.Request.POST
train
def POST fetch_header("action_dispatch.request.request_parameters") do pr = parse_formatted_parameters(params_parsers) do |params| super || {} end self.request_parameters = Request::Utils.normalize_encode_params(pr) end
ruby
{ "resource": "" }
q10383
ActionView.PartialRenderer.setup
train
def setup(context, options, as, block) @options = options @block = block @locals = options[:locals] || {} @details = extract_details(options) partial = options[:partial] if String === partial @has_object = options.key?(:object) @object = opti...
ruby
{ "resource": "" }
q10384
ActionView.PartialRenderer.partial_path
train
def partial_path(object, view) object = object.to_model if object.respond_to?(:to_model) path = if object.respond_to?(:to_partial_path) object.to_partial_path else raise ArgumentError.new("'#{object.inspect}' is not an ActiveModel-compatible object. It must implement :to_par...
ruby
{ "resource": "" }
q10385
ActiveModel.Serialization.serializable_hash
train
def serializable_hash(options = nil) options ||= {} attribute_names = attributes.keys if only = options[:only] attribute_names &= Array(only).map(&:to_s) elsif except = options[:except] attribute_names -= Array(except).map(&:to_s) end hash = {} attribute_names...
ruby
{ "resource": "" }
q10386
Rails.Engine.helpers
train
def helpers @helpers ||= begin helpers = Module.new all = ActionController::Base.all_helpers_from_path(helpers_paths) ActionController::Base.modules_for_helpers(all).each
ruby
{ "resource": "" }
q10387
Rails.Engine.app
train
def app @app || @app_build_lock.synchronize { @app ||= begin stack = default_middleware_stack
ruby
{ "resource": "" }
q10388
Rails.Engine.routes
train
def routes(&block) @routes ||= ActionDispatch::Routing::RouteSet.new_with_config(config)
ruby
{ "resource": "" }
q10389
ActiveStorage.Attached::One.attach
train
def attach(attachable) if record.persisted? && !record.changed? record.update(name => attachable) else
ruby
{ "resource": "" }
q10390
ActiveStorage.Service::GCSService.stream
train
def stream(key) file = file_for(key, skip_lookup: false) chunk_size = 5.megabytes offset = 0 raise ActiveStorage::FileNotFoundError unless file.present? while offset < file.size
ruby
{ "resource": "" }
q10391
ActiveSupport.FileUpdateChecker.updated?
train
def updated? current_watched = watched if @last_watched.size != current_watched.size @watched = current_watched true else current_updated_at = updated_at(current_watched) if @last_update_at < current_updated_at
ruby
{ "resource": "" }
q10392
ActiveSupport.FileUpdateChecker.max_mtime
train
def max_mtime(paths) time_now = Time.now max_mtime = nil # Time comparisons are performed with #compare_without_coercion because # AS redefines these operators in a way that is much slower and does not # bring any benefit in this particular code.
ruby
{ "resource": "" }
q10393
ActiveSupport.Benchmarkable.benchmark
train
def benchmark(message = "Benchmarking", options = {}) if logger options.assert_valid_keys(:level, :silence) options[:level] ||= :info result = nil ms = Benchmark.ms { result = options[:silence] ? logger.silence { yield } : yield }
ruby
{ "resource": "" }
q10394
ActiveRecord.Relation.new
train
def new(attributes = nil, &block) block = _deprecated_scope_block("new",
ruby
{ "resource": "" }
q10395
ActiveRecord.Relation.create
train
def create(attributes = nil, &block) if attributes.is_a?(Array) attributes.collect { |attr| create(attr, &block) } else block
ruby
{ "resource": "" }
q10396
ActiveRecord.Relation.to_sql
train
def to_sql @to_sql ||= begin if eager_loading? apply_join_dependency do |relation, join_dependency| relation = join_dependency.apply_column_aliases(relation) relation.to_sql end else
ruby
{ "resource": "" }
q10397
ActiveRecord.Core.init_with_attributes
train
def init_with_attributes(attributes, new_record = false) # :nodoc: @new_record = new_record @attributes = attributes init_internals yield
ruby
{ "resource": "" }
q10398
ActiveRecord.Core.inspect
train
def inspect # We check defined?(@attributes) not to issue warnings if the object is # allocated but not initialized. inspection = if defined?(@attributes) && @attributes self.class.attribute_names.collect do |name| if has_attribute?(name) attr = _read_attribute(name) ...
ruby
{ "resource": "" }
q10399
ActionMailer.Base.mail
train
def mail(headers = {}, &block) return message if @_mail_was_called && headers.blank? && !block # At the beginning, do not consider class default for content_type content_type = headers[:content_type] headers = apply_defaults(headers) # Apply charset at the beginning so all fields are pr...
ruby
{ "resource": "" }