_id stringlengths 2 6 | title stringlengths 9 130 | partition stringclasses 3
values | text stringlengths 66 10.5k | 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)
"#{dom_class(record, prefix)}#{JOIN}#{record_id}"
else
dom_class(record, prefix || NEW)
end
end | 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
end
else
@_included_block = block
end
else
super
... | ruby | {
"resource": ""
} |
q10302 | ActiveSupport.Concern.class_methods | train | 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 | 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, :controller), options, &block)
else
yield
end
end | 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? && digest.present? && ActiveSupport::SecurityUtils.secure_compare(digest, generate_digest(data))
end | 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
rescue ArgumentError => argument_error
... | 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), expires_at: expires_at, expires_in: expires_in, purpose: purpose))
"#{data}--#{generate_digest(data)}"
end | 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,
"arguments" => serialize_arguments_if_needed(arguments),
"executions" => executions,
... | 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
seconds = @parts[:seconds] + other
Duration.new(value + other, @parts.merge(seconds: second... | 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
Duration.new(value * other, parts.map { |type, number| [type, number * other] })
else
raise_type_error(oth... | ruby | {
"resource": ""
} |
q10312 | ActiveSupport.Duration.% | train | 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 | 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
config.locale = value
end
super(default_locale)
end | 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, prefix, partial], details, locals) do
_find_all(name, prefix, partial, details, key, locals)
end
end | ruby | {
"resource": ""
} |
q10315 | ActionView.Resolver.cached | train | def cached(key, path_info, details, locals)
name, prefix, partial = path_info
if key
@cache.cache(key, name, prefix, partial, locals) do
yield
end
else
yield
end
end | 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
format = if form... | 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 = layout_name && find_layout(layout_name, locals.keys, [formats.first])
Body.new do |buffer|
delayed_render(buffer,... | ruby | {
"resource": ""
} |
q10318 | ActiveRecord.AutosaveAssociation.record_changed? | train | def record_changed?(reflection, record, key)
record.new_record? ||
association_foreign_key_changed?(reflection, record, key) ||
record.will_save_change_to_attribute?(reflection.foreign_key)
end | 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(
ActiveSupport::Multibyte::Unicode.tidy_bytes(string).unicode_normalize(:nfc),
replacement: replaceme... | 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
end
end
@errors.append(NestedError.new(@base, error, override_options))
end | ruby | {
"resource": ""
} |
q10321 | ActiveModel.Errors.slice! | train | def slice!(*keys)
deprecation_removal_warning(:slice!)
keys = keys.map(&:to_sym)
results = messages.dup.slice!(*keys)
@errors.keep_if do |error|
keys.include?(error.attribute)
end
results
end | ruby | {
"resource": ""
} |
q10322 | ActiveModel.Errors.where | train | def where(attribute, type = nil, **options)
attribute, type, options = normalize_arguments(attribute, type, options)
@errors.select { |error|
error.match?(attribute, type, options)
}
end | 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)
matches.each do |error|
@errors.delete(error)
end
matches.map(&:message)
end | 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)
to_a.to_xml({ root: "errors", skip_types: true }.merge!(options))
end | 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 = recorder
suppress_... | 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
say("#{result} rows", :subitem) if result.is_a?(Integer)
result
end | 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
else
SchemaMigration.normalize_migration_number(number)
end
end | 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?
result = execute_migration_in_transaction(migration, @direction)
record_environment
result
end | 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|
execute_migration_in_transaction(migration, @direction)
end
record_environment
result
end | 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!
end
end
@permitted = true
self
end | 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
value
else
raise ParameterMissing.new(key)
end
end | 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 unless key =~ /\(\d+[if]?\)\z/
... | ruby | {
"resource": ""
} |
q10334 | ActionView.Rendering.process | train | def process(*) #:nodoc:
old_config, I18n.config = I18n.config, I18nProxy.new(I18n.config, lookup_context)
super
ensure
I18n.config = old_config
end | 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
end
if (options.keys & [:partial, :file, :template]).empty?
options[:prefixes] ||= _prefixes
end
options[:template] ||= (options[:ac... | 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,
model_class: model_class,
fixtures: fixtures,
config: config,
).to_hash
end | 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
blob.download { |chunk| file.write(chunk) }
file.flush
file.rewind
end | 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),
stale_while_revalidate: options.delete(:stale_while_revalidate),
stale_if_error: options.delete(:stale_... | 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,
last_modified: Time.new(2011, 1, 1).utc,
public: public)
end | ruby | {
"resource": ""
} |
q10343 | ActiveStorage.Previewer.draw | train | def draw(*argv) #:doc:
open_tempfile do |file|
instrument :preview, key: blob.key do
capture(*argv, to: file)
end
yield file
end
end | ruby | {
"resource": ""
} |
q10344 | ActionController.Rendering.render_to_string | train | def render_to_string(*)
result = super
if result.respond_to?(:each)
string = +""
result.each { |r| string << r }
string
else
result
end
end | 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
if options[:status]
options[:status] = Rack::Utils.status_code(options[:status])
end
super
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
self.content_type = content_type if content_type
headers["Location"] = url_for(location) if location
super
end | ruby | {
"resource": ""
} |
q10347 | ActionDispatch.RemoteIp.call | train | def call(env)
req = ActionDispatch::Request.new env
req.remote_ip = GetIp.new(req, check_ip, proxies)
@app.call(req.env)
end | 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|
validator = klass.new(options, &block)
validator.validate(self)
end
end | ruby | {
"resource": ""
} |
q10349 | ActionView.Template.render | train | def render(view, locals, buffer = ActionView::OutputBuffer.new, &block)
instrument_render_template do
compile!(view)
view._run(method_name, self, locals, buffer, &block)
end
rescue => e
handle_render_error(view, e)
end | 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) }
else
self.class.unscoped { self.class.find(id) }
end
@attributes = fresh_object.i... | 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 == "null"
request.origin.nil? || request.origin == request.base_url
... | 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: 0
}
@_start_transaction_state[:level] += 1
remember_... | 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}"
res = 0
b.each_byte { |byte| res |= byte ^ l.shift }
res == 0
end | ruby | {
"resource": ""
} |
q10358 | ActiveSupport.SecurityUtils.secure_compare | train | def secure_compare(a, b)
fixed_length_secure_compare(::Digest::SHA256.digest(a), ::Digest::SHA256.digest(b)) && a == b
end | 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)
end
@load_hooks[name] << [block, options]
end | 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 }
variables.each_with_object({}) { |name, hash|
hash[name.slice(1, name.length)] = instance_variable_get(name)
}
end | ruby | {
"resource": ""
} |
q10361 | AbstractController.Rendering._normalize_render | train | def _normalize_render(*args, &block) # :nodoc:
options = _normalize_args(*args, &block)
_process_variant(options)
_normalize_options(options)
options
end | 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)
default = find_db_config(env)
default.config if default
end | 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 ||
(db_config.for_current_env? && db_config.spec_name == env.to_s)
end
end | ruby | {
"resource": ""
} |
q10365 | ActiveRecord.DatabaseConfigurations.to_h | train | def to_h
configs = configurations.reverse.inject({}) do |memo, db_config|
memo.merge(db_config.to_legacy_hash)
end
Hash[configs.to_a.reverse]
end | 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
"Skipped delivery of mail #{event.payload[:message_id]} as `perform_deliveries` is... | ruby | {
"resource": ""
} |
q10367 | ActiveSupport.BacktraceCleaner.clean | train | def clean(backtrace, kind = :silent)
filtered = filter_backtrace(backtrace)
case kind
when :silent
silence(filtered)
when :noise
noise(filtered)
else
filtered
end
end | 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
template.render(view, locals) { |*name| view._layout_for(*name) }
... | 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"
headers["Transfer-Encoding"] = "chunked"
headers.delete("Content-Length")
... | ruby | {
"resource": ""
} |
q10371 | ActionController.Streaming._render_template | train | def _render_template(options)
if options.delete(:stream)
Rack::Chunked::Body.new view_renderer.render_body(view_context, options)
else
super
end
end | 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) }
when :default then Proc.new { |lookup_context, formats| _default_layou... | 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
raise Ar... | ruby | {
"resource": ""
} |
q10374 | ActiveModel.Validations.valid? | train | def valid?(context = nil)
current_context, self.validation_context = validation_context, context
errors.clear
run_validations!
ensure
self.validation_context = current_context
end | 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)
ActiveSupport::MessageVerifier.new(secret)
end
end | 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),
key_path: Rails.root.join(key_path),
env_key: env_key,
raise_if_missing_key: config.require_master_key
)
end | 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))
raw_post_body.rewind if raw_post_body.respond_to?(:rewind)
end
get_header "RAW_POST_DATA"
end | 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)
StringIO.new(raw_post)
else
body_stream
end
end | 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
rescue Rack::Utils::ParameterTypeError, Rack::Util... | 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 do |mod|
helpers.include(mod)
end
helpers
end
end | ruby | {
"resource": ""
} |
q10387 | Rails.Engine.app | train | def app
@app || @app_build_lock.synchronize {
@app ||= begin
stack = default_middleware_stack
config.middleware = build_middleware.merge_into(stack)
config.middleware.build(endpoint)
end
}
end | ruby | {
"resource": ""
} |
q10388 | Rails.Engine.routes | train | def routes(&block)
@routes ||= ActionDispatch::Routing::RouteSet.new_with_config(config)
@routes.append(&block) if block_given?
@routes
end | ruby | {
"resource": ""
} |
q10389 | ActiveStorage.Attached::One.attach | train | def attach(attachable)
if record.persisted? && !record.changed?
record.update(name => attachable)
else
record.public_send("#{name}=", attachable)
end
end | 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
yield file.download(range: offset..(offset + chunk_size - 1)).string
offset += ... | 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
@watched = current_watched
@updated_... | 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.
#
# Read t1.comp... | 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 }
logger.send(options[:level], "%s (%.1fms)"... | ruby | {
"resource": ""
} |
q10394 | ActiveRecord.Relation.new | train | def new(attributes = nil, &block)
block = _deprecated_scope_block("new", &block)
scoping { klass.new(attributes, &block) }
end | 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 = _deprecated_scope_block("create", &block)
scoping { klass.create(attributes, &block) }
end
end | 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
conn = klass.connection
conn.unprepared_statement {... | 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 self if block_given?
_run_find_callbacks
_run_initialize_callbacks
self
end | 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": ""
} |
Subsets and Splits
No community queries yet
The top public SQL queries from the community will appear here once available.