id
int32
0
24.9k
repo
stringlengths
5
58
path
stringlengths
9
168
func_name
stringlengths
9
130
original_string
stringlengths
66
10.5k
language
stringclasses
1 value
code
stringlengths
66
10.5k
code_tokens
list
docstring
stringlengths
8
16k
docstring_tokens
list
sha
stringlengths
40
40
url
stringlengths
94
266
10,300
rails/rails
actionview/lib/action_view/record_identifier.rb
ActionView.RecordIdentifier.dom_id
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
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
[ "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", ...
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 ...
[ "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", "." ]
85a8bc644be69908f05740a5886ec19cd3679df5
https://github.com/rails/rails/blob/85a8bc644be69908f05740a5886ec19cd3679df5/actionview/lib/action_view/record_identifier.rb#L89-L95
10,301
rails/rails
activesupport/lib/active_support/concern.rb
ActiveSupport.Concern.included
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
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 ...
[ "def", "included", "(", "base", "=", "nil", ",", "&", "block", ")", "if", "base", ".", "nil?", "if", "instance_variable_defined?", "(", ":@_included_block", ")", "if", "@_included_block", ".", "source_location", "!=", "block", ".", "source_location", "raise", ...
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.
[ "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", "...
85a8bc644be69908f05740a5886ec19cd3679df5
https://github.com/rails/rails/blob/85a8bc644be69908f05740a5886ec19cd3679df5/activesupport/lib/active_support/concern.rb#L129-L141
10,302
rails/rails
activesupport/lib/active_support/concern.rb
ActiveSupport.Concern.class_methods
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
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
[ "def", "class_methods", "(", "&", "class_methods_module_definition", ")", "mod", "=", "const_defined?", "(", ":ClassMethods", ",", "false", ")", "?", "const_get", "(", ":ClassMethods", ")", ":", "const_set", "(", ":ClassMethods", ",", "Module", ".", "new", ")", ...
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 # =...
[ "Define", "class", "methods", "from", "given", "block", ".", "You", "can", "define", "private", "class", "methods", "as", "well", "." ]
85a8bc644be69908f05740a5886ec19cd3679df5
https://github.com/rails/rails/blob/85a8bc644be69908f05740a5886ec19cd3679df5/activesupport/lib/active_support/concern.rb#L163-L169
10,303
rails/rails
actionpack/lib/abstract_controller/caching.rb
AbstractController.Caching.cache
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
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
[ "def", "cache", "(", "key", ",", "options", "=", "{", "}", ",", "&", "block", ")", "# :doc:", "if", "cache_configured?", "cache_store", ".", "fetch", "(", "ActiveSupport", "::", "Cache", ".", "expand_cache_key", "(", "key", ",", ":controller", ")", ",", ...
Convenience accessor.
[ "Convenience", "accessor", "." ]
85a8bc644be69908f05740a5886ec19cd3679df5
https://github.com/rails/rails/blob/85a8bc644be69908f05740a5886ec19cd3679df5/actionpack/lib/abstract_controller/caching.rb#L58-L64
10,304
rails/rails
activesupport/lib/active_support/message_verifier.rb
ActiveSupport.MessageVerifier.valid_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
ruby
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
[ "def", "valid_message?", "(", "signed_message", ")", "return", "if", "signed_message", ".", "nil?", "||", "!", "signed_message", ".", "valid_encoding?", "||", "signed_message", ".", "blank?", "data", ",", "digest", "=", "signed_message", ".", "split", "(", "\"--...
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....
[ "Checks", "if", "a", "signed", "message", "could", "have", "been", "generated", "by", "signing", "an", "object", "with", "the", "+", "MessageVerifier", "+", "s", "secret", "." ]
85a8bc644be69908f05740a5886ec19cd3679df5
https://github.com/rails/rails/blob/85a8bc644be69908f05740a5886ec19cd3679df5/activesupport/lib/active_support/message_verifier.rb#L122-L127
10,305
rails/rails
activesupport/lib/active_support/message_verifier.rb
ActiveSupport.MessageVerifier.verified
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
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 ...
[ "def", "verified", "(", "signed_message", ",", "purpose", ":", "nil", ",", "**", ")", "if", "valid_message?", "(", "signed_message", ")", "begin", "data", "=", "signed_message", ".", "split", "(", "\"--\"", ")", "[", "0", "]", "message", "=", "Messages", ...
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...
[ "Decodes", "the", "signed", "message", "using", "the", "+", "MessageVerifier", "+", "s", "secret", "." ]
85a8bc644be69908f05740a5886ec19cd3679df5
https://github.com/rails/rails/blob/85a8bc644be69908f05740a5886ec19cd3679df5/activesupport/lib/active_support/message_verifier.rb#L150-L161
10,306
rails/rails
activesupport/lib/active_support/message_verifier.rb
ActiveSupport.MessageVerifier.generate
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
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
[ "def", "generate", "(", "value", ",", "expires_at", ":", "nil", ",", "expires_in", ":", "nil", ",", "purpose", ":", "nil", ")", "data", "=", "encode", "(", "Messages", "::", "Metadata", ".", "wrap", "(", "@serializer", ".", "dump", "(", "value", ")", ...
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...
[ "Generates", "a", "signed", "message", "for", "the", "provided", "value", "." ]
85a8bc644be69908f05740a5886ec19cd3679df5
https://github.com/rails/rails/blob/85a8bc644be69908f05740a5886ec19cd3679df5/activesupport/lib/active_support/message_verifier.rb#L186-L189
10,307
rails/rails
activejob/lib/active_job/core.rb
ActiveJob.Core.serialize
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
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, ...
[ "def", "serialize", "{", "\"job_class\"", "=>", "self", ".", "class", ".", "name", ",", "\"job_id\"", "=>", "job_id", ",", "\"provider_job_id\"", "=>", "provider_job_id", ",", "\"queue_name\"", "=>", "queue_name", ",", "\"priority\"", "=>", "priority", ",", "\"a...
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.
[ "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",...
85a8bc644be69908f05740a5886ec19cd3679df5
https://github.com/rails/rails/blob/85a8bc644be69908f05740a5886ec19cd3679df5/activejob/lib/active_job/core.rb#L92-L106
10,308
rails/rails
activejob/lib/active_job/core.rb
ActiveJob.Core.deserialize
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
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....
[ "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\"", "]"...
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' =>...
[ "Attaches", "the", "stored", "job", "data", "to", "the", "current", "instance", ".", "Receives", "a", "hash", "returned", "from", "+", "serialize", "+" ]
85a8bc644be69908f05740a5886ec19cd3679df5
https://github.com/rails/rails/blob/85a8bc644be69908f05740a5886ec19cd3679df5/activejob/lib/active_job/core.rb#L134-L145
10,309
rails/rails
actionpack/lib/action_dispatch/middleware/static.rb
ActionDispatch.FileHandler.match?
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
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...
[ "def", "match?", "(", "path", ")", "path", "=", "::", "Rack", "::", "Utils", ".", "unescape_path", "path", "return", "false", "unless", "::", "Rack", "::", "Utils", ".", "valid_path?", "path", "path", "=", "::", "Rack", "::", "Utils", ".", "clean_path_in...
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...
[ "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", "fi...
85a8bc644be69908f05740a5886ec19cd3679df5
https://github.com/rails/rails/blob/85a8bc644be69908f05740a5886ec19cd3679df5/actionpack/lib/action_dispatch/middleware/static.rb#L30-L47
10,310
rails/rails
activesupport/lib/active_support/duration.rb
ActiveSupport.Duration.+
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
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...
[ "def", "+", "(", "other", ")", "if", "Duration", "===", "other", "parts", "=", "@parts", ".", "dup", "other", ".", "parts", ".", "each", "do", "|", "(", "key", ",", "value", ")", "|", "parts", "[", "key", "]", "+=", "value", "end", "Duration", "....
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.
[ "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",...
85a8bc644be69908f05740a5886ec19cd3679df5
https://github.com/rails/rails/blob/85a8bc644be69908f05740a5886ec19cd3679df5/activesupport/lib/active_support/duration.rb#L238-L249
10,311
rails/rails
activesupport/lib/active_support/duration.rb
ActiveSupport.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...
ruby
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...
[ "def", "*", "(", "other", ")", "if", "Scalar", "===", "other", "||", "Duration", "===", "other", "Duration", ".", "new", "(", "value", "*", "other", ".", "value", ",", "parts", ".", "map", "{", "|", "type", ",", "number", "|", "[", "type", ",", "...
Multiplies this Duration by a Numeric and returns a new Duration.
[ "Multiplies", "this", "Duration", "by", "a", "Numeric", "and", "returns", "a", "new", "Duration", "." ]
85a8bc644be69908f05740a5886ec19cd3679df5
https://github.com/rails/rails/blob/85a8bc644be69908f05740a5886ec19cd3679df5/activesupport/lib/active_support/duration.rb#L258-L266
10,312
rails/rails
activesupport/lib/active_support/duration.rb
ActiveSupport.Duration.%
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
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
[ "def", "%", "(", "other", ")", "if", "Duration", "===", "other", "||", "Scalar", "===", "other", "Duration", ".", "build", "(", "value", "%", "other", ".", "value", ")", "elsif", "Numeric", "===", "other", "Duration", ".", "build", "(", "value", "%", ...
Returns the modulo of this Duration by another Duration or Numeric. Numeric values are treated as seconds.
[ "Returns", "the", "modulo", "of", "this", "Duration", "by", "another", "Duration", "or", "Numeric", ".", "Numeric", "values", "are", "treated", "as", "seconds", "." ]
85a8bc644be69908f05740a5886ec19cd3679df5
https://github.com/rails/rails/blob/85a8bc644be69908f05740a5886ec19cd3679df5/activesupport/lib/active_support/duration.rb#L283-L291
10,313
rails/rails
actionview/lib/action_view/lookup_context.rb
ActionView.LookupContext.locale=
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
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
[ "def", "locale", "=", "(", "value", ")", "if", "value", "config", "=", "I18n", ".", "config", ".", "respond_to?", "(", ":original_config", ")", "?", "I18n", ".", "config", ".", "original_config", ":", "I18n", ".", "config", "config", ".", "locale", "=", ...
Overload locale= to also set the I18n.locale. If the current I18n.config object responds to original_config, it means that it has a copy of the original I18n configuration and it's acting as proxy, which we need to skip.
[ "Overload", "locale", "=", "to", "also", "set", "the", "I18n", ".", "locale", ".", "If", "the", "current", "I18n", ".", "config", "object", "responds", "to", "original_config", "it", "means", "that", "it", "has", "a", "copy", "of", "the", "original", "I1...
85a8bc644be69908f05740a5886ec19cd3679df5
https://github.com/rails/rails/blob/85a8bc644be69908f05740a5886ec19cd3679df5/actionview/lib/action_view/lookup_context.rb#L307-L314
10,314
rails/rails
actionview/lib/action_view/template/resolver.rb
ActionView.Resolver.find_all
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
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
[ "def", "find_all", "(", "name", ",", "prefix", "=", "nil", ",", "partial", "=", "false", ",", "details", "=", "{", "}", ",", "key", "=", "nil", ",", "locals", "=", "[", "]", ")", "locals", "=", "locals", ".", "map", "(", ":to_s", ")", ".", "sor...
Normalizes the arguments and passes it on to find_templates.
[ "Normalizes", "the", "arguments", "and", "passes", "it", "on", "to", "find_templates", "." ]
85a8bc644be69908f05740a5886ec19cd3679df5
https://github.com/rails/rails/blob/85a8bc644be69908f05740a5886ec19cd3679df5/actionview/lib/action_view/template/resolver.rb#L117-L123
10,315
rails/rails
actionview/lib/action_view/template/resolver.rb
ActionView.Resolver.cached
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
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
[ "def", "cached", "(", "key", ",", "path_info", ",", "details", ",", "locals", ")", "name", ",", "prefix", ",", "partial", "=", "path_info", "if", "key", "@cache", ".", "cache", "(", "key", ",", "name", ",", "prefix", ",", "partial", ",", "locals", ")...
Handles templates caching. If a key is given and caching is on always check the cache before hitting the resolver. Otherwise, it always hits the resolver but if the key is present, check if the resolver is fresher before returning it.
[ "Handles", "templates", "caching", ".", "If", "a", "key", "is", "given", "and", "caching", "is", "on", "always", "check", "the", "cache", "before", "hitting", "the", "resolver", ".", "Otherwise", "it", "always", "hits", "the", "resolver", "but", "if", "the...
85a8bc644be69908f05740a5886ec19cd3679df5
https://github.com/rails/rails/blob/85a8bc644be69908f05740a5886ec19cd3679df5/actionview/lib/action_view/template/resolver.rb#L151-L161
10,316
rails/rails
actionview/lib/action_view/template/resolver.rb
ActionView.PathResolver.extract_handler_and_format_and_variant
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
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...
[ "def", "extract_handler_and_format_and_variant", "(", "path", ")", "pieces", "=", "File", ".", "basename", "(", "path", ")", ".", "split", "(", "\".\"", ")", "pieces", ".", "shift", "extension", "=", "pieces", ".", "pop", "handler", "=", "Template", ".", "...
Extract handler, formats and variant from path. If a format cannot be found neither from the path, or the handler, we should return the array of formats given to the resolver.
[ "Extract", "handler", "formats", "and", "variant", "from", "path", ".", "If", "a", "format", "cannot", "be", "found", "neither", "from", "the", "path", "or", "the", "handler", "we", "should", "return", "the", "array", "of", "formats", "given", "to", "the",...
85a8bc644be69908f05740a5886ec19cd3679df5
https://github.com/rails/rails/blob/85a8bc644be69908f05740a5886ec19cd3679df5/actionview/lib/action_view/template/resolver.rb#L275-L295
10,317
rails/rails
actionview/lib/action_view/renderer/streaming_template_renderer.rb
ActionView.StreamingTemplateRenderer.render_template
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
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,...
[ "def", "render_template", "(", "view", ",", "template", ",", "layout_name", "=", "nil", ",", "locals", "=", "{", "}", ")", "#:nodoc:", "return", "[", "super", ".", "body", "]", "unless", "layout_name", "&&", "template", ".", "supports_streaming?", "locals", ...
For streaming, instead of rendering a given a template, we return a Body object that responds to each. This object is initialized with a block that knows how to render the template.
[ "For", "streaming", "instead", "of", "rendering", "a", "given", "a", "template", "we", "return", "a", "Body", "object", "that", "responds", "to", "each", ".", "This", "object", "is", "initialized", "with", "a", "block", "that", "knows", "how", "to", "rende...
85a8bc644be69908f05740a5886ec19cd3679df5
https://github.com/rails/rails/blob/85a8bc644be69908f05740a5886ec19cd3679df5/actionview/lib/action_view/renderer/streaming_template_renderer.rb#L46-L55
10,318
rails/rails
activerecord/lib/active_record/autosave_association.rb
ActiveRecord.AutosaveAssociation.record_changed?
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
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
[ "def", "record_changed?", "(", "reflection", ",", "record", ",", "key", ")", "record", ".", "new_record?", "||", "association_foreign_key_changed?", "(", "reflection", ",", "record", ",", "key", ")", "||", "record", ".", "will_save_change_to_attribute?", "(", "ref...
If the record is new or it has changed, returns true.
[ "If", "the", "record", "is", "new", "or", "it", "has", "changed", "returns", "true", "." ]
85a8bc644be69908f05740a5886ec19cd3679df5
https://github.com/rails/rails/blob/85a8bc644be69908f05740a5886ec19cd3679df5/activerecord/lib/active_record/autosave_association.rb#L457-L461
10,319
rails/rails
activesupport/lib/active_support/inflector/transliterate.rb
ActiveSupport.Inflector.transliterate
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
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...
[ "def", "transliterate", "(", "string", ",", "replacement", "=", "\"?\"", ",", "locale", ":", "nil", ")", "raise", "ArgumentError", ",", "\"Can only transliterate strings. Received #{string.class.name}\"", "unless", "string", ".", "is_a?", "(", "String", ")", "I18n", ...
Replaces non-ASCII characters with an ASCII approximation, or if none exists, a replacement character which defaults to "?". transliterate('Ærøskøbing') # => "AEroskobing" Default approximations are provided for Western/Latin characters, e.g, "ø", "ñ", "é", "ß", etc. This method is I18n aware, so you can...
[ "Replaces", "non", "-", "ASCII", "characters", "with", "an", "ASCII", "approximation", "or", "if", "none", "exists", "a", "replacement", "character", "which", "defaults", "to", "?", "." ]
85a8bc644be69908f05740a5886ec19cd3679df5
https://github.com/rails/rails/blob/85a8bc644be69908f05740a5886ec19cd3679df5/activesupport/lib/active_support/inflector/transliterate.rb#L59-L67
10,320
rails/rails
activemodel/lib/active_model/errors.rb
ActiveModel.Errors.import
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
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
[ "def", "import", "(", "error", ",", "override_options", "=", "{", "}", ")", "[", ":attribute", ",", ":type", "]", ".", "each", "do", "|", "key", "|", "if", "override_options", ".", "key?", "(", "key", ")", "override_options", "[", "key", "]", "=", "o...
Imports one error Imported errors are wrapped as a NestedError, providing access to original error object. If attribute or type needs to be overriden, use `override_options`. override_options - Hash @option override_options [Symbol] :attribute Override the attribute the error belongs to @option override_options ...
[ "Imports", "one", "error", "Imported", "errors", "are", "wrapped", "as", "a", "NestedError", "providing", "access", "to", "original", "error", "object", ".", "If", "attribute", "or", "type", "needs", "to", "be", "overriden", "use", "override_options", "." ]
85a8bc644be69908f05740a5886ec19cd3679df5
https://github.com/rails/rails/blob/85a8bc644be69908f05740a5886ec19cd3679df5/activemodel/lib/active_model/errors.rb#L121-L128
10,321
rails/rails
activemodel/lib/active_model/errors.rb
ActiveModel.Errors.slice!
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
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
[ "def", "slice!", "(", "*", "keys", ")", "deprecation_removal_warning", "(", ":slice!", ")", "keys", "=", "keys", ".", "map", "(", ":to_sym", ")", "results", "=", "messages", ".", "dup", ".", "slice!", "(", "keys", ")", "@errors", ".", "keep_if", "do", ...
Removes all errors except the given keys. Returns a hash containing the removed errors. person.errors.keys # => [:name, :age, :gender, :city] person.errors.slice!(:age, :gender) # => { :name=>["cannot be nil"], :city=>["cannot be nil"] } person.errors.keys # => [:age, :gender...
[ "Removes", "all", "errors", "except", "the", "given", "keys", ".", "Returns", "a", "hash", "containing", "the", "removed", "errors", "." ]
85a8bc644be69908f05740a5886ec19cd3679df5
https://github.com/rails/rails/blob/85a8bc644be69908f05740a5886ec19cd3679df5/activemodel/lib/active_model/errors.rb#L149-L161
10,322
rails/rails
activemodel/lib/active_model/errors.rb
ActiveModel.Errors.where
def where(attribute, type = nil, **options) attribute, type, options = normalize_arguments(attribute, type, options) @errors.select { |error| error.match?(attribute, type, options) } end
ruby
def where(attribute, type = nil, **options) attribute, type, options = normalize_arguments(attribute, type, options) @errors.select { |error| error.match?(attribute, type, options) } end
[ "def", "where", "(", "attribute", ",", "type", "=", "nil", ",", "**", "options", ")", "attribute", ",", "type", ",", "options", "=", "normalize_arguments", "(", "attribute", ",", "type", ",", "options", ")", "@errors", ".", "select", "{", "|", "error", ...
Search for errors matching +attribute+, +type+ or +options+. Only supplied params will be matched. person.errors.where(:name) # => all name errors. person.errors.where(:name, :too_short) # => all name errors being too short person.errors.where(:name, :too_short, minimum: 2) # => all name errors being too sh...
[ "Search", "for", "errors", "matching", "+", "attribute", "+", "+", "type", "+", "or", "+", "options", "+", "." ]
85a8bc644be69908f05740a5886ec19cd3679df5
https://github.com/rails/rails/blob/85a8bc644be69908f05740a5886ec19cd3679df5/activemodel/lib/active_model/errors.rb#L170-L175
10,323
rails/rails
activemodel/lib/active_model/errors.rb
ActiveModel.Errors.delete
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
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
[ "def", "delete", "(", "attribute", ",", "type", "=", "nil", ",", "**", "options", ")", "attribute", ",", "type", ",", "options", "=", "normalize_arguments", "(", "attribute", ",", "type", ",", "options", ")", "matches", "=", "where", "(", "attribute", ",...
Delete messages for +key+. Returns the deleted messages. person.errors[:name] # => ["cannot be nil"] person.errors.delete(:name) # => ["cannot be nil"] person.errors[:name] # => []
[ "Delete", "messages", "for", "+", "key", "+", ".", "Returns", "the", "deleted", "messages", "." ]
85a8bc644be69908f05740a5886ec19cd3679df5
https://github.com/rails/rails/blob/85a8bc644be69908f05740a5886ec19cd3679df5/activemodel/lib/active_model/errors.rb#L196-L203
10,324
rails/rails
activemodel/lib/active_model/errors.rb
ActiveModel.Errors.each
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
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 ...
[ "def", "each", "(", "&", "block", ")", "if", "block", ".", "arity", "==", "1", "@errors", ".", "each", "(", "block", ")", "else", "ActiveSupport", "::", "Deprecation", ".", "warn", "(", "<<~MSG", ")", "MSG", "@errors", ".", "sort", "{", "|", "a", "...
Iterates through each error key, value pair in the error messages hash. Yields the attribute and the error for that attribute. If the attribute has more than one error message, yields once for each error message. person.errors.add(:name, :blank, message: "can't be blank") person.errors.each do |attribute, erro...
[ "Iterates", "through", "each", "error", "key", "value", "pair", "in", "the", "error", "messages", "hash", ".", "Yields", "the", "attribute", "and", "the", "error", "for", "that", "attribute", ".", "If", "the", "attribute", "has", "more", "than", "one", "er...
85a8bc644be69908f05740a5886ec19cd3679df5
https://github.com/rails/rails/blob/85a8bc644be69908f05740a5886ec19cd3679df5/activemodel/lib/active_model/errors.rb#L228-L250
10,325
rails/rails
activemodel/lib/active_model/errors.rb
ActiveModel.Errors.to_xml
def to_xml(options = {}) deprecation_removal_warning(:to_xml) to_a.to_xml({ root: "errors", skip_types: true }.merge!(options)) end
ruby
def to_xml(options = {}) deprecation_removal_warning(:to_xml) to_a.to_xml({ root: "errors", skip_types: true }.merge!(options)) end
[ "def", "to_xml", "(", "options", "=", "{", "}", ")", "deprecation_removal_warning", "(", ":to_xml", ")", "to_a", ".", "to_xml", "(", "{", "root", ":", "\"errors\"", ",", "skip_types", ":", "true", "}", ".", "merge!", "(", "options", ")", ")", "end" ]
Returns an xml formatted representation of the Errors hash. person.errors.add(:name, :blank, message: "can't be blank") person.errors.add(:name, :not_specified, message: "must be specified") person.errors.to_xml # => # <?xml version=\"1.0\" encoding=\"UTF-8\"?> # <errors> # <error>name can't ...
[ "Returns", "an", "xml", "formatted", "representation", "of", "the", "Errors", "hash", "." ]
85a8bc644be69908f05740a5886ec19cd3679df5
https://github.com/rails/rails/blob/85a8bc644be69908f05740a5886ec19cd3679df5/activemodel/lib/active_model/errors.rb#L283-L286
10,326
rails/rails
activerecord/lib/active_record/migration.rb
ActiveRecord.Migration.revert
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
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_...
[ "def", "revert", "(", "*", "migration_classes", ")", "run", "(", "migration_classes", ".", "reverse", ",", "revert", ":", "true", ")", "unless", "migration_classes", ".", "empty?", "if", "block_given?", "if", "connection", ".", "respond_to?", ":revert", "connect...
Reverses the migration commands for the given block and the given migrations. The following migration will remove the table 'horses' and create the table 'apples' on the way up, and the reverse on the way down. class FixTLMigration < ActiveRecord::Migration[5.0] def change revert do create...
[ "Reverses", "the", "migration", "commands", "for", "the", "given", "block", "and", "the", "given", "migrations", "." ]
85a8bc644be69908f05740a5886ec19cd3679df5
https://github.com/rails/rails/blob/85a8bc644be69908f05740a5886ec19cd3679df5/activerecord/lib/active_record/migration.rb#L682-L697
10,327
rails/rails
activerecord/lib/active_record/migration.rb
ActiveRecord.Migration.say_with_time
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
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
[ "def", "say_with_time", "(", "message", ")", "say", "(", "message", ")", "result", "=", "nil", "time", "=", "Benchmark", ".", "measure", "{", "result", "=", "yield", "}", "say", "\"%.4fs\"", "%", "time", ".", "real", ",", ":subitem", "say", "(", "\"#{r...
Outputs text along with how long it took to run its block. If the block returns an integer it assumes it is the number of rows affected.
[ "Outputs", "text", "along", "with", "how", "long", "it", "took", "to", "run", "its", "block", ".", "If", "the", "block", "returns", "an", "integer", "it", "assumes", "it", "is", "the", "number", "of", "rows", "affected", "." ]
85a8bc644be69908f05740a5886ec19cd3679df5
https://github.com/rails/rails/blob/85a8bc644be69908f05740a5886ec19cd3679df5/activerecord/lib/active_record/migration.rb#L847-L854
10,328
rails/rails
activerecord/lib/active_record/migration.rb
ActiveRecord.Migration.next_migration_number
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
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
[ "def", "next_migration_number", "(", "number", ")", "if", "ActiveRecord", "::", "Base", ".", "timestamped_migrations", "[", "Time", ".", "now", ".", "utc", ".", "strftime", "(", "\"%Y%m%d%H%M%S\"", ")", ",", "\"%.14d\"", "%", "number", "]", ".", "max", "else...
Determines the version number of the next migration.
[ "Determines", "the", "version", "number", "of", "the", "next", "migration", "." ]
85a8bc644be69908f05740a5886ec19cd3679df5
https://github.com/rails/rails/blob/85a8bc644be69908f05740a5886ec19cd3679df5/activerecord/lib/active_record/migration.rb#L945-L951
10,329
rails/rails
activerecord/lib/active_record/migration.rb
ActiveRecord.Migrator.run_without_lock
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
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
[ "def", "run_without_lock", "migration", "=", "migrations", ".", "detect", "{", "|", "m", "|", "m", ".", "version", "==", "@target_version", "}", "raise", "UnknownMigrationVersionError", ".", "new", "(", "@target_version", ")", "if", "migration", ".", "nil?", "...
Used for running a specific migration.
[ "Used", "for", "running", "a", "specific", "migration", "." ]
85a8bc644be69908f05740a5886ec19cd3679df5
https://github.com/rails/rails/blob/85a8bc644be69908f05740a5886ec19cd3679df5/activerecord/lib/active_record/migration.rb#L1255-L1262
10,330
rails/rails
activerecord/lib/active_record/migration.rb
ActiveRecord.Migrator.migrate_without_lock
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
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
[ "def", "migrate_without_lock", "if", "invalid_target?", "raise", "UnknownMigrationVersionError", ".", "new", "(", "@target_version", ")", "end", "result", "=", "runnable", ".", "each", "do", "|", "migration", "|", "execute_migration_in_transaction", "(", "migration", ...
Used for running multiple migrations up to or down to a certain value.
[ "Used", "for", "running", "multiple", "migrations", "up", "to", "or", "down", "to", "a", "certain", "value", "." ]
85a8bc644be69908f05740a5886ec19cd3679df5
https://github.com/rails/rails/blob/85a8bc644be69908f05740a5886ec19cd3679df5/activerecord/lib/active_record/migration.rb#L1265-L1276
10,331
rails/rails
actionpack/lib/action_controller/metal/strong_parameters.rb
ActionController.Parameters.permit!
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
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
[ "def", "permit!", "each_pair", "do", "|", "key", ",", "value", "|", "Array", ".", "wrap", "(", "value", ")", ".", "flatten", ".", "each", "do", "|", "v", "|", "v", ".", "permit!", "if", "v", ".", "respond_to?", ":permit!", "end", "end", "@permitted",...
Sets the +permitted+ attribute to +true+. This can be used to pass mass assignment. Returns +self+. class Person < ActiveRecord::Base end params = ActionController::Parameters.new(name: "Francesco") params.permitted? # => false Person.new(params) # => ActiveModel::ForbiddenAttributesError params.p...
[ "Sets", "the", "+", "permitted", "+", "attribute", "to", "+", "true", "+", ".", "This", "can", "be", "used", "to", "pass", "mass", "assignment", ".", "Returns", "+", "self", "+", "." ]
85a8bc644be69908f05740a5886ec19cd3679df5
https://github.com/rails/rails/blob/85a8bc644be69908f05740a5886ec19cd3679df5/actionpack/lib/action_controller/metal/strong_parameters.rb#L391-L400
10,332
rails/rails
actionpack/lib/action_controller/metal/strong_parameters.rb
ActionController.Parameters.require
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
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
[ "def", "require", "(", "key", ")", "return", "key", ".", "map", "{", "|", "k", "|", "require", "(", "k", ")", "}", "if", "key", ".", "is_a?", "(", "Array", ")", "value", "=", "self", "[", "key", "]", "if", "value", ".", "present?", "||", "value...
This method accepts both a single key and an array of keys. When passed a single key, if it exists and its associated value is either present or the singleton +false+, returns said value: ActionController::Parameters.new(person: { name: "Francesco" }).require(:person) # => <ActionController::Parameters {"name...
[ "This", "method", "accepts", "both", "a", "single", "key", "and", "an", "array", "of", "keys", "." ]
85a8bc644be69908f05740a5886ec19cd3679df5
https://github.com/rails/rails/blob/85a8bc644be69908f05740a5886ec19cd3679df5/actionpack/lib/action_controller/metal/strong_parameters.rb#L452-L460
10,333
rails/rails
actionpack/lib/action_controller/metal/strong_parameters.rb
ActionController.Parameters.permitted_scalar_filter
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
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/ ...
[ "def", "permitted_scalar_filter", "(", "params", ",", "permitted_key", ")", "permitted_key", "=", "permitted_key", ".", "to_s", "if", "has_key?", "(", "permitted_key", ")", "&&", "permitted_scalar?", "(", "self", "[", "permitted_key", "]", ")", "params", "[", "p...
Adds existing keys to the params if their values are scalar. For example: puts self.keys #=> ["zipcode(90210i)"] params = {} permitted_scalar_filter(params, "zipcode") puts params.keys # => ["zipcode"]
[ "Adds", "existing", "keys", "to", "the", "params", "if", "their", "values", "are", "scalar", "." ]
85a8bc644be69908f05740a5886ec19cd3679df5
https://github.com/rails/rails/blob/85a8bc644be69908f05740a5886ec19cd3679df5/actionpack/lib/action_controller/metal/strong_parameters.rb#L933-L946
10,334
rails/rails
actionview/lib/action_view/rendering.rb
ActionView.Rendering.process
def process(*) #:nodoc: old_config, I18n.config = I18n.config, I18nProxy.new(I18n.config, lookup_context) super ensure I18n.config = old_config end
ruby
def process(*) #:nodoc: old_config, I18n.config = I18n.config, I18nProxy.new(I18n.config, lookup_context) super ensure I18n.config = old_config end
[ "def", "process", "(", "*", ")", "#:nodoc:", "old_config", ",", "I18n", ".", "config", "=", "I18n", ".", "config", ",", "I18nProxy", ".", "new", "(", "I18n", ".", "config", ",", "lookup_context", ")", "super", "ensure", "I18n", ".", "config", "=", "old...
Overwrite process to setup I18n proxy.
[ "Overwrite", "process", "to", "setup", "I18n", "proxy", "." ]
85a8bc644be69908f05740a5886ec19cd3679df5
https://github.com/rails/rails/blob/85a8bc644be69908f05740a5886ec19cd3679df5/actionview/lib/action_view/rendering.rb#L37-L42
10,335
rails/rails
actionview/lib/action_view/rendering.rb
ActionView.Rendering._render_template
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
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...
[ "def", "_render_template", "(", "options", ")", "variant", "=", "options", ".", "delete", "(", ":variant", ")", "assigns", "=", "options", ".", "delete", "(", ":assigns", ")", "context", "=", "view_context", "context", ".", "assign", "assigns", "if", "assign...
Find and render a template based on the options given.
[ "Find", "and", "render", "a", "template", "based", "on", "the", "options", "given", "." ]
85a8bc644be69908f05740a5886ec19cd3679df5
https://github.com/rails/rails/blob/85a8bc644be69908f05740a5886ec19cd3679df5/actionview/lib/action_view/rendering.rb#L109-L125
10,336
rails/rails
actionview/lib/action_view/rendering.rb
ActionView.Rendering._normalize_options
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
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...
[ "def", "_normalize_options", "(", "options", ")", "options", "=", "super", "(", "options", ")", "if", "options", "[", ":partial", "]", "==", "true", "options", "[", ":partial", "]", "=", "action_name", "end", "if", "(", "options", ".", "keys", "&", "[", ...
Normalize options.
[ "Normalize", "options", "." ]
85a8bc644be69908f05740a5886ec19cd3679df5
https://github.com/rails/rails/blob/85a8bc644be69908f05740a5886ec19cd3679df5/actionview/lib/action_view/rendering.rb#L157-L169
10,337
rails/rails
activejob/lib/active_job/enqueuing.rb
ActiveJob.Enqueuing.enqueue
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
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...
[ "def", "enqueue", "(", "options", "=", "{", "}", ")", "self", ".", "scheduled_at", "=", "options", "[", ":wait", "]", ".", "seconds", ".", "from_now", ".", "to_f", "if", "options", "[", ":wait", "]", "self", ".", "scheduled_at", "=", "options", "[", ...
Enqueues the job to be performed by the queue adapter. ==== Options * <tt>:wait</tt> - Enqueues the job with the specified delay * <tt>:wait_until</tt> - Enqueues the job at the time specified * <tt>:queue</tt> - Enqueues the job on the specified queue * <tt>:priority</tt> - Enqueues the job with the specified pr...
[ "Enqueues", "the", "job", "to", "be", "performed", "by", "the", "queue", "adapter", "." ]
85a8bc644be69908f05740a5886ec19cd3679df5
https://github.com/rails/rails/blob/85a8bc644be69908f05740a5886ec19cd3679df5/activejob/lib/active_job/enqueuing.rb#L46-L78
10,338
rails/rails
activerecord/lib/active_record/fixtures.rb
ActiveRecord.FixtureSet.table_rows
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
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
[ "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",...
Returns a hash of rows to be inserted. The key is the table, the value is a list of rows to insert to that table.
[ "Returns", "a", "hash", "of", "rows", "to", "be", "inserted", ".", "The", "key", "is", "the", "table", "the", "value", "is", "a", "list", "of", "rows", "to", "insert", "to", "that", "table", "." ]
85a8bc644be69908f05740a5886ec19cd3679df5
https://github.com/rails/rails/blob/85a8bc644be69908f05740a5886ec19cd3679df5/activerecord/lib/active_record/fixtures.rb#L651-L661
10,339
rails/rails
activerecord/lib/active_record/fixtures.rb
ActiveRecord.FixtureSet.read_fixture_files
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
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...
[ "def", "read_fixture_files", "(", "path", ")", "yaml_files", "=", "Dir", "[", "\"#{path}/{**,*}/*.yml\"", "]", ".", "select", "{", "|", "f", "|", "::", "File", ".", "file?", "(", "f", ")", "}", "+", "[", "yaml_file_path", "(", "path", ")", "]", "yaml_f...
Loads the fixtures from the YAML file at +path+. If the file sets the +model_class+ and current instance value is not set, it uses the file value.
[ "Loads", "the", "fixtures", "from", "the", "YAML", "file", "at", "+", "path", "+", ".", "If", "the", "file", "sets", "the", "+", "model_class", "+", "and", "current", "instance", "value", "is", "not", "set", "it", "uses", "the", "file", "value", "." ]
85a8bc644be69908f05740a5886ec19cd3679df5
https://github.com/rails/rails/blob/85a8bc644be69908f05740a5886ec19cd3679df5/activerecord/lib/active_record/fixtures.rb#L676-L689
10,340
rails/rails
activestorage/lib/active_storage/downloading.rb
ActiveStorage.Downloading.download_blob_to
def download_blob_to(file) #:doc: file.binmode blob.download { |chunk| file.write(chunk) } file.flush file.rewind end
ruby
def download_blob_to(file) #:doc: file.binmode blob.download { |chunk| file.write(chunk) } file.flush file.rewind end
[ "def", "download_blob_to", "(", "file", ")", "#:doc:", "file", ".", "binmode", "blob", ".", "download", "{", "|", "chunk", "|", "file", ".", "write", "(", "chunk", ")", "}", "file", ".", "flush", "file", ".", "rewind", "end" ]
Efficiently downloads blob data into the given file.
[ "Efficiently", "downloads", "blob", "data", "into", "the", "given", "file", "." ]
85a8bc644be69908f05740a5886ec19cd3679df5
https://github.com/rails/rails/blob/85a8bc644be69908f05740a5886ec19cd3679df5/activestorage/lib/active_storage/downloading.rb#L35-L40
10,341
rails/rails
actionpack/lib/action_controller/metal/conditional_get.rb
ActionController.ConditionalGet.expires_in
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
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_...
[ "def", "expires_in", "(", "seconds", ",", "options", "=", "{", "}", ")", "response", ".", "cache_control", ".", "merge!", "(", "max_age", ":", "seconds", ",", "public", ":", "options", ".", "delete", "(", ":public", ")", ",", "must_revalidate", ":", "opt...
Sets an HTTP 1.1 Cache-Control header. Defaults to issuing a +private+ instruction, so that intermediate caches must not cache the response. expires_in 20.minutes expires_in 3.hours, public: true expires_in 3.hours, public: true, must_revalidate: true This method will overwrite an existing Cache-Control he...
[ "Sets", "an", "HTTP", "1", ".", "1", "Cache", "-", "Control", "header", ".", "Defaults", "to", "issuing", "a", "+", "private", "+", "instruction", "so", "that", "intermediate", "caches", "must", "not", "cache", "the", "response", "." ]
85a8bc644be69908f05740a5886ec19cd3679df5
https://github.com/rails/rails/blob/85a8bc644be69908f05740a5886ec19cd3679df5/actionpack/lib/action_controller/metal/conditional_get.rb#L238-L250
10,342
rails/rails
actionpack/lib/action_controller/metal/conditional_get.rb
ActionController.ConditionalGet.http_cache_forever
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
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
[ "def", "http_cache_forever", "(", "public", ":", "false", ")", "expires_in", "100", ".", "years", ",", "public", ":", "public", "yield", "if", "stale?", "(", "etag", ":", "request", ".", "fullpath", ",", "last_modified", ":", "Time", ".", "new", "(", "20...
Cache or yield the block. The cache is supposed to never expire. You can use this method when you have an HTTP response that never changes, and the browser and proxies should cache it indefinitely. * +public+: By default, HTTP responses are private, cached only on the user's web browser. To allow proxies to cac...
[ "Cache", "or", "yield", "the", "block", ".", "The", "cache", "is", "supposed", "to", "never", "expire", "." ]
85a8bc644be69908f05740a5886ec19cd3679df5
https://github.com/rails/rails/blob/85a8bc644be69908f05740a5886ec19cd3679df5/actionpack/lib/action_controller/metal/conditional_get.rb#L267-L273
10,343
rails/rails
activestorage/lib/active_storage/previewer.rb
ActiveStorage.Previewer.draw
def draw(*argv) #:doc: open_tempfile do |file| instrument :preview, key: blob.key do capture(*argv, to: file) end yield file end end
ruby
def draw(*argv) #:doc: open_tempfile do |file| instrument :preview, key: blob.key do capture(*argv, to: file) end yield file end end
[ "def", "draw", "(", "*", "argv", ")", "#:doc:", "open_tempfile", "do", "|", "file", "|", "instrument", ":preview", ",", "key", ":", "blob", ".", "key", "do", "capture", "(", "argv", ",", "to", ":", "file", ")", "end", "yield", "file", "end", "end" ]
Executes a system command, capturing its binary output in a tempfile. Yields the tempfile. Use this method to shell out to a system library (e.g. muPDF or FFmpeg) for preview image generation. The resulting tempfile can be used as the +:io+ value in an attachable Hash: def preview download_blob_to_tempfile ...
[ "Executes", "a", "system", "command", "capturing", "its", "binary", "output", "in", "a", "tempfile", ".", "Yields", "the", "tempfile", "." ]
85a8bc644be69908f05740a5886ec19cd3679df5
https://github.com/rails/rails/blob/85a8bc644be69908f05740a5886ec19cd3679df5/activestorage/lib/active_storage/previewer.rb#L46-L54
10,344
rails/rails
actionpack/lib/action_controller/metal/rendering.rb
ActionController.Rendering.render_to_string
def render_to_string(*) result = super if result.respond_to?(:each) string = +"" result.each { |r| string << r } string else result end end
ruby
def render_to_string(*) result = super if result.respond_to?(:each) string = +"" result.each { |r| string << r } string else result end end
[ "def", "render_to_string", "(", "*", ")", "result", "=", "super", "if", "result", ".", "respond_to?", "(", ":each", ")", "string", "=", "+", "\"\"", "result", ".", "each", "{", "|", "r", "|", "string", "<<", "r", "}", "string", "else", "result", "end...
Overwrite render_to_string because body can now be set to a Rack body.
[ "Overwrite", "render_to_string", "because", "body", "can", "now", "be", "set", "to", "a", "Rack", "body", "." ]
85a8bc644be69908f05740a5886ec19cd3679df5
https://github.com/rails/rails/blob/85a8bc644be69908f05740a5886ec19cd3679df5/actionpack/lib/action_controller/metal/rendering.rb#L40-L49
10,345
rails/rails
actionpack/lib/action_controller/metal/rendering.rb
ActionController.Rendering._normalize_options
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
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
[ "def", "_normalize_options", "(", "options", ")", "_normalize_text", "(", "options", ")", "if", "options", "[", ":html", "]", "options", "[", ":html", "]", "=", "ERB", "::", "Util", ".", "html_escape", "(", "options", "[", ":html", "]", ")", "end", "if",...
Normalize both text and status options.
[ "Normalize", "both", "text", "and", "status", "options", "." ]
85a8bc644be69908f05740a5886ec19cd3679df5
https://github.com/rails/rails/blob/85a8bc644be69908f05740a5886ec19cd3679df5/actionpack/lib/action_controller/metal/rendering.rb#L89-L101
10,346
rails/rails
actionpack/lib/action_controller/metal/rendering.rb
ActionController.Rendering._process_options
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
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
[ "def", "_process_options", "(", "options", ")", "status", ",", "content_type", ",", "location", "=", "options", ".", "values_at", "(", ":status", ",", ":content_type", ",", ":location", ")", "self", ".", "status", "=", "status", "if", "status", "self", ".", ...
Process controller specific options, as status, content-type and location.
[ "Process", "controller", "specific", "options", "as", "status", "content", "-", "type", "and", "location", "." ]
85a8bc644be69908f05740a5886ec19cd3679df5
https://github.com/rails/rails/blob/85a8bc644be69908f05740a5886ec19cd3679df5/actionpack/lib/action_controller/metal/rendering.rb#L112-L120
10,347
rails/rails
actionpack/lib/action_dispatch/middleware/remote_ip.rb
ActionDispatch.RemoteIp.call
def call(env) req = ActionDispatch::Request.new env req.remote_ip = GetIp.new(req, check_ip, proxies) @app.call(req.env) end
ruby
def call(env) req = ActionDispatch::Request.new env req.remote_ip = GetIp.new(req, check_ip, proxies) @app.call(req.env) end
[ "def", "call", "(", "env", ")", "req", "=", "ActionDispatch", "::", "Request", ".", "new", "env", "req", ".", "remote_ip", "=", "GetIp", ".", "new", "(", "req", ",", "check_ip", ",", "proxies", ")", "@app", ".", "call", "(", "req", ".", "env", ")",...
Create a new +RemoteIp+ middleware instance. The +ip_spoofing_check+ option is on by default. When on, an exception is raised if it looks like the client is trying to lie about its own IP address. It makes sense to turn off this check on sites aimed at non-IP clients (like WAP devices), or behind proxies that set ...
[ "Create", "a", "new", "+", "RemoteIp", "+", "middleware", "instance", "." ]
85a8bc644be69908f05740a5886ec19cd3679df5
https://github.com/rails/rails/blob/85a8bc644be69908f05740a5886ec19cd3679df5/actionpack/lib/action_dispatch/middleware/remote_ip.rb#L78-L82
10,348
rails/rails
activemodel/lib/active_model/validations/with.rb
ActiveModel.Validations.validates_with
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
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
[ "def", "validates_with", "(", "*", "args", ",", "&", "block", ")", "options", "=", "args", ".", "extract_options!", "options", "[", ":class", "]", "=", "self", ".", "class", "args", ".", "each", "do", "|", "klass", "|", "validator", "=", "klass", ".", ...
Passes the record off to the class or classes specified and allows them to add errors based on more complex conditions. class Person include ActiveModel::Validations validate :instance_validations def instance_validations validates_with MyValidator end end Please consult the class...
[ "Passes", "the", "record", "off", "to", "the", "class", "or", "classes", "specified", "and", "allows", "them", "to", "add", "errors", "based", "on", "more", "complex", "conditions", "." ]
85a8bc644be69908f05740a5886ec19cd3679df5
https://github.com/rails/rails/blob/85a8bc644be69908f05740a5886ec19cd3679df5/activemodel/lib/active_model/validations/with.rb#L137-L145
10,349
rails/rails
actionview/lib/action_view/template.rb
ActionView.Template.render
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
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
[ "def", "render", "(", "view", ",", "locals", ",", "buffer", "=", "ActionView", "::", "OutputBuffer", ".", "new", ",", "&", "block", ")", "instrument_render_template", "do", "compile!", "(", "view", ")", "view", ".", "_run", "(", "method_name", ",", "self",...
Render a template. If the template was not compiled yet, it is done exactly before rendering. This method is instrumented as "!render_template.action_view". Notice that we use a bang in this instrumentation because you don't want to consume this in production. This is only slow if it's being listened to.
[ "Render", "a", "template", ".", "If", "the", "template", "was", "not", "compiled", "yet", "it", "is", "done", "exactly", "before", "rendering", "." ]
85a8bc644be69908f05740a5886ec19cd3679df5
https://github.com/rails/rails/blob/85a8bc644be69908f05740a5886ec19cd3679df5/actionview/lib/action_view/template.rb#L182-L189
10,350
rails/rails
actionview/lib/action_view/template.rb
ActionView.Template.compile!
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
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...
[ "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...
Compile a template. This method ensures a template is compiled just once and removes the source after it is compiled.
[ "Compile", "a", "template", ".", "This", "method", "ensures", "a", "template", "is", "compiled", "just", "once", "and", "removes", "the", "source", "after", "it", "is", "compiled", "." ]
85a8bc644be69908f05740a5886ec19cd3679df5
https://github.com/rails/rails/blob/85a8bc644be69908f05740a5886ec19cd3679df5/actionview/lib/action_view/template.rb#L270-L290
10,351
rails/rails
activerecord/lib/active_record/persistence.rb
ActiveRecord.Persistence.reload
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
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...
[ "def", "reload", "(", "options", "=", "nil", ")", "self", ".", "class", ".", "connection", ".", "clear_query_cache", "fresh_object", "=", "if", "options", "&&", "options", "[", ":lock", "]", "self", ".", "class", ".", "unscoped", "{", "self", ".", "class...
Reloads the record from the database. This method finds the record by its primary key (which could be assigned manually) and modifies the receiver in-place: account = Account.new # => #<Account id: nil, email: nil> account.id = 1 account.reload # Account Load (1.2ms) SELECT "accounts".* FROM "accoun...
[ "Reloads", "the", "record", "from", "the", "database", "." ]
85a8bc644be69908f05740a5886ec19cd3679df5
https://github.com/rails/rails/blob/85a8bc644be69908f05740a5886ec19cd3679df5/activerecord/lib/active_record/persistence.rb#L802-L815
10,352
rails/rails
actionpack/lib/action_controller/metal/request_forgery_protection.rb
ActionController.RequestForgeryProtection.masked_authenticity_token
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
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...
[ "def", "masked_authenticity_token", "(", "session", ",", "form_options", ":", "{", "}", ")", "# :doc:", "action", ",", "method", "=", "form_options", ".", "values_at", "(", ":action", ",", ":method", ")", "raw_token", "=", "if", "per_form_csrf_tokens", "&&", "...
Creates a masked version of the authenticity token that varies on each request. The masking is used to mitigate SSL attacks like BREACH.
[ "Creates", "a", "masked", "version", "of", "the", "authenticity", "token", "that", "varies", "on", "each", "request", ".", "The", "masking", "is", "used", "to", "mitigate", "SSL", "attacks", "like", "BREACH", "." ]
85a8bc644be69908f05740a5886ec19cd3679df5
https://github.com/rails/rails/blob/85a8bc644be69908f05740a5886ec19cd3679df5/actionpack/lib/action_controller/metal/request_forgery_protection.rb#L320-L334
10,353
rails/rails
actionpack/lib/action_controller/metal/request_forgery_protection.rb
ActionController.RequestForgeryProtection.valid_authenticity_token?
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
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...
[ "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", "f...
Checks the client's masked token to see if it matches the session token. Essentially the inverse of +masked_authenticity_token+.
[ "Checks", "the", "client", "s", "masked", "token", "to", "see", "if", "it", "matches", "the", "session", "token", ".", "Essentially", "the", "inverse", "of", "+", "masked_authenticity_token", "+", "." ]
85a8bc644be69908f05740a5886ec19cd3679df5
https://github.com/rails/rails/blob/85a8bc644be69908f05740a5886ec19cd3679df5/actionpack/lib/action_controller/metal/request_forgery_protection.rb#L339-L368
10,354
rails/rails
actionpack/lib/action_controller/metal/request_forgery_protection.rb
ActionController.RequestForgeryProtection.valid_request_origin?
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
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 ...
[ "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"...
Checks if the request originated from the same origin by looking at the Origin header.
[ "Checks", "if", "the", "request", "originated", "from", "the", "same", "origin", "by", "looking", "at", "the", "Origin", "header", "." ]
85a8bc644be69908f05740a5886ec19cd3679df5
https://github.com/rails/rails/blob/85a8bc644be69908f05740a5886ec19cd3679df5/actionpack/lib/action_controller/metal/request_forgery_protection.rb#L441-L449
10,355
rails/rails
activerecord/lib/active_record/transactions.rb
ActiveRecord.Transactions.remember_transaction_record_state
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
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_...
[ "def", "remember_transaction_record_state", "@_start_transaction_state", "||=", "{", "id", ":", "id", ",", "new_record", ":", "@new_record", ",", "destroyed", ":", "@destroyed", ",", "attributes", ":", "@attributes", ",", "frozen?", ":", "frozen?", ",", "level", "...
Save the new record state and id of a record so it can be restored later if a transaction fails.
[ "Save", "the", "new", "record", "state", "and", "id", "of", "a", "record", "so", "it", "can", "be", "restored", "later", "if", "a", "transaction", "fails", "." ]
85a8bc644be69908f05740a5886ec19cd3679df5
https://github.com/rails/rails/blob/85a8bc644be69908f05740a5886ec19cd3679df5/activerecord/lib/active_record/transactions.rb#L385-L396
10,356
rails/rails
activerecord/lib/active_record/transactions.rb
ActiveRecord.Transactions.sync_with_transaction_state
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
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? ...
[ "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", "trans...
Updates the attributes on this particular Active Record object so that if it's associated with a transaction, then the state of the Active Record object will be updated to reflect the current state of the transaction. The <tt>@transaction_state</tt> variable stores the states of the associated transaction. This re...
[ "Updates", "the", "attributes", "on", "this", "particular", "Active", "Record", "object", "so", "that", "if", "it", "s", "associated", "with", "a", "transaction", "then", "the", "state", "of", "the", "Active", "Record", "object", "will", "be", "updated", "to...
85a8bc644be69908f05740a5886ec19cd3679df5
https://github.com/rails/rails/blob/85a8bc644be69908f05740a5886ec19cd3679df5/activerecord/lib/active_record/transactions.rb#L481-L493
10,357
rails/rails
activesupport/lib/active_support/security_utils.rb
ActiveSupport.SecurityUtils.fixed_length_secure_compare
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
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
[ "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", ...
Constant time string comparison, for fixed length strings. The values compared should be of fixed length, such as strings that have already been processed by HMAC. Raises in case of length mismatch.
[ "Constant", "time", "string", "comparison", "for", "fixed", "length", "strings", "." ]
85a8bc644be69908f05740a5886ec19cd3679df5
https://github.com/rails/rails/blob/85a8bc644be69908f05740a5886ec19cd3679df5/activesupport/lib/active_support/security_utils.rb#L11-L19
10,358
rails/rails
activesupport/lib/active_support/security_utils.rb
ActiveSupport.SecurityUtils.secure_compare
def secure_compare(a, b) fixed_length_secure_compare(::Digest::SHA256.digest(a), ::Digest::SHA256.digest(b)) && a == b end
ruby
def secure_compare(a, b) fixed_length_secure_compare(::Digest::SHA256.digest(a), ::Digest::SHA256.digest(b)) && a == b end
[ "def", "secure_compare", "(", "a", ",", "b", ")", "fixed_length_secure_compare", "(", "::", "Digest", "::", "SHA256", ".", "digest", "(", "a", ")", ",", "::", "Digest", "::", "SHA256", ".", "digest", "(", "b", ")", ")", "&&", "a", "==", "b", "end" ]
Constant time string comparison, for variable length strings. The values are first processed by SHA256, so that we don't leak length info via timing attacks.
[ "Constant", "time", "string", "comparison", "for", "variable", "length", "strings", "." ]
85a8bc644be69908f05740a5886ec19cd3679df5
https://github.com/rails/rails/blob/85a8bc644be69908f05740a5886ec19cd3679df5/activesupport/lib/active_support/security_utils.rb#L26-L28
10,359
rails/rails
activesupport/lib/active_support/lazy_load_hooks.rb
ActiveSupport.LazyLoadHooks.on_load
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
def on_load(name, options = {}, &block) @loaded[name].each do |base| execute_hook(name, base, options, block) end @load_hooks[name] << [block, options] end
[ "def", "on_load", "(", "name", ",", "options", "=", "{", "}", ",", "&", "block", ")", "@loaded", "[", "name", "]", ".", "each", "do", "|", "base", "|", "execute_hook", "(", "name", ",", "base", ",", "options", ",", "block", ")", "end", "@load_hooks...
Declares a block that will be executed when a Rails component is fully loaded. Options: * <tt>:yield</tt> - Yields the object that run_load_hooks to +block+. * <tt>:run_once</tt> - Given +block+ will run only once.
[ "Declares", "a", "block", "that", "will", "be", "executed", "when", "a", "Rails", "component", "is", "fully", "loaded", "." ]
85a8bc644be69908f05740a5886ec19cd3679df5
https://github.com/rails/rails/blob/85a8bc644be69908f05740a5886ec19cd3679df5/activesupport/lib/active_support/lazy_load_hooks.rb#L41-L47
10,360
rails/rails
actionpack/lib/abstract_controller/rendering.rb
AbstractController.Rendering.view_assigns
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
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
[ "def", "view_assigns", "protected_vars", "=", "_protected_ivars", "variables", "=", "instance_variables", "variables", ".", "reject!", "{", "|", "s", "|", "protected_vars", ".", "include?", "s", "}", "variables", ".", "each_with_object", "(", "{", "}", ")", "{",...
This method should return a hash with assigns. You can overwrite this configuration per controller.
[ "This", "method", "should", "return", "a", "hash", "with", "assigns", ".", "You", "can", "overwrite", "this", "configuration", "per", "controller", "." ]
85a8bc644be69908f05740a5886ec19cd3679df5
https://github.com/rails/rails/blob/85a8bc644be69908f05740a5886ec19cd3679df5/actionpack/lib/abstract_controller/rendering.rb#L64-L72
10,361
rails/rails
actionpack/lib/abstract_controller/rendering.rb
AbstractController.Rendering._normalize_render
def _normalize_render(*args, &block) # :nodoc: options = _normalize_args(*args, &block) _process_variant(options) _normalize_options(options) options end
ruby
def _normalize_render(*args, &block) # :nodoc: options = _normalize_args(*args, &block) _process_variant(options) _normalize_options(options) options end
[ "def", "_normalize_render", "(", "*", "args", ",", "&", "block", ")", "# :nodoc:", "options", "=", "_normalize_args", "(", "args", ",", "block", ")", "_process_variant", "(", "options", ")", "_normalize_options", "(", "options", ")", "options", "end" ]
Normalize args and options.
[ "Normalize", "args", "and", "options", "." ]
85a8bc644be69908f05740a5886ec19cd3679df5
https://github.com/rails/rails/blob/85a8bc644be69908f05740a5886ec19cd3679df5/actionpack/lib/abstract_controller/rendering.rb#L116-L121
10,362
rails/rails
activesupport/lib/active_support/core_ext/numeric/conversions.rb
ActiveSupport.NumericWithFormat.to_s
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
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 || ...
[ "def", "to_s", "(", "format", "=", "nil", ",", "options", "=", "nil", ")", "case", "format", "when", "nil", "super", "(", ")", "when", "Integer", ",", "String", "super", "(", "format", ")", "when", ":phone", "ActiveSupport", "::", "NumberHelper", ".", ...
Provides options for converting numbers into formatted strings. Options are provided for phone numbers, currency, percentage, precision, positional notation, file size and pretty printing. ==== Options For details on which formats use which options, see ActiveSupport::NumberHelper ==== Examples Phone Numbers...
[ "Provides", "options", "for", "converting", "numbers", "into", "formatted", "strings", ".", "Options", "are", "provided", "for", "phone", "numbers", "currency", "percentage", "precision", "positional", "notation", "file", "size", "and", "pretty", "printing", "." ]
85a8bc644be69908f05740a5886ec19cd3679df5
https://github.com/rails/rails/blob/85a8bc644be69908f05740a5886ec19cd3679df5/activesupport/lib/active_support/core_ext/numeric/conversions.rb#L105-L130
10,363
rails/rails
activerecord/lib/active_record/database_configurations.rb
ActiveRecord.DatabaseConfigurations.default_hash
def default_hash(env = ActiveRecord::ConnectionHandling::DEFAULT_ENV.call.to_s) default = find_db_config(env) default.config if default end
ruby
def default_hash(env = ActiveRecord::ConnectionHandling::DEFAULT_ENV.call.to_s) default = find_db_config(env) default.config if default end
[ "def", "default_hash", "(", "env", "=", "ActiveRecord", "::", "ConnectionHandling", "::", "DEFAULT_ENV", ".", "call", ".", "to_s", ")", "default", "=", "find_db_config", "(", "env", ")", "default", ".", "config", "if", "default", "end" ]
Returns the config hash that corresponds with the environment If the application has multiple databases +default_hash+ will return the first config hash for the environment. { database: "my_db", adapter: "mysql2" }
[ "Returns", "the", "config", "hash", "that", "corresponds", "with", "the", "environment" ]
85a8bc644be69908f05740a5886ec19cd3679df5
https://github.com/rails/rails/blob/85a8bc644be69908f05740a5886ec19cd3679df5/activerecord/lib/active_record/database_configurations.rb#L60-L63
10,364
rails/rails
activerecord/lib/active_record/database_configurations.rb
ActiveRecord.DatabaseConfigurations.find_db_config
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
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
[ "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", ...
Returns a single DatabaseConfig object based on the requested environment. If the application has multiple databases +find_db_config+ will return the first DatabaseConfig for the environment.
[ "Returns", "a", "single", "DatabaseConfig", "object", "based", "on", "the", "requested", "environment", "." ]
85a8bc644be69908f05740a5886ec19cd3679df5
https://github.com/rails/rails/blob/85a8bc644be69908f05740a5886ec19cd3679df5/activerecord/lib/active_record/database_configurations.rb#L70-L75
10,365
rails/rails
activerecord/lib/active_record/database_configurations.rb
ActiveRecord.DatabaseConfigurations.to_h
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
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
[ "def", "to_h", "configs", "=", "configurations", ".", "reverse", ".", "inject", "(", "{", "}", ")", "do", "|", "memo", ",", "db_config", "|", "memo", ".", "merge", "(", "db_config", ".", "to_legacy_hash", ")", "end", "Hash", "[", "configs", ".", "to_a"...
Returns the DatabaseConfigurations object as a Hash.
[ "Returns", "the", "DatabaseConfigurations", "object", "as", "a", "Hash", "." ]
85a8bc644be69908f05740a5886ec19cd3679df5
https://github.com/rails/rails/blob/85a8bc644be69908f05740a5886ec19cd3679df5/activerecord/lib/active_record/database_configurations.rb#L78-L84
10,366
rails/rails
actionmailer/lib/action_mailer/log_subscriber.rb
ActionMailer.LogSubscriber.deliver
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
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...
[ "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 ...
An email was delivered.
[ "An", "email", "was", "delivered", "." ]
85a8bc644be69908f05740a5886ec19cd3679df5
https://github.com/rails/rails/blob/85a8bc644be69908f05740a5886ec19cd3679df5/actionmailer/lib/action_mailer/log_subscriber.rb#L10-L21
10,367
rails/rails
activesupport/lib/active_support/backtrace_cleaner.rb
ActiveSupport.BacktraceCleaner.clean
def clean(backtrace, kind = :silent) filtered = filter_backtrace(backtrace) case kind when :silent silence(filtered) when :noise noise(filtered) else filtered end end
ruby
def clean(backtrace, kind = :silent) filtered = filter_backtrace(backtrace) case kind when :silent silence(filtered) when :noise noise(filtered) else filtered end end
[ "def", "clean", "(", "backtrace", ",", "kind", "=", ":silent", ")", "filtered", "=", "filter_backtrace", "(", "backtrace", ")", "case", "kind", "when", ":silent", "silence", "(", "filtered", ")", "when", ":noise", "noise", "(", "filtered", ")", "else", "fi...
Returns the backtrace after all filters and silencers have been run against it. Filters run first, then silencers.
[ "Returns", "the", "backtrace", "after", "all", "filters", "and", "silencers", "have", "been", "run", "against", "it", ".", "Filters", "run", "first", "then", "silencers", "." ]
85a8bc644be69908f05740a5886ec19cd3679df5
https://github.com/rails/rails/blob/85a8bc644be69908f05740a5886ec19cd3679df5/activesupport/lib/active_support/backtrace_cleaner.rb#L41-L52
10,368
rails/rails
actionview/lib/action_view/renderer/template_renderer.rb
ActionView.TemplateRenderer.determine_template
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
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...
[ "def", "determine_template", "(", "options", ")", "keys", "=", "options", ".", "has_key?", "(", ":locals", ")", "?", "options", "[", ":locals", "]", ".", "keys", ":", "[", "]", "if", "options", ".", "key?", "(", ":body", ")", "Template", "::", "Text", ...
Determine the template to be rendered using the given options.
[ "Determine", "the", "template", "to", "be", "rendered", "using", "the", "given", "options", "." ]
85a8bc644be69908f05740a5886ec19cd3679df5
https://github.com/rails/rails/blob/85a8bc644be69908f05740a5886ec19cd3679df5/actionview/lib/action_view/renderer/template_renderer.rb#L19-L52
10,369
rails/rails
actionview/lib/action_view/renderer/template_renderer.rb
ActionView.TemplateRenderer.render_template
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
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) } ...
[ "def", "render_template", "(", "view", ",", "template", ",", "layout_name", ",", "locals", ")", "render_with_layout", "(", "view", ",", "template", ",", "layout_name", ",", "locals", ")", "do", "|", "layout", "|", "instrument", "(", ":template", ",", "identi...
Renders the given template. A string representing the layout can be supplied as well.
[ "Renders", "the", "given", "template", ".", "A", "string", "representing", "the", "layout", "can", "be", "supplied", "as", "well", "." ]
85a8bc644be69908f05740a5886ec19cd3679df5
https://github.com/rails/rails/blob/85a8bc644be69908f05740a5886ec19cd3679df5/actionview/lib/action_view/renderer/template_renderer.rb#L56-L62
10,370
rails/rails
actionpack/lib/action_controller/metal/streaming.rb
ActionController.Streaming._process_options
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
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") ...
[ "def", "_process_options", "(", "options", ")", "super", "if", "options", "[", ":stream", "]", "if", "request", ".", "version", "==", "\"HTTP/1.0\"", "options", ".", "delete", "(", ":stream", ")", "else", "headers", "[", "\"Cache-Control\"", "]", "||=", "\"n...
Set proper cache control and transfer encoding when streaming
[ "Set", "proper", "cache", "control", "and", "transfer", "encoding", "when", "streaming" ]
85a8bc644be69908f05740a5886ec19cd3679df5
https://github.com/rails/rails/blob/85a8bc644be69908f05740a5886ec19cd3679df5/actionpack/lib/action_controller/metal/streaming.rb#L201-L212
10,371
rails/rails
actionpack/lib/action_controller/metal/streaming.rb
ActionController.Streaming._render_template
def _render_template(options) if options.delete(:stream) Rack::Chunked::Body.new view_renderer.render_body(view_context, options) else super end end
ruby
def _render_template(options) if options.delete(:stream) Rack::Chunked::Body.new view_renderer.render_body(view_context, options) else super end end
[ "def", "_render_template", "(", "options", ")", "if", "options", ".", "delete", "(", ":stream", ")", "Rack", "::", "Chunked", "::", "Body", ".", "new", "view_renderer", ".", "render_body", "(", "view_context", ",", "options", ")", "else", "super", "end", "...
Call render_body if we are streaming instead of usual +render+.
[ "Call", "render_body", "if", "we", "are", "streaming", "instead", "of", "usual", "+", "render", "+", "." ]
85a8bc644be69908f05740a5886ec19cd3679df5
https://github.com/rails/rails/blob/85a8bc644be69908f05740a5886ec19cd3679df5/actionpack/lib/action_controller/metal/streaming.rb#L215-L221
10,372
rails/rails
actionview/lib/action_view/layouts.rb
ActionView.Layouts._layout_for_option
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
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...
[ "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", "|", "_d...
Determine the layout for a given name, taking into account the name type. ==== Parameters * <tt>name</tt> - The name of the template
[ "Determine", "the", "layout", "for", "a", "given", "name", "taking", "into", "account", "the", "name", "type", "." ]
85a8bc644be69908f05740a5886ec19cd3679df5
https://github.com/rails/rails/blob/85a8bc644be69908f05740a5886ec19cd3679df5/actionview/lib/action_view/layouts.rb#L387-L398
10,373
rails/rails
actionview/lib/action_view/layouts.rb
ActionView.Layouts._default_layout
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
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...
[ "def", "_default_layout", "(", "lookup_context", ",", "formats", ",", "require_layout", "=", "false", ")", "begin", "value", "=", "_layout", "(", "lookup_context", ",", "formats", ")", "if", "action_has_layout?", "rescue", "NameError", "=>", "e", "raise", "e", ...
Returns the default layout for this controller. Optionally raises an exception if the layout could not be found. ==== Parameters * <tt>formats</tt> - The formats accepted to this layout * <tt>require_layout</tt> - If set to +true+ and layout is not found, an +ArgumentError+ exception is raised (defaults to +fal...
[ "Returns", "the", "default", "layout", "for", "this", "controller", ".", "Optionally", "raises", "an", "exception", "if", "the", "layout", "could", "not", "be", "found", "." ]
85a8bc644be69908f05740a5886ec19cd3679df5
https://github.com/rails/rails/blob/85a8bc644be69908f05740a5886ec19cd3679df5/actionview/lib/action_view/layouts.rb#L414-L427
10,374
rails/rails
activemodel/lib/active_model/validations.rb
ActiveModel.Validations.valid?
def valid?(context = nil) current_context, self.validation_context = validation_context, context errors.clear run_validations! ensure self.validation_context = current_context end
ruby
def valid?(context = nil) current_context, self.validation_context = validation_context, context errors.clear run_validations! ensure self.validation_context = current_context end
[ "def", "valid?", "(", "context", "=", "nil", ")", "current_context", ",", "self", ".", "validation_context", "=", "validation_context", ",", "context", "errors", ".", "clear", "run_validations!", "ensure", "self", ".", "validation_context", "=", "current_context", ...
Runs all the specified validations and returns +true+ if no errors were added otherwise +false+. class Person include ActiveModel::Validations attr_accessor :name validates_presence_of :name end person = Person.new person.name = '' person.valid? # => false person.name = 'david' p...
[ "Runs", "all", "the", "specified", "validations", "and", "returns", "+", "true", "+", "if", "no", "errors", "were", "added", "otherwise", "+", "false", "+", "." ]
85a8bc644be69908f05740a5886ec19cd3679df5
https://github.com/rails/rails/blob/85a8bc644be69908f05740a5886ec19cd3679df5/activemodel/lib/active_model/validations.rb#L334-L340
10,375
rails/rails
railties/lib/rails/application.rb
Rails.Application.message_verifier
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
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
[ "def", "message_verifier", "(", "verifier_name", ")", "@message_verifiers", "[", "verifier_name", "]", "||=", "begin", "secret", "=", "key_generator", ".", "generate_key", "(", "verifier_name", ".", "to_s", ")", "ActiveSupport", "::", "MessageVerifier", ".", "new", ...
Returns a message verifier object. This verifier can be used to generate and verify signed messages in the application. It is recommended not to use the same verifier for different things, so you can get different verifiers passing the +verifier_name+ argument. ==== Parameters * +verifier_name+ - the name of t...
[ "Returns", "a", "message", "verifier", "object", "." ]
85a8bc644be69908f05740a5886ec19cd3679df5
https://github.com/rails/rails/blob/85a8bc644be69908f05740a5886ec19cd3679df5/railties/lib/rails/application.rb#L199-L204
10,376
rails/rails
railties/lib/rails/application.rb
Rails.Application.env_config
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
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"...
[ "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....
Stores some of the Rails initial environment parameters which will be used by middlewares and engines to configure themselves.
[ "Stores", "some", "of", "the", "Rails", "initial", "environment", "parameters", "which", "will", "be", "used", "by", "middlewares", "and", "engines", "to", "configure", "themselves", "." ]
85a8bc644be69908f05740a5886ec19cd3679df5
https://github.com/rails/rails/blob/85a8bc644be69908f05740a5886ec19cd3679df5/railties/lib/rails/application.rb#L248-L276
10,377
rails/rails
railties/lib/rails/application.rb
Rails.Application.encrypted
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
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
[ "def", "encrypted", "(", "path", ",", "key_path", ":", "\"config/master.key\"", ",", "env_key", ":", "\"RAILS_MASTER_KEY\"", ")", "ActiveSupport", "::", "EncryptedConfiguration", ".", "new", "(", "config_path", ":", "Rails", ".", "root", ".", "join", "(", "path"...
Shorthand to decrypt any encrypted configurations or files. For any file added with <tt>rails encrypted:edit</tt> call +read+ to decrypt the file with the master key. The master key is either stored in +config/master.key+ or <tt>ENV["RAILS_MASTER_KEY"]</tt>. Rails.application.encrypted("config/mystery_man.txt.e...
[ "Shorthand", "to", "decrypt", "any", "encrypted", "configurations", "or", "files", "." ]
85a8bc644be69908f05740a5886ec19cd3679df5
https://github.com/rails/rails/blob/85a8bc644be69908f05740a5886ec19cd3679df5/railties/lib/rails/application.rb#L466-L473
10,378
rails/rails
railties/lib/rails/application.rb
Rails.Application.ordered_railties
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
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 ...
[ "def", "ordered_railties", "#:nodoc:", "@ordered_railties", "||=", "begin", "order", "=", "config", ".", "railties_order", ".", "map", "do", "|", "railtie", "|", "if", "railtie", "==", ":main_app", "self", "elsif", "railtie", ".", "respond_to?", "(", ":instance"...
Returns the ordered railties for this application considering railties_order.
[ "Returns", "the", "ordered", "railties", "for", "this", "application", "considering", "railties_order", "." ]
85a8bc644be69908f05740a5886ec19cd3679df5
https://github.com/rails/rails/blob/85a8bc644be69908f05740a5886ec19cd3679df5/railties/lib/rails/application.rb#L534-L554
10,379
rails/rails
actionpack/lib/action_dispatch/http/request.rb
ActionDispatch.Request.raw_post
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
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
[ "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", ".", "re...
Read the request \body. This is useful for web services that need to work with raw requests directly.
[ "Read", "the", "request", "\\", "body", ".", "This", "is", "useful", "for", "web", "services", "that", "need", "to", "work", "with", "raw", "requests", "directly", "." ]
85a8bc644be69908f05740a5886ec19cd3679df5
https://github.com/rails/rails/blob/85a8bc644be69908f05740a5886ec19cd3679df5/actionpack/lib/action_dispatch/http/request.rb#L311-L318
10,380
rails/rails
actionpack/lib/action_dispatch/http/request.rb
ActionDispatch.Request.body
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
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
[ "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...
The request body is an IO input stream. If the RAW_POST_DATA environment variable is already set, wrap it in a StringIO.
[ "The", "request", "body", "is", "an", "IO", "input", "stream", ".", "If", "the", "RAW_POST_DATA", "environment", "variable", "is", "already", "set", "wrap", "it", "in", "a", "StringIO", "." ]
85a8bc644be69908f05740a5886ec19cd3679df5
https://github.com/rails/rails/blob/85a8bc644be69908f05740a5886ec19cd3679df5/actionpack/lib/action_dispatch/http/request.rb#L322-L329
10,381
rails/rails
actionpack/lib/action_dispatch/http/request.rb
ActionDispatch.Request.GET
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
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...
[ "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_pa...
Override Rack's GET method to support indifferent access.
[ "Override", "Rack", "s", "GET", "method", "to", "support", "indifferent", "access", "." ]
85a8bc644be69908f05740a5886ec19cd3679df5
https://github.com/rails/rails/blob/85a8bc644be69908f05740a5886ec19cd3679df5/actionpack/lib/action_dispatch/http/request.rb#L366-L375
10,382
rails/rails
actionpack/lib/action_dispatch/http/request.rb
ActionDispatch.Request.POST
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
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...
[ "def", "POST", "fetch_header", "(", "\"action_dispatch.request.request_parameters\"", ")", "do", "pr", "=", "parse_formatted_parameters", "(", "params_parsers", ")", "do", "|", "params", "|", "super", "||", "{", "}", "end", "self", ".", "request_parameters", "=", ...
Override Rack's POST method to support indifferent access.
[ "Override", "Rack", "s", "POST", "method", "to", "support", "indifferent", "access", "." ]
85a8bc644be69908f05740a5886ec19cd3679df5
https://github.com/rails/rails/blob/85a8bc644be69908f05740a5886ec19cd3679df5/actionpack/lib/action_dispatch/http/request.rb#L379-L388
10,383
rails/rails
actionview/lib/action_view/renderer/partial_renderer.rb
ActionView.PartialRenderer.setup
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
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...
[ "def", "setup", "(", "context", ",", "options", ",", "as", ",", "block", ")", "@options", "=", "options", "@block", "=", "block", "@locals", "=", "options", "[", ":locals", "]", "||", "{", "}", "@details", "=", "extract_details", "(", "options", ")", "...
Sets up instance variables needed for rendering a partial. This method finds the options and details and extracts them. The method also contains logic that handles the type of object passed in as the partial. If +options[:partial]+ is a string, then the <tt>@path</tt> instance variable is set to that string. Other...
[ "Sets", "up", "instance", "variables", "needed", "for", "rendering", "a", "partial", ".", "This", "method", "finds", "the", "options", "and", "details", "and", "extracts", "them", ".", "The", "method", "also", "contains", "logic", "that", "handles", "the", "...
85a8bc644be69908f05740a5886ec19cd3679df5
https://github.com/rails/rails/blob/85a8bc644be69908f05740a5886ec19cd3679df5/actionview/lib/action_view/renderer/partial_renderer.rb#L378-L411
10,384
rails/rails
actionview/lib/action_view/renderer/partial_renderer.rb
ActionView.PartialRenderer.partial_path
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
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...
[ "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_p...
Obtains the path to where the object's partial is located. If the object responds to +to_partial_path+, then +to_partial_path+ will be called and will provide the path. If the object does not respond to +to_partial_path+, then an +ArgumentError+ is raised. If +prefix_partial_path_with_controller_namespace+ is true...
[ "Obtains", "the", "path", "to", "where", "the", "object", "s", "partial", "is", "located", ".", "If", "the", "object", "responds", "to", "+", "to_partial_path", "+", "then", "+", "to_partial_path", "+", "will", "be", "called", "and", "will", "provide", "th...
85a8bc644be69908f05740a5886ec19cd3679df5
https://github.com/rails/rails/blob/85a8bc644be69908f05740a5886ec19cd3679df5/actionview/lib/action_view/renderer/partial_renderer.rb#L491-L505
10,385
rails/rails
activemodel/lib/active_model/serialization.rb
ActiveModel.Serialization.serializable_hash
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
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...
[ "def", "serializable_hash", "(", "options", "=", "nil", ")", "options", "||=", "{", "}", "attribute_names", "=", "attributes", ".", "keys", "if", "only", "=", "options", "[", ":only", "]", "attribute_names", "&=", "Array", "(", "only", ")", ".", "map", "...
Returns a serialized hash of your object. class Person include ActiveModel::Serialization attr_accessor :name, :age def attributes {'name' => nil, 'age' => nil} end def capitalized_name name.capitalize end end person = Person.new person.name = 'bob' person...
[ "Returns", "a", "serialized", "hash", "of", "your", "object", "." ]
85a8bc644be69908f05740a5886ec19cd3679df5
https://github.com/rails/rails/blob/85a8bc644be69908f05740a5886ec19cd3679df5/activemodel/lib/active_model/serialization.rb#L126-L150
10,386
rails/rails
railties/lib/rails/engine.rb
Rails.Engine.helpers
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
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
[ "def", "helpers", "@helpers", "||=", "begin", "helpers", "=", "Module", ".", "new", "all", "=", "ActionController", "::", "Base", ".", "all_helpers_from_path", "(", "helpers_paths", ")", "ActionController", "::", "Base", ".", "modules_for_helpers", "(", "all", "...
Returns a module with all the helpers defined for the engine.
[ "Returns", "a", "module", "with", "all", "the", "helpers", "defined", "for", "the", "engine", "." ]
85a8bc644be69908f05740a5886ec19cd3679df5
https://github.com/rails/rails/blob/85a8bc644be69908f05740a5886ec19cd3679df5/railties/lib/rails/engine.rb#L490-L499
10,387
rails/rails
railties/lib/rails/engine.rb
Rails.Engine.app
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
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
[ "def", "app", "@app", "||", "@app_build_lock", ".", "synchronize", "{", "@app", "||=", "begin", "stack", "=", "default_middleware_stack", "config", ".", "middleware", "=", "build_middleware", ".", "merge_into", "(", "stack", ")", "config", ".", "middleware", "."...
Returns the underlying Rack application for this engine.
[ "Returns", "the", "underlying", "Rack", "application", "for", "this", "engine", "." ]
85a8bc644be69908f05740a5886ec19cd3679df5
https://github.com/rails/rails/blob/85a8bc644be69908f05740a5886ec19cd3679df5/railties/lib/rails/engine.rb#L507-L515
10,388
rails/rails
railties/lib/rails/engine.rb
Rails.Engine.routes
def routes(&block) @routes ||= ActionDispatch::Routing::RouteSet.new_with_config(config) @routes.append(&block) if block_given? @routes end
ruby
def routes(&block) @routes ||= ActionDispatch::Routing::RouteSet.new_with_config(config) @routes.append(&block) if block_given? @routes end
[ "def", "routes", "(", "&", "block", ")", "@routes", "||=", "ActionDispatch", "::", "Routing", "::", "RouteSet", ".", "new_with_config", "(", "config", ")", "@routes", ".", "append", "(", "block", ")", "if", "block_given?", "@routes", "end" ]
Defines the routes for this engine. If a block is given to routes, it is appended to the engine.
[ "Defines", "the", "routes", "for", "this", "engine", ".", "If", "a", "block", "is", "given", "to", "routes", "it", "is", "appended", "to", "the", "engine", "." ]
85a8bc644be69908f05740a5886ec19cd3679df5
https://github.com/rails/rails/blob/85a8bc644be69908f05740a5886ec19cd3679df5/railties/lib/rails/engine.rb#L536-L540
10,389
rails/rails
activestorage/lib/active_storage/attached/one.rb
ActiveStorage.Attached::One.attach
def attach(attachable) if record.persisted? && !record.changed? record.update(name => attachable) else record.public_send("#{name}=", attachable) end end
ruby
def attach(attachable) if record.persisted? && !record.changed? record.update(name => attachable) else record.public_send("#{name}=", attachable) end end
[ "def", "attach", "(", "attachable", ")", "if", "record", ".", "persisted?", "&&", "!", "record", ".", "changed?", "record", ".", "update", "(", "name", "=>", "attachable", ")", "else", "record", ".", "public_send", "(", "\"#{name}=\"", ",", "attachable", "...
Attaches an +attachable+ to the record. If the record is persisted and unchanged, the attachment is saved to the database immediately. Otherwise, it'll be saved to the DB when the record is next saved. person.avatar.attach(params[:avatar]) # ActionDispatch::Http::UploadedFile object person.avatar.attach(para...
[ "Attaches", "an", "+", "attachable", "+", "to", "the", "record", "." ]
85a8bc644be69908f05740a5886ec19cd3679df5
https://github.com/rails/rails/blob/85a8bc644be69908f05740a5886ec19cd3679df5/activestorage/lib/active_storage/attached/one.rb#L30-L36
10,390
rails/rails
activestorage/lib/active_storage/service/gcs_service.rb
ActiveStorage.Service::GCSService.stream
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
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 += ...
[ "def", "stream", "(", "key", ")", "file", "=", "file_for", "(", "key", ",", "skip_lookup", ":", "false", ")", "chunk_size", "=", "5", ".", "megabytes", "offset", "=", "0", "raise", "ActiveStorage", "::", "FileNotFoundError", "unless", "file", ".", "present...
Reads the file for the given key in chunks, yielding each to the block.
[ "Reads", "the", "file", "for", "the", "given", "key", "in", "chunks", "yielding", "each", "to", "the", "block", "." ]
85a8bc644be69908f05740a5886ec19cd3679df5
https://github.com/rails/rails/blob/85a8bc644be69908f05740a5886ec19cd3679df5/activestorage/lib/active_storage/service/gcs_service.rb#L119-L131
10,391
rails/rails
activesupport/lib/active_support/file_update_checker.rb
ActiveSupport.FileUpdateChecker.updated?
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
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_...
[ "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_upd...
It accepts two parameters on initialization. The first is an array of files and the second is an optional hash of directories. The hash must have directories as keys and the value is an array of extensions to be watched under that directory. This method must also receive a block that will be called once a path ch...
[ "It", "accepts", "two", "parameters", "on", "initialization", ".", "The", "first", "is", "an", "array", "of", "files", "and", "the", "second", "is", "an", "optional", "hash", "of", "directories", ".", "The", "hash", "must", "have", "directories", "as", "ke...
85a8bc644be69908f05740a5886ec19cd3679df5
https://github.com/rails/rails/blob/85a8bc644be69908f05740a5886ec19cd3679df5/activesupport/lib/active_support/file_update_checker.rb#L61-L76
10,392
rails/rails
activesupport/lib/active_support/file_update_checker.rb
ActiveSupport.FileUpdateChecker.max_mtime
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
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...
[ "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 parti...
This method returns the maximum mtime of the files in +paths+, or +nil+ if the array is empty. Files with a mtime in the future are ignored. Such abnormal situation can happen for example if the user changes the clock by hand. It is healthy to consider this edge case because with mtimes in the future reloading is...
[ "This", "method", "returns", "the", "maximum", "mtime", "of", "the", "files", "in", "+", "paths", "+", "or", "+", "nil", "+", "if", "the", "array", "is", "empty", "." ]
85a8bc644be69908f05740a5886ec19cd3679df5
https://github.com/rails/rails/blob/85a8bc644be69908f05740a5886ec19cd3679df5/activesupport/lib/active_support/file_update_checker.rb#L121-L141
10,393
rails/rails
activesupport/lib/active_support/benchmarkable.rb
ActiveSupport.Benchmarkable.benchmark
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
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)"...
[ "def", "benchmark", "(", "message", "=", "\"Benchmarking\"", ",", "options", "=", "{", "}", ")", "if", "logger", "options", ".", "assert_valid_keys", "(", ":level", ",", ":silence", ")", "options", "[", ":level", "]", "||=", ":info", "result", "=", "nil", ...
Allows you to measure the execution time of a block in a template and records the result to the log. Wrap this block around expensive operations or possible bottlenecks to get a time reading for the operation. For example, let's say you thought your file processing method was taking too long; you could wrap it in a...
[ "Allows", "you", "to", "measure", "the", "execution", "time", "of", "a", "block", "in", "a", "template", "and", "records", "the", "result", "to", "the", "log", ".", "Wrap", "this", "block", "around", "expensive", "operations", "or", "possible", "bottlenecks"...
85a8bc644be69908f05740a5886ec19cd3679df5
https://github.com/rails/rails/blob/85a8bc644be69908f05740a5886ec19cd3679df5/activesupport/lib/active_support/benchmarkable.rb#L37-L49
10,394
rails/rails
activerecord/lib/active_record/relation.rb
ActiveRecord.Relation.new
def new(attributes = nil, &block) block = _deprecated_scope_block("new", &block) scoping { klass.new(attributes, &block) } end
ruby
def new(attributes = nil, &block) block = _deprecated_scope_block("new", &block) scoping { klass.new(attributes, &block) } end
[ "def", "new", "(", "attributes", "=", "nil", ",", "&", "block", ")", "block", "=", "_deprecated_scope_block", "(", "\"new\"", ",", "block", ")", "scoping", "{", "klass", ".", "new", "(", "attributes", ",", "block", ")", "}", "end" ]
Initializes new record from relation while maintaining the current scope. Expects arguments in the same format as {ActiveRecord::Base.new}[rdoc-ref:Core.new]. users = User.where(name: 'DHH') user = users.new # => #<User id: nil, name: "DHH", created_at: nil, updated_at: nil> You can also pass a block to new...
[ "Initializes", "new", "record", "from", "relation", "while", "maintaining", "the", "current", "scope", "." ]
85a8bc644be69908f05740a5886ec19cd3679df5
https://github.com/rails/rails/blob/85a8bc644be69908f05740a5886ec19cd3679df5/activerecord/lib/active_record/relation.rb#L69-L72
10,395
rails/rails
activerecord/lib/active_record/relation.rb
ActiveRecord.Relation.create
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
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
[ "def", "create", "(", "attributes", "=", "nil", ",", "&", "block", ")", "if", "attributes", ".", "is_a?", "(", "Array", ")", "attributes", ".", "collect", "{", "|", "attr", "|", "create", "(", "attr", ",", "block", ")", "}", "else", "block", "=", "...
Tries to create a new record with the same scoped attributes defined in the relation. Returns the initialized object if validation fails. Expects arguments in the same format as {ActiveRecord::Base.create}[rdoc-ref:Persistence::ClassMethods#create]. ==== Examples users = User.where(name: 'Oscar') users.cre...
[ "Tries", "to", "create", "a", "new", "record", "with", "the", "same", "scoped", "attributes", "defined", "in", "the", "relation", ".", "Returns", "the", "initialized", "object", "if", "validation", "fails", "." ]
85a8bc644be69908f05740a5886ec19cd3679df5
https://github.com/rails/rails/blob/85a8bc644be69908f05740a5886ec19cd3679df5/activerecord/lib/active_record/relation.rb#L95-L102
10,396
rails/rails
activerecord/lib/active_record/relation.rb
ActiveRecord.Relation.to_sql
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
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 {...
[ "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", ...
Returns sql statement for the relation. User.where(name: 'Oscar').to_sql # => SELECT "users".* FROM "users" WHERE "users"."name" = 'Oscar'
[ "Returns", "sql", "statement", "for", "the", "relation", "." ]
85a8bc644be69908f05740a5886ec19cd3679df5
https://github.com/rails/rails/blob/85a8bc644be69908f05740a5886ec19cd3679df5/activerecord/lib/active_record/relation.rb#L639-L651
10,397
rails/rails
activerecord/lib/active_record/core.rb
ActiveRecord.Core.init_with_attributes
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
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
[ "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_callba...
Initialize an empty model object from +attributes+. +attributes+ should be an attributes object, and unlike the `initialize` method, no assignment calls are made per attribute.
[ "Initialize", "an", "empty", "model", "object", "from", "+", "attributes", "+", ".", "+", "attributes", "+", "should", "be", "an", "attributes", "object", "and", "unlike", "the", "initialize", "method", "no", "assignment", "calls", "are", "made", "per", "att...
85a8bc644be69908f05740a5886ec19cd3679df5
https://github.com/rails/rails/blob/85a8bc644be69908f05740a5886ec19cd3679df5/activerecord/lib/active_record/core.rb#L356-L368
10,398
rails/rails
activerecord/lib/active_record/core.rb
ActiveRecord.Core.inspect
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
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) ...
[ "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", "d...
Returns the contents of the record as a nicely formatted string.
[ "Returns", "the", "contents", "of", "the", "record", "as", "a", "nicely", "formatted", "string", "." ]
85a8bc644be69908f05740a5886ec19cd3679df5
https://github.com/rails/rails/blob/85a8bc644be69908f05740a5886ec19cd3679df5/activerecord/lib/active_record/core.rb#L503-L524
10,399
rails/rails
actionmailer/lib/action_mailer/base.rb
ActionMailer.Base.mail
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
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...
[ "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", "=", "head...
The main method that creates the message and renders the email templates. There are two ways to call this method, with a block, or without a block. It accepts a headers hash. This hash allows you to specify the most used headers in an email message, these are: * +:subject+ - The subject of the message, if this is...
[ "The", "main", "method", "that", "creates", "the", "message", "and", "renders", "the", "email", "templates", ".", "There", "are", "two", "ways", "to", "call", "this", "method", "with", "a", "block", "or", "without", "a", "block", "." ]
85a8bc644be69908f05740a5886ec19cd3679df5
https://github.com/rails/rails/blob/85a8bc644be69908f05740a5886ec19cd3679df5/actionmailer/lib/action_mailer/base.rb#L841-L873