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
partition
stringclasses
1 value
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
train
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
train
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
train
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
train
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
train
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
train
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
train
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
train
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
train
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
train
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
train
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
train
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
train
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
train
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
train
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
train
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
train
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
train
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
train
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
train
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
train
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
train
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
train
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
train
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
train
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
train
rails/rails
activestorage/lib/active_storage/attached/many.rb
ActiveStorage.Attached::Many.attach
def attach(*attachables) if record.persisted? && !record.changed? record.update(name => blobs + attachables.flatten) else record.public_send("#{name}=", blobs + attachables.flatten) end end
ruby
def attach(*attachables) if record.persisted? && !record.changed? record.update(name => blobs + attachables.flatten) else record.public_send("#{name}=", blobs + attachables.flatten) end end
[ "def", "attach", "(", "*", "attachables", ")", "if", "record", ".", "persisted?", "&&", "!", "record", ".", "changed?", "record", ".", "update", "(", "name", "=>", "blobs", "+", "attachables", ".", "flatten", ")", "else", "record", ".", "public_send", "(...
Attaches one or more +attachables+ to the record. If the record is persisted and unchanged, the attachments are saved to the database immediately. Otherwise, they'll be saved to the DB when the record is next saved. document.images.attach(params[:images]) # Array of ActionDispatch::Http::UploadedFile objects ...
[ "Attaches", "one", "or", "more", "+", "attachables", "+", "to", "the", "record", "." ]
85a8bc644be69908f05740a5886ec19cd3679df5
https://github.com/rails/rails/blob/85a8bc644be69908f05740a5886ec19cd3679df5/activestorage/lib/active_storage/attached/many.rb#L30-L36
train
rails/rails
actionpack/lib/action_dispatch/http/response.rb
ActionDispatch.Response.charset=
def charset=(charset) content_type = parsed_content_type_header.mime_type if false == charset set_content_type content_type, nil else set_content_type content_type, charset || self.class.default_charset end end
ruby
def charset=(charset) content_type = parsed_content_type_header.mime_type if false == charset set_content_type content_type, nil else set_content_type content_type, charset || self.class.default_charset end end
[ "def", "charset", "=", "(", "charset", ")", "content_type", "=", "parsed_content_type_header", ".", "mime_type", "if", "false", "==", "charset", "set_content_type", "content_type", ",", "nil", "else", "set_content_type", "content_type", ",", "charset", "||", "self",...
Sets the HTTP character set. In case of +nil+ parameter it sets the charset to +default_charset+. response.charset = 'utf-16' # => 'utf-16' response.charset = nil # => 'utf-8'
[ "Sets", "the", "HTTP", "character", "set", ".", "In", "case", "of", "+", "nil", "+", "parameter", "it", "sets", "the", "charset", "to", "+", "default_charset", "+", "." ]
85a8bc644be69908f05740a5886ec19cd3679df5
https://github.com/rails/rails/blob/85a8bc644be69908f05740a5886ec19cd3679df5/actionpack/lib/action_dispatch/http/response.rb#L262-L269
train
rails/rails
activesupport/lib/active_support/core_ext/date_and_time/calculations.rb
DateAndTime.Calculations.days_to_week_start
def days_to_week_start(start_day = Date.beginning_of_week) start_day_number = DAYS_INTO_WEEK.fetch(start_day) (wday - start_day_number) % 7 end
ruby
def days_to_week_start(start_day = Date.beginning_of_week) start_day_number = DAYS_INTO_WEEK.fetch(start_day) (wday - start_day_number) % 7 end
[ "def", "days_to_week_start", "(", "start_day", "=", "Date", ".", "beginning_of_week", ")", "start_day_number", "=", "DAYS_INTO_WEEK", ".", "fetch", "(", "start_day", ")", "(", "wday", "-", "start_day_number", ")", "%", "7", "end" ]
Returns the number of days to the start of the week on the given day. Week is assumed to start on +start_day+, default is +Date.beginning_of_week+ or +config.beginning_of_week+ when set.
[ "Returns", "the", "number", "of", "days", "to", "the", "start", "of", "the", "week", "on", "the", "given", "day", ".", "Week", "is", "assumed", "to", "start", "on", "+", "start_day", "+", "default", "is", "+", "Date", ".", "beginning_of_week", "+", "or...
85a8bc644be69908f05740a5886ec19cd3679df5
https://github.com/rails/rails/blob/85a8bc644be69908f05740a5886ec19cd3679df5/activesupport/lib/active_support/core_ext/date_and_time/calculations.rb#L265-L268
train
grpc/grpc
src/ruby/lib/grpc/generic/active_call.rb
GRPC.ActiveCall.remote_send
def remote_send(req, marshalled = false) send_initial_metadata GRPC.logger.debug("sending #{req}, marshalled? #{marshalled}") payload = marshalled ? req : @marshal.call(req) @call.run_batch(SEND_MESSAGE => payload) end
ruby
def remote_send(req, marshalled = false) send_initial_metadata GRPC.logger.debug("sending #{req}, marshalled? #{marshalled}") payload = marshalled ? req : @marshal.call(req) @call.run_batch(SEND_MESSAGE => payload) end
[ "def", "remote_send", "(", "req", ",", "marshalled", "=", "false", ")", "send_initial_metadata", "GRPC", ".", "logger", ".", "debug", "(", "\"sending #{req}, marshalled? #{marshalled}\"", ")", "payload", "=", "marshalled", "?", "req", ":", "@marshal", ".", "call",...
remote_send sends a request to the remote endpoint. It blocks until the remote endpoint accepts the message. @param req [Object, String] the object to send or it's marshal form. @param marshalled [false, true] indicates if the object is already marshalled.
[ "remote_send", "sends", "a", "request", "to", "the", "remote", "endpoint", "." ]
f3937f0e55227a4ef3a23f895d3b204a947610f8
https://github.com/grpc/grpc/blob/f3937f0e55227a4ef3a23f895d3b204a947610f8/src/ruby/lib/grpc/generic/active_call.rb#L191-L196
train
grpc/grpc
src/ruby/lib/grpc/generic/active_call.rb
GRPC.ActiveCall.send_status
def send_status(code = OK, details = '', assert_finished = false, metadata: {}) send_initial_metadata ops = { SEND_STATUS_FROM_SERVER => Struct::Status.new(code, details, metadata) } ops[RECV_CLOSE_ON_SERVER] = nil if assert_finished @call.run_batch(ops) s...
ruby
def send_status(code = OK, details = '', assert_finished = false, metadata: {}) send_initial_metadata ops = { SEND_STATUS_FROM_SERVER => Struct::Status.new(code, details, metadata) } ops[RECV_CLOSE_ON_SERVER] = nil if assert_finished @call.run_batch(ops) s...
[ "def", "send_status", "(", "code", "=", "OK", ",", "details", "=", "''", ",", "assert_finished", "=", "false", ",", "metadata", ":", "{", "}", ")", "send_initial_metadata", "ops", "=", "{", "SEND_STATUS_FROM_SERVER", "=>", "Struct", "::", "Status", ".", "n...
send_status sends a status to the remote endpoint. @param code [int] the status code to send @param details [String] details @param assert_finished [true, false] when true(default), waits for FINISHED. @param metadata [Hash] metadata to send to the server. If a value is a list, mulitple metadata for its key are ...
[ "send_status", "sends", "a", "status", "to", "the", "remote", "endpoint", "." ]
f3937f0e55227a4ef3a23f895d3b204a947610f8
https://github.com/grpc/grpc/blob/f3937f0e55227a4ef3a23f895d3b204a947610f8/src/ruby/lib/grpc/generic/active_call.rb#L206-L217
train
grpc/grpc
src/ruby/lib/grpc/generic/active_call.rb
GRPC.ActiveCall.remote_read
def remote_read ops = { RECV_MESSAGE => nil } ops[RECV_INITIAL_METADATA] = nil unless @metadata_received batch_result = @call.run_batch(ops) unless @metadata_received @call.metadata = batch_result.metadata @metadata_received = true end get_message_from_batch_result(ba...
ruby
def remote_read ops = { RECV_MESSAGE => nil } ops[RECV_INITIAL_METADATA] = nil unless @metadata_received batch_result = @call.run_batch(ops) unless @metadata_received @call.metadata = batch_result.metadata @metadata_received = true end get_message_from_batch_result(ba...
[ "def", "remote_read", "ops", "=", "{", "RECV_MESSAGE", "=>", "nil", "}", "ops", "[", "RECV_INITIAL_METADATA", "]", "=", "nil", "unless", "@metadata_received", "batch_result", "=", "@call", ".", "run_batch", "(", "ops", ")", "unless", "@metadata_received", "@call...
remote_read reads a response from the remote endpoint. It blocks until the remote endpoint replies with a message or status. On receiving a message, it returns the response after unmarshalling it. On receiving a status, it returns nil if the status is OK, otherwise raising BadStatus
[ "remote_read", "reads", "a", "response", "from", "the", "remote", "endpoint", "." ]
f3937f0e55227a4ef3a23f895d3b204a947610f8
https://github.com/grpc/grpc/blob/f3937f0e55227a4ef3a23f895d3b204a947610f8/src/ruby/lib/grpc/generic/active_call.rb#L251-L260
train
grpc/grpc
src/ruby/lib/grpc/generic/active_call.rb
GRPC.ActiveCall.each_remote_read
def each_remote_read return enum_for(:each_remote_read) unless block_given? begin loop do resp = remote_read break if resp.nil? # the last response was received yield resp end ensure set_input_stream_done end end
ruby
def each_remote_read return enum_for(:each_remote_read) unless block_given? begin loop do resp = remote_read break if resp.nil? # the last response was received yield resp end ensure set_input_stream_done end end
[ "def", "each_remote_read", "return", "enum_for", "(", ":each_remote_read", ")", "unless", "block_given?", "begin", "loop", "do", "resp", "=", "remote_read", "break", "if", "resp", ".", "nil?", "# the last response was received", "yield", "resp", "end", "ensure", "se...
each_remote_read passes each response to the given block or returns an enumerator the responses if no block is given. Used to generate the request enumerable for server-side client-streaming RPC's. == Enumerator == * #next blocks until the remote endpoint sends a READ or FINISHED * for each read, enumerator#nex...
[ "each_remote_read", "passes", "each", "response", "to", "the", "given", "block", "or", "returns", "an", "enumerator", "the", "responses", "if", "no", "block", "is", "given", ".", "Used", "to", "generate", "the", "request", "enumerable", "for", "server", "-", ...
f3937f0e55227a4ef3a23f895d3b204a947610f8
https://github.com/grpc/grpc/blob/f3937f0e55227a4ef3a23f895d3b204a947610f8/src/ruby/lib/grpc/generic/active_call.rb#L290-L301
train
grpc/grpc
src/ruby/lib/grpc/generic/active_call.rb
GRPC.ActiveCall.each_remote_read_then_finish
def each_remote_read_then_finish return enum_for(:each_remote_read_then_finish) unless block_given? loop do resp = begin remote_read rescue GRPC::Core::CallError => e GRPC.logger.warn("In each_remote_read_then_finish: #{e}") nil end ...
ruby
def each_remote_read_then_finish return enum_for(:each_remote_read_then_finish) unless block_given? loop do resp = begin remote_read rescue GRPC::Core::CallError => e GRPC.logger.warn("In each_remote_read_then_finish: #{e}") nil end ...
[ "def", "each_remote_read_then_finish", "return", "enum_for", "(", ":each_remote_read_then_finish", ")", "unless", "block_given?", "loop", "do", "resp", "=", "begin", "remote_read", "rescue", "GRPC", "::", "Core", "::", "CallError", "=>", "e", "GRPC", ".", "logger", ...
each_remote_read_then_finish passes each response to the given block or returns an enumerator of the responses if no block is given. It is like each_remote_read, but it blocks on finishing on detecting the final message. == Enumerator == * #next blocks until the remote endpoint sends a READ or FINISHED * for e...
[ "each_remote_read_then_finish", "passes", "each", "response", "to", "the", "given", "block", "or", "returns", "an", "enumerator", "of", "the", "responses", "if", "no", "block", "is", "given", "." ]
f3937f0e55227a4ef3a23f895d3b204a947610f8
https://github.com/grpc/grpc/blob/f3937f0e55227a4ef3a23f895d3b204a947610f8/src/ruby/lib/grpc/generic/active_call.rb#L323-L341
train
grpc/grpc
src/ruby/lib/grpc/generic/active_call.rb
GRPC.ActiveCall.request_response
def request_response(req, metadata: {}) raise_error_if_already_executed ops = { SEND_MESSAGE => @marshal.call(req), SEND_CLOSE_FROM_CLIENT => nil, RECV_INITIAL_METADATA => nil, RECV_MESSAGE => nil, RECV_STATUS_ON_CLIENT => nil } @send_initial_md_mutex.sync...
ruby
def request_response(req, metadata: {}) raise_error_if_already_executed ops = { SEND_MESSAGE => @marshal.call(req), SEND_CLOSE_FROM_CLIENT => nil, RECV_INITIAL_METADATA => nil, RECV_MESSAGE => nil, RECV_STATUS_ON_CLIENT => nil } @send_initial_md_mutex.sync...
[ "def", "request_response", "(", "req", ",", "metadata", ":", "{", "}", ")", "raise_error_if_already_executed", "ops", "=", "{", "SEND_MESSAGE", "=>", "@marshal", ".", "call", "(", "req", ")", ",", "SEND_CLOSE_FROM_CLIENT", "=>", "nil", ",", "RECV_INITIAL_METADAT...
request_response sends a request to a GRPC server, and returns the response. @param req [Object] the request sent to the server @param metadata [Hash] metadata to be sent to the server. If a value is a list, multiple metadata for its key are sent @return [Object] the response received from the server
[ "request_response", "sends", "a", "request", "to", "a", "GRPC", "server", "and", "returns", "the", "response", "." ]
f3937f0e55227a4ef3a23f895d3b204a947610f8
https://github.com/grpc/grpc/blob/f3937f0e55227a4ef3a23f895d3b204a947610f8/src/ruby/lib/grpc/generic/active_call.rb#L350-L379
train
grpc/grpc
src/ruby/lib/grpc/generic/active_call.rb
GRPC.ActiveCall.client_streamer
def client_streamer(requests, metadata: {}) raise_error_if_already_executed begin send_initial_metadata(metadata) requests.each { |r| @call.run_batch(SEND_MESSAGE => @marshal.call(r)) } rescue GRPC::Core::CallError => e receive_and_check_status # check for Cancelled rai...
ruby
def client_streamer(requests, metadata: {}) raise_error_if_already_executed begin send_initial_metadata(metadata) requests.each { |r| @call.run_batch(SEND_MESSAGE => @marshal.call(r)) } rescue GRPC::Core::CallError => e receive_and_check_status # check for Cancelled rai...
[ "def", "client_streamer", "(", "requests", ",", "metadata", ":", "{", "}", ")", "raise_error_if_already_executed", "begin", "send_initial_metadata", "(", "metadata", ")", "requests", ".", "each", "{", "|", "r", "|", "@call", ".", "run_batch", "(", "SEND_MESSAGE"...
client_streamer sends a stream of requests to a GRPC server, and returns a single response. requests provides an 'iterable' of Requests. I.e. it follows Ruby's #each enumeration protocol. In the simplest case, requests will be an array of marshallable objects; in typical case it will be an Enumerable that allows ...
[ "client_streamer", "sends", "a", "stream", "of", "requests", "to", "a", "GRPC", "server", "and", "returns", "a", "single", "response", "." ]
f3937f0e55227a4ef3a23f895d3b204a947610f8
https://github.com/grpc/grpc/blob/f3937f0e55227a4ef3a23f895d3b204a947610f8/src/ruby/lib/grpc/generic/active_call.rb#L393-L420
train
grpc/grpc
src/ruby/lib/grpc/generic/active_call.rb
GRPC.ActiveCall.server_streamer
def server_streamer(req, metadata: {}) raise_error_if_already_executed ops = { SEND_MESSAGE => @marshal.call(req), SEND_CLOSE_FROM_CLIENT => nil } @send_initial_md_mutex.synchronize do # Metadata might have already been sent if this is an operation view unless @me...
ruby
def server_streamer(req, metadata: {}) raise_error_if_already_executed ops = { SEND_MESSAGE => @marshal.call(req), SEND_CLOSE_FROM_CLIENT => nil } @send_initial_md_mutex.synchronize do # Metadata might have already been sent if this is an operation view unless @me...
[ "def", "server_streamer", "(", "req", ",", "metadata", ":", "{", "}", ")", "raise_error_if_already_executed", "ops", "=", "{", "SEND_MESSAGE", "=>", "@marshal", ".", "call", "(", "req", ")", ",", "SEND_CLOSE_FROM_CLIENT", "=>", "nil", "}", "@send_initial_md_mute...
server_streamer sends one request to the GRPC server, which yields a stream of responses. responses provides an enumerator over the streamed responses, i.e. it follows Ruby's #each iteration protocol. The enumerator blocks while waiting for each response, stops when the server signals that no further responses w...
[ "server_streamer", "sends", "one", "request", "to", "the", "GRPC", "server", "which", "yields", "a", "stream", "of", "responses", "." ]
f3937f0e55227a4ef3a23f895d3b204a947610f8
https://github.com/grpc/grpc/blob/f3937f0e55227a4ef3a23f895d3b204a947610f8/src/ruby/lib/grpc/generic/active_call.rb#L436-L465
train
grpc/grpc
src/ruby/lib/grpc/generic/active_call.rb
GRPC.ActiveCall.bidi_streamer
def bidi_streamer(requests, metadata: {}, &blk) raise_error_if_already_executed # Metadata might have already been sent if this is an operation view begin send_initial_metadata(metadata) rescue GRPC::Core::CallError => e batch_result = @call.run_batch(RECV_STATUS_ON_CLIENT => nil...
ruby
def bidi_streamer(requests, metadata: {}, &blk) raise_error_if_already_executed # Metadata might have already been sent if this is an operation view begin send_initial_metadata(metadata) rescue GRPC::Core::CallError => e batch_result = @call.run_batch(RECV_STATUS_ON_CLIENT => nil...
[ "def", "bidi_streamer", "(", "requests", ",", "metadata", ":", "{", "}", ",", "&", "blk", ")", "raise_error_if_already_executed", "# Metadata might have already been sent if this is an operation view", "begin", "send_initial_metadata", "(", "metadata", ")", "rescue", "GRPC"...
bidi_streamer sends a stream of requests to the GRPC server, and yields a stream of responses. This method takes an Enumerable of requests, and returns and enumerable of responses. == requests == requests provides an 'iterable' of Requests. I.e. it follows Ruby's #each enumeration protocol. In the simplest cas...
[ "bidi_streamer", "sends", "a", "stream", "of", "requests", "to", "the", "GRPC", "server", "and", "yields", "a", "stream", "of", "responses", "." ]
f3937f0e55227a4ef3a23f895d3b204a947610f8
https://github.com/grpc/grpc/blob/f3937f0e55227a4ef3a23f895d3b204a947610f8/src/ruby/lib/grpc/generic/active_call.rb#L494-L520
train
grpc/grpc
src/ruby/lib/grpc/generic/active_call.rb
GRPC.ActiveCall.run_server_bidi
def run_server_bidi(mth, interception_ctx) view = multi_req_view bidi_call = BidiCall.new( @call, @marshal, @unmarshal, metadata_received: @metadata_received, req_view: view ) requests = bidi_call.read_next_loop(proc { set_input_stream_done }, false) ...
ruby
def run_server_bidi(mth, interception_ctx) view = multi_req_view bidi_call = BidiCall.new( @call, @marshal, @unmarshal, metadata_received: @metadata_received, req_view: view ) requests = bidi_call.read_next_loop(proc { set_input_stream_done }, false) ...
[ "def", "run_server_bidi", "(", "mth", ",", "interception_ctx", ")", "view", "=", "multi_req_view", "bidi_call", "=", "BidiCall", ".", "new", "(", "@call", ",", "@marshal", ",", "@unmarshal", ",", "metadata_received", ":", "@metadata_received", ",", "req_view", "...
run_server_bidi orchestrates a BiDi stream processing on a server. N.B. gen_each_reply is a func(Enumerable<Requests>) It takes an enumerable of requests as an arg, in case there is a relationship between the stream of requests and the stream of replies. This does not mean that must necessarily be one. E.g, the...
[ "run_server_bidi", "orchestrates", "a", "BiDi", "stream", "processing", "on", "a", "server", "." ]
f3937f0e55227a4ef3a23f895d3b204a947610f8
https://github.com/grpc/grpc/blob/f3937f0e55227a4ef3a23f895d3b204a947610f8/src/ruby/lib/grpc/generic/active_call.rb#L535-L553
train
grpc/grpc
src/ruby/lib/grpc/generic/bidi_call.rb
GRPC.BidiCall.run_on_client
def run_on_client(requests, set_input_stream_done, set_output_stream_done, &blk) @enq_th = Thread.new do write_loop(requests, set_output_stream_done: set_output_stream_done) end read_loop(set_input_stream_done, &blk) end
ruby
def run_on_client(requests, set_input_stream_done, set_output_stream_done, &blk) @enq_th = Thread.new do write_loop(requests, set_output_stream_done: set_output_stream_done) end read_loop(set_input_stream_done, &blk) end
[ "def", "run_on_client", "(", "requests", ",", "set_input_stream_done", ",", "set_output_stream_done", ",", "&", "blk", ")", "@enq_th", "=", "Thread", ".", "new", "do", "write_loop", "(", "requests", ",", "set_output_stream_done", ":", "set_output_stream_done", ")", ...
Creates a BidiCall. BidiCall should only be created after a call is accepted. That means different things on a client and a server. On the client, the call is accepted after call.invoke. On the server, this is after call.accept. #initialize cannot determine if the call is accepted or not; so if a call that's n...
[ "Creates", "a", "BidiCall", "." ]
f3937f0e55227a4ef3a23f895d3b204a947610f8
https://github.com/grpc/grpc/blob/f3937f0e55227a4ef3a23f895d3b204a947610f8/src/ruby/lib/grpc/generic/bidi_call.rb#L70-L78
train
grpc/grpc
src/ruby/lib/grpc/generic/bidi_call.rb
GRPC.BidiCall.run_on_server
def run_on_server(gen_each_reply, requests) replies = nil # Pass in the optional call object parameter if possible if gen_each_reply.arity == 1 replies = gen_each_reply.call(requests) elsif gen_each_reply.arity == 2 replies = gen_each_reply.call(requests, @req_view) else ...
ruby
def run_on_server(gen_each_reply, requests) replies = nil # Pass in the optional call object parameter if possible if gen_each_reply.arity == 1 replies = gen_each_reply.call(requests) elsif gen_each_reply.arity == 2 replies = gen_each_reply.call(requests, @req_view) else ...
[ "def", "run_on_server", "(", "gen_each_reply", ",", "requests", ")", "replies", "=", "nil", "# Pass in the optional call object parameter if possible", "if", "gen_each_reply", ".", "arity", "==", "1", "replies", "=", "gen_each_reply", ".", "call", "(", "requests", ")"...
Begins orchestration of the Bidi stream for a server generating replies. N.B. gen_each_reply is a func(Enumerable<Requests>) It takes an enumerable of requests as an arg, in case there is a relationship between the stream of requests and the stream of replies. This does not mean that must necessarily be one. E....
[ "Begins", "orchestration", "of", "the", "Bidi", "stream", "for", "a", "server", "generating", "replies", "." ]
f3937f0e55227a4ef3a23f895d3b204a947610f8
https://github.com/grpc/grpc/blob/f3937f0e55227a4ef3a23f895d3b204a947610f8/src/ruby/lib/grpc/generic/bidi_call.rb#L92-L105
train
grpc/grpc
src/ruby/lib/grpc/generic/bidi_call.rb
GRPC.BidiCall.read_using_run_batch
def read_using_run_batch ops = { RECV_MESSAGE => nil } ops[RECV_INITIAL_METADATA] = nil unless @metadata_received begin batch_result = @call.run_batch(ops) unless @metadata_received @call.metadata = batch_result.metadata @metadata_received = true end ...
ruby
def read_using_run_batch ops = { RECV_MESSAGE => nil } ops[RECV_INITIAL_METADATA] = nil unless @metadata_received begin batch_result = @call.run_batch(ops) unless @metadata_received @call.metadata = batch_result.metadata @metadata_received = true end ...
[ "def", "read_using_run_batch", "ops", "=", "{", "RECV_MESSAGE", "=>", "nil", "}", "ops", "[", "RECV_INITIAL_METADATA", "]", "=", "nil", "unless", "@metadata_received", "begin", "batch_result", "=", "@call", ".", "run_batch", "(", "ops", ")", "unless", "@metadata...
performs a read using @call.run_batch, ensures metadata is set up
[ "performs", "a", "read", "using" ]
f3937f0e55227a4ef3a23f895d3b204a947610f8
https://github.com/grpc/grpc/blob/f3937f0e55227a4ef3a23f895d3b204a947610f8/src/ruby/lib/grpc/generic/bidi_call.rb#L124-L139
train
grpc/grpc
src/ruby/lib/grpc/generic/bidi_call.rb
GRPC.BidiCall.write_loop
def write_loop(requests, is_client: true, set_output_stream_done: nil) GRPC.logger.debug('bidi-write-loop: starting') count = 0 requests.each do |req| GRPC.logger.debug("bidi-write-loop: #{count}") count += 1 payload = @marshal.call(req) # Fails if status already receiv...
ruby
def write_loop(requests, is_client: true, set_output_stream_done: nil) GRPC.logger.debug('bidi-write-loop: starting') count = 0 requests.each do |req| GRPC.logger.debug("bidi-write-loop: #{count}") count += 1 payload = @marshal.call(req) # Fails if status already receiv...
[ "def", "write_loop", "(", "requests", ",", "is_client", ":", "true", ",", "set_output_stream_done", ":", "nil", ")", "GRPC", ".", "logger", ".", "debug", "(", "'bidi-write-loop: starting'", ")", "count", "=", "0", "requests", ".", "each", "do", "|", "req", ...
set_output_stream_done is relevant on client-side
[ "set_output_stream_done", "is", "relevant", "on", "client", "-", "side" ]
f3937f0e55227a4ef3a23f895d3b204a947610f8
https://github.com/grpc/grpc/blob/f3937f0e55227a4ef3a23f895d3b204a947610f8/src/ruby/lib/grpc/generic/bidi_call.rb#L142-L184
train
grpc/grpc
src/ruby/lib/grpc/generic/bidi_call.rb
GRPC.BidiCall.read_loop
def read_loop(set_input_stream_done, is_client: true) return enum_for(:read_loop, set_input_stream_done, is_client: is_client) unless block_given? GRPC.logger.debug('bidi-read-loop: starting') begin count = 0 # queue the initial read before b...
ruby
def read_loop(set_input_stream_done, is_client: true) return enum_for(:read_loop, set_input_stream_done, is_client: is_client) unless block_given? GRPC.logger.debug('bidi-read-loop: starting') begin count = 0 # queue the initial read before b...
[ "def", "read_loop", "(", "set_input_stream_done", ",", "is_client", ":", "true", ")", "return", "enum_for", "(", ":read_loop", ",", "set_input_stream_done", ",", "is_client", ":", "is_client", ")", "unless", "block_given?", "GRPC", ".", "logger", ".", "debug", "...
Provides an enumerator that yields results of remote reads
[ "Provides", "an", "enumerator", "that", "yields", "results", "of", "remote", "reads" ]
f3937f0e55227a4ef3a23f895d3b204a947610f8
https://github.com/grpc/grpc/blob/f3937f0e55227a4ef3a23f895d3b204a947610f8/src/ruby/lib/grpc/generic/bidi_call.rb#L187-L231
train
grpc/grpc
src/ruby/lib/grpc/generic/rpc_server.rb
GRPC.Pool.schedule
def schedule(*args, &blk) return if blk.nil? @stop_mutex.synchronize do if @stopped GRPC.logger.warn('did not schedule job, already stopped') return end GRPC.logger.info('schedule another job') fail 'No worker threads available' if @ready_workers.empty? ...
ruby
def schedule(*args, &blk) return if blk.nil? @stop_mutex.synchronize do if @stopped GRPC.logger.warn('did not schedule job, already stopped') return end GRPC.logger.info('schedule another job') fail 'No worker threads available' if @ready_workers.empty? ...
[ "def", "schedule", "(", "*", "args", ",", "&", "blk", ")", "return", "if", "blk", ".", "nil?", "@stop_mutex", ".", "synchronize", "do", "if", "@stopped", "GRPC", ".", "logger", ".", "warn", "(", "'did not schedule job, already stopped'", ")", "return", "end"...
Runs the given block on the queue with the provided args. @param args the args passed blk when it is called @param blk the block to call
[ "Runs", "the", "given", "block", "on", "the", "queue", "with", "the", "provided", "args", "." ]
f3937f0e55227a4ef3a23f895d3b204a947610f8
https://github.com/grpc/grpc/blob/f3937f0e55227a4ef3a23f895d3b204a947610f8/src/ruby/lib/grpc/generic/rpc_server.rb#L58-L72
train
grpc/grpc
src/ruby/lib/grpc/generic/rpc_server.rb
GRPC.Pool.start
def start @stop_mutex.synchronize do fail 'already stopped' if @stopped end until @workers.size == @size.to_i new_worker_queue = Queue.new @ready_workers << new_worker_queue next_thread = Thread.new(new_worker_queue) do |jobs| catch(:exit) do # allows { throw...
ruby
def start @stop_mutex.synchronize do fail 'already stopped' if @stopped end until @workers.size == @size.to_i new_worker_queue = Queue.new @ready_workers << new_worker_queue next_thread = Thread.new(new_worker_queue) do |jobs| catch(:exit) do # allows { throw...
[ "def", "start", "@stop_mutex", ".", "synchronize", "do", "fail", "'already stopped'", "if", "@stopped", "end", "until", "@workers", ".", "size", "==", "@size", ".", "to_i", "new_worker_queue", "=", "Queue", ".", "new", "@ready_workers", "<<", "new_worker_queue", ...
Starts running the jobs in the thread pool.
[ "Starts", "running", "the", "jobs", "in", "the", "thread", "pool", "." ]
f3937f0e55227a4ef3a23f895d3b204a947610f8
https://github.com/grpc/grpc/blob/f3937f0e55227a4ef3a23f895d3b204a947610f8/src/ruby/lib/grpc/generic/rpc_server.rb#L75-L90
train
grpc/grpc
src/ruby/lib/grpc/generic/rpc_server.rb
GRPC.Pool.stop
def stop GRPC.logger.info('stopping, will wait for all the workers to exit') @stop_mutex.synchronize do # wait @keep_alive seconds for workers to stop @stopped = true loop do break unless ready_for_work? worker_queue = @ready_workers.pop worker_queue << [proc {...
ruby
def stop GRPC.logger.info('stopping, will wait for all the workers to exit') @stop_mutex.synchronize do # wait @keep_alive seconds for workers to stop @stopped = true loop do break unless ready_for_work? worker_queue = @ready_workers.pop worker_queue << [proc {...
[ "def", "stop", "GRPC", ".", "logger", ".", "info", "(", "'stopping, will wait for all the workers to exit'", ")", "@stop_mutex", ".", "synchronize", "do", "# wait @keep_alive seconds for workers to stop", "@stopped", "=", "true", "loop", "do", "break", "unless", "ready_fo...
Stops the jobs in the pool
[ "Stops", "the", "jobs", "in", "the", "pool" ]
f3937f0e55227a4ef3a23f895d3b204a947610f8
https://github.com/grpc/grpc/blob/f3937f0e55227a4ef3a23f895d3b204a947610f8/src/ruby/lib/grpc/generic/rpc_server.rb#L93-L106
train
grpc/grpc
src/ruby/lib/grpc/generic/rpc_server.rb
GRPC.Pool.forcibly_stop_workers
def forcibly_stop_workers return unless @workers.size > 0 GRPC.logger.info("forcibly terminating #{@workers.size} worker(s)") @workers.each do |t| next unless t.alive? begin t.exit rescue StandardError => e GRPC.logger.warn('error while terminating a worker'...
ruby
def forcibly_stop_workers return unless @workers.size > 0 GRPC.logger.info("forcibly terminating #{@workers.size} worker(s)") @workers.each do |t| next unless t.alive? begin t.exit rescue StandardError => e GRPC.logger.warn('error while terminating a worker'...
[ "def", "forcibly_stop_workers", "return", "unless", "@workers", ".", "size", ">", "0", "GRPC", ".", "logger", ".", "info", "(", "\"forcibly terminating #{@workers.size} worker(s)\"", ")", "@workers", ".", "each", "do", "|", "t", "|", "next", "unless", "t", ".", ...
Forcibly shutdown any threads that are still alive.
[ "Forcibly", "shutdown", "any", "threads", "that", "are", "still", "alive", "." ]
f3937f0e55227a4ef3a23f895d3b204a947610f8
https://github.com/grpc/grpc/blob/f3937f0e55227a4ef3a23f895d3b204a947610f8/src/ruby/lib/grpc/generic/rpc_server.rb#L111-L123
train
grpc/grpc
src/ruby/lib/grpc/generic/rpc_server.rb
GRPC.RpcServer.stop
def stop # if called via run_till_terminated_or_interrupted, # signal stop_server_thread and dont do anything if @stop_server.nil? == false && @stop_server == false @stop_server = true @stop_server_cv.broadcast return end @run_mutex.synchronize do fail 'Ca...
ruby
def stop # if called via run_till_terminated_or_interrupted, # signal stop_server_thread and dont do anything if @stop_server.nil? == false && @stop_server == false @stop_server = true @stop_server_cv.broadcast return end @run_mutex.synchronize do fail 'Ca...
[ "def", "stop", "# if called via run_till_terminated_or_interrupted,", "# signal stop_server_thread and dont do anything", "if", "@stop_server", ".", "nil?", "==", "false", "&&", "@stop_server", "==", "false", "@stop_server", "=", "true", "@stop_server_cv", ".", "broadcast", ...
Creates a new RpcServer. The RPC server is configured using keyword arguments. There are some specific keyword args used to configure the RpcServer instance. * pool_size: the size of the thread pool the server uses to run its threads. No more concurrent requests can be made than the size of the thread pool *...
[ "Creates", "a", "new", "RpcServer", "." ]
f3937f0e55227a4ef3a23f895d3b204a947610f8
https://github.com/grpc/grpc/blob/f3937f0e55227a4ef3a23f895d3b204a947610f8/src/ruby/lib/grpc/generic/rpc_server.rb#L242-L258
train
grpc/grpc
src/ruby/lib/grpc/generic/rpc_server.rb
GRPC.RpcServer.transition_running_state
def transition_running_state(target_state) state_transitions = { not_started: :running, running: :stopping, stopping: :stopped } if state_transitions[@running_state] == target_state @running_state = target_state else fail "Bad server state transition: #{@r...
ruby
def transition_running_state(target_state) state_transitions = { not_started: :running, running: :stopping, stopping: :stopped } if state_transitions[@running_state] == target_state @running_state = target_state else fail "Bad server state transition: #{@r...
[ "def", "transition_running_state", "(", "target_state", ")", "state_transitions", "=", "{", "not_started", ":", ":running", ",", "running", ":", ":stopping", ",", "stopping", ":", ":stopped", "}", "if", "state_transitions", "[", "@running_state", "]", "==", "targe...
Can only be called while holding @run_mutex
[ "Can", "only", "be", "called", "while", "holding" ]
f3937f0e55227a4ef3a23f895d3b204a947610f8
https://github.com/grpc/grpc/blob/f3937f0e55227a4ef3a23f895d3b204a947610f8/src/ruby/lib/grpc/generic/rpc_server.rb#L267-L278
train
grpc/grpc
src/ruby/lib/grpc/generic/rpc_server.rb
GRPC.RpcServer.handle
def handle(service) @run_mutex.synchronize do unless @running_state == :not_started fail 'cannot add services if the server has been started' end cls = service.is_a?(Class) ? service : service.class assert_valid_service_class(cls) add_rpc_descs_for(service) ...
ruby
def handle(service) @run_mutex.synchronize do unless @running_state == :not_started fail 'cannot add services if the server has been started' end cls = service.is_a?(Class) ? service : service.class assert_valid_service_class(cls) add_rpc_descs_for(service) ...
[ "def", "handle", "(", "service", ")", "@run_mutex", ".", "synchronize", "do", "unless", "@running_state", "==", ":not_started", "fail", "'cannot add services if the server has been started'", "end", "cls", "=", "service", ".", "is_a?", "(", "Class", ")", "?", "servi...
handle registration of classes service is either a class that includes GRPC::GenericService and whose #new function can be called without argument or any instance of such a class. E.g, after class Divider include GRPC::GenericService rpc :div DivArgs, DivReply # single request, single response def i...
[ "handle", "registration", "of", "classes" ]
f3937f0e55227a4ef3a23f895d3b204a947610f8
https://github.com/grpc/grpc/blob/f3937f0e55227a4ef3a23f895d3b204a947610f8/src/ruby/lib/grpc/generic/rpc_server.rb#L333-L342
train
grpc/grpc
src/ruby/lib/grpc/generic/rpc_server.rb
GRPC.RpcServer.run
def run @run_mutex.synchronize do fail 'cannot run without registering services' if rpc_descs.size.zero? @pool.start @server.start transition_running_state(:running) @run_cond.broadcast end loop_handle_server_calls end
ruby
def run @run_mutex.synchronize do fail 'cannot run without registering services' if rpc_descs.size.zero? @pool.start @server.start transition_running_state(:running) @run_cond.broadcast end loop_handle_server_calls end
[ "def", "run", "@run_mutex", ".", "synchronize", "do", "fail", "'cannot run without registering services'", "if", "rpc_descs", ".", "size", ".", "zero?", "@pool", ".", "start", "@server", ".", "start", "transition_running_state", "(", ":running", ")", "@run_cond", "....
runs the server - if no rpc_descs are registered, this exits immediately, otherwise it continues running permanently and does not return until program exit. - #running? returns true after this is called, until #stop cause the the server to stop.
[ "runs", "the", "server" ]
f3937f0e55227a4ef3a23f895d3b204a947610f8
https://github.com/grpc/grpc/blob/f3937f0e55227a4ef3a23f895d3b204a947610f8/src/ruby/lib/grpc/generic/rpc_server.rb#L351-L360
train
grpc/grpc
src/ruby/lib/grpc/generic/rpc_server.rb
GRPC.RpcServer.run_till_terminated_or_interrupted
def run_till_terminated_or_interrupted(signals, wait_interval = 60) @stop_server = false @stop_server_mu = Mutex.new @stop_server_cv = ConditionVariable.new @stop_server_thread = Thread.new do loop do break if @stop_server @stop_server_mu.synchronize do @...
ruby
def run_till_terminated_or_interrupted(signals, wait_interval = 60) @stop_server = false @stop_server_mu = Mutex.new @stop_server_cv = ConditionVariable.new @stop_server_thread = Thread.new do loop do break if @stop_server @stop_server_mu.synchronize do @...
[ "def", "run_till_terminated_or_interrupted", "(", "signals", ",", "wait_interval", "=", "60", ")", "@stop_server", "=", "false", "@stop_server_mu", "=", "Mutex", ".", "new", "@stop_server_cv", "=", "ConditionVariable", ".", "new", "@stop_server_thread", "=", "Thread",...
runs the server with signal handlers @param signals List of String, Integer or both representing signals that the user would like to send to the server for graceful shutdown @param wait_interval (optional) Integer seconds that user would like stop_server_thread to poll stop_server
[ "runs", "the", "server", "with", "signal", "handlers" ]
f3937f0e55227a4ef3a23f895d3b204a947610f8
https://github.com/grpc/grpc/blob/f3937f0e55227a4ef3a23f895d3b204a947610f8/src/ruby/lib/grpc/generic/rpc_server.rb#L371-L416
train
grpc/grpc
src/ruby/lib/grpc/generic/rpc_server.rb
GRPC.RpcServer.available?
def available?(an_rpc) return an_rpc if @pool.ready_for_work? GRPC.logger.warn('no free worker threads currently') noop = proc { |x| x } # Create a new active call that knows that metadata hasn't been # sent yet c = ActiveCall.new(an_rpc.call, noop, noop, an_rpc.deadline, ...
ruby
def available?(an_rpc) return an_rpc if @pool.ready_for_work? GRPC.logger.warn('no free worker threads currently') noop = proc { |x| x } # Create a new active call that knows that metadata hasn't been # sent yet c = ActiveCall.new(an_rpc.call, noop, noop, an_rpc.deadline, ...
[ "def", "available?", "(", "an_rpc", ")", "return", "an_rpc", "if", "@pool", ".", "ready_for_work?", "GRPC", ".", "logger", ".", "warn", "(", "'no free worker threads currently'", ")", "noop", "=", "proc", "{", "|", "x", "|", "x", "}", "# Create a new active ca...
Sends RESOURCE_EXHAUSTED if there are too many unprocessed jobs
[ "Sends", "RESOURCE_EXHAUSTED", "if", "there", "are", "too", "many", "unprocessed", "jobs" ]
f3937f0e55227a4ef3a23f895d3b204a947610f8
https://github.com/grpc/grpc/blob/f3937f0e55227a4ef3a23f895d3b204a947610f8/src/ruby/lib/grpc/generic/rpc_server.rb#L419-L431
train
grpc/grpc
src/ruby/lib/grpc/generic/rpc_server.rb
GRPC.RpcServer.implemented?
def implemented?(an_rpc) mth = an_rpc.method.to_sym return an_rpc if rpc_descs.key?(mth) GRPC.logger.warn("UNIMPLEMENTED: #{an_rpc}") noop = proc { |x| x } # Create a new active call that knows that # metadata hasn't been sent yet c = ActiveCall.new(an_rpc.call, noop, noop, an...
ruby
def implemented?(an_rpc) mth = an_rpc.method.to_sym return an_rpc if rpc_descs.key?(mth) GRPC.logger.warn("UNIMPLEMENTED: #{an_rpc}") noop = proc { |x| x } # Create a new active call that knows that # metadata hasn't been sent yet c = ActiveCall.new(an_rpc.call, noop, noop, an...
[ "def", "implemented?", "(", "an_rpc", ")", "mth", "=", "an_rpc", ".", "method", ".", "to_sym", "return", "an_rpc", "if", "rpc_descs", ".", "key?", "(", "mth", ")", "GRPC", ".", "logger", ".", "warn", "(", "\"UNIMPLEMENTED: #{an_rpc}\"", ")", "noop", "=", ...
Sends UNIMPLEMENTED if the method is not implemented by this server
[ "Sends", "UNIMPLEMENTED", "if", "the", "method", "is", "not", "implemented", "by", "this", "server" ]
f3937f0e55227a4ef3a23f895d3b204a947610f8
https://github.com/grpc/grpc/blob/f3937f0e55227a4ef3a23f895d3b204a947610f8/src/ruby/lib/grpc/generic/rpc_server.rb#L434-L446
train
grpc/grpc
src/ruby/lib/grpc/generic/rpc_server.rb
GRPC.RpcServer.loop_handle_server_calls
def loop_handle_server_calls fail 'not started' if running_state == :not_started while running_state == :running begin an_rpc = @server.request_call break if (!an_rpc.nil?) && an_rpc.call.nil? active_call = new_active_server_call(an_rpc) unless active_call.nil...
ruby
def loop_handle_server_calls fail 'not started' if running_state == :not_started while running_state == :running begin an_rpc = @server.request_call break if (!an_rpc.nil?) && an_rpc.call.nil? active_call = new_active_server_call(an_rpc) unless active_call.nil...
[ "def", "loop_handle_server_calls", "fail", "'not started'", "if", "running_state", "==", ":not_started", "while", "running_state", "==", ":running", "begin", "an_rpc", "=", "@server", ".", "request_call", "break", "if", "(", "!", "an_rpc", ".", "nil?", ")", "&&", ...
handles calls to the server
[ "handles", "calls", "to", "the", "server" ]
f3937f0e55227a4ef3a23f895d3b204a947610f8
https://github.com/grpc/grpc/blob/f3937f0e55227a4ef3a23f895d3b204a947610f8/src/ruby/lib/grpc/generic/rpc_server.rb#L449-L486
train
grpc/grpc
src/ruby/lib/grpc/generic/client_stub.rb
GRPC.ClientStub.request_response
def request_response(method, req, marshal, unmarshal, deadline: nil, return_op: false, parent: nil, credentials: nil, metadata: {}) c = new_active_call(method, marshal, unmarshal, ...
ruby
def request_response(method, req, marshal, unmarshal, deadline: nil, return_op: false, parent: nil, credentials: nil, metadata: {}) c = new_active_call(method, marshal, unmarshal, ...
[ "def", "request_response", "(", "method", ",", "req", ",", "marshal", ",", "unmarshal", ",", "deadline", ":", "nil", ",", "return_op", ":", "false", ",", "parent", ":", "nil", ",", "credentials", ":", "nil", ",", "metadata", ":", "{", "}", ")", "c", ...
Creates a new ClientStub. Minimally, a stub is created with the just the host of the gRPC service it wishes to access, e.g., my_stub = ClientStub.new(example.host.com:50505, :this_channel_is_insecure) If a channel_override argument is passed, it will be used as the underlying chann...
[ "Creates", "a", "new", "ClientStub", "." ]
f3937f0e55227a4ef3a23f895d3b204a947610f8
https://github.com/grpc/grpc/blob/f3937f0e55227a4ef3a23f895d3b204a947610f8/src/ruby/lib/grpc/generic/client_stub.rb#L148-L181
train
grpc/grpc
src/ruby/lib/grpc/generic/client_stub.rb
GRPC.ClientStub.new_active_call
def new_active_call(method, marshal, unmarshal, deadline: nil, parent: nil, credentials: nil) deadline = from_relative_time(@timeout) if deadline.nil? # Provide each new client call with its own completion queue call = @ch.create_...
ruby
def new_active_call(method, marshal, unmarshal, deadline: nil, parent: nil, credentials: nil) deadline = from_relative_time(@timeout) if deadline.nil? # Provide each new client call with its own completion queue call = @ch.create_...
[ "def", "new_active_call", "(", "method", ",", "marshal", ",", "unmarshal", ",", "deadline", ":", "nil", ",", "parent", ":", "nil", ",", "credentials", ":", "nil", ")", "deadline", "=", "from_relative_time", "(", "@timeout", ")", "if", "deadline", ".", "nil...
Creates a new active stub @param method [string] the method being called. @param marshal [Function] f(obj)->string that marshals requests @param unmarshal [Function] f(string)->obj that unmarshals responses @param parent [Grpc::Call] a parent call, available when calls are made from server @param credentials [...
[ "Creates", "a", "new", "active", "stub" ]
f3937f0e55227a4ef3a23f895d3b204a947610f8
https://github.com/grpc/grpc/blob/f3937f0e55227a4ef3a23f895d3b204a947610f8/src/ruby/lib/grpc/generic/client_stub.rb#L485-L499
train
jekyll/jekyll
lib/jekyll/liquid_extensions.rb
Jekyll.LiquidExtensions.lookup_variable
def lookup_variable(context, variable) lookup = context variable.split(".").each do |value| lookup = lookup[value] end lookup || variable end
ruby
def lookup_variable(context, variable) lookup = context variable.split(".").each do |value| lookup = lookup[value] end lookup || variable end
[ "def", "lookup_variable", "(", "context", ",", "variable", ")", "lookup", "=", "context", "variable", ".", "split", "(", "\".\"", ")", ".", "each", "do", "|", "value", "|", "lookup", "=", "lookup", "[", "value", "]", "end", "lookup", "||", "variable", ...
Lookup a Liquid variable in the given context. context - the Liquid context in question. variable - the variable name, as a string. Returns the value of the variable in the context or the variable name if not found.
[ "Lookup", "a", "Liquid", "variable", "in", "the", "given", "context", "." ]
fd74fe3e93a1fb506fa6621a2e271d7b9c5c3e3b
https://github.com/jekyll/jekyll/blob/fd74fe3e93a1fb506fa6621a2e271d7b9c5c3e3b/lib/jekyll/liquid_extensions.rb#L12-L20
train
jekyll/jekyll
lib/jekyll/renderer.rb
Jekyll.Renderer.converters
def converters @converters ||= site.converters.select { |c| c.matches(document.extname) }.sort end
ruby
def converters @converters ||= site.converters.select { |c| c.matches(document.extname) }.sort end
[ "def", "converters", "@converters", "||=", "site", ".", "converters", ".", "select", "{", "|", "c", "|", "c", ".", "matches", "(", "document", ".", "extname", ")", "}", ".", "sort", "end" ]
Determine which converters to use based on this document's extension. Returns Array of Converter instances.
[ "Determine", "which", "converters", "to", "use", "based", "on", "this", "document", "s", "extension", "." ]
fd74fe3e93a1fb506fa6621a2e271d7b9c5c3e3b
https://github.com/jekyll/jekyll/blob/fd74fe3e93a1fb506fa6621a2e271d7b9c5c3e3b/lib/jekyll/renderer.rb#L38-L40
train
jekyll/jekyll
lib/jekyll/renderer.rb
Jekyll.Renderer.run
def run Jekyll.logger.debug "Rendering:", document.relative_path assign_pages! assign_current_document! assign_highlighter_options! assign_layout_data! Jekyll.logger.debug "Pre-Render Hooks:", document.relative_path document.trigger_hooks(:pre_render, payload) render_d...
ruby
def run Jekyll.logger.debug "Rendering:", document.relative_path assign_pages! assign_current_document! assign_highlighter_options! assign_layout_data! Jekyll.logger.debug "Pre-Render Hooks:", document.relative_path document.trigger_hooks(:pre_render, payload) render_d...
[ "def", "run", "Jekyll", ".", "logger", ".", "debug", "\"Rendering:\"", ",", "document", ".", "relative_path", "assign_pages!", "assign_current_document!", "assign_highlighter_options!", "assign_layout_data!", "Jekyll", ".", "logger", ".", "debug", "\"Pre-Render Hooks:\"", ...
Prepare payload and render the document Returns String rendered document output
[ "Prepare", "payload", "and", "render", "the", "document" ]
fd74fe3e93a1fb506fa6621a2e271d7b9c5c3e3b
https://github.com/jekyll/jekyll/blob/fd74fe3e93a1fb506fa6621a2e271d7b9c5c3e3b/lib/jekyll/renderer.rb#L52-L64
train
jekyll/jekyll
lib/jekyll/renderer.rb
Jekyll.Renderer.render_document
def render_document info = { :registers => { :site => site, :page => payload["page"] }, :strict_filters => liquid_options["strict_filters"], :strict_variables => liquid_options["strict_variables"], } output = document.content if document.render_with_liquid? ...
ruby
def render_document info = { :registers => { :site => site, :page => payload["page"] }, :strict_filters => liquid_options["strict_filters"], :strict_variables => liquid_options["strict_variables"], } output = document.content if document.render_with_liquid? ...
[ "def", "render_document", "info", "=", "{", ":registers", "=>", "{", ":site", "=>", "site", ",", ":page", "=>", "payload", "[", "\"page\"", "]", "}", ",", ":strict_filters", "=>", "liquid_options", "[", "\"strict_filters\"", "]", ",", ":strict_variables", "=>"...
Render the document. Returns String rendered document output rubocop: disable AbcSize
[ "Render", "the", "document", "." ]
fd74fe3e93a1fb506fa6621a2e271d7b9c5c3e3b
https://github.com/jekyll/jekyll/blob/fd74fe3e93a1fb506fa6621a2e271d7b9c5c3e3b/lib/jekyll/renderer.rb#L70-L93
train
jekyll/jekyll
lib/jekyll/renderer.rb
Jekyll.Renderer.place_in_layouts
def place_in_layouts(content, payload, info) output = content.dup layout = layouts[document.data["layout"].to_s] validate_layout(layout) used = Set.new([layout]) # Reset the payload layout data to ensure it starts fresh for each page. payload["layout"] = nil while layout ...
ruby
def place_in_layouts(content, payload, info) output = content.dup layout = layouts[document.data["layout"].to_s] validate_layout(layout) used = Set.new([layout]) # Reset the payload layout data to ensure it starts fresh for each page. payload["layout"] = nil while layout ...
[ "def", "place_in_layouts", "(", "content", ",", "payload", ",", "info", ")", "output", "=", "content", ".", "dup", "layout", "=", "layouts", "[", "document", ".", "data", "[", "\"layout\"", "]", ".", "to_s", "]", "validate_layout", "(", "layout", ")", "u...
Render layouts and place document content inside. Returns String rendered content
[ "Render", "layouts", "and", "place", "document", "content", "inside", "." ]
fd74fe3e93a1fb506fa6621a2e271d7b9c5c3e3b
https://github.com/jekyll/jekyll/blob/fd74fe3e93a1fb506fa6621a2e271d7b9c5c3e3b/lib/jekyll/renderer.rb#L148-L168
train
jekyll/jekyll
lib/jekyll/renderer.rb
Jekyll.Renderer.validate_layout
def validate_layout(layout) if invalid_layout?(layout) Jekyll.logger.warn( "Build Warning:", "Layout '#{document.data["layout"]}' requested "\ "in #{document.relative_path} does not exist." ) elsif !layout.nil? layout_source = layout.path.start_with?(sit...
ruby
def validate_layout(layout) if invalid_layout?(layout) Jekyll.logger.warn( "Build Warning:", "Layout '#{document.data["layout"]}' requested "\ "in #{document.relative_path} does not exist." ) elsif !layout.nil? layout_source = layout.path.start_with?(sit...
[ "def", "validate_layout", "(", "layout", ")", "if", "invalid_layout?", "(", "layout", ")", "Jekyll", ".", "logger", ".", "warn", "(", "\"Build Warning:\"", ",", "\"Layout '#{document.data[\"layout\"]}' requested \"", "\"in #{document.relative_path} does not exist.\"", ")", ...
Checks if the layout specified in the document actually exists layout - the layout to check Returns nothing
[ "Checks", "if", "the", "layout", "specified", "in", "the", "document", "actually", "exists" ]
fd74fe3e93a1fb506fa6621a2e271d7b9c5c3e3b
https://github.com/jekyll/jekyll/blob/fd74fe3e93a1fb506fa6621a2e271d7b9c5c3e3b/lib/jekyll/renderer.rb#L176-L187
train
jekyll/jekyll
lib/jekyll/renderer.rb
Jekyll.Renderer.render_layout
def render_layout(output, layout, info) payload["content"] = output payload["layout"] = Utils.deep_merge_hashes(layout.data, payload["layout"] || {}) render_liquid( layout.content, payload, info, layout.relative_path ) end
ruby
def render_layout(output, layout, info) payload["content"] = output payload["layout"] = Utils.deep_merge_hashes(layout.data, payload["layout"] || {}) render_liquid( layout.content, payload, info, layout.relative_path ) end
[ "def", "render_layout", "(", "output", ",", "layout", ",", "info", ")", "payload", "[", "\"content\"", "]", "=", "output", "payload", "[", "\"layout\"", "]", "=", "Utils", ".", "deep_merge_hashes", "(", "layout", ".", "data", ",", "payload", "[", "\"layout...
Render layout content into document.output Returns String rendered content
[ "Render", "layout", "content", "into", "document", ".", "output" ]
fd74fe3e93a1fb506fa6621a2e271d7b9c5c3e3b
https://github.com/jekyll/jekyll/blob/fd74fe3e93a1fb506fa6621a2e271d7b9c5c3e3b/lib/jekyll/renderer.rb#L192-L202
train
jekyll/jekyll
lib/jekyll/renderer.rb
Jekyll.Renderer.assign_pages!
def assign_pages! payload["page"] = document.to_liquid payload["paginator"] = (document.pager.to_liquid if document.respond_to?(:pager)) end
ruby
def assign_pages! payload["page"] = document.to_liquid payload["paginator"] = (document.pager.to_liquid if document.respond_to?(:pager)) end
[ "def", "assign_pages!", "payload", "[", "\"page\"", "]", "=", "document", ".", "to_liquid", "payload", "[", "\"paginator\"", "]", "=", "(", "document", ".", "pager", ".", "to_liquid", "if", "document", ".", "respond_to?", "(", ":pager", ")", ")", "end" ]
Set page content to payload and assign pager if document has one. Returns nothing
[ "Set", "page", "content", "to", "payload", "and", "assign", "pager", "if", "document", "has", "one", "." ]
fd74fe3e93a1fb506fa6621a2e271d7b9c5c3e3b
https://github.com/jekyll/jekyll/blob/fd74fe3e93a1fb506fa6621a2e271d7b9c5c3e3b/lib/jekyll/renderer.rb#L216-L219
train
jekyll/jekyll
lib/jekyll/reader.rb
Jekyll.Reader.read
def read @site.layouts = LayoutReader.new(site).read read_directories read_included_excludes sort_files! @site.data = DataReader.new(site).read(site.config["data_dir"]) CollectionReader.new(site).read ThemeAssetsReader.new(site).read end
ruby
def read @site.layouts = LayoutReader.new(site).read read_directories read_included_excludes sort_files! @site.data = DataReader.new(site).read(site.config["data_dir"]) CollectionReader.new(site).read ThemeAssetsReader.new(site).read end
[ "def", "read", "@site", ".", "layouts", "=", "LayoutReader", ".", "new", "(", "site", ")", ".", "read", "read_directories", "read_included_excludes", "sort_files!", "@site", ".", "data", "=", "DataReader", ".", "new", "(", "site", ")", ".", "read", "(", "s...
Read Site data from disk and load it into internal data structures. Returns nothing.
[ "Read", "Site", "data", "from", "disk", "and", "load", "it", "into", "internal", "data", "structures", "." ]
fd74fe3e93a1fb506fa6621a2e271d7b9c5c3e3b
https://github.com/jekyll/jekyll/blob/fd74fe3e93a1fb506fa6621a2e271d7b9c5c3e3b/lib/jekyll/reader.rb#L14-L22
train
jekyll/jekyll
lib/jekyll/reader.rb
Jekyll.Reader.retrieve_dirs
def retrieve_dirs(_base, dir, dot_dirs) dot_dirs.each do |file| dir_path = site.in_source_dir(dir, file) rel_path = File.join(dir, file) @site.reader.read_directories(rel_path) unless @site.dest.chomp("/") == dir_path end end
ruby
def retrieve_dirs(_base, dir, dot_dirs) dot_dirs.each do |file| dir_path = site.in_source_dir(dir, file) rel_path = File.join(dir, file) @site.reader.read_directories(rel_path) unless @site.dest.chomp("/") == dir_path end end
[ "def", "retrieve_dirs", "(", "_base", ",", "dir", ",", "dot_dirs", ")", "dot_dirs", ".", "each", "do", "|", "file", "|", "dir_path", "=", "site", ".", "in_source_dir", "(", "dir", ",", "file", ")", "rel_path", "=", "File", ".", "join", "(", "dir", ",...
Recursively traverse directories with the read_directories function. base - The String representing the site's base directory. dir - The String representing the directory to traverse down. dot_dirs - The Array of subdirectories in the dir. Returns nothing.
[ "Recursively", "traverse", "directories", "with", "the", "read_directories", "function", "." ]
fd74fe3e93a1fb506fa6621a2e271d7b9c5c3e3b
https://github.com/jekyll/jekyll/blob/fd74fe3e93a1fb506fa6621a2e271d7b9c5c3e3b/lib/jekyll/reader.rb#L85-L91
train
jekyll/jekyll
lib/jekyll/reader.rb
Jekyll.Reader.get_entries
def get_entries(dir, subfolder) base = site.in_source_dir(dir, subfolder) return [] unless File.exist?(base) entries = Dir.chdir(base) { filter_entries(Dir["**/*"], base) } entries.delete_if { |e| File.directory?(site.in_source_dir(base, e)) } end
ruby
def get_entries(dir, subfolder) base = site.in_source_dir(dir, subfolder) return [] unless File.exist?(base) entries = Dir.chdir(base) { filter_entries(Dir["**/*"], base) } entries.delete_if { |e| File.directory?(site.in_source_dir(base, e)) } end
[ "def", "get_entries", "(", "dir", ",", "subfolder", ")", "base", "=", "site", ".", "in_source_dir", "(", "dir", ",", "subfolder", ")", "return", "[", "]", "unless", "File", ".", "exist?", "(", "base", ")", "entries", "=", "Dir", ".", "chdir", "(", "b...
Read the entries from a particular directory for processing dir - The String representing the relative path of the directory to read. subfolder - The String representing the directory to read. Returns the list of entries to process
[ "Read", "the", "entries", "from", "a", "particular", "directory", "for", "processing" ]
fd74fe3e93a1fb506fa6621a2e271d7b9c5c3e3b
https://github.com/jekyll/jekyll/blob/fd74fe3e93a1fb506fa6621a2e271d7b9c5c3e3b/lib/jekyll/reader.rb#L134-L140
train
jekyll/jekyll
lib/jekyll/site.rb
Jekyll.Site.write
def write each_site_file do |item| item.write(dest) if regenerator.regenerate?(item) end regenerator.write_metadata Jekyll::Hooks.trigger :site, :post_write, self end
ruby
def write each_site_file do |item| item.write(dest) if regenerator.regenerate?(item) end regenerator.write_metadata Jekyll::Hooks.trigger :site, :post_write, self end
[ "def", "write", "each_site_file", "do", "|", "item", "|", "item", ".", "write", "(", "dest", ")", "if", "regenerator", ".", "regenerate?", "(", "item", ")", "end", "regenerator", ".", "write_metadata", "Jekyll", "::", "Hooks", ".", "trigger", ":site", ",",...
Write static files, pages, and posts. Returns nothing.
[ "Write", "static", "files", "pages", "and", "posts", "." ]
fd74fe3e93a1fb506fa6621a2e271d7b9c5c3e3b
https://github.com/jekyll/jekyll/blob/fd74fe3e93a1fb506fa6621a2e271d7b9c5c3e3b/lib/jekyll/site.rb#L217-L223
train
jekyll/jekyll
lib/jekyll/site.rb
Jekyll.Site.post_attr_hash
def post_attr_hash(post_attr) # Build a hash map based on the specified post attribute ( post attr => # array of posts ) then sort each array in reverse order. @post_attr_hash[post_attr] ||= begin hash = Hash.new { |h, key| h[key] = [] } posts.docs.each do |p| p.data[post_att...
ruby
def post_attr_hash(post_attr) # Build a hash map based on the specified post attribute ( post attr => # array of posts ) then sort each array in reverse order. @post_attr_hash[post_attr] ||= begin hash = Hash.new { |h, key| h[key] = [] } posts.docs.each do |p| p.data[post_att...
[ "def", "post_attr_hash", "(", "post_attr", ")", "# Build a hash map based on the specified post attribute ( post attr =>", "# array of posts ) then sort each array in reverse order.", "@post_attr_hash", "[", "post_attr", "]", "||=", "begin", "hash", "=", "Hash", ".", "new", "{", ...
Construct a Hash of Posts indexed by the specified Post attribute. post_attr - The String name of the Post attribute. Examples post_attr_hash('categories') # => { 'tech' => [<Post A>, <Post B>], # 'ruby' => [<Post B>] } Returns the Hash: { attr => posts } where attr - One of the values for the ...
[ "Construct", "a", "Hash", "of", "Posts", "indexed", "by", "the", "specified", "Post", "attribute", "." ]
fd74fe3e93a1fb506fa6621a2e271d7b9c5c3e3b
https://github.com/jekyll/jekyll/blob/fd74fe3e93a1fb506fa6621a2e271d7b9c5c3e3b/lib/jekyll/site.rb#L242-L253
train
jekyll/jekyll
lib/jekyll/site.rb
Jekyll.Site.find_converter_instance
def find_converter_instance(klass) @find_converter_instance ||= {} @find_converter_instance[klass] ||= begin converters.find { |converter| converter.instance_of?(klass) } || \ raise("No Converters found for #{klass}") end end
ruby
def find_converter_instance(klass) @find_converter_instance ||= {} @find_converter_instance[klass] ||= begin converters.find { |converter| converter.instance_of?(klass) } || \ raise("No Converters found for #{klass}") end end
[ "def", "find_converter_instance", "(", "klass", ")", "@find_converter_instance", "||=", "{", "}", "@find_converter_instance", "[", "klass", "]", "||=", "begin", "converters", ".", "find", "{", "|", "converter", "|", "converter", ".", "instance_of?", "(", "klass", ...
Get the implementation class for the given Converter. Returns the Converter instance implementing the given Converter. klass - The Class of the Converter to fetch.
[ "Get", "the", "implementation", "class", "for", "the", "given", "Converter", ".", "Returns", "the", "Converter", "instance", "implementing", "the", "given", "Converter", ".", "klass", "-", "The", "Class", "of", "the", "Converter", "to", "fetch", "." ]
fd74fe3e93a1fb506fa6621a2e271d7b9c5c3e3b
https://github.com/jekyll/jekyll/blob/fd74fe3e93a1fb506fa6621a2e271d7b9c5c3e3b/lib/jekyll/site.rb#L292-L298
train
jekyll/jekyll
lib/jekyll/site.rb
Jekyll.Site.instantiate_subclasses
def instantiate_subclasses(klass) klass.descendants.select { |c| !safe || c.safe }.sort.map do |c| c.new(config) end end
ruby
def instantiate_subclasses(klass) klass.descendants.select { |c| !safe || c.safe }.sort.map do |c| c.new(config) end end
[ "def", "instantiate_subclasses", "(", "klass", ")", "klass", ".", "descendants", ".", "select", "{", "|", "c", "|", "!", "safe", "||", "c", ".", "safe", "}", ".", "sort", ".", "map", "do", "|", "c", "|", "c", ".", "new", "(", "config", ")", "end"...
klass - class or module containing the subclasses. Returns array of instances of subclasses of parameter. Create array of instances of the subclasses of the class or module passed in as argument.
[ "klass", "-", "class", "or", "module", "containing", "the", "subclasses", ".", "Returns", "array", "of", "instances", "of", "subclasses", "of", "parameter", ".", "Create", "array", "of", "instances", "of", "the", "subclasses", "of", "the", "class", "or", "mo...
fd74fe3e93a1fb506fa6621a2e271d7b9c5c3e3b
https://github.com/jekyll/jekyll/blob/fd74fe3e93a1fb506fa6621a2e271d7b9c5c3e3b/lib/jekyll/site.rb#L305-L309
train
jekyll/jekyll
lib/jekyll/site.rb
Jekyll.Site.documents
def documents @documents ||= collections.reduce(Set.new) do |docs, (_, collection)| docs + collection.docs + collection.files end.to_a end
ruby
def documents @documents ||= collections.reduce(Set.new) do |docs, (_, collection)| docs + collection.docs + collection.files end.to_a end
[ "def", "documents", "@documents", "||=", "collections", ".", "reduce", "(", "Set", ".", "new", ")", "do", "|", "docs", ",", "(", "_", ",", "collection", ")", "|", "docs", "+", "collection", ".", "docs", "+", "collection", ".", "files", "end", ".", "t...
Get all the documents Returns an Array of all Documents
[ "Get", "all", "the", "documents" ]
fd74fe3e93a1fb506fa6621a2e271d7b9c5c3e3b
https://github.com/jekyll/jekyll/blob/fd74fe3e93a1fb506fa6621a2e271d7b9c5c3e3b/lib/jekyll/site.rb#L335-L339
train
jekyll/jekyll
lib/jekyll/site.rb
Jekyll.Site.configure_cache
def configure_cache Jekyll::Cache.cache_dir = in_source_dir(config["cache_dir"], "Jekyll/Cache") Jekyll::Cache.disable_disk_cache! if safe end
ruby
def configure_cache Jekyll::Cache.cache_dir = in_source_dir(config["cache_dir"], "Jekyll/Cache") Jekyll::Cache.disable_disk_cache! if safe end
[ "def", "configure_cache", "Jekyll", "::", "Cache", ".", "cache_dir", "=", "in_source_dir", "(", "config", "[", "\"cache_dir\"", "]", ",", "\"Jekyll/Cache\"", ")", "Jekyll", "::", "Cache", ".", "disable_disk_cache!", "if", "safe", "end" ]
Disable Marshaling cache to disk in Safe Mode
[ "Disable", "Marshaling", "cache", "to", "disk", "in", "Safe", "Mode" ]
fd74fe3e93a1fb506fa6621a2e271d7b9c5c3e3b
https://github.com/jekyll/jekyll/blob/fd74fe3e93a1fb506fa6621a2e271d7b9c5c3e3b/lib/jekyll/site.rb#L471-L474
train
jekyll/jekyll
lib/jekyll/frontmatter_defaults.rb
Jekyll.FrontmatterDefaults.find
def find(path, type, setting) value = nil old_scope = nil matching_sets(path, type).each do |set| if set["values"].key?(setting) && has_precedence?(old_scope, set["scope"]) value = set["values"][setting] old_scope = set["scope"] end end value end
ruby
def find(path, type, setting) value = nil old_scope = nil matching_sets(path, type).each do |set| if set["values"].key?(setting) && has_precedence?(old_scope, set["scope"]) value = set["values"][setting] old_scope = set["scope"] end end value end
[ "def", "find", "(", "path", ",", "type", ",", "setting", ")", "value", "=", "nil", "old_scope", "=", "nil", "matching_sets", "(", "path", ",", "type", ")", ".", "each", "do", "|", "set", "|", "if", "set", "[", "\"values\"", "]", ".", "key?", "(", ...
Finds a default value for a given setting, filtered by path and type path - the path (relative to the source) of the page, post or :draft the default is used in type - a symbol indicating whether a :page, a :post or a :draft calls this method Returns the default value or nil if none was found
[ "Finds", "a", "default", "value", "for", "a", "given", "setting", "filtered", "by", "path", "and", "type" ]
fd74fe3e93a1fb506fa6621a2e271d7b9c5c3e3b
https://github.com/jekyll/jekyll/blob/fd74fe3e93a1fb506fa6621a2e271d7b9c5c3e3b/lib/jekyll/frontmatter_defaults.rb#L60-L71
train
jekyll/jekyll
lib/jekyll/frontmatter_defaults.rb
Jekyll.FrontmatterDefaults.all
def all(path, type) defaults = {} old_scope = nil matching_sets(path, type).each do |set| if has_precedence?(old_scope, set["scope"]) defaults = Utils.deep_merge_hashes(defaults, set["values"]) old_scope = set["scope"] else defaults = Utils.deep_merge_hash...
ruby
def all(path, type) defaults = {} old_scope = nil matching_sets(path, type).each do |set| if has_precedence?(old_scope, set["scope"]) defaults = Utils.deep_merge_hashes(defaults, set["values"]) old_scope = set["scope"] else defaults = Utils.deep_merge_hash...
[ "def", "all", "(", "path", ",", "type", ")", "defaults", "=", "{", "}", "old_scope", "=", "nil", "matching_sets", "(", "path", ",", "type", ")", ".", "each", "do", "|", "set", "|", "if", "has_precedence?", "(", "old_scope", ",", "set", "[", "\"scope\...
Collects a hash with all default values for a page or post path - the relative path of the page or post type - a symbol indicating the type (:post, :page or :draft) Returns a hash with all default values (an empty hash if there are none)
[ "Collects", "a", "hash", "with", "all", "default", "values", "for", "a", "page", "or", "post" ]
fd74fe3e93a1fb506fa6621a2e271d7b9c5c3e3b
https://github.com/jekyll/jekyll/blob/fd74fe3e93a1fb506fa6621a2e271d7b9c5c3e3b/lib/jekyll/frontmatter_defaults.rb#L79-L91
train
jekyll/jekyll
lib/jekyll/frontmatter_defaults.rb
Jekyll.FrontmatterDefaults.valid_sets
def valid_sets sets = @site.config["defaults"] return [] unless sets.is_a?(Array) sets.map do |set| if valid?(set) ensure_time!(update_deprecated_types(set)) else Jekyll.logger.warn "Defaults:", "An invalid front-matter default set was found:" Jekyll.logg...
ruby
def valid_sets sets = @site.config["defaults"] return [] unless sets.is_a?(Array) sets.map do |set| if valid?(set) ensure_time!(update_deprecated_types(set)) else Jekyll.logger.warn "Defaults:", "An invalid front-matter default set was found:" Jekyll.logg...
[ "def", "valid_sets", "sets", "=", "@site", ".", "config", "[", "\"defaults\"", "]", "return", "[", "]", "unless", "sets", ".", "is_a?", "(", "Array", ")", "sets", ".", "map", "do", "|", "set", "|", "if", "valid?", "(", "set", ")", "ensure_time!", "("...
Returns a list of valid sets This is not cached to allow plugins to modify the configuration and have their changes take effect Returns an array of hashes
[ "Returns", "a", "list", "of", "valid", "sets" ]
fd74fe3e93a1fb506fa6621a2e271d7b9c5c3e3b
https://github.com/jekyll/jekyll/blob/fd74fe3e93a1fb506fa6621a2e271d7b9c5c3e3b/lib/jekyll/frontmatter_defaults.rb#L218-L231
train
jekyll/jekyll
lib/jekyll/cache.rb
Jekyll.Cache.[]
def [](key) return @cache[key] if @cache.key?(key) path = path_to(hash(key)) if disk_cache_enabled? && File.file?(path) && File.readable?(path) @cache[key] = load(path) else raise end end
ruby
def [](key) return @cache[key] if @cache.key?(key) path = path_to(hash(key)) if disk_cache_enabled? && File.file?(path) && File.readable?(path) @cache[key] = load(path) else raise end end
[ "def", "[]", "(", "key", ")", "return", "@cache", "[", "key", "]", "if", "@cache", ".", "key?", "(", "key", ")", "path", "=", "path_to", "(", "hash", "(", "key", ")", ")", "if", "disk_cache_enabled?", "&&", "File", ".", "file?", "(", "path", ")", ...
Retrieve a cached item Raises if key does not exist in cache Returns cached value
[ "Retrieve", "a", "cached", "item", "Raises", "if", "key", "does", "not", "exist", "in", "cache" ]
fd74fe3e93a1fb506fa6621a2e271d7b9c5c3e3b
https://github.com/jekyll/jekyll/blob/fd74fe3e93a1fb506fa6621a2e271d7b9c5c3e3b/lib/jekyll/cache.rb#L81-L90
train
jekyll/jekyll
lib/jekyll/cache.rb
Jekyll.Cache.[]=
def []=(key, value) @cache[key] = value return unless disk_cache_enabled? path = path_to(hash(key)) value = new Hash(value) if value.is_a?(Hash) && !value.default.nil? dump(path, value) rescue TypeError Jekyll.logger.debug "Cache:", "Cannot dump object #{key}" end
ruby
def []=(key, value) @cache[key] = value return unless disk_cache_enabled? path = path_to(hash(key)) value = new Hash(value) if value.is_a?(Hash) && !value.default.nil? dump(path, value) rescue TypeError Jekyll.logger.debug "Cache:", "Cannot dump object #{key}" end
[ "def", "[]=", "(", "key", ",", "value", ")", "@cache", "[", "key", "]", "=", "value", "return", "unless", "disk_cache_enabled?", "path", "=", "path_to", "(", "hash", "(", "key", ")", ")", "value", "=", "new", "Hash", "(", "value", ")", "if", "value",...
Add an item to cache Returns nothing.
[ "Add", "an", "item", "to", "cache" ]
fd74fe3e93a1fb506fa6621a2e271d7b9c5c3e3b
https://github.com/jekyll/jekyll/blob/fd74fe3e93a1fb506fa6621a2e271d7b9c5c3e3b/lib/jekyll/cache.rb#L95-L104
train
jekyll/jekyll
lib/jekyll/cache.rb
Jekyll.Cache.delete
def delete(key) @cache.delete(key) File.delete(path_to(hash(key))) if disk_cache_enabled? end
ruby
def delete(key) @cache.delete(key) File.delete(path_to(hash(key))) if disk_cache_enabled? end
[ "def", "delete", "(", "key", ")", "@cache", ".", "delete", "(", "key", ")", "File", ".", "delete", "(", "path_to", "(", "hash", "(", "key", ")", ")", ")", "if", "disk_cache_enabled?", "end" ]
Remove one particular item from the cache Returns nothing.
[ "Remove", "one", "particular", "item", "from", "the", "cache" ]
fd74fe3e93a1fb506fa6621a2e271d7b9c5c3e3b
https://github.com/jekyll/jekyll/blob/fd74fe3e93a1fb506fa6621a2e271d7b9c5c3e3b/lib/jekyll/cache.rb#L119-L122
train
jekyll/jekyll
lib/jekyll/cache.rb
Jekyll.Cache.key?
def key?(key) # First, check if item is already cached in memory return true if @cache.key?(key) # Otherwise, it might be cached on disk # but we should not consider the disk cache if it is disabled return false unless disk_cache_enabled? path = path_to(hash(key)) File.file?(p...
ruby
def key?(key) # First, check if item is already cached in memory return true if @cache.key?(key) # Otherwise, it might be cached on disk # but we should not consider the disk cache if it is disabled return false unless disk_cache_enabled? path = path_to(hash(key)) File.file?(p...
[ "def", "key?", "(", "key", ")", "# First, check if item is already cached in memory", "return", "true", "if", "@cache", ".", "key?", "(", "key", ")", "# Otherwise, it might be cached on disk", "# but we should not consider the disk cache if it is disabled", "return", "false", "...
Check if `key` already exists in this cache Returns true if key exists in the cache, false otherwise
[ "Check", "if", "key", "already", "exists", "in", "this", "cache" ]
fd74fe3e93a1fb506fa6621a2e271d7b9c5c3e3b
https://github.com/jekyll/jekyll/blob/fd74fe3e93a1fb506fa6621a2e271d7b9c5c3e3b/lib/jekyll/cache.rb#L127-L136
train
jekyll/jekyll
lib/jekyll/cache.rb
Jekyll.Cache.path_to
def path_to(hash = nil) @base_dir ||= File.join(Jekyll::Cache.cache_dir, @name) return @base_dir if hash.nil? File.join(@base_dir, hash[0..1], hash[2..-1]).freeze end
ruby
def path_to(hash = nil) @base_dir ||= File.join(Jekyll::Cache.cache_dir, @name) return @base_dir if hash.nil? File.join(@base_dir, hash[0..1], hash[2..-1]).freeze end
[ "def", "path_to", "(", "hash", "=", "nil", ")", "@base_dir", "||=", "File", ".", "join", "(", "Jekyll", "::", "Cache", ".", "cache_dir", ",", "@name", ")", "return", "@base_dir", "if", "hash", ".", "nil?", "File", ".", "join", "(", "@base_dir", ",", ...
Given a hashed key, return the path to where this item would be saved on disk.
[ "Given", "a", "hashed", "key", "return", "the", "path", "to", "where", "this", "item", "would", "be", "saved", "on", "disk", "." ]
fd74fe3e93a1fb506fa6621a2e271d7b9c5c3e3b
https://github.com/jekyll/jekyll/blob/fd74fe3e93a1fb506fa6621a2e271d7b9c5c3e3b/lib/jekyll/cache.rb#L145-L150
train
jekyll/jekyll
lib/jekyll/convertible.rb
Jekyll.Convertible.render_liquid
def render_liquid(content, payload, info, path) _renderer.render_liquid(content, payload, info, path) end
ruby
def render_liquid(content, payload, info, path) _renderer.render_liquid(content, payload, info, path) end
[ "def", "render_liquid", "(", "content", ",", "payload", ",", "info", ",", "path", ")", "_renderer", ".", "render_liquid", "(", "content", ",", "payload", ",", "info", ",", "path", ")", "end" ]
Render Liquid in the content content - the raw Liquid content to render payload - the payload for Liquid info - the info for Liquid Returns the converted content
[ "Render", "Liquid", "in", "the", "content" ]
fd74fe3e93a1fb506fa6621a2e271d7b9c5c3e3b
https://github.com/jekyll/jekyll/blob/fd74fe3e93a1fb506fa6621a2e271d7b9c5c3e3b/lib/jekyll/convertible.rb#L107-L109
train
jekyll/jekyll
lib/jekyll/convertible.rb
Jekyll.Convertible.to_liquid
def to_liquid(attrs = nil) further_data = Hash[(attrs || self.class::ATTRIBUTES_FOR_LIQUID).map do |attribute| [attribute, send(attribute)] end] defaults = site.frontmatter_defaults.all(relative_path, type) Utils.deep_merge_hashes defaults, Utils.deep_merge_hashes(data, further_data) ...
ruby
def to_liquid(attrs = nil) further_data = Hash[(attrs || self.class::ATTRIBUTES_FOR_LIQUID).map do |attribute| [attribute, send(attribute)] end] defaults = site.frontmatter_defaults.all(relative_path, type) Utils.deep_merge_hashes defaults, Utils.deep_merge_hashes(data, further_data) ...
[ "def", "to_liquid", "(", "attrs", "=", "nil", ")", "further_data", "=", "Hash", "[", "(", "attrs", "||", "self", ".", "class", "::", "ATTRIBUTES_FOR_LIQUID", ")", ".", "map", "do", "|", "attribute", "|", "[", "attribute", ",", "send", "(", "attribute", ...
Convert this Convertible's data to a Hash suitable for use by Liquid. Returns the Hash representation of this Convertible.
[ "Convert", "this", "Convertible", "s", "data", "to", "a", "Hash", "suitable", "for", "use", "by", "Liquid", "." ]
fd74fe3e93a1fb506fa6621a2e271d7b9c5c3e3b
https://github.com/jekyll/jekyll/blob/fd74fe3e93a1fb506fa6621a2e271d7b9c5c3e3b/lib/jekyll/convertible.rb#L114-L121
train
jekyll/jekyll
lib/jekyll/convertible.rb
Jekyll.Convertible.render_all_layouts
def render_all_layouts(layouts, payload, info) _renderer.layouts = layouts self.output = _renderer.place_in_layouts(output, payload, info) ensure @_renderer = nil # this will allow the modifications above to disappear end
ruby
def render_all_layouts(layouts, payload, info) _renderer.layouts = layouts self.output = _renderer.place_in_layouts(output, payload, info) ensure @_renderer = nil # this will allow the modifications above to disappear end
[ "def", "render_all_layouts", "(", "layouts", ",", "payload", ",", "info", ")", "_renderer", ".", "layouts", "=", "layouts", "self", ".", "output", "=", "_renderer", ".", "place_in_layouts", "(", "output", ",", "payload", ",", "info", ")", "ensure", "@_render...
Recursively render layouts layouts - a list of the layouts payload - the payload for Liquid info - the info for Liquid Returns nothing
[ "Recursively", "render", "layouts" ]
fd74fe3e93a1fb506fa6621a2e271d7b9c5c3e3b
https://github.com/jekyll/jekyll/blob/fd74fe3e93a1fb506fa6621a2e271d7b9c5c3e3b/lib/jekyll/convertible.rb#L192-L197
train
jekyll/jekyll
lib/jekyll/convertible.rb
Jekyll.Convertible.do_layout
def do_layout(payload, layouts) self.output = _renderer.tap do |renderer| renderer.layouts = layouts renderer.payload = payload end.run Jekyll.logger.debug "Post-Render Hooks:", relative_path Jekyll::Hooks.trigger hook_owner, :post_render, self ensure @_renderer = nil ...
ruby
def do_layout(payload, layouts) self.output = _renderer.tap do |renderer| renderer.layouts = layouts renderer.payload = payload end.run Jekyll.logger.debug "Post-Render Hooks:", relative_path Jekyll::Hooks.trigger hook_owner, :post_render, self ensure @_renderer = nil ...
[ "def", "do_layout", "(", "payload", ",", "layouts", ")", "self", ".", "output", "=", "_renderer", ".", "tap", "do", "|", "renderer", "|", "renderer", ".", "layouts", "=", "layouts", "renderer", ".", "payload", "=", "payload", "end", ".", "run", "Jekyll",...
Add any necessary layouts to this convertible document. payload - The site payload Drop or Hash. layouts - A Hash of {"name" => "layout"}. Returns nothing.
[ "Add", "any", "necessary", "layouts", "to", "this", "convertible", "document", "." ]
fd74fe3e93a1fb506fa6621a2e271d7b9c5c3e3b
https://github.com/jekyll/jekyll/blob/fd74fe3e93a1fb506fa6621a2e271d7b9c5c3e3b/lib/jekyll/convertible.rb#L205-L215
train
jekyll/jekyll
lib/jekyll/plugin_manager.rb
Jekyll.PluginManager.require_theme_deps
def require_theme_deps return false unless site.theme.runtime_dependencies site.theme.runtime_dependencies.each do |dep| next if dep.name == "jekyll" External.require_with_graceful_fail(dep.name) if plugin_allowed?(dep.name) end end
ruby
def require_theme_deps return false unless site.theme.runtime_dependencies site.theme.runtime_dependencies.each do |dep| next if dep.name == "jekyll" External.require_with_graceful_fail(dep.name) if plugin_allowed?(dep.name) end end
[ "def", "require_theme_deps", "return", "false", "unless", "site", ".", "theme", ".", "runtime_dependencies", "site", ".", "theme", ".", "runtime_dependencies", ".", "each", "do", "|", "dep", "|", "next", "if", "dep", ".", "name", "==", "\"jekyll\"", "External"...
Require each of the runtime_dependencies specified by the theme's gemspec. Returns false only if no dependencies have been specified, otherwise nothing.
[ "Require", "each", "of", "the", "runtime_dependencies", "specified", "by", "the", "theme", "s", "gemspec", "." ]
fd74fe3e93a1fb506fa6621a2e271d7b9c5c3e3b
https://github.com/jekyll/jekyll/blob/fd74fe3e93a1fb506fa6621a2e271d7b9c5c3e3b/lib/jekyll/plugin_manager.rb#L38-L46
train
jekyll/jekyll
lib/jekyll/plugin_manager.rb
Jekyll.PluginManager.require_plugin_files
def require_plugin_files unless site.safe plugins_path.each do |plugin_search_path| plugin_files = Utils.safe_glob(plugin_search_path, File.join("**", "*.rb")) Jekyll::External.require_with_graceful_fail(plugin_files) end end end
ruby
def require_plugin_files unless site.safe plugins_path.each do |plugin_search_path| plugin_files = Utils.safe_glob(plugin_search_path, File.join("**", "*.rb")) Jekyll::External.require_with_graceful_fail(plugin_files) end end end
[ "def", "require_plugin_files", "unless", "site", ".", "safe", "plugins_path", ".", "each", "do", "|", "plugin_search_path", "|", "plugin_files", "=", "Utils", ".", "safe_glob", "(", "plugin_search_path", ",", "File", ".", "join", "(", "\"**\"", ",", "\"*.rb\"", ...
Require all .rb files if safe mode is off Returns nothing.
[ "Require", "all", ".", "rb", "files", "if", "safe", "mode", "is", "off" ]
fd74fe3e93a1fb506fa6621a2e271d7b9c5c3e3b
https://github.com/jekyll/jekyll/blob/fd74fe3e93a1fb506fa6621a2e271d7b9c5c3e3b/lib/jekyll/plugin_manager.rb#L85-L92
train
jekyll/jekyll
lib/jekyll/static_file.rb
Jekyll.StaticFile.path
def path # Static file is from a collection inside custom collections directory if !@collection.nil? && !@site.config["collections_dir"].empty? File.join(*[@base, @site.config["collections_dir"], @dir, @name].compact) else File.join(*[@base, @dir, @name].compact) end end
ruby
def path # Static file is from a collection inside custom collections directory if !@collection.nil? && !@site.config["collections_dir"].empty? File.join(*[@base, @site.config["collections_dir"], @dir, @name].compact) else File.join(*[@base, @dir, @name].compact) end end
[ "def", "path", "# Static file is from a collection inside custom collections directory", "if", "!", "@collection", ".", "nil?", "&&", "!", "@site", ".", "config", "[", "\"collections_dir\"", "]", ".", "empty?", "File", ".", "join", "(", "[", "@base", ",", "@site", ...
Initialize a new StaticFile. site - The Site. base - The String path to the <source>. dir - The String path between <source> and the file. name - The String filename of the file. rubocop: disable ParameterLists rubocop: enable ParameterLists Returns source file path.
[ "Initialize", "a", "new", "StaticFile", "." ]
fd74fe3e93a1fb506fa6621a2e271d7b9c5c3e3b
https://github.com/jekyll/jekyll/blob/fd74fe3e93a1fb506fa6621a2e271d7b9c5c3e3b/lib/jekyll/static_file.rb#L42-L49
train
jekyll/jekyll
lib/jekyll/document.rb
Jekyll.Document.merge_data!
def merge_data!(other, source: "YAML front matter") merge_categories!(other) Utils.deep_merge_hashes!(data, other) merge_date!(source) data end
ruby
def merge_data!(other, source: "YAML front matter") merge_categories!(other) Utils.deep_merge_hashes!(data, other) merge_date!(source) data end
[ "def", "merge_data!", "(", "other", ",", "source", ":", "\"YAML front matter\"", ")", "merge_categories!", "(", "other", ")", "Utils", ".", "deep_merge_hashes!", "(", "data", ",", "other", ")", "merge_date!", "(", "source", ")", "data", "end" ]
Merge some data in with this document's data. Returns the merged data.
[ "Merge", "some", "data", "in", "with", "this", "document", "s", "data", "." ]
fd74fe3e93a1fb506fa6621a2e271d7b9c5c3e3b
https://github.com/jekyll/jekyll/blob/fd74fe3e93a1fb506fa6621a2e271d7b9c5c3e3b/lib/jekyll/document.rb#L59-L64
train
jekyll/jekyll
lib/jekyll/utils.rb
Jekyll.Utils.deep_merge_hashes!
def deep_merge_hashes!(target, overwrite) merge_values(target, overwrite) merge_default_proc(target, overwrite) duplicate_frozen_values(target) target end
ruby
def deep_merge_hashes!(target, overwrite) merge_values(target, overwrite) merge_default_proc(target, overwrite) duplicate_frozen_values(target) target end
[ "def", "deep_merge_hashes!", "(", "target", ",", "overwrite", ")", "merge_values", "(", "target", ",", "overwrite", ")", "merge_default_proc", "(", "target", ",", "overwrite", ")", "duplicate_frozen_values", "(", "target", ")", "target", "end" ]
Merges a master hash with another hash, recursively. master_hash - the "parent" hash whose values will be overridden other_hash - the other hash whose values will be persisted after the merge This code was lovingly stolen from some random gem: http://gemjack.com/gems/tartan-0.1.1/classes/Hash.html Thanks to wh...
[ "Merges", "a", "master", "hash", "with", "another", "hash", "recursively", "." ]
fd74fe3e93a1fb506fa6621a2e271d7b9c5c3e3b
https://github.com/jekyll/jekyll/blob/fd74fe3e93a1fb506fa6621a2e271d7b9c5c3e3b/lib/jekyll/utils.rb#L41-L47
train
jekyll/jekyll
lib/jekyll/utils.rb
Jekyll.Utils.pluralized_array_from_hash
def pluralized_array_from_hash(hash, singular_key, plural_key) [].tap do |array| value = value_from_singular_key(hash, singular_key) value ||= value_from_plural_key(hash, plural_key) array << value end.flatten.compact end
ruby
def pluralized_array_from_hash(hash, singular_key, plural_key) [].tap do |array| value = value_from_singular_key(hash, singular_key) value ||= value_from_plural_key(hash, plural_key) array << value end.flatten.compact end
[ "def", "pluralized_array_from_hash", "(", "hash", ",", "singular_key", ",", "plural_key", ")", "[", "]", ".", "tap", "do", "|", "array", "|", "value", "=", "value_from_singular_key", "(", "hash", ",", "singular_key", ")", "value", "||=", "value_from_plural_key",...
Read array from the supplied hash favouring the singular key and then the plural key, and handling any nil entries. hash - the hash to read from singular_key - the singular key plural_key - the plural key Returns an array
[ "Read", "array", "from", "the", "supplied", "hash", "favouring", "the", "singular", "key", "and", "then", "the", "plural", "key", "and", "handling", "any", "nil", "entries", "." ]
fd74fe3e93a1fb506fa6621a2e271d7b9c5c3e3b
https://github.com/jekyll/jekyll/blob/fd74fe3e93a1fb506fa6621a2e271d7b9c5c3e3b/lib/jekyll/utils.rb#L70-L76
train
jekyll/jekyll
lib/jekyll/utils.rb
Jekyll.Utils.has_liquid_construct?
def has_liquid_construct?(content) return false if content.nil? || content.empty? content.include?("{%") || content.include?("{{") end
ruby
def has_liquid_construct?(content) return false if content.nil? || content.empty? content.include?("{%") || content.include?("{{") end
[ "def", "has_liquid_construct?", "(", "content", ")", "return", "false", "if", "content", ".", "nil?", "||", "content", ".", "empty?", "content", ".", "include?", "(", "\"{%\"", ")", "||", "content", ".", "include?", "(", "\"{{\"", ")", "end" ]
Determine whether the given content string contains Liquid Tags or Vaiables Returns true is the string contains sequences of `{%` or `{{`
[ "Determine", "whether", "the", "given", "content", "string", "contains", "Liquid", "Tags", "or", "Vaiables" ]
fd74fe3e93a1fb506fa6621a2e271d7b9c5c3e3b
https://github.com/jekyll/jekyll/blob/fd74fe3e93a1fb506fa6621a2e271d7b9c5c3e3b/lib/jekyll/utils.rb#L146-L150
train
jekyll/jekyll
lib/jekyll/utils.rb
Jekyll.Utils.add_permalink_suffix
def add_permalink_suffix(template, permalink_style) template = template.dup case permalink_style when :pretty template << "/" when :date, :ordinal, :none template << ":output_ext" else template << "/" if permalink_style.to_s.end_with?("/") template << ":out...
ruby
def add_permalink_suffix(template, permalink_style) template = template.dup case permalink_style when :pretty template << "/" when :date, :ordinal, :none template << ":output_ext" else template << "/" if permalink_style.to_s.end_with?("/") template << ":out...
[ "def", "add_permalink_suffix", "(", "template", ",", "permalink_style", ")", "template", "=", "template", ".", "dup", "case", "permalink_style", "when", ":pretty", "template", "<<", "\"/\"", "when", ":date", ",", ":ordinal", ",", ":none", "template", "<<", "\":o...
Add an appropriate suffix to template so that it matches the specified permalink style. template - permalink template without trailing slash or file extension permalink_style - permalink style, either built-in or custom The returned permalink template will use the same ending style as specified in permalink_styl...
[ "Add", "an", "appropriate", "suffix", "to", "template", "so", "that", "it", "matches", "the", "specified", "permalink", "style", "." ]
fd74fe3e93a1fb506fa6621a2e271d7b9c5c3e3b
https://github.com/jekyll/jekyll/blob/fd74fe3e93a1fb506fa6621a2e271d7b9c5c3e3b/lib/jekyll/utils.rb#L249-L263
train
jekyll/jekyll
lib/jekyll/utils.rb
Jekyll.Utils.replace_character_sequence_with_hyphen
def replace_character_sequence_with_hyphen(string, mode: "default") replaceable_char = case mode when "raw" SLUGIFY_RAW_REGEXP when "pretty" # "._~!$&'()+,;=@" is human readable (not URI-escaped) in URL # and is allowed in both extN and NTFS. SLUGIFY...
ruby
def replace_character_sequence_with_hyphen(string, mode: "default") replaceable_char = case mode when "raw" SLUGIFY_RAW_REGEXP when "pretty" # "._~!$&'()+,;=@" is human readable (not URI-escaped) in URL # and is allowed in both extN and NTFS. SLUGIFY...
[ "def", "replace_character_sequence_with_hyphen", "(", "string", ",", "mode", ":", "\"default\"", ")", "replaceable_char", "=", "case", "mode", "when", "\"raw\"", "SLUGIFY_RAW_REGEXP", "when", "\"pretty\"", "# \"._~!$&'()+,;=@\" is human readable (not URI-escaped) in URL", "# an...
Replace each character sequence with a hyphen. See Utils#slugify for a description of the character sequence specified by each mode.
[ "Replace", "each", "character", "sequence", "with", "a", "hyphen", "." ]
fd74fe3e93a1fb506fa6621a2e271d7b9c5c3e3b
https://github.com/jekyll/jekyll/blob/fd74fe3e93a1fb506fa6621a2e271d7b9c5c3e3b/lib/jekyll/utils.rb#L342-L362
train
jekyll/jekyll
lib/jekyll/page.rb
Jekyll.Page.process
def process(name) self.ext = File.extname(name) self.basename = name[0..-ext.length - 1].gsub(%r!\.*\z!, "") end
ruby
def process(name) self.ext = File.extname(name) self.basename = name[0..-ext.length - 1].gsub(%r!\.*\z!, "") end
[ "def", "process", "(", "name", ")", "self", ".", "ext", "=", "File", ".", "extname", "(", "name", ")", "self", ".", "basename", "=", "name", "[", "0", "..", "-", "ext", ".", "length", "-", "1", "]", ".", "gsub", "(", "%r!", "\\.", "\\z", "!", ...
Extract information from the page filename. name - The String filename of the page file. NOTE: `String#gsub` removes all trailing periods (in comparison to `String#chomp`) Returns nothing.
[ "Extract", "information", "from", "the", "page", "filename", "." ]
fd74fe3e93a1fb506fa6621a2e271d7b9c5c3e3b
https://github.com/jekyll/jekyll/blob/fd74fe3e93a1fb506fa6621a2e271d7b9c5c3e3b/lib/jekyll/page.rb#L121-L124
train
jekyll/jekyll
lib/jekyll/page.rb
Jekyll.Page.render
def render(layouts, site_payload) site_payload["page"] = to_liquid site_payload["paginator"] = pager.to_liquid do_layout(site_payload, layouts) end
ruby
def render(layouts, site_payload) site_payload["page"] = to_liquid site_payload["paginator"] = pager.to_liquid do_layout(site_payload, layouts) end
[ "def", "render", "(", "layouts", ",", "site_payload", ")", "site_payload", "[", "\"page\"", "]", "=", "to_liquid", "site_payload", "[", "\"paginator\"", "]", "=", "pager", ".", "to_liquid", "do_layout", "(", "site_payload", ",", "layouts", ")", "end" ]
Add any necessary layouts to this post layouts - The Hash of {"name" => "layout"}. site_payload - The site payload Hash. Returns String rendered page.
[ "Add", "any", "necessary", "layouts", "to", "this", "post" ]
fd74fe3e93a1fb506fa6621a2e271d7b9c5c3e3b
https://github.com/jekyll/jekyll/blob/fd74fe3e93a1fb506fa6621a2e271d7b9c5c3e3b/lib/jekyll/page.rb#L132-L137
train
jekyll/jekyll
lib/jekyll/filters.rb
Jekyll.Filters.where_exp
def where_exp(input, variable, expression) return input unless input.respond_to?(:select) input = input.values if input.is_a?(Hash) # FIXME condition = parse_condition(expression) @context.stack do input.select do |object| @context[variable] = object condition.evalu...
ruby
def where_exp(input, variable, expression) return input unless input.respond_to?(:select) input = input.values if input.is_a?(Hash) # FIXME condition = parse_condition(expression) @context.stack do input.select do |object| @context[variable] = object condition.evalu...
[ "def", "where_exp", "(", "input", ",", "variable", ",", "expression", ")", "return", "input", "unless", "input", ".", "respond_to?", "(", ":select", ")", "input", "=", "input", ".", "values", "if", "input", ".", "is_a?", "(", "Hash", ")", "# FIXME", "con...
Filters an array of objects against an expression input - the object array variable - the variable to assign each item to in the expression expression - a Liquid comparison expression passed in as a string Returns the filtered array of objects
[ "Filters", "an", "array", "of", "objects", "against", "an", "expression" ]
fd74fe3e93a1fb506fa6621a2e271d7b9c5c3e3b
https://github.com/jekyll/jekyll/blob/fd74fe3e93a1fb506fa6621a2e271d7b9c5c3e3b/lib/jekyll/filters.rb#L199-L211
train
jekyll/jekyll
lib/jekyll/filters.rb
Jekyll.Filters.sort
def sort(input, property = nil, nils = "first") raise ArgumentError, "Cannot sort a null object." if input.nil? if property.nil? input.sort else if nils == "first" order = - 1 elsif nils == "last" order = + 1 else raise ArgumentError, "Inv...
ruby
def sort(input, property = nil, nils = "first") raise ArgumentError, "Cannot sort a null object." if input.nil? if property.nil? input.sort else if nils == "first" order = - 1 elsif nils == "last" order = + 1 else raise ArgumentError, "Inv...
[ "def", "sort", "(", "input", ",", "property", "=", "nil", ",", "nils", "=", "\"first\"", ")", "raise", "ArgumentError", ",", "\"Cannot sort a null object.\"", "if", "input", ".", "nil?", "if", "property", ".", "nil?", "input", ".", "sort", "else", "if", "n...
Sort an array of objects input - the object array property - property within each object to filter by nils ('first' | 'last') - nils appear before or after non-nil values Returns the filtered array of objects
[ "Sort", "an", "array", "of", "objects" ]
fd74fe3e93a1fb506fa6621a2e271d7b9c5c3e3b
https://github.com/jekyll/jekyll/blob/fd74fe3e93a1fb506fa6621a2e271d7b9c5c3e3b/lib/jekyll/filters.rb#L232-L249
train