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 |
|---|---|---|---|---|---|---|---|---|---|---|---|
sds/overcommit | lib/overcommit/hook/pre_commit/yard_coverage.rb | Overcommit::Hook::PreCommit.YardCoverage.check_yard_coverage | def check_yard_coverage(stat_lines)
if config['min_coverage_percentage']
match = stat_lines.last.match(/^\s*([\d.]+)%\s+documented\s*$/)
unless match
return :warn
end
yard_coverage = match.captures[0].to_f
if yard_coverage >= config['min_coverage_percentage'].to_... | ruby | def check_yard_coverage(stat_lines)
if config['min_coverage_percentage']
match = stat_lines.last.match(/^\s*([\d.]+)%\s+documented\s*$/)
unless match
return :warn
end
yard_coverage = match.captures[0].to_f
if yard_coverage >= config['min_coverage_percentage'].to_... | [
"def",
"check_yard_coverage",
"(",
"stat_lines",
")",
"if",
"config",
"[",
"'min_coverage_percentage'",
"]",
"match",
"=",
"stat_lines",
".",
"last",
".",
"match",
"(",
"/",
"\\s",
"\\d",
"\\s",
"\\s",
"/",
")",
"unless",
"match",
"return",
":warn",
"end",
... | Check the yard coverage
Return a :pass if the coverage is enough, :warn if it couldn't be read,
otherwise, it has been read successfully. | [
"Check",
"the",
"yard",
"coverage"
] | 35d60adb41da942178b789560968e3ad030b0ac7 | https://github.com/sds/overcommit/blob/35d60adb41da942178b789560968e3ad030b0ac7/lib/overcommit/hook/pre_commit/yard_coverage.rb#L49-L63 | train |
sds/overcommit | lib/overcommit/hook/pre_commit/yard_coverage.rb | Overcommit::Hook::PreCommit.YardCoverage.error_messages | def error_messages(yard_coverage, error_text)
first_message = "You have a #{yard_coverage}% yard documentation coverage. "\
"#{config['min_coverage_percentage']}% is the minimum required."
# Add the undocumented objects text as error messages
messages = [Overcommit::Hook::Messag... | ruby | def error_messages(yard_coverage, error_text)
first_message = "You have a #{yard_coverage}% yard documentation coverage. "\
"#{config['min_coverage_percentage']}% is the minimum required."
# Add the undocumented objects text as error messages
messages = [Overcommit::Hook::Messag... | [
"def",
"error_messages",
"(",
"yard_coverage",
",",
"error_text",
")",
"first_message",
"=",
"\"You have a #{yard_coverage}% yard documentation coverage. \"",
"\"#{config['min_coverage_percentage']}% is the minimum required.\"",
"# Add the undocumented objects text as error messages",
"messa... | Create the error messages | [
"Create",
"the",
"error",
"messages"
] | 35d60adb41da942178b789560968e3ad030b0ac7 | https://github.com/sds/overcommit/blob/35d60adb41da942178b789560968e3ad030b0ac7/lib/overcommit/hook/pre_commit/yard_coverage.rb#L66-L88 | train |
sds/overcommit | lib/overcommit/hook_context/post_merge.rb | Overcommit::HookContext.PostMerge.modified_files | def modified_files
staged = squash?
refs = 'HEAD^ HEAD' if merge_commit?
@modified_files ||= Overcommit::GitRepo.modified_files(staged: staged, refs: refs)
end | ruby | def modified_files
staged = squash?
refs = 'HEAD^ HEAD' if merge_commit?
@modified_files ||= Overcommit::GitRepo.modified_files(staged: staged, refs: refs)
end | [
"def",
"modified_files",
"staged",
"=",
"squash?",
"refs",
"=",
"'HEAD^ HEAD'",
"if",
"merge_commit?",
"@modified_files",
"||=",
"Overcommit",
"::",
"GitRepo",
".",
"modified_files",
"(",
"staged",
":",
"staged",
",",
"refs",
":",
"refs",
")",
"end"
] | Get a list of files that were added, copied, or modified in the merge
commit. Renames and deletions are ignored, since there should be nothing
to check. | [
"Get",
"a",
"list",
"of",
"files",
"that",
"were",
"added",
"copied",
"or",
"modified",
"in",
"the",
"merge",
"commit",
".",
"Renames",
"and",
"deletions",
"are",
"ignored",
"since",
"there",
"should",
"be",
"nothing",
"to",
"check",
"."
] | 35d60adb41da942178b789560968e3ad030b0ac7 | https://github.com/sds/overcommit/blob/35d60adb41da942178b789560968e3ad030b0ac7/lib/overcommit/hook_context/post_merge.rb#L11-L15 | train |
sds/overcommit | lib/overcommit/hook_context/post_rewrite.rb | Overcommit::HookContext.PostRewrite.modified_files | def modified_files
@modified_files ||= begin
@modified_files = []
rewritten_commits.each do |rewritten_commit|
refs = "#{rewritten_commit.old_hash} #{rewritten_commit.new_hash}"
@modified_files |= Overcommit::GitRepo.modified_files(refs: refs)
end
filter_modif... | ruby | def modified_files
@modified_files ||= begin
@modified_files = []
rewritten_commits.each do |rewritten_commit|
refs = "#{rewritten_commit.old_hash} #{rewritten_commit.new_hash}"
@modified_files |= Overcommit::GitRepo.modified_files(refs: refs)
end
filter_modif... | [
"def",
"modified_files",
"@modified_files",
"||=",
"begin",
"@modified_files",
"=",
"[",
"]",
"rewritten_commits",
".",
"each",
"do",
"|",
"rewritten_commit",
"|",
"refs",
"=",
"\"#{rewritten_commit.old_hash} #{rewritten_commit.new_hash}\"",
"@modified_files",
"|=",
"Overco... | Get a list of files that have been added or modified as part of a
rewritten commit. Renames and deletions are ignored, since there should be
nothing to check. | [
"Get",
"a",
"list",
"of",
"files",
"that",
"have",
"been",
"added",
"or",
"modified",
"as",
"part",
"of",
"a",
"rewritten",
"commit",
".",
"Renames",
"and",
"deletions",
"are",
"ignored",
"since",
"there",
"should",
"be",
"nothing",
"to",
"check",
"."
] | 35d60adb41da942178b789560968e3ad030b0ac7 | https://github.com/sds/overcommit/blob/35d60adb41da942178b789560968e3ad030b0ac7/lib/overcommit/hook_context/post_rewrite.rb#L33-L44 | train |
sds/overcommit | lib/overcommit/message_processor.rb | Overcommit.MessageProcessor.basic_status_and_output | def basic_status_and_output(messages)
status =
if messages.any? { |message| message.type == :error }
:fail
elsif messages.any? { |message| message.type == :warning }
:warn
else
:pass
end
output = ''
if messages.any?
output += messa... | ruby | def basic_status_and_output(messages)
status =
if messages.any? { |message| message.type == :error }
:fail
elsif messages.any? { |message| message.type == :warning }
:warn
else
:pass
end
output = ''
if messages.any?
output += messa... | [
"def",
"basic_status_and_output",
"(",
"messages",
")",
"status",
"=",
"if",
"messages",
".",
"any?",
"{",
"|",
"message",
"|",
"message",
".",
"type",
"==",
":error",
"}",
":fail",
"elsif",
"messages",
".",
"any?",
"{",
"|",
"message",
"|",
"message",
"... | Returns status and output for messages assuming no special treatment of
messages occurring on unmodified lines. | [
"Returns",
"status",
"and",
"output",
"for",
"messages",
"assuming",
"no",
"special",
"treatment",
"of",
"messages",
"occurring",
"on",
"unmodified",
"lines",
"."
] | 35d60adb41da942178b789560968e3ad030b0ac7 | https://github.com/sds/overcommit/blob/35d60adb41da942178b789560968e3ad030b0ac7/lib/overcommit/message_processor.rb#L101-L117 | train |
sds/overcommit | lib/overcommit/hook/base.rb | Overcommit::Hook.Base.run_and_transform | def run_and_transform
if output = check_for_requirements
status = :fail
else
result = Overcommit::Utils.with_environment(@config.fetch('env') { {} }) { run }
status, output = process_hook_return_value(result)
end
[transform_status(status), output]
end | ruby | def run_and_transform
if output = check_for_requirements
status = :fail
else
result = Overcommit::Utils.with_environment(@config.fetch('env') { {} }) { run }
status, output = process_hook_return_value(result)
end
[transform_status(status), output]
end | [
"def",
"run_and_transform",
"if",
"output",
"=",
"check_for_requirements",
"status",
"=",
":fail",
"else",
"result",
"=",
"Overcommit",
"::",
"Utils",
".",
"with_environment",
"(",
"@config",
".",
"fetch",
"(",
"'env'",
")",
"{",
"{",
"}",
"}",
")",
"{",
"... | Runs the hook and transforms the status returned based on the hook's
configuration.
Poorly named because we already have a bunch of hooks in the wild that
implement `#run`, and we needed a wrapper step to transform the status
based on any custom configuration. | [
"Runs",
"the",
"hook",
"and",
"transforms",
"the",
"status",
"returned",
"based",
"on",
"the",
"hook",
"s",
"configuration",
"."
] | 35d60adb41da942178b789560968e3ad030b0ac7 | https://github.com/sds/overcommit/blob/35d60adb41da942178b789560968e3ad030b0ac7/lib/overcommit/hook/base.rb#L43-L52 | train |
sds/overcommit | lib/overcommit/hook/base.rb | Overcommit::Hook.Base.check_for_libraries | def check_for_libraries
output = []
required_libraries.each do |library|
begin
require library
rescue LoadError
install_command = @config['install_command']
install_command = " -- install via #{install_command}" if install_command
output << "Unable t... | ruby | def check_for_libraries
output = []
required_libraries.each do |library|
begin
require library
rescue LoadError
install_command = @config['install_command']
install_command = " -- install via #{install_command}" if install_command
output << "Unable t... | [
"def",
"check_for_libraries",
"output",
"=",
"[",
"]",
"required_libraries",
".",
"each",
"do",
"|",
"library",
"|",
"begin",
"require",
"library",
"rescue",
"LoadError",
"install_command",
"=",
"@config",
"[",
"'install_command'",
"]",
"install_command",
"=",
"\"... | If the hook defines required library paths that it wants to load, attempt
to load them. | [
"If",
"the",
"hook",
"defines",
"required",
"library",
"paths",
"that",
"it",
"wants",
"to",
"load",
"attempt",
"to",
"load",
"them",
"."
] | 35d60adb41da942178b789560968e3ad030b0ac7 | https://github.com/sds/overcommit/blob/35d60adb41da942178b789560968e3ad030b0ac7/lib/overcommit/hook/base.rb#L221-L238 | train |
sds/overcommit | lib/overcommit/hook_context/pre_commit.rb | Overcommit::HookContext.PreCommit.setup_environment | def setup_environment
store_modified_times
Overcommit::GitRepo.store_merge_state
Overcommit::GitRepo.store_cherry_pick_state
if !initial_commit? && any_changes?
@stash_attempted = true
stash_message = "Overcommit: Stash of repo state before hook run at #{Time.now}"
resu... | ruby | def setup_environment
store_modified_times
Overcommit::GitRepo.store_merge_state
Overcommit::GitRepo.store_cherry_pick_state
if !initial_commit? && any_changes?
@stash_attempted = true
stash_message = "Overcommit: Stash of repo state before hook run at #{Time.now}"
resu... | [
"def",
"setup_environment",
"store_modified_times",
"Overcommit",
"::",
"GitRepo",
".",
"store_merge_state",
"Overcommit",
"::",
"GitRepo",
".",
"store_cherry_pick_state",
"if",
"!",
"initial_commit?",
"&&",
"any_changes?",
"@stash_attempted",
"=",
"true",
"stash_message",
... | Stash unstaged contents of files so hooks don't see changes that aren't
about to be committed. | [
"Stash",
"unstaged",
"contents",
"of",
"files",
"so",
"hooks",
"don",
"t",
"see",
"changes",
"that",
"aren",
"t",
"about",
"to",
"be",
"committed",
"."
] | 35d60adb41da942178b789560968e3ad030b0ac7 | https://github.com/sds/overcommit/blob/35d60adb41da942178b789560968e3ad030b0ac7/lib/overcommit/hook_context/pre_commit.rb#L46-L72 | train |
sds/overcommit | lib/overcommit/hook_context/pre_commit.rb | Overcommit::HookContext.PreCommit.cleanup_environment | def cleanup_environment
unless initial_commit? || (@stash_attempted && !@changes_stashed)
clear_working_tree # Ensure working tree is clean before restoring it
restore_modified_times
end
if @changes_stashed
restore_working_tree
restore_modified_times
end
O... | ruby | def cleanup_environment
unless initial_commit? || (@stash_attempted && !@changes_stashed)
clear_working_tree # Ensure working tree is clean before restoring it
restore_modified_times
end
if @changes_stashed
restore_working_tree
restore_modified_times
end
O... | [
"def",
"cleanup_environment",
"unless",
"initial_commit?",
"||",
"(",
"@stash_attempted",
"&&",
"!",
"@changes_stashed",
")",
"clear_working_tree",
"# Ensure working tree is clean before restoring it",
"restore_modified_times",
"end",
"if",
"@changes_stashed",
"restore_working_tree... | Restore unstaged changes and reset file modification times so it appears
as if nothing ever changed.
We want to restore the modification times for each of the files after
every step to ensure as little time as possible has passed while the
modification time on the file was newer. This helps us play more nicely
wi... | [
"Restore",
"unstaged",
"changes",
"and",
"reset",
"file",
"modification",
"times",
"so",
"it",
"appears",
"as",
"if",
"nothing",
"ever",
"changed",
"."
] | 35d60adb41da942178b789560968e3ad030b0ac7 | https://github.com/sds/overcommit/blob/35d60adb41da942178b789560968e3ad030b0ac7/lib/overcommit/hook_context/pre_commit.rb#L81-L95 | train |
sds/overcommit | lib/overcommit/hook_context/pre_commit.rb | Overcommit::HookContext.PreCommit.modified_files | def modified_files
unless @modified_files
currently_staged = Overcommit::GitRepo.modified_files(staged: true)
@modified_files = currently_staged
# Include files modified in last commit if amending
if amendment?
subcmd = 'show --format=%n'
previously_modified = ... | ruby | def modified_files
unless @modified_files
currently_staged = Overcommit::GitRepo.modified_files(staged: true)
@modified_files = currently_staged
# Include files modified in last commit if amending
if amendment?
subcmd = 'show --format=%n'
previously_modified = ... | [
"def",
"modified_files",
"unless",
"@modified_files",
"currently_staged",
"=",
"Overcommit",
"::",
"GitRepo",
".",
"modified_files",
"(",
"staged",
":",
"true",
")",
"@modified_files",
"=",
"currently_staged",
"# Include files modified in last commit if amending",
"if",
"am... | Get a list of added, copied, or modified files that have been staged.
Renames and deletions are ignored, since there should be nothing to check. | [
"Get",
"a",
"list",
"of",
"added",
"copied",
"or",
"modified",
"files",
"that",
"have",
"been",
"staged",
".",
"Renames",
"and",
"deletions",
"are",
"ignored",
"since",
"there",
"should",
"be",
"nothing",
"to",
"check",
"."
] | 35d60adb41da942178b789560968e3ad030b0ac7 | https://github.com/sds/overcommit/blob/35d60adb41da942178b789560968e3ad030b0ac7/lib/overcommit/hook_context/pre_commit.rb#L99-L112 | train |
sds/overcommit | lib/overcommit/hook_context/pre_commit.rb | Overcommit::HookContext.PreCommit.clear_working_tree | def clear_working_tree
removed_submodules = Overcommit::GitRepo.staged_submodule_removals
result = Overcommit::Utils.execute(%w[git reset --hard])
unless result.success?
raise Overcommit::Exceptions::HookCleanupFailed,
"Unable to cleanup working tree after #{hook_script_name} ho... | ruby | def clear_working_tree
removed_submodules = Overcommit::GitRepo.staged_submodule_removals
result = Overcommit::Utils.execute(%w[git reset --hard])
unless result.success?
raise Overcommit::Exceptions::HookCleanupFailed,
"Unable to cleanup working tree after #{hook_script_name} ho... | [
"def",
"clear_working_tree",
"removed_submodules",
"=",
"Overcommit",
"::",
"GitRepo",
".",
"staged_submodule_removals",
"result",
"=",
"Overcommit",
"::",
"Utils",
".",
"execute",
"(",
"%w[",
"git",
"reset",
"--hard",
"]",
")",
"unless",
"result",
".",
"success?"... | Clears the working tree so that the stash can be applied. | [
"Clears",
"the",
"working",
"tree",
"so",
"that",
"the",
"stash",
"can",
"be",
"applied",
"."
] | 35d60adb41da942178b789560968e3ad030b0ac7 | https://github.com/sds/overcommit/blob/35d60adb41da942178b789560968e3ad030b0ac7/lib/overcommit/hook_context/pre_commit.rb#L141-L160 | train |
sds/overcommit | lib/overcommit/hook_context/pre_commit.rb | Overcommit::HookContext.PreCommit.restore_working_tree | def restore_working_tree
result = Overcommit::Utils.execute(%w[git stash pop --index --quiet])
unless result.success?
raise Overcommit::Exceptions::HookCleanupFailed,
"Unable to restore working tree after #{hook_script_name} hooks run:" \
"\nSTDOUT:#{result.stdout}\nSTDER... | ruby | def restore_working_tree
result = Overcommit::Utils.execute(%w[git stash pop --index --quiet])
unless result.success?
raise Overcommit::Exceptions::HookCleanupFailed,
"Unable to restore working tree after #{hook_script_name} hooks run:" \
"\nSTDOUT:#{result.stdout}\nSTDER... | [
"def",
"restore_working_tree",
"result",
"=",
"Overcommit",
"::",
"Utils",
".",
"execute",
"(",
"%w[",
"git",
"stash",
"pop",
"--index",
"--quiet",
"]",
")",
"unless",
"result",
".",
"success?",
"raise",
"Overcommit",
"::",
"Exceptions",
"::",
"HookCleanupFailed... | Applies the stash to the working tree to restore the user's state. | [
"Applies",
"the",
"stash",
"to",
"the",
"working",
"tree",
"to",
"restore",
"the",
"user",
"s",
"state",
"."
] | 35d60adb41da942178b789560968e3ad030b0ac7 | https://github.com/sds/overcommit/blob/35d60adb41da942178b789560968e3ad030b0ac7/lib/overcommit/hook_context/pre_commit.rb#L163-L170 | train |
sds/overcommit | lib/overcommit/hook_context/pre_commit.rb | Overcommit::HookContext.PreCommit.store_modified_times | def store_modified_times
@modified_times = {}
staged_files = modified_files
unstaged_files = Overcommit::GitRepo.modified_files(staged: false)
(staged_files + unstaged_files).each do |file|
next if Overcommit::Utils.broken_symlink?(file)
next unless File.exist?(file) # Ignore r... | ruby | def store_modified_times
@modified_times = {}
staged_files = modified_files
unstaged_files = Overcommit::GitRepo.modified_files(staged: false)
(staged_files + unstaged_files).each do |file|
next if Overcommit::Utils.broken_symlink?(file)
next unless File.exist?(file) # Ignore r... | [
"def",
"store_modified_times",
"@modified_times",
"=",
"{",
"}",
"staged_files",
"=",
"modified_files",
"unstaged_files",
"=",
"Overcommit",
"::",
"GitRepo",
".",
"modified_files",
"(",
"staged",
":",
"false",
")",
"(",
"staged_files",
"+",
"unstaged_files",
")",
... | Stores the modification times for all modified files to make it appear like
they never changed.
This prevents (some) editors from complaining about files changing when we
stash changes before running the hooks. | [
"Stores",
"the",
"modification",
"times",
"for",
"all",
"modified",
"files",
"to",
"make",
"it",
"appear",
"like",
"they",
"never",
"changed",
"."
] | 35d60adb41da942178b789560968e3ad030b0ac7 | https://github.com/sds/overcommit/blob/35d60adb41da942178b789560968e3ad030b0ac7/lib/overcommit/hook_context/pre_commit.rb#L187-L198 | train |
sds/overcommit | lib/overcommit/hook_context/pre_commit.rb | Overcommit::HookContext.PreCommit.restore_modified_times | def restore_modified_times
@modified_times.each do |file, time|
next if Overcommit::Utils.broken_symlink?(file)
next unless File.exist?(file)
File.utime(time, time, file)
end
end | ruby | def restore_modified_times
@modified_times.each do |file, time|
next if Overcommit::Utils.broken_symlink?(file)
next unless File.exist?(file)
File.utime(time, time, file)
end
end | [
"def",
"restore_modified_times",
"@modified_times",
".",
"each",
"do",
"|",
"file",
",",
"time",
"|",
"next",
"if",
"Overcommit",
"::",
"Utils",
".",
"broken_symlink?",
"(",
"file",
")",
"next",
"unless",
"File",
".",
"exist?",
"(",
"file",
")",
"File",
".... | Restores the file modification times for all modified files to make it
appear like they never changed. | [
"Restores",
"the",
"file",
"modification",
"times",
"for",
"all",
"modified",
"files",
"to",
"make",
"it",
"appear",
"like",
"they",
"never",
"changed",
"."
] | 35d60adb41da942178b789560968e3ad030b0ac7 | https://github.com/sds/overcommit/blob/35d60adb41da942178b789560968e3ad030b0ac7/lib/overcommit/hook_context/pre_commit.rb#L202-L208 | train |
sds/overcommit | lib/overcommit/configuration_validator.rb | Overcommit.ConfigurationValidator.validate | def validate(config, hash, options)
@options = options.dup
@log = options[:logger]
hash = convert_nils_to_empty_hashes(hash)
ensure_hook_type_sections_exist(hash)
check_hook_name_format(hash)
check_hook_env(hash)
check_for_missing_enabled_option(hash) unless @options[:default]... | ruby | def validate(config, hash, options)
@options = options.dup
@log = options[:logger]
hash = convert_nils_to_empty_hashes(hash)
ensure_hook_type_sections_exist(hash)
check_hook_name_format(hash)
check_hook_env(hash)
check_for_missing_enabled_option(hash) unless @options[:default]... | [
"def",
"validate",
"(",
"config",
",",
"hash",
",",
"options",
")",
"@options",
"=",
"options",
".",
"dup",
"@log",
"=",
"options",
"[",
":logger",
"]",
"hash",
"=",
"convert_nils_to_empty_hashes",
"(",
"hash",
")",
"ensure_hook_type_sections_exist",
"(",
"has... | Validates hash for any invalid options, normalizing where possible.
@param config [Overcommit::Configuration]
@param hash [Hash] hash representation of YAML config
@param options[Hash]
@option default [Boolean] whether hash represents the default built-in config
@option logger [Overcommit::Logger] logger to outpu... | [
"Validates",
"hash",
"for",
"any",
"invalid",
"options",
"normalizing",
"where",
"possible",
"."
] | 35d60adb41da942178b789560968e3ad030b0ac7 | https://github.com/sds/overcommit/blob/35d60adb41da942178b789560968e3ad030b0ac7/lib/overcommit/configuration_validator.rb#L15-L28 | train |
sds/overcommit | lib/overcommit/configuration_validator.rb | Overcommit.ConfigurationValidator.convert_nils_to_empty_hashes | def convert_nils_to_empty_hashes(hash)
hash.each_with_object({}) do |(key, value), h|
h[key] =
case value
when nil then {}
when Hash then convert_nils_to_empty_hashes(value)
else
value
end
end
end | ruby | def convert_nils_to_empty_hashes(hash)
hash.each_with_object({}) do |(key, value), h|
h[key] =
case value
when nil then {}
when Hash then convert_nils_to_empty_hashes(value)
else
value
end
end
end | [
"def",
"convert_nils_to_empty_hashes",
"(",
"hash",
")",
"hash",
".",
"each_with_object",
"(",
"{",
"}",
")",
"do",
"|",
"(",
"key",
",",
"value",
")",
",",
"h",
"|",
"h",
"[",
"key",
"]",
"=",
"case",
"value",
"when",
"nil",
"then",
"{",
"}",
"whe... | Normalizes `nil` values to empty hashes.
This is useful for when we want to merge two configuration hashes
together, since it's easier to merge two hashes than to have to check if
one of the values is nil. | [
"Normalizes",
"nil",
"values",
"to",
"empty",
"hashes",
"."
] | 35d60adb41da942178b789560968e3ad030b0ac7 | https://github.com/sds/overcommit/blob/35d60adb41da942178b789560968e3ad030b0ac7/lib/overcommit/configuration_validator.rb#L46-L56 | train |
sds/overcommit | lib/overcommit/configuration_validator.rb | Overcommit.ConfigurationValidator.check_hook_name_format | def check_hook_name_format(hash)
errors = []
Overcommit::Utils.supported_hook_type_classes.each do |hook_type|
hash.fetch(hook_type) { {} }.each_key do |hook_name|
next if hook_name == 'ALL'
unless hook_name.match?(/\A[A-Za-z0-9]+\z/)
errors << "#{hook_type}::#{hook... | ruby | def check_hook_name_format(hash)
errors = []
Overcommit::Utils.supported_hook_type_classes.each do |hook_type|
hash.fetch(hook_type) { {} }.each_key do |hook_name|
next if hook_name == 'ALL'
unless hook_name.match?(/\A[A-Za-z0-9]+\z/)
errors << "#{hook_type}::#{hook... | [
"def",
"check_hook_name_format",
"(",
"hash",
")",
"errors",
"=",
"[",
"]",
"Overcommit",
"::",
"Utils",
".",
"supported_hook_type_classes",
".",
"each",
"do",
"|",
"hook_type",
"|",
"hash",
".",
"fetch",
"(",
"hook_type",
")",
"{",
"{",
"}",
"}",
".",
"... | Prints an error message and raises an exception if a hook has an
invalid name, since this can result in strange errors elsewhere. | [
"Prints",
"an",
"error",
"message",
"and",
"raises",
"an",
"exception",
"if",
"a",
"hook",
"has",
"an",
"invalid",
"name",
"since",
"this",
"can",
"result",
"in",
"strange",
"errors",
"elsewhere",
"."
] | 35d60adb41da942178b789560968e3ad030b0ac7 | https://github.com/sds/overcommit/blob/35d60adb41da942178b789560968e3ad030b0ac7/lib/overcommit/configuration_validator.rb#L98-L121 | train |
sds/overcommit | lib/overcommit/configuration_validator.rb | Overcommit.ConfigurationValidator.check_for_missing_enabled_option | def check_for_missing_enabled_option(hash)
return unless @log
any_warnings = false
Overcommit::Utils.supported_hook_type_classes.each do |hook_type|
hash.fetch(hook_type) { {} }.each do |hook_name, hook_config|
next if hook_name == 'ALL'
if hook_config['enabled'].nil?
... | ruby | def check_for_missing_enabled_option(hash)
return unless @log
any_warnings = false
Overcommit::Utils.supported_hook_type_classes.each do |hook_type|
hash.fetch(hook_type) { {} }.each do |hook_name, hook_config|
next if hook_name == 'ALL'
if hook_config['enabled'].nil?
... | [
"def",
"check_for_missing_enabled_option",
"(",
"hash",
")",
"return",
"unless",
"@log",
"any_warnings",
"=",
"false",
"Overcommit",
"::",
"Utils",
".",
"supported_hook_type_classes",
".",
"each",
"do",
"|",
"hook_type",
"|",
"hash",
".",
"fetch",
"(",
"hook_type"... | Prints a warning if there are any hooks listed in the configuration
without `enabled` explicitly set. | [
"Prints",
"a",
"warning",
"if",
"there",
"are",
"any",
"hooks",
"listed",
"in",
"the",
"configuration",
"without",
"enabled",
"explicitly",
"set",
"."
] | 35d60adb41da942178b789560968e3ad030b0ac7 | https://github.com/sds/overcommit/blob/35d60adb41da942178b789560968e3ad030b0ac7/lib/overcommit/configuration_validator.rb#L125-L143 | train |
sds/overcommit | lib/overcommit/configuration_validator.rb | Overcommit.ConfigurationValidator.check_for_too_many_processors | def check_for_too_many_processors(config, hash)
concurrency = config.concurrency
errors = []
Overcommit::Utils.supported_hook_type_classes.each do |hook_type|
hash.fetch(hook_type) { {} }.each do |hook_name, hook_config|
processors = hook_config.fetch('processors') { 1 }
i... | ruby | def check_for_too_many_processors(config, hash)
concurrency = config.concurrency
errors = []
Overcommit::Utils.supported_hook_type_classes.each do |hook_type|
hash.fetch(hook_type) { {} }.each do |hook_name, hook_config|
processors = hook_config.fetch('processors') { 1 }
i... | [
"def",
"check_for_too_many_processors",
"(",
"config",
",",
"hash",
")",
"concurrency",
"=",
"config",
".",
"concurrency",
"errors",
"=",
"[",
"]",
"Overcommit",
"::",
"Utils",
".",
"supported_hook_type_classes",
".",
"each",
"do",
"|",
"hook_type",
"|",
"hash",... | Prints a warning if any hook has a number of processors larger than the
global `concurrency` setting. | [
"Prints",
"a",
"warning",
"if",
"any",
"hook",
"has",
"a",
"number",
"of",
"processors",
"larger",
"than",
"the",
"global",
"concurrency",
"setting",
"."
] | 35d60adb41da942178b789560968e3ad030b0ac7 | https://github.com/sds/overcommit/blob/35d60adb41da942178b789560968e3ad030b0ac7/lib/overcommit/configuration_validator.rb#L147-L170 | train |
sds/overcommit | lib/overcommit/configuration.rb | Overcommit.Configuration.all_builtin_hook_configs | def all_builtin_hook_configs
hook_configs = {}
Overcommit::Utils.supported_hook_type_classes.each do |hook_type|
hook_names = @hash[hook_type].keys.reject { |name| name == 'ALL' }
hook_configs[hook_type] = Hash[
hook_names.map do |hook_name|
[hook_name, for_hook(hook_... | ruby | def all_builtin_hook_configs
hook_configs = {}
Overcommit::Utils.supported_hook_type_classes.each do |hook_type|
hook_names = @hash[hook_type].keys.reject { |name| name == 'ALL' }
hook_configs[hook_type] = Hash[
hook_names.map do |hook_name|
[hook_name, for_hook(hook_... | [
"def",
"all_builtin_hook_configs",
"hook_configs",
"=",
"{",
"}",
"Overcommit",
"::",
"Utils",
".",
"supported_hook_type_classes",
".",
"each",
"do",
"|",
"hook_type",
"|",
"hook_names",
"=",
"@hash",
"[",
"hook_type",
"]",
".",
"keys",
".",
"reject",
"{",
"|"... | Returns configuration for all built-in hooks in each hook type.
@return [Hash] | [
"Returns",
"configuration",
"for",
"all",
"built",
"-",
"in",
"hooks",
"in",
"each",
"hook",
"type",
"."
] | 35d60adb41da942178b789560968e3ad030b0ac7 | https://github.com/sds/overcommit/blob/35d60adb41da942178b789560968e3ad030b0ac7/lib/overcommit/configuration.rb#L72-L86 | train |
sds/overcommit | lib/overcommit/configuration.rb | Overcommit.Configuration.all_plugin_hook_configs | def all_plugin_hook_configs
hook_configs = {}
Overcommit::Utils.supported_hook_types.each do |hook_type|
hook_type_class_name = Overcommit::Utils.camel_case(hook_type)
directory = File.join(plugin_directory, hook_type.tr('-', '_'))
plugin_paths = Dir[File.join(directory, '*.rb')].s... | ruby | def all_plugin_hook_configs
hook_configs = {}
Overcommit::Utils.supported_hook_types.each do |hook_type|
hook_type_class_name = Overcommit::Utils.camel_case(hook_type)
directory = File.join(plugin_directory, hook_type.tr('-', '_'))
plugin_paths = Dir[File.join(directory, '*.rb')].s... | [
"def",
"all_plugin_hook_configs",
"hook_configs",
"=",
"{",
"}",
"Overcommit",
"::",
"Utils",
".",
"supported_hook_types",
".",
"each",
"do",
"|",
"hook_type",
"|",
"hook_type_class_name",
"=",
"Overcommit",
"::",
"Utils",
".",
"camel_case",
"(",
"hook_type",
")",... | Returns configuration for all plugin hooks in each hook type.
@return [Hash] | [
"Returns",
"configuration",
"for",
"all",
"plugin",
"hooks",
"in",
"each",
"hook",
"type",
"."
] | 35d60adb41da942178b789560968e3ad030b0ac7 | https://github.com/sds/overcommit/blob/35d60adb41da942178b789560968e3ad030b0ac7/lib/overcommit/configuration.rb#L91-L112 | train |
sds/overcommit | lib/overcommit/configuration.rb | Overcommit.Configuration.enabled_builtin_hooks | def enabled_builtin_hooks(hook_context)
@hash[hook_context.hook_class_name].keys.
reject { |hook_name| hook_name == 'ALL' }.
select { |hook_name| built_in_hook?(hook_context, hook_name) }.
select { |hook_name| hook_enabled?(hook_context, hook_name) }
end | ruby | def enabled_builtin_hooks(hook_context)
@hash[hook_context.hook_class_name].keys.
reject { |hook_name| hook_name == 'ALL' }.
select { |hook_name| built_in_hook?(hook_context, hook_name) }.
select { |hook_name| hook_enabled?(hook_context, hook_name) }
end | [
"def",
"enabled_builtin_hooks",
"(",
"hook_context",
")",
"@hash",
"[",
"hook_context",
".",
"hook_class_name",
"]",
".",
"keys",
".",
"reject",
"{",
"|",
"hook_name",
"|",
"hook_name",
"==",
"'ALL'",
"}",
".",
"select",
"{",
"|",
"hook_name",
"|",
"built_in... | Returns the built-in hooks that have been enabled for a hook type. | [
"Returns",
"the",
"built",
"-",
"in",
"hooks",
"that",
"have",
"been",
"enabled",
"for",
"a",
"hook",
"type",
"."
] | 35d60adb41da942178b789560968e3ad030b0ac7 | https://github.com/sds/overcommit/blob/35d60adb41da942178b789560968e3ad030b0ac7/lib/overcommit/configuration.rb#L115-L120 | train |
sds/overcommit | lib/overcommit/configuration.rb | Overcommit.Configuration.enabled_ad_hoc_hooks | def enabled_ad_hoc_hooks(hook_context)
@hash[hook_context.hook_class_name].keys.
reject { |hook_name| hook_name == 'ALL' }.
select { |hook_name| ad_hoc_hook?(hook_context, hook_name) }.
select { |hook_name| hook_enabled?(hook_context, hook_name) }
end | ruby | def enabled_ad_hoc_hooks(hook_context)
@hash[hook_context.hook_class_name].keys.
reject { |hook_name| hook_name == 'ALL' }.
select { |hook_name| ad_hoc_hook?(hook_context, hook_name) }.
select { |hook_name| hook_enabled?(hook_context, hook_name) }
end | [
"def",
"enabled_ad_hoc_hooks",
"(",
"hook_context",
")",
"@hash",
"[",
"hook_context",
".",
"hook_class_name",
"]",
".",
"keys",
".",
"reject",
"{",
"|",
"hook_name",
"|",
"hook_name",
"==",
"'ALL'",
"}",
".",
"select",
"{",
"|",
"hook_name",
"|",
"ad_hoc_ho... | Returns the ad hoc hooks that have been enabled for a hook type. | [
"Returns",
"the",
"ad",
"hoc",
"hooks",
"that",
"have",
"been",
"enabled",
"for",
"a",
"hook",
"type",
"."
] | 35d60adb41da942178b789560968e3ad030b0ac7 | https://github.com/sds/overcommit/blob/35d60adb41da942178b789560968e3ad030b0ac7/lib/overcommit/configuration.rb#L123-L128 | train |
sds/overcommit | lib/overcommit/configuration.rb | Overcommit.Configuration.for_hook | def for_hook(hook, hook_type = nil)
unless hook_type
components = hook.class.name.split('::')
hook = components.last
hook_type = components[-2]
end
# Merge hook configuration with special 'ALL' config
hook_config = smart_merge(@hash[hook_type]['ALL'], @hash[hook_type][ho... | ruby | def for_hook(hook, hook_type = nil)
unless hook_type
components = hook.class.name.split('::')
hook = components.last
hook_type = components[-2]
end
# Merge hook configuration with special 'ALL' config
hook_config = smart_merge(@hash[hook_type]['ALL'], @hash[hook_type][ho... | [
"def",
"for_hook",
"(",
"hook",
",",
"hook_type",
"=",
"nil",
")",
"unless",
"hook_type",
"components",
"=",
"hook",
".",
"class",
".",
"name",
".",
"split",
"(",
"'::'",
")",
"hook",
"=",
"components",
".",
"last",
"hook_type",
"=",
"components",
"[",
... | Returns a non-modifiable configuration for a hook. | [
"Returns",
"a",
"non",
"-",
"modifiable",
"configuration",
"for",
"a",
"hook",
"."
] | 35d60adb41da942178b789560968e3ad030b0ac7 | https://github.com/sds/overcommit/blob/35d60adb41da942178b789560968e3ad030b0ac7/lib/overcommit/configuration.rb#L131-L146 | train |
sds/overcommit | lib/overcommit/configuration.rb | Overcommit.Configuration.apply_environment! | def apply_environment!(hook_context, env)
skipped_hooks = "#{env['SKIP']} #{env['SKIP_CHECKS']} #{env['SKIP_HOOKS']}".split(/[:, ]/)
only_hooks = env.fetch('ONLY') { '' }.split(/[:, ]/)
hook_type = hook_context.hook_class_name
if only_hooks.any? || skipped_hooks.include?('all') || skipped_hooks... | ruby | def apply_environment!(hook_context, env)
skipped_hooks = "#{env['SKIP']} #{env['SKIP_CHECKS']} #{env['SKIP_HOOKS']}".split(/[:, ]/)
only_hooks = env.fetch('ONLY') { '' }.split(/[:, ]/)
hook_type = hook_context.hook_class_name
if only_hooks.any? || skipped_hooks.include?('all') || skipped_hooks... | [
"def",
"apply_environment!",
"(",
"hook_context",
",",
"env",
")",
"skipped_hooks",
"=",
"\"#{env['SKIP']} #{env['SKIP_CHECKS']} #{env['SKIP_HOOKS']}\"",
".",
"split",
"(",
"/",
"/",
")",
"only_hooks",
"=",
"env",
".",
"fetch",
"(",
"'ONLY'",
")",
"{",
"''",
"}",
... | Applies additional configuration settings based on the provided
environment variables. | [
"Applies",
"additional",
"configuration",
"settings",
"based",
"on",
"the",
"provided",
"environment",
"variables",
"."
] | 35d60adb41da942178b789560968e3ad030b0ac7 | https://github.com/sds/overcommit/blob/35d60adb41da942178b789560968e3ad030b0ac7/lib/overcommit/configuration.rb#L157-L179 | train |
sds/overcommit | lib/overcommit/configuration.rb | Overcommit.Configuration.stored_signature | def stored_signature
result = Overcommit::Utils.execute(
%w[git config --local --get] + [signature_config_key]
)
if result.status == 1 # Key doesn't exist
return ''
elsif result.status != 0
raise Overcommit::Exceptions::GitConfigError,
"Unable to read from ... | ruby | def stored_signature
result = Overcommit::Utils.execute(
%w[git config --local --get] + [signature_config_key]
)
if result.status == 1 # Key doesn't exist
return ''
elsif result.status != 0
raise Overcommit::Exceptions::GitConfigError,
"Unable to read from ... | [
"def",
"stored_signature",
"result",
"=",
"Overcommit",
"::",
"Utils",
".",
"execute",
"(",
"%w[",
"git",
"config",
"--local",
"--get",
"]",
"+",
"[",
"signature_config_key",
"]",
")",
"if",
"result",
".",
"status",
"==",
"1",
"# Key doesn't exist",
"return",
... | Returns the stored signature of this repo's Overcommit configuration.
This is intended to be compared against the current signature of this
configuration object.
@return [String] | [
"Returns",
"the",
"stored",
"signature",
"of",
"this",
"repo",
"s",
"Overcommit",
"configuration",
"."
] | 35d60adb41da942178b789560968e3ad030b0ac7 | https://github.com/sds/overcommit/blob/35d60adb41da942178b789560968e3ad030b0ac7/lib/overcommit/configuration.rb#L327-L340 | train |
sds/overcommit | lib/overcommit/git_repo.rb | Overcommit.GitRepo.all_files | def all_files
`git ls-files`.
split(/\n/).
map { |relative_file| File.expand_path(relative_file) }.
reject { |file| File.directory?(file) } # Exclude submodule directories
end | ruby | def all_files
`git ls-files`.
split(/\n/).
map { |relative_file| File.expand_path(relative_file) }.
reject { |file| File.directory?(file) } # Exclude submodule directories
end | [
"def",
"all_files",
"`",
"`",
".",
"split",
"(",
"/",
"\\n",
"/",
")",
".",
"map",
"{",
"|",
"relative_file",
"|",
"File",
".",
"expand_path",
"(",
"relative_file",
")",
"}",
".",
"reject",
"{",
"|",
"file",
"|",
"File",
".",
"directory?",
"(",
"fi... | Returns the names of all files that are tracked by git.
@return [Array<String>] list of absolute file paths | [
"Returns",
"the",
"names",
"of",
"all",
"files",
"that",
"are",
"tracked",
"by",
"git",
"."
] | 35d60adb41da942178b789560968e3ad030b0ac7 | https://github.com/sds/overcommit/blob/35d60adb41da942178b789560968e3ad030b0ac7/lib/overcommit/git_repo.rb#L129-L134 | train |
sds/overcommit | lib/overcommit/git_repo.rb | Overcommit.GitRepo.restore_merge_state | def restore_merge_state
if @merge_head
FileUtils.touch(File.expand_path('MERGE_MODE', Overcommit::Utils.git_dir))
File.open(File.expand_path('MERGE_HEAD', Overcommit::Utils.git_dir), 'w') do |f|
f.write(@merge_head)
end
@merge_head = nil
end
if @merge_msg
... | ruby | def restore_merge_state
if @merge_head
FileUtils.touch(File.expand_path('MERGE_MODE', Overcommit::Utils.git_dir))
File.open(File.expand_path('MERGE_HEAD', Overcommit::Utils.git_dir), 'w') do |f|
f.write(@merge_head)
end
@merge_head = nil
end
if @merge_msg
... | [
"def",
"restore_merge_state",
"if",
"@merge_head",
"FileUtils",
".",
"touch",
"(",
"File",
".",
"expand_path",
"(",
"'MERGE_MODE'",
",",
"Overcommit",
"::",
"Utils",
".",
"git_dir",
")",
")",
"File",
".",
"open",
"(",
"File",
".",
"expand_path",
"(",
"'MERGE... | Restore any relevant files that were present when repo was in the middle
of a merge. | [
"Restore",
"any",
"relevant",
"files",
"that",
"were",
"present",
"when",
"repo",
"was",
"in",
"the",
"middle",
"of",
"a",
"merge",
"."
] | 35d60adb41da942178b789560968e3ad030b0ac7 | https://github.com/sds/overcommit/blob/35d60adb41da942178b789560968e3ad030b0ac7/lib/overcommit/git_repo.rb#L175-L191 | train |
sds/overcommit | lib/overcommit/git_repo.rb | Overcommit.GitRepo.restore_cherry_pick_state | def restore_cherry_pick_state
if @cherry_head
File.open(File.expand_path('CHERRY_PICK_HEAD',
Overcommit::Utils.git_dir), 'w') do |f|
f.write(@cherry_head)
end
@cherry_head = nil
end
end | ruby | def restore_cherry_pick_state
if @cherry_head
File.open(File.expand_path('CHERRY_PICK_HEAD',
Overcommit::Utils.git_dir), 'w') do |f|
f.write(@cherry_head)
end
@cherry_head = nil
end
end | [
"def",
"restore_cherry_pick_state",
"if",
"@cherry_head",
"File",
".",
"open",
"(",
"File",
".",
"expand_path",
"(",
"'CHERRY_PICK_HEAD'",
",",
"Overcommit",
"::",
"Utils",
".",
"git_dir",
")",
",",
"'w'",
")",
"do",
"|",
"f",
"|",
"f",
".",
"write",
"(",
... | Restore any relevant files that were present when repo was in the middle
of a cherry-pick. | [
"Restore",
"any",
"relevant",
"files",
"that",
"were",
"present",
"when",
"repo",
"was",
"in",
"the",
"middle",
"of",
"a",
"cherry",
"-",
"pick",
"."
] | 35d60adb41da942178b789560968e3ad030b0ac7 | https://github.com/sds/overcommit/blob/35d60adb41da942178b789560968e3ad030b0ac7/lib/overcommit/git_repo.rb#L195-L203 | train |
sds/overcommit | lib/overcommit/hook_signer.rb | Overcommit.HookSigner.update_signature! | def update_signature!
result = Overcommit::Utils.execute(
%w[git config --local] + [signature_config_key, signature]
)
unless result.success?
raise Overcommit::Exceptions::GitConfigError,
"Unable to write to local repo git config: #{result.stderr}"
end
end | ruby | def update_signature!
result = Overcommit::Utils.execute(
%w[git config --local] + [signature_config_key, signature]
)
unless result.success?
raise Overcommit::Exceptions::GitConfigError,
"Unable to write to local repo git config: #{result.stderr}"
end
end | [
"def",
"update_signature!",
"result",
"=",
"Overcommit",
"::",
"Utils",
".",
"execute",
"(",
"%w[",
"git",
"config",
"--local",
"]",
"+",
"[",
"signature_config_key",
",",
"signature",
"]",
")",
"unless",
"result",
".",
"success?",
"raise",
"Overcommit",
"::",... | Update the current stored signature for this hook. | [
"Update",
"the",
"current",
"stored",
"signature",
"for",
"this",
"hook",
"."
] | 35d60adb41da942178b789560968e3ad030b0ac7 | https://github.com/sds/overcommit/blob/35d60adb41da942178b789560968e3ad030b0ac7/lib/overcommit/hook_signer.rb#L69-L78 | train |
sds/overcommit | lib/overcommit/hook_signer.rb | Overcommit.HookSigner.signature | def signature
hook_config = @config.for_hook(@hook_name, @context.hook_class_name).
dup.
tap { |config| IGNORED_CONFIG_KEYS.each { |k| config.delete(k) } }
content_to_sign =
if signable_file?(hook_path) && Overcommit::GitRepo.tracked?(hook_pat... | ruby | def signature
hook_config = @config.for_hook(@hook_name, @context.hook_class_name).
dup.
tap { |config| IGNORED_CONFIG_KEYS.each { |k| config.delete(k) } }
content_to_sign =
if signable_file?(hook_path) && Overcommit::GitRepo.tracked?(hook_pat... | [
"def",
"signature",
"hook_config",
"=",
"@config",
".",
"for_hook",
"(",
"@hook_name",
",",
"@context",
".",
"hook_class_name",
")",
".",
"dup",
".",
"tap",
"{",
"|",
"config",
"|",
"IGNORED_CONFIG_KEYS",
".",
"each",
"{",
"|",
"k",
"|",
"config",
".",
"... | Calculates a hash of a hook using a combination of its configuration and
file contents.
This way, if either the plugin code changes or its configuration changes,
the hash will change and we can alert the user to this change. | [
"Calculates",
"a",
"hash",
"of",
"a",
"hook",
"using",
"a",
"combination",
"of",
"its",
"configuration",
"and",
"file",
"contents",
"."
] | 35d60adb41da942178b789560968e3ad030b0ac7 | https://github.com/sds/overcommit/blob/35d60adb41da942178b789560968e3ad030b0ac7/lib/overcommit/hook_signer.rb#L87-L98 | train |
sds/overcommit | lib/overcommit/printer.rb | Overcommit.Printer.end_hook | def end_hook(hook, status, output)
# Want to print the header for quiet hooks only if the result wasn't good
# so that the user knows what failed
print_header(hook) if (!hook.quiet? && !@config['quiet']) || status != :pass
print_result(hook, status, output)
end | ruby | def end_hook(hook, status, output)
# Want to print the header for quiet hooks only if the result wasn't good
# so that the user knows what failed
print_header(hook) if (!hook.quiet? && !@config['quiet']) || status != :pass
print_result(hook, status, output)
end | [
"def",
"end_hook",
"(",
"hook",
",",
"status",
",",
"output",
")",
"# Want to print the header for quiet hooks only if the result wasn't good",
"# so that the user knows what failed",
"print_header",
"(",
"hook",
")",
"if",
"(",
"!",
"hook",
".",
"quiet?",
"&&",
"!",
"@... | Executed at the end of an individual hook run. | [
"Executed",
"at",
"the",
"end",
"of",
"an",
"individual",
"hook",
"run",
"."
] | 35d60adb41da942178b789560968e3ad030b0ac7 | https://github.com/sds/overcommit/blob/35d60adb41da942178b789560968e3ad030b0ac7/lib/overcommit/printer.rb#L37-L43 | train |
ruby/rake | lib/rake/loaders/makefile.rb | Rake.MakefileLoader.process_line | def process_line(line) # :nodoc:
file_tasks, args = line.split(":", 2)
return if args.nil?
dependents = args.split.map { |d| respace(d) }
file_tasks.scan(/\S+/) do |file_task|
file_task = respace(file_task)
file file_task => dependents
end
end | ruby | def process_line(line) # :nodoc:
file_tasks, args = line.split(":", 2)
return if args.nil?
dependents = args.split.map { |d| respace(d) }
file_tasks.scan(/\S+/) do |file_task|
file_task = respace(file_task)
file file_task => dependents
end
end | [
"def",
"process_line",
"(",
"line",
")",
"# :nodoc:",
"file_tasks",
",",
"args",
"=",
"line",
".",
"split",
"(",
"\":\"",
",",
"2",
")",
"return",
"if",
"args",
".",
"nil?",
"dependents",
"=",
"args",
".",
"split",
".",
"map",
"{",
"|",
"d",
"|",
"... | Process one logical line of makefile data. | [
"Process",
"one",
"logical",
"line",
"of",
"makefile",
"data",
"."
] | 1c22b490ee6cb8bd614fa8d0d6145f671466206b | https://github.com/ruby/rake/blob/1c22b490ee6cb8bd614fa8d0d6145f671466206b/lib/rake/loaders/makefile.rb#L37-L45 | train |
ruby/rake | lib/rake/task.rb | Rake.Task.invoke | def invoke(*args)
task_args = TaskArguments.new(arg_names, args)
invoke_with_call_chain(task_args, InvocationChain::EMPTY)
end | ruby | def invoke(*args)
task_args = TaskArguments.new(arg_names, args)
invoke_with_call_chain(task_args, InvocationChain::EMPTY)
end | [
"def",
"invoke",
"(",
"*",
"args",
")",
"task_args",
"=",
"TaskArguments",
".",
"new",
"(",
"arg_names",
",",
"args",
")",
"invoke_with_call_chain",
"(",
"task_args",
",",
"InvocationChain",
"::",
"EMPTY",
")",
"end"
] | Invoke the task if it is needed. Prerequisites are invoked first. | [
"Invoke",
"the",
"task",
"if",
"it",
"is",
"needed",
".",
"Prerequisites",
"are",
"invoked",
"first",
"."
] | 1c22b490ee6cb8bd614fa8d0d6145f671466206b | https://github.com/ruby/rake/blob/1c22b490ee6cb8bd614fa8d0d6145f671466206b/lib/rake/task.rb#L181-L184 | train |
ruby/rake | lib/rake/task.rb | Rake.Task.transform_comments | def transform_comments(separator, &block)
if @comments.empty?
nil
else
block ||= lambda { |c| c }
@comments.map(&block).join(separator)
end
end | ruby | def transform_comments(separator, &block)
if @comments.empty?
nil
else
block ||= lambda { |c| c }
@comments.map(&block).join(separator)
end
end | [
"def",
"transform_comments",
"(",
"separator",
",",
"&",
"block",
")",
"if",
"@comments",
".",
"empty?",
"nil",
"else",
"block",
"||=",
"lambda",
"{",
"|",
"c",
"|",
"c",
"}",
"@comments",
".",
"map",
"(",
"block",
")",
".",
"join",
"(",
"separator",
... | Transform the list of comments as specified by the block and
join with the separator. | [
"Transform",
"the",
"list",
"of",
"comments",
"as",
"specified",
"by",
"the",
"block",
"and",
"join",
"with",
"the",
"separator",
"."
] | 1c22b490ee6cb8bd614fa8d0d6145f671466206b | https://github.com/ruby/rake/blob/1c22b490ee6cb8bd614fa8d0d6145f671466206b/lib/rake/task.rb#L319-L326 | train |
ruby/rake | lib/rake/file_utils_ext.rb | Rake.FileUtilsExt.rake_merge_option | def rake_merge_option(args, defaults)
if Hash === args.last
defaults.update(args.last)
args.pop
end
args.push defaults
args
end | ruby | def rake_merge_option(args, defaults)
if Hash === args.last
defaults.update(args.last)
args.pop
end
args.push defaults
args
end | [
"def",
"rake_merge_option",
"(",
"args",
",",
"defaults",
")",
"if",
"Hash",
"===",
"args",
".",
"last",
"defaults",
".",
"update",
"(",
"args",
".",
"last",
")",
"args",
".",
"pop",
"end",
"args",
".",
"push",
"defaults",
"args",
"end"
] | Merge the given options with the default values. | [
"Merge",
"the",
"given",
"options",
"with",
"the",
"default",
"values",
"."
] | 1c22b490ee6cb8bd614fa8d0d6145f671466206b | https://github.com/ruby/rake/blob/1c22b490ee6cb8bd614fa8d0d6145f671466206b/lib/rake/file_utils_ext.rb#L117-L124 | train |
ruby/rake | lib/rake/file_utils_ext.rb | Rake.FileUtilsExt.rake_check_options | def rake_check_options(options, *optdecl)
h = options.dup
optdecl.each do |name|
h.delete name
end
raise ArgumentError, "no such option: #{h.keys.join(' ')}" unless
h.empty?
end | ruby | def rake_check_options(options, *optdecl)
h = options.dup
optdecl.each do |name|
h.delete name
end
raise ArgumentError, "no such option: #{h.keys.join(' ')}" unless
h.empty?
end | [
"def",
"rake_check_options",
"(",
"options",
",",
"*",
"optdecl",
")",
"h",
"=",
"options",
".",
"dup",
"optdecl",
".",
"each",
"do",
"|",
"name",
"|",
"h",
".",
"delete",
"name",
"end",
"raise",
"ArgumentError",
",",
"\"no such option: #{h.keys.join(' ')}\"",... | Check that the options do not contain options not listed in
+optdecl+. An ArgumentError exception is thrown if non-declared
options are found. | [
"Check",
"that",
"the",
"options",
"do",
"not",
"contain",
"options",
"not",
"listed",
"in",
"+",
"optdecl",
"+",
".",
"An",
"ArgumentError",
"exception",
"is",
"thrown",
"if",
"non",
"-",
"declared",
"options",
"are",
"found",
"."
] | 1c22b490ee6cb8bd614fa8d0d6145f671466206b | https://github.com/ruby/rake/blob/1c22b490ee6cb8bd614fa8d0d6145f671466206b/lib/rake/file_utils_ext.rb#L134-L141 | train |
ruby/rake | lib/rake/scope.rb | Rake.Scope.trim | def trim(n)
result = self
while n > 0 && !result.empty?
result = result.tail
n -= 1
end
result
end | ruby | def trim(n)
result = self
while n > 0 && !result.empty?
result = result.tail
n -= 1
end
result
end | [
"def",
"trim",
"(",
"n",
")",
"result",
"=",
"self",
"while",
"n",
">",
"0",
"&&",
"!",
"result",
".",
"empty?",
"result",
"=",
"result",
".",
"tail",
"n",
"-=",
"1",
"end",
"result",
"end"
] | Trim +n+ innermost scope levels from the scope. In no case will
this trim beyond the toplevel scope. | [
"Trim",
"+",
"n",
"+",
"innermost",
"scope",
"levels",
"from",
"the",
"scope",
".",
"In",
"no",
"case",
"will",
"this",
"trim",
"beyond",
"the",
"toplevel",
"scope",
"."
] | 1c22b490ee6cb8bd614fa8d0d6145f671466206b | https://github.com/ruby/rake/blob/1c22b490ee6cb8bd614fa8d0d6145f671466206b/lib/rake/scope.rb#L17-L24 | train |
ruby/rake | lib/rake/application.rb | Rake.Application.init | def init(app_name="rake", argv = ARGV)
standard_exception_handling do
@name = app_name
begin
args = handle_options argv
rescue ArgumentError
# Backward compatibility for capistrano
args = handle_options
end
collect_command_line_tasks(args)
... | ruby | def init(app_name="rake", argv = ARGV)
standard_exception_handling do
@name = app_name
begin
args = handle_options argv
rescue ArgumentError
# Backward compatibility for capistrano
args = handle_options
end
collect_command_line_tasks(args)
... | [
"def",
"init",
"(",
"app_name",
"=",
"\"rake\"",
",",
"argv",
"=",
"ARGV",
")",
"standard_exception_handling",
"do",
"@name",
"=",
"app_name",
"begin",
"args",
"=",
"handle_options",
"argv",
"rescue",
"ArgumentError",
"# Backward compatibility for capistrano",
"args",... | Initialize the command line parameters and app name. | [
"Initialize",
"the",
"command",
"line",
"parameters",
"and",
"app",
"name",
"."
] | 1c22b490ee6cb8bd614fa8d0d6145f671466206b | https://github.com/ruby/rake/blob/1c22b490ee6cb8bd614fa8d0d6145f671466206b/lib/rake/application.rb#L88-L99 | train |
ruby/rake | lib/rake/application.rb | Rake.Application.have_rakefile | def have_rakefile # :nodoc:
@rakefiles.each do |fn|
if File.exist?(fn)
others = FileList.glob(fn, File::FNM_CASEFOLD)
return others.size == 1 ? others.first : fn
elsif fn == ""
return fn
end
end
return nil
end | ruby | def have_rakefile # :nodoc:
@rakefiles.each do |fn|
if File.exist?(fn)
others = FileList.glob(fn, File::FNM_CASEFOLD)
return others.size == 1 ? others.first : fn
elsif fn == ""
return fn
end
end
return nil
end | [
"def",
"have_rakefile",
"# :nodoc:",
"@rakefiles",
".",
"each",
"do",
"|",
"fn",
"|",
"if",
"File",
".",
"exist?",
"(",
"fn",
")",
"others",
"=",
"FileList",
".",
"glob",
"(",
"fn",
",",
"File",
"::",
"FNM_CASEFOLD",
")",
"return",
"others",
".",
"size... | True if one of the files in RAKEFILES is in the current directory.
If a match is found, it is copied into @rakefile. | [
"True",
"if",
"one",
"of",
"the",
"files",
"in",
"RAKEFILES",
"is",
"in",
"the",
"current",
"directory",
".",
"If",
"a",
"match",
"is",
"found",
"it",
"is",
"copied",
"into"
] | 1c22b490ee6cb8bd614fa8d0d6145f671466206b | https://github.com/ruby/rake/blob/1c22b490ee6cb8bd614fa8d0d6145f671466206b/lib/rake/application.rb#L274-L284 | train |
ruby/rake | lib/rake/file_list.rb | Rake.FileList.sub | def sub(pat, rep)
inject(self.class.new) { |res, fn| res << fn.sub(pat, rep) }
end | ruby | def sub(pat, rep)
inject(self.class.new) { |res, fn| res << fn.sub(pat, rep) }
end | [
"def",
"sub",
"(",
"pat",
",",
"rep",
")",
"inject",
"(",
"self",
".",
"class",
".",
"new",
")",
"{",
"|",
"res",
",",
"fn",
"|",
"res",
"<<",
"fn",
".",
"sub",
"(",
"pat",
",",
"rep",
")",
"}",
"end"
] | Return a new FileList with the results of running +sub+ against each
element of the original list.
Example:
FileList['a.c', 'b.c'].sub(/\.c$/, '.o') => ['a.o', 'b.o'] | [
"Return",
"a",
"new",
"FileList",
"with",
"the",
"results",
"of",
"running",
"+",
"sub",
"+",
"against",
"each",
"element",
"of",
"the",
"original",
"list",
"."
] | 1c22b490ee6cb8bd614fa8d0d6145f671466206b | https://github.com/ruby/rake/blob/1c22b490ee6cb8bd614fa8d0d6145f671466206b/lib/rake/file_list.rb#L242-L244 | train |
ruby/rake | lib/rake/file_list.rb | Rake.FileList.gsub | def gsub(pat, rep)
inject(self.class.new) { |res, fn| res << fn.gsub(pat, rep) }
end | ruby | def gsub(pat, rep)
inject(self.class.new) { |res, fn| res << fn.gsub(pat, rep) }
end | [
"def",
"gsub",
"(",
"pat",
",",
"rep",
")",
"inject",
"(",
"self",
".",
"class",
".",
"new",
")",
"{",
"|",
"res",
",",
"fn",
"|",
"res",
"<<",
"fn",
".",
"gsub",
"(",
"pat",
",",
"rep",
")",
"}",
"end"
] | Return a new FileList with the results of running +gsub+ against each
element of the original list.
Example:
FileList['lib/test/file', 'x/y'].gsub(/\//, "\\")
=> ['lib\\test\\file', 'x\\y'] | [
"Return",
"a",
"new",
"FileList",
"with",
"the",
"results",
"of",
"running",
"+",
"gsub",
"+",
"against",
"each",
"element",
"of",
"the",
"original",
"list",
"."
] | 1c22b490ee6cb8bd614fa8d0d6145f671466206b | https://github.com/ruby/rake/blob/1c22b490ee6cb8bd614fa8d0d6145f671466206b/lib/rake/file_list.rb#L253-L255 | train |
ruby/rake | lib/rake/file_list.rb | Rake.FileList.sub! | def sub!(pat, rep)
each_with_index { |fn, i| self[i] = fn.sub(pat, rep) }
self
end | ruby | def sub!(pat, rep)
each_with_index { |fn, i| self[i] = fn.sub(pat, rep) }
self
end | [
"def",
"sub!",
"(",
"pat",
",",
"rep",
")",
"each_with_index",
"{",
"|",
"fn",
",",
"i",
"|",
"self",
"[",
"i",
"]",
"=",
"fn",
".",
"sub",
"(",
"pat",
",",
"rep",
")",
"}",
"self",
"end"
] | Same as +sub+ except that the original file list is modified. | [
"Same",
"as",
"+",
"sub",
"+",
"except",
"that",
"the",
"original",
"file",
"list",
"is",
"modified",
"."
] | 1c22b490ee6cb8bd614fa8d0d6145f671466206b | https://github.com/ruby/rake/blob/1c22b490ee6cb8bd614fa8d0d6145f671466206b/lib/rake/file_list.rb#L258-L261 | train |
ruby/rake | lib/rake/file_list.rb | Rake.FileList.gsub! | def gsub!(pat, rep)
each_with_index { |fn, i| self[i] = fn.gsub(pat, rep) }
self
end | ruby | def gsub!(pat, rep)
each_with_index { |fn, i| self[i] = fn.gsub(pat, rep) }
self
end | [
"def",
"gsub!",
"(",
"pat",
",",
"rep",
")",
"each_with_index",
"{",
"|",
"fn",
",",
"i",
"|",
"self",
"[",
"i",
"]",
"=",
"fn",
".",
"gsub",
"(",
"pat",
",",
"rep",
")",
"}",
"self",
"end"
] | Same as +gsub+ except that the original file list is modified. | [
"Same",
"as",
"+",
"gsub",
"+",
"except",
"that",
"the",
"original",
"file",
"list",
"is",
"modified",
"."
] | 1c22b490ee6cb8bd614fa8d0d6145f671466206b | https://github.com/ruby/rake/blob/1c22b490ee6cb8bd614fa8d0d6145f671466206b/lib/rake/file_list.rb#L264-L267 | train |
ruby/rake | lib/rake/packagetask.rb | Rake.PackageTask.define | def define
fail "Version required (or :noversion)" if @version.nil?
@version = nil if :noversion == @version
desc "Build all the packages"
task :package
desc "Force a rebuild of the package files"
task repackage: [:clobber_package, :package]
desc "Remove package products"
... | ruby | def define
fail "Version required (or :noversion)" if @version.nil?
@version = nil if :noversion == @version
desc "Build all the packages"
task :package
desc "Force a rebuild of the package files"
task repackage: [:clobber_package, :package]
desc "Remove package products"
... | [
"def",
"define",
"fail",
"\"Version required (or :noversion)\"",
"if",
"@version",
".",
"nil?",
"@version",
"=",
"nil",
"if",
":noversion",
"==",
"@version",
"desc",
"\"Build all the packages\"",
"task",
":package",
"desc",
"\"Force a rebuild of the package files\"",
"task"... | Create the tasks defined by this task library. | [
"Create",
"the",
"tasks",
"defined",
"by",
"this",
"task",
"library",
"."
] | 1c22b490ee6cb8bd614fa8d0d6145f671466206b | https://github.com/ruby/rake/blob/1c22b490ee6cb8bd614fa8d0d6145f671466206b/lib/rake/packagetask.rb#L108-L162 | train |
ruby/rake | lib/rake/thread_pool.rb | Rake.ThreadPool.join | def join
@threads_mon.synchronize do
begin
stat :joining
@join_cond.wait unless @threads.empty?
stat :joined
rescue Exception => e
stat :joined
$stderr.puts e
$stderr.print "Queue contains #{@queue.size} items. " +
"Thread poo... | ruby | def join
@threads_mon.synchronize do
begin
stat :joining
@join_cond.wait unless @threads.empty?
stat :joined
rescue Exception => e
stat :joined
$stderr.puts e
$stderr.print "Queue contains #{@queue.size} items. " +
"Thread poo... | [
"def",
"join",
"@threads_mon",
".",
"synchronize",
"do",
"begin",
"stat",
":joining",
"@join_cond",
".",
"wait",
"unless",
"@threads",
".",
"empty?",
"stat",
":joined",
"rescue",
"Exception",
"=>",
"e",
"stat",
":joined",
"$stderr",
".",
"puts",
"e",
"$stderr"... | Waits until the queue of futures is empty and all threads have exited. | [
"Waits",
"until",
"the",
"queue",
"of",
"futures",
"is",
"empty",
"and",
"all",
"threads",
"have",
"exited",
"."
] | 1c22b490ee6cb8bd614fa8d0d6145f671466206b | https://github.com/ruby/rake/blob/1c22b490ee6cb8bd614fa8d0d6145f671466206b/lib/rake/thread_pool.rb#L44-L65 | train |
ruby/rake | lib/rake/thread_pool.rb | Rake.ThreadPool.process_queue_item | def process_queue_item #:nodoc:
return false if @queue.empty?
# Even though we just asked if the queue was empty, it
# still could have had an item which by this statement
# is now gone. For this reason we pass true to Queue#deq
# because we will sleep indefinitely if it is empty.
... | ruby | def process_queue_item #:nodoc:
return false if @queue.empty?
# Even though we just asked if the queue was empty, it
# still could have had an item which by this statement
# is now gone. For this reason we pass true to Queue#deq
# because we will sleep indefinitely if it is empty.
... | [
"def",
"process_queue_item",
"#:nodoc:",
"return",
"false",
"if",
"@queue",
".",
"empty?",
"# Even though we just asked if the queue was empty, it",
"# still could have had an item which by this statement",
"# is now gone. For this reason we pass true to Queue#deq",
"# because we will sleep ... | processes one item on the queue. Returns true if there was an
item to process, false if there was no item | [
"processes",
"one",
"item",
"on",
"the",
"queue",
".",
"Returns",
"true",
"if",
"there",
"was",
"an",
"item",
"to",
"process",
"false",
"if",
"there",
"was",
"no",
"item"
] | 1c22b490ee6cb8bd614fa8d0d6145f671466206b | https://github.com/ruby/rake/blob/1c22b490ee6cb8bd614fa8d0d6145f671466206b/lib/rake/thread_pool.rb#L95-L109 | train |
ruby/rake | lib/rake/task_manager.rb | Rake.TaskManager.resolve_args_without_dependencies | def resolve_args_without_dependencies(args)
task_name = args.shift
if args.size == 1 && args.first.respond_to?(:to_ary)
arg_names = args.first.to_ary
else
arg_names = args
end
[task_name, arg_names, []]
end | ruby | def resolve_args_without_dependencies(args)
task_name = args.shift
if args.size == 1 && args.first.respond_to?(:to_ary)
arg_names = args.first.to_ary
else
arg_names = args
end
[task_name, arg_names, []]
end | [
"def",
"resolve_args_without_dependencies",
"(",
"args",
")",
"task_name",
"=",
"args",
".",
"shift",
"if",
"args",
".",
"size",
"==",
"1",
"&&",
"args",
".",
"first",
".",
"respond_to?",
"(",
":to_ary",
")",
"arg_names",
"=",
"args",
".",
"first",
".",
... | Resolve task arguments for a task or rule when there are no
dependencies declared.
The patterns recognized by this argument resolving function are:
task :t
task :t, [:a] | [
"Resolve",
"task",
"arguments",
"for",
"a",
"task",
"or",
"rule",
"when",
"there",
"are",
"no",
"dependencies",
"declared",
"."
] | 1c22b490ee6cb8bd614fa8d0d6145f671466206b | https://github.com/ruby/rake/blob/1c22b490ee6cb8bd614fa8d0d6145f671466206b/lib/rake/task_manager.rb#L105-L113 | train |
ruby/rake | lib/rake/task_manager.rb | Rake.TaskManager.enhance_with_matching_rule | def enhance_with_matching_rule(task_name, level=0)
fail Rake::RuleRecursionOverflowError,
"Rule Recursion Too Deep" if level >= 16
@rules.each do |pattern, args, extensions, block|
if pattern && pattern.match(task_name)
task = attempt_rule(task_name, pattern, args, extensions, bloc... | ruby | def enhance_with_matching_rule(task_name, level=0)
fail Rake::RuleRecursionOverflowError,
"Rule Recursion Too Deep" if level >= 16
@rules.each do |pattern, args, extensions, block|
if pattern && pattern.match(task_name)
task = attempt_rule(task_name, pattern, args, extensions, bloc... | [
"def",
"enhance_with_matching_rule",
"(",
"task_name",
",",
"level",
"=",
"0",
")",
"fail",
"Rake",
"::",
"RuleRecursionOverflowError",
",",
"\"Rule Recursion Too Deep\"",
"if",
"level",
">=",
"16",
"@rules",
".",
"each",
"do",
"|",
"pattern",
",",
"args",
",",
... | If a rule can be found that matches the task name, enhance the
task with the prerequisites and actions from the rule. Set the
source attribute of the task appropriately for the rule. Return
the enhanced task or nil of no rule was found. | [
"If",
"a",
"rule",
"can",
"be",
"found",
"that",
"matches",
"the",
"task",
"name",
"enhance",
"the",
"task",
"with",
"the",
"prerequisites",
"and",
"actions",
"from",
"the",
"rule",
".",
"Set",
"the",
"source",
"attribute",
"of",
"the",
"task",
"appropriat... | 1c22b490ee6cb8bd614fa8d0d6145f671466206b | https://github.com/ruby/rake/blob/1c22b490ee6cb8bd614fa8d0d6145f671466206b/lib/rake/task_manager.rb#L145-L158 | train |
ruby/rake | lib/rake/task_manager.rb | Rake.TaskManager.find_location | def find_location
locations = caller
i = 0
while locations[i]
return locations[i + 1] if locations[i] =~ /rake\/dsl_definition.rb/
i += 1
end
nil
end | ruby | def find_location
locations = caller
i = 0
while locations[i]
return locations[i + 1] if locations[i] =~ /rake\/dsl_definition.rb/
i += 1
end
nil
end | [
"def",
"find_location",
"locations",
"=",
"caller",
"i",
"=",
"0",
"while",
"locations",
"[",
"i",
"]",
"return",
"locations",
"[",
"i",
"+",
"1",
"]",
"if",
"locations",
"[",
"i",
"]",
"=~",
"/",
"\\/",
"/",
"i",
"+=",
"1",
"end",
"nil",
"end"
] | Find the location that called into the dsl layer. | [
"Find",
"the",
"location",
"that",
"called",
"into",
"the",
"dsl",
"layer",
"."
] | 1c22b490ee6cb8bd614fa8d0d6145f671466206b | https://github.com/ruby/rake/blob/1c22b490ee6cb8bd614fa8d0d6145f671466206b/lib/rake/task_manager.rb#L241-L249 | train |
ruby/rake | lib/rake/task_manager.rb | Rake.TaskManager.attempt_rule | def attempt_rule(task_name, task_pattern, args, extensions, block, level)
sources = make_sources(task_name, task_pattern, extensions)
prereqs = sources.map { |source|
trace_rule level, "Attempting Rule #{task_name} => #{source}"
if File.exist?(source) || Rake::Task.task_defined?(source)
... | ruby | def attempt_rule(task_name, task_pattern, args, extensions, block, level)
sources = make_sources(task_name, task_pattern, extensions)
prereqs = sources.map { |source|
trace_rule level, "Attempting Rule #{task_name} => #{source}"
if File.exist?(source) || Rake::Task.task_defined?(source)
... | [
"def",
"attempt_rule",
"(",
"task_name",
",",
"task_pattern",
",",
"args",
",",
"extensions",
",",
"block",
",",
"level",
")",
"sources",
"=",
"make_sources",
"(",
"task_name",
",",
"task_pattern",
",",
"extensions",
")",
"prereqs",
"=",
"sources",
".",
"map... | Attempt to create a rule given the list of prerequisites. | [
"Attempt",
"to",
"create",
"a",
"rule",
"given",
"the",
"list",
"of",
"prerequisites",
"."
] | 1c22b490ee6cb8bd614fa8d0d6145f671466206b | https://github.com/ruby/rake/blob/1c22b490ee6cb8bd614fa8d0d6145f671466206b/lib/rake/task_manager.rb#L264-L282 | train |
ruby/rake | lib/rake/file_task.rb | Rake.FileTask.out_of_date? | def out_of_date?(stamp)
all_prerequisite_tasks.any? { |prereq|
prereq_task = application[prereq, @scope]
if prereq_task.instance_of?(Rake::FileTask)
prereq_task.timestamp > stamp || @application.options.build_all
else
prereq_task.timestamp > stamp
end
}
... | ruby | def out_of_date?(stamp)
all_prerequisite_tasks.any? { |prereq|
prereq_task = application[prereq, @scope]
if prereq_task.instance_of?(Rake::FileTask)
prereq_task.timestamp > stamp || @application.options.build_all
else
prereq_task.timestamp > stamp
end
}
... | [
"def",
"out_of_date?",
"(",
"stamp",
")",
"all_prerequisite_tasks",
".",
"any?",
"{",
"|",
"prereq",
"|",
"prereq_task",
"=",
"application",
"[",
"prereq",
",",
"@scope",
"]",
"if",
"prereq_task",
".",
"instance_of?",
"(",
"Rake",
"::",
"FileTask",
")",
"pre... | Are there any prerequisites with a later time than the given time stamp? | [
"Are",
"there",
"any",
"prerequisites",
"with",
"a",
"later",
"time",
"than",
"the",
"given",
"time",
"stamp?"
] | 1c22b490ee6cb8bd614fa8d0d6145f671466206b | https://github.com/ruby/rake/blob/1c22b490ee6cb8bd614fa8d0d6145f671466206b/lib/rake/file_task.rb#L32-L41 | train |
ruby/rake | lib/rake/task_arguments.rb | Rake.TaskArguments.new_scope | def new_scope(names)
values = names.map { |n| self[n] }
self.class.new(names, values + extras, self)
end | ruby | def new_scope(names)
values = names.map { |n| self[n] }
self.class.new(names, values + extras, self)
end | [
"def",
"new_scope",
"(",
"names",
")",
"values",
"=",
"names",
".",
"map",
"{",
"|",
"n",
"|",
"self",
"[",
"n",
"]",
"}",
"self",
".",
"class",
".",
"new",
"(",
"names",
",",
"values",
"+",
"extras",
",",
"self",
")",
"end"
] | Create a new argument scope using the prerequisite argument
names. | [
"Create",
"a",
"new",
"argument",
"scope",
"using",
"the",
"prerequisite",
"argument",
"names",
"."
] | 1c22b490ee6cb8bd614fa8d0d6145f671466206b | https://github.com/ruby/rake/blob/1c22b490ee6cb8bd614fa8d0d6145f671466206b/lib/rake/task_arguments.rb#L38-L41 | train |
ruby/rake | lib/rake/promise.rb | Rake.Promise.work | def work
stat :attempting_lock_on, item_id: object_id
if @mutex.try_lock
stat :has_lock_on, item_id: object_id
chore
stat :releasing_lock_on, item_id: object_id
@mutex.unlock
else
stat :bailed_on, item_id: object_id
end
end | ruby | def work
stat :attempting_lock_on, item_id: object_id
if @mutex.try_lock
stat :has_lock_on, item_id: object_id
chore
stat :releasing_lock_on, item_id: object_id
@mutex.unlock
else
stat :bailed_on, item_id: object_id
end
end | [
"def",
"work",
"stat",
":attempting_lock_on",
",",
"item_id",
":",
"object_id",
"if",
"@mutex",
".",
"try_lock",
"stat",
":has_lock_on",
",",
"item_id",
":",
"object_id",
"chore",
"stat",
":releasing_lock_on",
",",
"item_id",
":",
"object_id",
"@mutex",
".",
"un... | If no one else is working this promise, go ahead and do the chore. | [
"If",
"no",
"one",
"else",
"is",
"working",
"this",
"promise",
"go",
"ahead",
"and",
"do",
"the",
"chore",
"."
] | 1c22b490ee6cb8bd614fa8d0d6145f671466206b | https://github.com/ruby/rake/blob/1c22b490ee6cb8bd614fa8d0d6145f671466206b/lib/rake/promise.rb#L42-L52 | train |
cloudfoundry/bosh | src/bosh_common/lib/common/retryable.rb | Bosh.Retryable.retryer | def retryer(&blk)
loop do
@try_count += 1
y = blk.call(@try_count, @retry_exception)
@retry_exception = nil # no exception was raised in the block
return y if y
raise Bosh::Common::RetryCountExceeded if @try_count >= @retry_limit
wait
end
rescue Exception ... | ruby | def retryer(&blk)
loop do
@try_count += 1
y = blk.call(@try_count, @retry_exception)
@retry_exception = nil # no exception was raised in the block
return y if y
raise Bosh::Common::RetryCountExceeded if @try_count >= @retry_limit
wait
end
rescue Exception ... | [
"def",
"retryer",
"(",
"&",
"blk",
")",
"loop",
"do",
"@try_count",
"+=",
"1",
"y",
"=",
"blk",
".",
"call",
"(",
"@try_count",
",",
"@retry_exception",
")",
"@retry_exception",
"=",
"nil",
"# no exception was raised in the block",
"return",
"y",
"if",
"y",
... | Loops until the block returns a true value | [
"Loops",
"until",
"the",
"block",
"returns",
"a",
"true",
"value"
] | 2eaa7100879ddd20cd909cd698514746195e28b7 | https://github.com/cloudfoundry/bosh/blob/2eaa7100879ddd20cd909cd698514746195e28b7/src/bosh_common/lib/common/retryable.rb#L25-L44 | train |
cloudfoundry/bosh | src/bosh-director/lib/bosh/director/dns/power_dns_manager.rb | Bosh::Director.PowerDnsManager.flush_dns_cache | def flush_dns_cache
if @flush_command && !@flush_command.empty?
stdout, stderr, status = Open3.capture3(@flush_command)
if status == 0
@logger.debug("Flushed #{stdout.chomp} records from DNS cache")
else
@logger.warn("Failed to flush DNS cache: #{stderr.chomp}")
... | ruby | def flush_dns_cache
if @flush_command && !@flush_command.empty?
stdout, stderr, status = Open3.capture3(@flush_command)
if status == 0
@logger.debug("Flushed #{stdout.chomp} records from DNS cache")
else
@logger.warn("Failed to flush DNS cache: #{stderr.chomp}")
... | [
"def",
"flush_dns_cache",
"if",
"@flush_command",
"&&",
"!",
"@flush_command",
".",
"empty?",
"stdout",
",",
"stderr",
",",
"status",
"=",
"Open3",
".",
"capture3",
"(",
"@flush_command",
")",
"if",
"status",
"==",
"0",
"@logger",
".",
"debug",
"(",
"\"Flush... | Purge cached DNS records | [
"Purge",
"cached",
"DNS",
"records"
] | 2eaa7100879ddd20cd909cd698514746195e28b7 | https://github.com/cloudfoundry/bosh/blob/2eaa7100879ddd20cd909cd698514746195e28b7/src/bosh-director/lib/bosh/director/dns/power_dns_manager.rb#L101-L110 | train |
cloudfoundry/bosh | src/spec/support/director.rb | Bosh::Spec.Director.instance | def instance(instance_group_name, index_or_id, options = { deployment_name: Deployments::DEFAULT_DEPLOYMENT_NAME })
find_instance(instances(options), instance_group_name, index_or_id)
end | ruby | def instance(instance_group_name, index_or_id, options = { deployment_name: Deployments::DEFAULT_DEPLOYMENT_NAME })
find_instance(instances(options), instance_group_name, index_or_id)
end | [
"def",
"instance",
"(",
"instance_group_name",
",",
"index_or_id",
",",
"options",
"=",
"{",
"deployment_name",
":",
"Deployments",
"::",
"DEFAULT_DEPLOYMENT_NAME",
"}",
")",
"find_instance",
"(",
"instances",
"(",
"options",
")",
",",
"instance_group_name",
",",
... | vm always returns a vm | [
"vm",
"always",
"returns",
"a",
"vm"
] | 2eaa7100879ddd20cd909cd698514746195e28b7 | https://github.com/cloudfoundry/bosh/blob/2eaa7100879ddd20cd909cd698514746195e28b7/src/spec/support/director.rb#L61-L63 | train |
cloudfoundry/bosh | src/bosh-monitor/lib/bosh/monitor/deployment.rb | Bosh::Monitor.Deployment.upsert_agent | def upsert_agent(instance)
@logger.info("Adding agent #{instance.agent_id} (#{instance.job}/#{instance.id}) to #{name}...")
agent_id = instance.agent_id
if agent_id.nil?
@logger.warn("No agent id for instance #{instance.job}/#{instance.id} in deployment #{name}")
#count agents for in... | ruby | def upsert_agent(instance)
@logger.info("Adding agent #{instance.agent_id} (#{instance.job}/#{instance.id}) to #{name}...")
agent_id = instance.agent_id
if agent_id.nil?
@logger.warn("No agent id for instance #{instance.job}/#{instance.id} in deployment #{name}")
#count agents for in... | [
"def",
"upsert_agent",
"(",
"instance",
")",
"@logger",
".",
"info",
"(",
"\"Adding agent #{instance.agent_id} (#{instance.job}/#{instance.id}) to #{name}...\"",
")",
"agent_id",
"=",
"instance",
".",
"agent_id",
"if",
"agent_id",
".",
"nil?",
"@logger",
".",
"warn",
"(... | Processes VM data from BOSH Director,
extracts relevant agent data, wraps it into Agent object
and adds it to a list of managed agents. | [
"Processes",
"VM",
"data",
"from",
"BOSH",
"Director",
"extracts",
"relevant",
"agent",
"data",
"wraps",
"it",
"into",
"Agent",
"object",
"and",
"adds",
"it",
"to",
"a",
"list",
"of",
"managed",
"agents",
"."
] | 2eaa7100879ddd20cd909cd698514746195e28b7 | https://github.com/cloudfoundry/bosh/blob/2eaa7100879ddd20cd909cd698514746195e28b7/src/bosh-monitor/lib/bosh/monitor/deployment.rb#L63-L96 | train |
cloudfoundry/bosh | src/bosh-director/lib/bosh/director/nats_rpc.rb | Bosh::Director.NatsRpc.subscribe_inbox | def subscribe_inbox
# double-check locking to reduce synchronization
if @subject_id.nil?
# nats lazy-load needs to be outside the synchronized block
client = nats
@lock.synchronize do
if @subject_id.nil?
@subject_id = client.subscribe("#{@inbox_name}.>") do |mes... | ruby | def subscribe_inbox
# double-check locking to reduce synchronization
if @subject_id.nil?
# nats lazy-load needs to be outside the synchronized block
client = nats
@lock.synchronize do
if @subject_id.nil?
@subject_id = client.subscribe("#{@inbox_name}.>") do |mes... | [
"def",
"subscribe_inbox",
"# double-check locking to reduce synchronization",
"if",
"@subject_id",
".",
"nil?",
"# nats lazy-load needs to be outside the synchronized block",
"client",
"=",
"nats",
"@lock",
".",
"synchronize",
"do",
"if",
"@subject_id",
".",
"nil?",
"@subject_i... | subscribe to an inbox, if not already subscribed | [
"subscribe",
"to",
"an",
"inbox",
"if",
"not",
"already",
"subscribed"
] | 2eaa7100879ddd20cd909cd698514746195e28b7 | https://github.com/cloudfoundry/bosh/blob/2eaa7100879ddd20cd909cd698514746195e28b7/src/bosh-director/lib/bosh/director/nats_rpc.rb#L114-L128 | train |
cloudfoundry/bosh | src/bosh-director/lib/bosh/director/compiled_package_requirement.rb | Bosh::Director.CompiledPackageRequirement.dependency_spec | def dependency_spec
spec = {}
@dependencies.each do |dependency|
unless dependency.compiled?
raise DirectorError,
'Cannot generate package dependency spec ' \
"for '#{@package.name}', " \
"'#{dependency.package.name}' hasn't been compiled ye... | ruby | def dependency_spec
spec = {}
@dependencies.each do |dependency|
unless dependency.compiled?
raise DirectorError,
'Cannot generate package dependency spec ' \
"for '#{@package.name}', " \
"'#{dependency.package.name}' hasn't been compiled ye... | [
"def",
"dependency_spec",
"spec",
"=",
"{",
"}",
"@dependencies",
".",
"each",
"do",
"|",
"dependency",
"|",
"unless",
"dependency",
".",
"compiled?",
"raise",
"DirectorError",
",",
"'Cannot generate package dependency spec '",
"\"for '#{@package.name}', \"",
"\"'#{depend... | This call only makes sense if all dependencies have already been compiled,
otherwise it raises an exception
@return [Hash] Hash representation of all package dependencies. Agent uses
that to download package dependencies before compiling the package on a
compilation VM. | [
"This",
"call",
"only",
"makes",
"sense",
"if",
"all",
"dependencies",
"have",
"already",
"been",
"compiled",
"otherwise",
"it",
"raises",
"an",
"exception"
] | 2eaa7100879ddd20cd909cd698514746195e28b7 | https://github.com/cloudfoundry/bosh/blob/2eaa7100879ddd20cd909cd698514746195e28b7/src/bosh-director/lib/bosh/director/compiled_package_requirement.rb#L107-L129 | train |
cloudfoundry/bosh | src/bosh-director/lib/bosh/director/agent_client.rb | Bosh::Director.AgentClient.format_exception | def format_exception(exception)
return exception.to_s unless exception.is_a?(Hash)
msg = exception['message'].to_s
if exception['backtrace']
msg += "\n"
msg += Array(exception['backtrace']).join("\n")
end
if exception['blobstore_id']
blob = download_and_delete_bl... | ruby | def format_exception(exception)
return exception.to_s unless exception.is_a?(Hash)
msg = exception['message'].to_s
if exception['backtrace']
msg += "\n"
msg += Array(exception['backtrace']).join("\n")
end
if exception['blobstore_id']
blob = download_and_delete_bl... | [
"def",
"format_exception",
"(",
"exception",
")",
"return",
"exception",
".",
"to_s",
"unless",
"exception",
".",
"is_a?",
"(",
"Hash",
")",
"msg",
"=",
"exception",
"[",
"'message'",
"]",
".",
"to_s",
"if",
"exception",
"[",
"'backtrace'",
"]",
"msg",
"+=... | Returns formatted exception information
@param [Hash|#to_s] exception Serialized exception
@return [String] | [
"Returns",
"formatted",
"exception",
"information"
] | 2eaa7100879ddd20cd909cd698514746195e28b7 | https://github.com/cloudfoundry/bosh/blob/2eaa7100879ddd20cd909cd698514746195e28b7/src/bosh-director/lib/bosh/director/agent_client.rb#L287-L304 | train |
cloudfoundry/bosh | src/bosh-director/lib/bosh/director/agent_client.rb | Bosh::Director.AgentClient.inject_compile_log | def inject_compile_log(response)
if response['value'] && response['value'].is_a?(Hash) &&
response['value']['result'].is_a?(Hash) &&
blob_id = response['value']['result']['compile_log_id']
compile_log = download_and_delete_blob(blob_id)
response['value']['result']['compile_log'] = ... | ruby | def inject_compile_log(response)
if response['value'] && response['value'].is_a?(Hash) &&
response['value']['result'].is_a?(Hash) &&
blob_id = response['value']['result']['compile_log_id']
compile_log = download_and_delete_blob(blob_id)
response['value']['result']['compile_log'] = ... | [
"def",
"inject_compile_log",
"(",
"response",
")",
"if",
"response",
"[",
"'value'",
"]",
"&&",
"response",
"[",
"'value'",
"]",
".",
"is_a?",
"(",
"Hash",
")",
"&&",
"response",
"[",
"'value'",
"]",
"[",
"'result'",
"]",
".",
"is_a?",
"(",
"Hash",
")"... | the blob is removed from the blobstore once we have fetched it,
but if there is a crash before it is injected into the response
and then logged, there is a chance that we lose it | [
"the",
"blob",
"is",
"removed",
"from",
"the",
"blobstore",
"once",
"we",
"have",
"fetched",
"it",
"but",
"if",
"there",
"is",
"a",
"crash",
"before",
"it",
"is",
"injected",
"into",
"the",
"response",
"and",
"then",
"logged",
"there",
"is",
"a",
"chance... | 2eaa7100879ddd20cd909cd698514746195e28b7 | https://github.com/cloudfoundry/bosh/blob/2eaa7100879ddd20cd909cd698514746195e28b7/src/bosh-director/lib/bosh/director/agent_client.rb#L311-L318 | train |
cloudfoundry/bosh | src/bosh-director/lib/bosh/director/download_helper.rb | Bosh::Director.DownloadHelper.download_remote_file | def download_remote_file(resource, remote_file, local_file, num_redirects = 0)
@logger.info("Downloading remote #{resource} from #{remote_file}") if @logger
uri = URI.parse(remote_file)
req = Net::HTTP::Get.new(uri)
if uri.user && uri.password
req.basic_auth uri.user, uri.password
... | ruby | def download_remote_file(resource, remote_file, local_file, num_redirects = 0)
@logger.info("Downloading remote #{resource} from #{remote_file}") if @logger
uri = URI.parse(remote_file)
req = Net::HTTP::Get.new(uri)
if uri.user && uri.password
req.basic_auth uri.user, uri.password
... | [
"def",
"download_remote_file",
"(",
"resource",
",",
"remote_file",
",",
"local_file",
",",
"num_redirects",
"=",
"0",
")",
"@logger",
".",
"info",
"(",
"\"Downloading remote #{resource} from #{remote_file}\"",
")",
"if",
"@logger",
"uri",
"=",
"URI",
".",
"parse",
... | Downloads a remote file
@param [String] resource Resource name to be logged
@param [String] remote_file Remote file to download
@param [String] local_file Local file to store the downloaded file
@raise [Bosh::Director::ResourceNotFound] If remote file is not found
@raise [Bosh::Director::ResourceError] If there's ... | [
"Downloads",
"a",
"remote",
"file"
] | 2eaa7100879ddd20cd909cd698514746195e28b7 | https://github.com/cloudfoundry/bosh/blob/2eaa7100879ddd20cd909cd698514746195e28b7/src/bosh-director/lib/bosh/director/download_helper.rb#L13-L55 | train |
cloudfoundry/bosh | src/bosh-registry/lib/bosh/registry/instance_manager.rb | Bosh::Registry.InstanceManager.update_settings | def update_settings(instance_id, settings)
params = {
:instance_id => instance_id
}
instance = Models::RegistryInstance[params] || Models::RegistryInstance.new(params)
instance.settings = settings
instance.save
end | ruby | def update_settings(instance_id, settings)
params = {
:instance_id => instance_id
}
instance = Models::RegistryInstance[params] || Models::RegistryInstance.new(params)
instance.settings = settings
instance.save
end | [
"def",
"update_settings",
"(",
"instance_id",
",",
"settings",
")",
"params",
"=",
"{",
":instance_id",
"=>",
"instance_id",
"}",
"instance",
"=",
"Models",
"::",
"RegistryInstance",
"[",
"params",
"]",
"||",
"Models",
"::",
"RegistryInstance",
".",
"new",
"("... | Updates instance settings
@param [String] instance_id instance id (instance record
will be created in DB if it doesn't already exist)
@param [String] settings New settings for the instance | [
"Updates",
"instance",
"settings"
] | 2eaa7100879ddd20cd909cd698514746195e28b7 | https://github.com/cloudfoundry/bosh/blob/2eaa7100879ddd20cd909cd698514746195e28b7/src/bosh-registry/lib/bosh/registry/instance_manager.rb#L10-L18 | train |
cloudfoundry/bosh | src/bosh-registry/lib/bosh/registry/instance_manager.rb | Bosh::Registry.InstanceManager.read_settings | def read_settings(instance_id, remote_ip = nil)
check_instance_ips(remote_ip, instance_id) if remote_ip
get_instance(instance_id).settings
end | ruby | def read_settings(instance_id, remote_ip = nil)
check_instance_ips(remote_ip, instance_id) if remote_ip
get_instance(instance_id).settings
end | [
"def",
"read_settings",
"(",
"instance_id",
",",
"remote_ip",
"=",
"nil",
")",
"check_instance_ips",
"(",
"remote_ip",
",",
"instance_id",
")",
"if",
"remote_ip",
"get_instance",
"(",
"instance_id",
")",
".",
"settings",
"end"
] | Reads instance settings
@param [String] instance_id instance id
@param [optional, String] remote_ip If this IP is provided,
check will be performed to see if it instance id
actually has this IP address according to the IaaS. | [
"Reads",
"instance",
"settings"
] | 2eaa7100879ddd20cd909cd698514746195e28b7 | https://github.com/cloudfoundry/bosh/blob/2eaa7100879ddd20cd909cd698514746195e28b7/src/bosh-registry/lib/bosh/registry/instance_manager.rb#L26-L30 | train |
cloudfoundry/bosh | src/bosh-director/lib/bosh/director/links/links_manager.rb | Bosh::Director::Links.LinksManager.find_or_create_provider_intent | def find_or_create_provider_intent(link_provider:, link_original_name:, link_type:)
intent = Bosh::Director::Models::Links::LinkProviderIntent.find(
link_provider: link_provider,
original_name: link_original_name,
)
if intent.nil?
intent = Bosh::Director::Models::Links::LinkPr... | ruby | def find_or_create_provider_intent(link_provider:, link_original_name:, link_type:)
intent = Bosh::Director::Models::Links::LinkProviderIntent.find(
link_provider: link_provider,
original_name: link_original_name,
)
if intent.nil?
intent = Bosh::Director::Models::Links::LinkPr... | [
"def",
"find_or_create_provider_intent",
"(",
"link_provider",
":",
",",
"link_original_name",
":",
",",
"link_type",
":",
")",
"intent",
"=",
"Bosh",
"::",
"Director",
"::",
"Models",
"::",
"Links",
"::",
"LinkProviderIntent",
".",
"find",
"(",
"link_provider",
... | Used by provider, not using alias because want to update existing provider intent when alias changes | [
"Used",
"by",
"provider",
"not",
"using",
"alias",
"because",
"want",
"to",
"update",
"existing",
"provider",
"intent",
"when",
"alias",
"changes"
] | 2eaa7100879ddd20cd909cd698514746195e28b7 | https://github.com/cloudfoundry/bosh/blob/2eaa7100879ddd20cd909cd698514746195e28b7/src/bosh-director/lib/bosh/director/links/links_manager.rb#L46-L64 | train |
cloudfoundry/bosh | src/bosh-director/lib/bosh/director/links/links_manager.rb | Bosh::Director::Links.LinksManager.consumer? | def consumer?(provider_intent, deployment_plan)
return true if provider_intent.shared
link_consumers = deployment_plan.model.link_consumers
link_consumers = link_consumers.select do |consumer|
consumer.serial_id == @serial_id
end
link_consumers.any? do |consumer|
consumer... | ruby | def consumer?(provider_intent, deployment_plan)
return true if provider_intent.shared
link_consumers = deployment_plan.model.link_consumers
link_consumers = link_consumers.select do |consumer|
consumer.serial_id == @serial_id
end
link_consumers.any? do |consumer|
consumer... | [
"def",
"consumer?",
"(",
"provider_intent",
",",
"deployment_plan",
")",
"return",
"true",
"if",
"provider_intent",
".",
"shared",
"link_consumers",
"=",
"deployment_plan",
".",
"model",
".",
"link_consumers",
"link_consumers",
"=",
"link_consumers",
".",
"select",
... | A consumer which is within the same deployment | [
"A",
"consumer",
"which",
"is",
"within",
"the",
"same",
"deployment"
] | 2eaa7100879ddd20cd909cd698514746195e28b7 | https://github.com/cloudfoundry/bosh/blob/2eaa7100879ddd20cd909cd698514746195e28b7/src/bosh-director/lib/bosh/director/links/links_manager.rb#L466-L479 | train |
cloudfoundry/bosh | src/spec/support/wait.rb | Bosh::Spec.Waiter.wait | def wait(retries_left, &blk)
blk.call
rescue Exception => e
retries_left -= 1
if retries_left > 0
sleep(0.5)
retry
else
raise
end
end | ruby | def wait(retries_left, &blk)
blk.call
rescue Exception => e
retries_left -= 1
if retries_left > 0
sleep(0.5)
retry
else
raise
end
end | [
"def",
"wait",
"(",
"retries_left",
",",
"&",
"blk",
")",
"blk",
".",
"call",
"rescue",
"Exception",
"=>",
"e",
"retries_left",
"-=",
"1",
"if",
"retries_left",
">",
"0",
"sleep",
"(",
"0.5",
")",
"retry",
"else",
"raise",
"end",
"end"
] | Do not add retries_left default value | [
"Do",
"not",
"add",
"retries_left",
"default",
"value"
] | 2eaa7100879ddd20cd909cd698514746195e28b7 | https://github.com/cloudfoundry/bosh/blob/2eaa7100879ddd20cd909cd698514746195e28b7/src/spec/support/wait.rb#L8-L18 | train |
cloudfoundry/bosh | src/bosh-director/lib/bosh/director/lock.rb | Bosh::Director.Lock.lock | def lock
acquire
@refresh_thread = Thread.new do
renew_interval = [1.0, @expiration/2].max
begin
done_refreshing = false
until @unlock || done_refreshing
@refresh_mutex.synchronize do
@refresh_signal.wait(@refresh_mutex, renew_interval)
... | ruby | def lock
acquire
@refresh_thread = Thread.new do
renew_interval = [1.0, @expiration/2].max
begin
done_refreshing = false
until @unlock || done_refreshing
@refresh_mutex.synchronize do
@refresh_signal.wait(@refresh_mutex, renew_interval)
... | [
"def",
"lock",
"acquire",
"@refresh_thread",
"=",
"Thread",
".",
"new",
"do",
"renew_interval",
"=",
"[",
"1.0",
",",
"@expiration",
"/",
"2",
"]",
".",
"max",
"begin",
"done_refreshing",
"=",
"false",
"until",
"@unlock",
"||",
"done_refreshing",
"@refresh_mut... | Creates new lock with the given name.
@param name lock name
@option opts [Number] timeout how long to wait before giving up
@option opts [Number] expiration how long to wait before expiring an old
lock
Acquire a lock.
@yield [void] optional block to do work before automatically releasing
the lock.
@return... | [
"Creates",
"new",
"lock",
"with",
"the",
"given",
"name",
"."
] | 2eaa7100879ddd20cd909cd698514746195e28b7 | https://github.com/cloudfoundry/bosh/blob/2eaa7100879ddd20cd909cd698514746195e28b7/src/bosh-director/lib/bosh/director/lock.rb#L36-L84 | train |
cloudfoundry/bosh | src/bosh-director/lib/bosh/director/lock.rb | Bosh::Director.Lock.release | def release
@refresh_mutex.synchronize {
@unlock = true
delete
@refresh_signal.signal
}
@refresh_thread.join if @refresh_thread
@event_manager.create_event(
{
user: Config.current_job.username,
action: 'release',
object_type: 'loc... | ruby | def release
@refresh_mutex.synchronize {
@unlock = true
delete
@refresh_signal.signal
}
@refresh_thread.join if @refresh_thread
@event_manager.create_event(
{
user: Config.current_job.username,
action: 'release',
object_type: 'loc... | [
"def",
"release",
"@refresh_mutex",
".",
"synchronize",
"{",
"@unlock",
"=",
"true",
"delete",
"@refresh_signal",
".",
"signal",
"}",
"@refresh_thread",
".",
"join",
"if",
"@refresh_thread",
"@event_manager",
".",
"create_event",
"(",
"{",
"user",
":",
"Config",
... | Release a lock that was not auto released by the lock method.
@return [void] | [
"Release",
"a",
"lock",
"that",
"was",
"not",
"auto",
"released",
"by",
"the",
"lock",
"method",
"."
] | 2eaa7100879ddd20cd909cd698514746195e28b7 | https://github.com/cloudfoundry/bosh/blob/2eaa7100879ddd20cd909cd698514746195e28b7/src/bosh-director/lib/bosh/director/lock.rb#L89-L110 | train |
cloudfoundry/bosh | src/bosh-director/lib/bosh/director/orphan_network_manager.rb | Bosh::Director.OrphanNetworkManager.list_orphan_networks | def list_orphan_networks
Models::Network.where(orphaned: true).map do |network|
{
'name' => network.name,
'type' => network.type,
'created_at' => network.created_at.to_s,
'orphaned_at' => network.orphaned_at.to_s,
}
end
end | ruby | def list_orphan_networks
Models::Network.where(orphaned: true).map do |network|
{
'name' => network.name,
'type' => network.type,
'created_at' => network.created_at.to_s,
'orphaned_at' => network.orphaned_at.to_s,
}
end
end | [
"def",
"list_orphan_networks",
"Models",
"::",
"Network",
".",
"where",
"(",
"orphaned",
":",
"true",
")",
".",
"map",
"do",
"|",
"network",
"|",
"{",
"'name'",
"=>",
"network",
".",
"name",
",",
"'type'",
"=>",
"network",
".",
"type",
",",
"'created_at'... | returns a list of orphaned networks | [
"returns",
"a",
"list",
"of",
"orphaned",
"networks"
] | 2eaa7100879ddd20cd909cd698514746195e28b7 | https://github.com/cloudfoundry/bosh/blob/2eaa7100879ddd20cd909cd698514746195e28b7/src/bosh-director/lib/bosh/director/orphan_network_manager.rb#L38-L47 | train |
cloudfoundry/bosh | src/bosh-director/lib/bosh/director/job_runner.rb | Bosh::Director.JobRunner.perform_job | def perform_job(*args)
@task_logger.info('Creating job')
job = @job_class.new(*args)
Config.current_job = job
job.task_id = @task_id
job.task_checkpoint # cancelled in the queue?
run_checkpointing
@task_logger.info("Performing task: #{@task.inspect}")
@task.timestamp... | ruby | def perform_job(*args)
@task_logger.info('Creating job')
job = @job_class.new(*args)
Config.current_job = job
job.task_id = @task_id
job.task_checkpoint # cancelled in the queue?
run_checkpointing
@task_logger.info("Performing task: #{@task.inspect}")
@task.timestamp... | [
"def",
"perform_job",
"(",
"*",
"args",
")",
"@task_logger",
".",
"info",
"(",
"'Creating job'",
")",
"job",
"=",
"@job_class",
".",
"new",
"(",
"args",
")",
"Config",
".",
"current_job",
"=",
"job",
"job",
".",
"task_id",
"=",
"@task_id",
"job",
".",
... | Instantiates and performs director job.
@param [Array] args Opaque list of job arguments that will be used to
instantiate the new job object.
@return [void] | [
"Instantiates",
"and",
"performs",
"director",
"job",
"."
] | 2eaa7100879ddd20cd909cd698514746195e28b7 | https://github.com/cloudfoundry/bosh/blob/2eaa7100879ddd20cd909cd698514746195e28b7/src/bosh-director/lib/bosh/director/job_runner.rb#L81-L112 | train |
cloudfoundry/bosh | src/bosh-director/lib/bosh/director/job_runner.rb | Bosh::Director.JobRunner.run_checkpointing | def run_checkpointing
# task check pointer is scoped to separate class to avoid
# the secondary thread and main thread modifying the same @task
# variable (and accidentally clobbering it in the process)
task_checkpointer = TaskCheckPointer.new(@task.id)
Thread.new do
with_thread_na... | ruby | def run_checkpointing
# task check pointer is scoped to separate class to avoid
# the secondary thread and main thread modifying the same @task
# variable (and accidentally clobbering it in the process)
task_checkpointer = TaskCheckPointer.new(@task.id)
Thread.new do
with_thread_na... | [
"def",
"run_checkpointing",
"# task check pointer is scoped to separate class to avoid",
"# the secondary thread and main thread modifying the same @task",
"# variable (and accidentally clobbering it in the process)",
"task_checkpointer",
"=",
"TaskCheckPointer",
".",
"new",
"(",
"@task",
".... | Spawns a thread that periodically updates task checkpoint time.
There is no need to kill this thread as job execution lifetime is the
same as worker process lifetime.
@return [Thread] Checkpoint thread | [
"Spawns",
"a",
"thread",
"that",
"periodically",
"updates",
"task",
"checkpoint",
"time",
".",
"There",
"is",
"no",
"need",
"to",
"kill",
"this",
"thread",
"as",
"job",
"execution",
"lifetime",
"is",
"the",
"same",
"as",
"worker",
"process",
"lifetime",
"."
... | 2eaa7100879ddd20cd909cd698514746195e28b7 | https://github.com/cloudfoundry/bosh/blob/2eaa7100879ddd20cd909cd698514746195e28b7/src/bosh-director/lib/bosh/director/job_runner.rb#L118-L131 | train |
cloudfoundry/bosh | src/bosh-director/lib/bosh/director/job_runner.rb | Bosh::Director.JobRunner.truncate | def truncate(string, len = 128)
stripped = string.strip[0..len]
if stripped.length > len
stripped.gsub(/\s+?(\S+)?$/, "") + "..."
else
stripped
end
end | ruby | def truncate(string, len = 128)
stripped = string.strip[0..len]
if stripped.length > len
stripped.gsub(/\s+?(\S+)?$/, "") + "..."
else
stripped
end
end | [
"def",
"truncate",
"(",
"string",
",",
"len",
"=",
"128",
")",
"stripped",
"=",
"string",
".",
"strip",
"[",
"0",
"..",
"len",
"]",
"if",
"stripped",
".",
"length",
">",
"len",
"stripped",
".",
"gsub",
"(",
"/",
"\\s",
"\\S",
"/",
",",
"\"\"",
")... | Truncates string to fit task result length
@param [String] string The original string
@param [Integer] len Desired string length
@return [String] Truncated string | [
"Truncates",
"string",
"to",
"fit",
"task",
"result",
"length"
] | 2eaa7100879ddd20cd909cd698514746195e28b7 | https://github.com/cloudfoundry/bosh/blob/2eaa7100879ddd20cd909cd698514746195e28b7/src/bosh-director/lib/bosh/director/job_runner.rb#L137-L144 | train |
cloudfoundry/bosh | src/bosh-director/lib/bosh/director/job_runner.rb | Bosh::Director.JobRunner.finish_task | def finish_task(state, result)
@task.refresh
@task.state = state
@task.result = truncate(result.to_s)
@task.timestamp = Time.now
@task.save
end | ruby | def finish_task(state, result)
@task.refresh
@task.state = state
@task.result = truncate(result.to_s)
@task.timestamp = Time.now
@task.save
end | [
"def",
"finish_task",
"(",
"state",
",",
"result",
")",
"@task",
".",
"refresh",
"@task",
".",
"state",
"=",
"state",
"@task",
".",
"result",
"=",
"truncate",
"(",
"result",
".",
"to_s",
")",
"@task",
".",
"timestamp",
"=",
"Time",
".",
"now",
"@task",... | Marks task completion
@param [Symbol] state Task completion state
@param [#to_s] result | [
"Marks",
"task",
"completion"
] | 2eaa7100879ddd20cd909cd698514746195e28b7 | https://github.com/cloudfoundry/bosh/blob/2eaa7100879ddd20cd909cd698514746195e28b7/src/bosh-director/lib/bosh/director/job_runner.rb#L149-L155 | train |
cloudfoundry/bosh | src/bosh-director/lib/bosh/director/job_runner.rb | Bosh::Director.JobRunner.log_exception | def log_exception(exception)
# Event log is being used here to propagate the error.
# It's up to event log renderer to find the error and
# signal it properly.
director_error = DirectorError.create_from_exception(exception)
Config.event_log.log_error(director_error)
end | ruby | def log_exception(exception)
# Event log is being used here to propagate the error.
# It's up to event log renderer to find the error and
# signal it properly.
director_error = DirectorError.create_from_exception(exception)
Config.event_log.log_error(director_error)
end | [
"def",
"log_exception",
"(",
"exception",
")",
"# Event log is being used here to propagate the error.",
"# It's up to event log renderer to find the error and",
"# signal it properly.",
"director_error",
"=",
"DirectorError",
".",
"create_from_exception",
"(",
"exception",
")",
"Con... | Logs the exception in the event log
@param [Exception] exception | [
"Logs",
"the",
"exception",
"in",
"the",
"event",
"log"
] | 2eaa7100879ddd20cd909cd698514746195e28b7 | https://github.com/cloudfoundry/bosh/blob/2eaa7100879ddd20cd909cd698514746195e28b7/src/bosh-director/lib/bosh/director/job_runner.rb#L159-L165 | train |
cloudfoundry/bosh | src/bosh-director/lib/bosh/director/compiled_package_requirement_generator.rb | Bosh::Director.CompiledPackageRequirementGenerator.generate! | def generate!(requirements, instance_group, job, package, stemcell)
# Our assumption here is that package dependency graph
# has no cycles: this is being enforced on release upload.
# Other than that it's a vanilla Depth-First Search (DFS).
@logger.info("Checking whether package '#{package.desc... | ruby | def generate!(requirements, instance_group, job, package, stemcell)
# Our assumption here is that package dependency graph
# has no cycles: this is being enforced on release upload.
# Other than that it's a vanilla Depth-First Search (DFS).
@logger.info("Checking whether package '#{package.desc... | [
"def",
"generate!",
"(",
"requirements",
",",
"instance_group",
",",
"job",
",",
"package",
",",
"stemcell",
")",
"# Our assumption here is that package dependency graph",
"# has no cycles: this is being enforced on release upload.",
"# Other than that it's a vanilla Depth-First Search... | The rquirements hash passed in by the caller will be populated with CompiledPackageRequirement objects | [
"The",
"rquirements",
"hash",
"passed",
"in",
"by",
"the",
"caller",
"will",
"be",
"populated",
"with",
"CompiledPackageRequirement",
"objects"
] | 2eaa7100879ddd20cd909cd698514746195e28b7 | https://github.com/cloudfoundry/bosh/blob/2eaa7100879ddd20cd909cd698514746195e28b7/src/bosh-director/lib/bosh/director/compiled_package_requirement_generator.rb#L12-L40 | train |
cloudfoundry/bosh | src/bosh-director/lib/bosh/director/deployment_plan/assembler.rb | Bosh::Director.DeploymentPlan::Assembler.bind_jobs | def bind_jobs
@deployment_plan.releases.each do |release|
release.bind_jobs
end
@deployment_plan.instance_groups.each(&:validate_package_names_do_not_collide!)
@deployment_plan.instance_groups.each(&:validate_exported_from_matches_stemcell!)
end | ruby | def bind_jobs
@deployment_plan.releases.each do |release|
release.bind_jobs
end
@deployment_plan.instance_groups.each(&:validate_package_names_do_not_collide!)
@deployment_plan.instance_groups.each(&:validate_exported_from_matches_stemcell!)
end | [
"def",
"bind_jobs",
"@deployment_plan",
".",
"releases",
".",
"each",
"do",
"|",
"release",
"|",
"release",
".",
"bind_jobs",
"end",
"@deployment_plan",
".",
"instance_groups",
".",
"each",
"(",
":validate_package_names_do_not_collide!",
")",
"@deployment_plan",
".",
... | Binds template models for each release spec in the deployment plan
@return [void] | [
"Binds",
"template",
"models",
"for",
"each",
"release",
"spec",
"in",
"the",
"deployment",
"plan"
] | 2eaa7100879ddd20cd909cd698514746195e28b7 | https://github.com/cloudfoundry/bosh/blob/2eaa7100879ddd20cd909cd698514746195e28b7/src/bosh-director/lib/bosh/director/deployment_plan/assembler.rb#L190-L197 | train |
GeorgeKaraszi/ActiveRecordExtended | lib/active_record_extended/utilities.rb | ActiveRecordExtended.Utilities.double_quote | def double_quote(value)
return if value.nil?
case value.to_s
# Ignore keys that contain double quotes or a Arel.star (*)[all columns]
# or if a table has already been explicitly declared (ex: users.id)
when "*", /((^".+"$)|(^[[:alpha:]]+\.[[:alnum:]]+))/
value
else
... | ruby | def double_quote(value)
return if value.nil?
case value.to_s
# Ignore keys that contain double quotes or a Arel.star (*)[all columns]
# or if a table has already been explicitly declared (ex: users.id)
when "*", /((^".+"$)|(^[[:alpha:]]+\.[[:alnum:]]+))/
value
else
... | [
"def",
"double_quote",
"(",
"value",
")",
"return",
"if",
"value",
".",
"nil?",
"case",
"value",
".",
"to_s",
"# Ignore keys that contain double quotes or a Arel.star (*)[all columns]",
"# or if a table has already been explicitly declared (ex: users.id)",
"when",
"\"*\"",
",",
... | Ensures the given value is properly double quoted.
This also ensures we don't have conflicts with reversed keywords.
IE: `user` is a reserved keyword in PG. But `"user"` is allowed and works the same
when used as an column/tbl alias. | [
"Ensures",
"the",
"given",
"value",
"is",
"properly",
"double",
"quoted",
".",
"This",
"also",
"ensures",
"we",
"don",
"t",
"have",
"conflicts",
"with",
"reversed",
"keywords",
"."
] | aca74eebb64b9957a2c8765bef6e43c7d5736fd8 | https://github.com/GeorgeKaraszi/ActiveRecordExtended/blob/aca74eebb64b9957a2c8765bef6e43c7d5736fd8/lib/active_record_extended/utilities.rb#L108-L119 | train |
GeorgeKaraszi/ActiveRecordExtended | lib/active_record_extended/utilities.rb | ActiveRecordExtended.Utilities.literal_key | def literal_key(key)
case key
when TrueClass then "'t'"
when FalseClass then "'f'"
when Numeric then key
else
key = key.to_s
key.start_with?("'") && key.end_with?("'") ? key : "'#{key}'"
end
end | ruby | def literal_key(key)
case key
when TrueClass then "'t'"
when FalseClass then "'f'"
when Numeric then key
else
key = key.to_s
key.start_with?("'") && key.end_with?("'") ? key : "'#{key}'"
end
end | [
"def",
"literal_key",
"(",
"key",
")",
"case",
"key",
"when",
"TrueClass",
"then",
"\"'t'\"",
"when",
"FalseClass",
"then",
"\"'f'\"",
"when",
"Numeric",
"then",
"key",
"else",
"key",
"=",
"key",
".",
"to_s",
"key",
".",
"start_with?",
"(",
"\"'\"",
")",
... | Ensures the key is properly single quoted and treated as a actual PG key reference. | [
"Ensures",
"the",
"key",
"is",
"properly",
"single",
"quoted",
"and",
"treated",
"as",
"a",
"actual",
"PG",
"key",
"reference",
"."
] | aca74eebb64b9957a2c8765bef6e43c7d5736fd8 | https://github.com/GeorgeKaraszi/ActiveRecordExtended/blob/aca74eebb64b9957a2c8765bef6e43c7d5736fd8/lib/active_record_extended/utilities.rb#L122-L131 | train |
GeorgeKaraszi/ActiveRecordExtended | lib/active_record_extended/utilities.rb | ActiveRecordExtended.Utilities.to_arel_sql | def to_arel_sql(value)
case value
when Arel::Node, Arel::Nodes::SqlLiteral, nil
value
when ActiveRecord::Relation
Arel.sql(value.spawn.to_sql)
else
Arel.sql(value.respond_to?(:to_sql) ? value.to_sql : value.to_s)
end
end | ruby | def to_arel_sql(value)
case value
when Arel::Node, Arel::Nodes::SqlLiteral, nil
value
when ActiveRecord::Relation
Arel.sql(value.spawn.to_sql)
else
Arel.sql(value.respond_to?(:to_sql) ? value.to_sql : value.to_s)
end
end | [
"def",
"to_arel_sql",
"(",
"value",
")",
"case",
"value",
"when",
"Arel",
"::",
"Node",
",",
"Arel",
"::",
"Nodes",
"::",
"SqlLiteral",
",",
"nil",
"value",
"when",
"ActiveRecord",
"::",
"Relation",
"Arel",
".",
"sql",
"(",
"value",
".",
"spawn",
".",
... | Converts a potential subquery into a compatible Arel SQL node.
Note:
We convert relations to SQL to maintain compatibility with Rails 5.[0/1].
Only Rails 5.2+ maintains bound attributes in Arel, so its better to be safe then sorry.
When we drop support for Rails 5.[0/1], we then can then drop the '.to_sql' convers... | [
"Converts",
"a",
"potential",
"subquery",
"into",
"a",
"compatible",
"Arel",
"SQL",
"node",
"."
] | aca74eebb64b9957a2c8765bef6e43c7d5736fd8 | https://github.com/GeorgeKaraszi/ActiveRecordExtended/blob/aca74eebb64b9957a2c8765bef6e43c7d5736fd8/lib/active_record_extended/utilities.rb#L140-L149 | train |
GeorgeKaraszi/ActiveRecordExtended | lib/active_record_extended/query_methods/where_chain.rb | ActiveRecordExtended.WhereChain.contains | def contains(opts, *rest)
build_where_chain(opts, rest) do |arel|
case arel
when Arel::Nodes::In, Arel::Nodes::Equality
column = left_column(arel) || column_from_association(arel)
if [:hstore, :jsonb].include?(column.type)
Arel::Nodes::ContainsHStore.new(arel.left,... | ruby | def contains(opts, *rest)
build_where_chain(opts, rest) do |arel|
case arel
when Arel::Nodes::In, Arel::Nodes::Equality
column = left_column(arel) || column_from_association(arel)
if [:hstore, :jsonb].include?(column.type)
Arel::Nodes::ContainsHStore.new(arel.left,... | [
"def",
"contains",
"(",
"opts",
",",
"*",
"rest",
")",
"build_where_chain",
"(",
"opts",
",",
"rest",
")",
"do",
"|",
"arel",
"|",
"case",
"arel",
"when",
"Arel",
"::",
"Nodes",
"::",
"In",
",",
"Arel",
"::",
"Nodes",
"::",
"Equality",
"column",
"=",... | Finds Records that contains a nested set elements
Array Column Type:
User.where.contains(tags: [1, 3])
# SELECT user.* FROM user WHERE user.tags @> {1,3}
HStore Column Type:
User.where.contains(data: { nickname: 'chainer' })
# SELECT user.* FROM user WHERE user.data @> 'nickname' => 'chainer'
JSONB Co... | [
"Finds",
"Records",
"that",
"contains",
"a",
"nested",
"set",
"elements"
] | aca74eebb64b9957a2c8765bef6e43c7d5736fd8 | https://github.com/GeorgeKaraszi/ActiveRecordExtended/blob/aca74eebb64b9957a2c8765bef6e43c7d5736fd8/lib/active_record_extended/query_methods/where_chain.rb#L46-L63 | train |
jekyll/jekyll-admin | lib/jekyll-admin/urlable.rb | JekyllAdmin.URLable.api_url | def api_url
@api_url ||= Addressable::URI.new(
:scheme => scheme, :host => host, :port => port,
:path => path_with_base("/_api", resource_path)
).normalize.to_s
end | ruby | def api_url
@api_url ||= Addressable::URI.new(
:scheme => scheme, :host => host, :port => port,
:path => path_with_base("/_api", resource_path)
).normalize.to_s
end | [
"def",
"api_url",
"@api_url",
"||=",
"Addressable",
"::",
"URI",
".",
"new",
"(",
":scheme",
"=>",
"scheme",
",",
":host",
"=>",
"host",
",",
":port",
"=>",
"port",
",",
":path",
"=>",
"path_with_base",
"(",
"\"/_api\"",
",",
"resource_path",
")",
")",
"... | Absolute URL to the API representation of this resource | [
"Absolute",
"URL",
"to",
"the",
"API",
"representation",
"of",
"this",
"resource"
] | bc053b3b93faba679e8666091c42c47970e3bb5e | https://github.com/jekyll/jekyll-admin/blob/bc053b3b93faba679e8666091c42c47970e3bb5e/lib/jekyll-admin/urlable.rb#L17-L22 | train |
jekyll/jekyll-admin | lib/jekyll-admin/apiable.rb | JekyllAdmin.APIable.to_api | def to_api(include_content: false)
output = hash_for_api
output = output.merge(url_fields)
# Include content, if requested, otherwise remove it
if include_content
output = output.merge(content_fields)
else
CONTENT_FIELDS.each { |field| output.delete(field) }
end
... | ruby | def to_api(include_content: false)
output = hash_for_api
output = output.merge(url_fields)
# Include content, if requested, otherwise remove it
if include_content
output = output.merge(content_fields)
else
CONTENT_FIELDS.each { |field| output.delete(field) }
end
... | [
"def",
"to_api",
"(",
"include_content",
":",
"false",
")",
"output",
"=",
"hash_for_api",
"output",
"=",
"output",
".",
"merge",
"(",
"url_fields",
")",
"# Include content, if requested, otherwise remove it",
"if",
"include_content",
"output",
"=",
"output",
".",
"... | Returns a hash suitable for use as an API response.
For Documents and Pages:
1. Adds the file's raw content to the `raw_content` field
2. Adds the file's raw YAML front matter to the `front_matter` field
For Static Files it addes the Base64 `encoded_content` field
Options:
include_content - if true, includes... | [
"Returns",
"a",
"hash",
"suitable",
"for",
"use",
"as",
"an",
"API",
"response",
"."
] | bc053b3b93faba679e8666091c42c47970e3bb5e | https://github.com/jekyll/jekyll-admin/blob/bc053b3b93faba679e8666091c42c47970e3bb5e/lib/jekyll-admin/apiable.rb#L24-L56 | train |
jekyll/jekyll-admin | lib/jekyll-admin/apiable.rb | JekyllAdmin.APIable.content_fields | def content_fields
output = {}
# Include file content-related fields
if is_a?(Jekyll::StaticFile)
output["encoded_content"] = encoded_content
elsif is_a?(JekyllAdmin::DataFile)
output["content"] = content
output["raw_content"] = raw_content
else
output["raw... | ruby | def content_fields
output = {}
# Include file content-related fields
if is_a?(Jekyll::StaticFile)
output["encoded_content"] = encoded_content
elsif is_a?(JekyllAdmin::DataFile)
output["content"] = content
output["raw_content"] = raw_content
else
output["raw... | [
"def",
"content_fields",
"output",
"=",
"{",
"}",
"# Include file content-related fields",
"if",
"is_a?",
"(",
"Jekyll",
"::",
"StaticFile",
")",
"output",
"[",
"\"encoded_content\"",
"]",
"=",
"encoded_content",
"elsif",
"is_a?",
"(",
"JekyllAdmin",
"::",
"DataFile... | Returns a hash of content fields for inclusion in the API output | [
"Returns",
"a",
"hash",
"of",
"content",
"fields",
"for",
"inclusion",
"in",
"the",
"API",
"output"
] | bc053b3b93faba679e8666091c42c47970e3bb5e | https://github.com/jekyll/jekyll-admin/blob/bc053b3b93faba679e8666091c42c47970e3bb5e/lib/jekyll-admin/apiable.rb#L128-L152 | train |
jekyll/jekyll-admin | lib/jekyll-admin/path_helper.rb | JekyllAdmin.PathHelper.directory_path | def directory_path
sanitized_path(
case namespace
when "collections"
File.join(collection.relative_directory, params["splat"].first)
when "data"
File.join(DataFile.data_dir, params["splat"].first)
when "drafts"
File.join("_drafts", params["splat"].firs... | ruby | def directory_path
sanitized_path(
case namespace
when "collections"
File.join(collection.relative_directory, params["splat"].first)
when "data"
File.join(DataFile.data_dir, params["splat"].first)
when "drafts"
File.join("_drafts", params["splat"].firs... | [
"def",
"directory_path",
"sanitized_path",
"(",
"case",
"namespace",
"when",
"\"collections\"",
"File",
".",
"join",
"(",
"collection",
".",
"relative_directory",
",",
"params",
"[",
"\"splat\"",
"]",
".",
"first",
")",
"when",
"\"data\"",
"File",
".",
"join",
... | Returns the path to the requested file's containing directory | [
"Returns",
"the",
"path",
"to",
"the",
"requested",
"file",
"s",
"containing",
"directory"
] | bc053b3b93faba679e8666091c42c47970e3bb5e | https://github.com/jekyll/jekyll-admin/blob/bc053b3b93faba679e8666091c42c47970e3bb5e/lib/jekyll-admin/path_helper.rb#L54-L67 | train |
jekyll/jekyll-admin | lib/jekyll-admin/file_helper.rb | JekyllAdmin.FileHelper.write_file | def write_file(path, content)
Jekyll.logger.debug "WRITING:", path
path = sanitized_path(path)
FileUtils.mkdir_p File.dirname(path)
File.open(path, "wb") do |file|
file.write(content)
end
# we should fully process in dev mode for tests to pass
if ENV["RACK_ENV"] == "pro... | ruby | def write_file(path, content)
Jekyll.logger.debug "WRITING:", path
path = sanitized_path(path)
FileUtils.mkdir_p File.dirname(path)
File.open(path, "wb") do |file|
file.write(content)
end
# we should fully process in dev mode for tests to pass
if ENV["RACK_ENV"] == "pro... | [
"def",
"write_file",
"(",
"path",
",",
"content",
")",
"Jekyll",
".",
"logger",
".",
"debug",
"\"WRITING:\"",
",",
"path",
"path",
"=",
"sanitized_path",
"(",
"path",
")",
"FileUtils",
".",
"mkdir_p",
"File",
".",
"dirname",
"(",
"path",
")",
"File",
"."... | Write a file to disk with the given content | [
"Write",
"a",
"file",
"to",
"disk",
"with",
"the",
"given",
"content"
] | bc053b3b93faba679e8666091c42c47970e3bb5e | https://github.com/jekyll/jekyll-admin/blob/bc053b3b93faba679e8666091c42c47970e3bb5e/lib/jekyll-admin/file_helper.rb#L17-L30 | train |
jekyll/jekyll-admin | lib/jekyll-admin/file_helper.rb | JekyllAdmin.FileHelper.delete_file | def delete_file(path)
Jekyll.logger.debug "DELETING:", path
FileUtils.rm_f sanitized_path(path)
site.process
end | ruby | def delete_file(path)
Jekyll.logger.debug "DELETING:", path
FileUtils.rm_f sanitized_path(path)
site.process
end | [
"def",
"delete_file",
"(",
"path",
")",
"Jekyll",
".",
"logger",
".",
"debug",
"\"DELETING:\"",
",",
"path",
"FileUtils",
".",
"rm_f",
"sanitized_path",
"(",
"path",
")",
"site",
".",
"process",
"end"
] | Delete the file at the given path | [
"Delete",
"the",
"file",
"at",
"the",
"given",
"path"
] | bc053b3b93faba679e8666091c42c47970e3bb5e | https://github.com/jekyll/jekyll-admin/blob/bc053b3b93faba679e8666091c42c47970e3bb5e/lib/jekyll-admin/file_helper.rb#L33-L37 | train |
jekyll/jekyll-admin | lib/jekyll-admin/server.rb | JekyllAdmin.Server.restored_front_matter | def restored_front_matter
front_matter.map do |key, value|
value = "null" if value.nil?
[key, value]
end.to_h
end | ruby | def restored_front_matter
front_matter.map do |key, value|
value = "null" if value.nil?
[key, value]
end.to_h
end | [
"def",
"restored_front_matter",
"front_matter",
".",
"map",
"do",
"|",
"key",
",",
"value",
"|",
"value",
"=",
"\"null\"",
"if",
"value",
".",
"nil?",
"[",
"key",
",",
"value",
"]",
"end",
".",
"to_h",
"end"
] | verbose 'null' values in front matter | [
"verbose",
"null",
"values",
"in",
"front",
"matter"
] | bc053b3b93faba679e8666091c42c47970e3bb5e | https://github.com/jekyll/jekyll-admin/blob/bc053b3b93faba679e8666091c42c47970e3bb5e/lib/jekyll-admin/server.rb#L87-L92 | train |
sds/scss-lint | lib/scss_lint/linter/single_line_per_property.rb | SCSSLint.Linter::SingleLinePerProperty.single_line_rule_set? | def single_line_rule_set?(rule)
rule.children.all? { |child| child.line == rule.source_range.end_pos.line }
end | ruby | def single_line_rule_set?(rule)
rule.children.all? { |child| child.line == rule.source_range.end_pos.line }
end | [
"def",
"single_line_rule_set?",
"(",
"rule",
")",
"rule",
".",
"children",
".",
"all?",
"{",
"|",
"child",
"|",
"child",
".",
"line",
"==",
"rule",
".",
"source_range",
".",
"end_pos",
".",
"line",
"}",
"end"
] | Return whether this rule set occupies a single line.
Note that this allows:
a,
b,
i { margin: 0; padding: 0; }
and:
p { margin: 0; padding: 0; }
In other words, the line of the opening curly brace is the line that the
rule set is considered to occupy. | [
"Return",
"whether",
"this",
"rule",
"set",
"occupies",
"a",
"single",
"line",
"."
] | e99afe4ede041a431a06e585c12ce82f6ad50116 | https://github.com/sds/scss-lint/blob/e99afe4ede041a431a06e585c12ce82f6ad50116/lib/scss_lint/linter/single_line_per_property.rb#L41-L43 | train |
sds/scss-lint | lib/scss_lint/linter/single_line_per_property.rb | SCSSLint.Linter::SingleLinePerProperty.check_adjacent_properties | def check_adjacent_properties(properties)
properties[0..-2].zip(properties[1..-1]).each do |first, second|
next unless first.line == second.line
add_lint(second, "Property '#{second.name.join}' should be placed on own line")
end
end | ruby | def check_adjacent_properties(properties)
properties[0..-2].zip(properties[1..-1]).each do |first, second|
next unless first.line == second.line
add_lint(second, "Property '#{second.name.join}' should be placed on own line")
end
end | [
"def",
"check_adjacent_properties",
"(",
"properties",
")",
"properties",
"[",
"0",
"..",
"-",
"2",
"]",
".",
"zip",
"(",
"properties",
"[",
"1",
"..",
"-",
"1",
"]",
")",
".",
"each",
"do",
"|",
"first",
",",
"second",
"|",
"next",
"unless",
"first"... | Compare each property against the next property to see if they are on
the same line.
@param properties [Array<Sass::Tree::PropNode>] | [
"Compare",
"each",
"property",
"against",
"the",
"next",
"property",
"to",
"see",
"if",
"they",
"are",
"on",
"the",
"same",
"line",
"."
] | e99afe4ede041a431a06e585c12ce82f6ad50116 | https://github.com/sds/scss-lint/blob/e99afe4ede041a431a06e585c12ce82f6ad50116/lib/scss_lint/linter/single_line_per_property.rb#L53-L59 | train |
sds/scss-lint | lib/scss_lint/control_comment_processor.rb | SCSSLint.ControlCommentProcessor.before_node_visit | def before_node_visit(node)
return unless (commands = Array(extract_commands(node))).any?
commands.each do |command|
linters = command[:linters]
next unless linters.include?('all') || linters.include?(@linter.name)
process_command(command, node)
# Is the control comment th... | ruby | def before_node_visit(node)
return unless (commands = Array(extract_commands(node))).any?
commands.each do |command|
linters = command[:linters]
next unless linters.include?('all') || linters.include?(@linter.name)
process_command(command, node)
# Is the control comment th... | [
"def",
"before_node_visit",
"(",
"node",
")",
"return",
"unless",
"(",
"commands",
"=",
"Array",
"(",
"extract_commands",
"(",
"node",
")",
")",
")",
".",
"any?",
"commands",
".",
"each",
"do",
"|",
"command",
"|",
"linters",
"=",
"command",
"[",
":linte... | Executed before a node has been visited.
@param node [Sass::Tree::Node] | [
"Executed",
"before",
"a",
"node",
"has",
"been",
"visited",
"."
] | e99afe4ede041a431a06e585c12ce82f6ad50116 | https://github.com/sds/scss-lint/blob/e99afe4ede041a431a06e585c12ce82f6ad50116/lib/scss_lint/control_comment_processor.rb#L22-L38 | train |
sds/scss-lint | lib/scss_lint/control_comment_processor.rb | SCSSLint.ControlCommentProcessor.last_child | def last_child(node)
last = node.children.inject(node) do |lowest, child|
return lowest unless child.respond_to?(:line)
lowest.line < child.line ? child : lowest
end
# In this case, none of the children have associated line numbers or the
# node has no children at all, so return... | ruby | def last_child(node)
last = node.children.inject(node) do |lowest, child|
return lowest unless child.respond_to?(:line)
lowest.line < child.line ? child : lowest
end
# In this case, none of the children have associated line numbers or the
# node has no children at all, so return... | [
"def",
"last_child",
"(",
"node",
")",
"last",
"=",
"node",
".",
"children",
".",
"inject",
"(",
"node",
")",
"do",
"|",
"lowest",
",",
"child",
"|",
"return",
"lowest",
"unless",
"child",
".",
"respond_to?",
"(",
":line",
")",
"lowest",
".",
"line",
... | Gets the child of the node that resides on the lowest line in the file.
This is necessary due to the fact that our monkey patching of the parse
tree's {#children} method does not return nodes sorted by their line
number.
Returns `nil` if node has no children or no children with associated line
numbers.
@param ... | [
"Gets",
"the",
"child",
"of",
"the",
"node",
"that",
"resides",
"on",
"the",
"lowest",
"line",
"in",
"the",
"file",
"."
] | e99afe4ede041a431a06e585c12ce82f6ad50116 | https://github.com/sds/scss-lint/blob/e99afe4ede041a431a06e585c12ce82f6ad50116/lib/scss_lint/control_comment_processor.rb#L137-L148 | train |
sds/scss-lint | lib/scss_lint/linter/qualifying_element.rb | SCSSLint.Linter::QualifyingElement.seq_contains_sel_class? | def seq_contains_sel_class?(seq, selector_class)
seq.members.any? do |simple|
simple.is_a?(selector_class)
end
end | ruby | def seq_contains_sel_class?(seq, selector_class)
seq.members.any? do |simple|
simple.is_a?(selector_class)
end
end | [
"def",
"seq_contains_sel_class?",
"(",
"seq",
",",
"selector_class",
")",
"seq",
".",
"members",
".",
"any?",
"do",
"|",
"simple",
"|",
"simple",
".",
"is_a?",
"(",
"selector_class",
")",
"end",
"end"
] | Checks if a simple sequence contains a
simple selector of a certain class.
@param seq [Sass::Selector::SimpleSequence]
@param selector_class [Sass::Selector::Simple]
@returns [Boolean] | [
"Checks",
"if",
"a",
"simple",
"sequence",
"contains",
"a",
"simple",
"selector",
"of",
"a",
"certain",
"class",
"."
] | e99afe4ede041a431a06e585c12ce82f6ad50116 | https://github.com/sds/scss-lint/blob/e99afe4ede041a431a06e585c12ce82f6ad50116/lib/scss_lint/linter/qualifying_element.rb#L21-L25 | train |
sds/scss-lint | lib/scss_lint/linter/selector_depth.rb | SCSSLint.Linter::SelectorDepth.max_sequence_depth | def max_sequence_depth(comma_sequence, current_depth)
# Sequence contains interpolation; assume a depth of 1
return current_depth + 1 unless comma_sequence
comma_sequence.members.map { |sequence| sequence_depth(sequence, current_depth) }.max
end | ruby | def max_sequence_depth(comma_sequence, current_depth)
# Sequence contains interpolation; assume a depth of 1
return current_depth + 1 unless comma_sequence
comma_sequence.members.map { |sequence| sequence_depth(sequence, current_depth) }.max
end | [
"def",
"max_sequence_depth",
"(",
"comma_sequence",
",",
"current_depth",
")",
"# Sequence contains interpolation; assume a depth of 1",
"return",
"current_depth",
"+",
"1",
"unless",
"comma_sequence",
"comma_sequence",
".",
"members",
".",
"map",
"{",
"|",
"sequence",
"|... | Find the maximum depth of all sequences in a comma sequence. | [
"Find",
"the",
"maximum",
"depth",
"of",
"all",
"sequences",
"in",
"a",
"comma",
"sequence",
"."
] | e99afe4ede041a431a06e585c12ce82f6ad50116 | https://github.com/sds/scss-lint/blob/e99afe4ede041a431a06e585c12ce82f6ad50116/lib/scss_lint/linter/selector_depth.rb#L29-L34 | train |
sds/scss-lint | lib/scss_lint/linter/indentation.rb | SCSSLint.Linter::Indentation.check_root_ruleset_indent | def check_root_ruleset_indent(node, actual_indent)
# Whether node is a ruleset not nested within any other ruleset.
if @indent == 0 && node.is_a?(Sass::Tree::RuleNode)
unless actual_indent % @indent_width == 0
add_lint(node.line, lint_message("a multiple of #{@indent_width}", actual_indent... | ruby | def check_root_ruleset_indent(node, actual_indent)
# Whether node is a ruleset not nested within any other ruleset.
if @indent == 0 && node.is_a?(Sass::Tree::RuleNode)
unless actual_indent % @indent_width == 0
add_lint(node.line, lint_message("a multiple of #{@indent_width}", actual_indent... | [
"def",
"check_root_ruleset_indent",
"(",
"node",
",",
"actual_indent",
")",
"# Whether node is a ruleset not nested within any other ruleset.",
"if",
"@indent",
"==",
"0",
"&&",
"node",
".",
"is_a?",
"(",
"Sass",
"::",
"Tree",
"::",
"RuleNode",
")",
"unless",
"actual_... | Allow rulesets to be indented any amount when the indent is zero, as long
as it's a multiple of the indent width | [
"Allow",
"rulesets",
"to",
"be",
"indented",
"any",
"amount",
"when",
"the",
"indent",
"is",
"zero",
"as",
"long",
"as",
"it",
"s",
"a",
"multiple",
"of",
"the",
"indent",
"width"
] | e99afe4ede041a431a06e585c12ce82f6ad50116 | https://github.com/sds/scss-lint/blob/e99afe4ede041a431a06e585c12ce82f6ad50116/lib/scss_lint/linter/indentation.rb#L166-L176 | train |
sds/scss-lint | lib/scss_lint/linter/indentation.rb | SCSSLint.Linter::Indentation.one_shift_greater_than_parent? | def one_shift_greater_than_parent?(node, actual_indent)
parent_indent = node_indent(node_indent_parent(node)).length
expected_indent = parent_indent + @indent_width
expected_indent == actual_indent
end | ruby | def one_shift_greater_than_parent?(node, actual_indent)
parent_indent = node_indent(node_indent_parent(node)).length
expected_indent = parent_indent + @indent_width
expected_indent == actual_indent
end | [
"def",
"one_shift_greater_than_parent?",
"(",
"node",
",",
"actual_indent",
")",
"parent_indent",
"=",
"node_indent",
"(",
"node_indent_parent",
"(",
"node",
")",
")",
".",
"length",
"expected_indent",
"=",
"parent_indent",
"+",
"@indent_width",
"expected_indent",
"==... | Returns whether node is indented exactly one indent width greater than its
parent.
@param node [Sass::Tree::Node]
@return [true,false] | [
"Returns",
"whether",
"node",
"is",
"indented",
"exactly",
"one",
"indent",
"width",
"greater",
"than",
"its",
"parent",
"."
] | e99afe4ede041a431a06e585c12ce82f6ad50116 | https://github.com/sds/scss-lint/blob/e99afe4ede041a431a06e585c12ce82f6ad50116/lib/scss_lint/linter/indentation.rb#L183-L187 | train |
sds/scss-lint | lib/scss_lint/linter/space_between_parens.rb | SCSSLint.Linter::SpaceBetweenParens.feel_for_enclosing_parens | def feel_for_enclosing_parens(node) # rubocop:disable Metrics/AbcSize, Metrics/CyclomaticComplexity
range = node.source_range
original_source = source_from_range(range)
left_offset = -1
right_offset = 0
if original_source[-1] != ')'
right_offset += 1 while character_at(range.end_p... | ruby | def feel_for_enclosing_parens(node) # rubocop:disable Metrics/AbcSize, Metrics/CyclomaticComplexity
range = node.source_range
original_source = source_from_range(range)
left_offset = -1
right_offset = 0
if original_source[-1] != ')'
right_offset += 1 while character_at(range.end_p... | [
"def",
"feel_for_enclosing_parens",
"(",
"node",
")",
"# rubocop:disable Metrics/AbcSize, Metrics/CyclomaticComplexity",
"range",
"=",
"node",
".",
"source_range",
"original_source",
"=",
"source_from_range",
"(",
"range",
")",
"left_offset",
"=",
"-",
"1",
"right_offset",
... | An expression enclosed in parens will include or not include each paren, depending
on whitespace. Here we feel out for enclosing parens, and return them as the new
source for the node. | [
"An",
"expression",
"enclosed",
"in",
"parens",
"will",
"include",
"or",
"not",
"include",
"each",
"paren",
"depending",
"on",
"whitespace",
".",
"Here",
"we",
"feel",
"out",
"for",
"enclosing",
"parens",
"and",
"return",
"them",
"as",
"the",
"new",
"source"... | e99afe4ede041a431a06e585c12ce82f6ad50116 | https://github.com/sds/scss-lint/blob/e99afe4ede041a431a06e585c12ce82f6ad50116/lib/scss_lint/linter/space_between_parens.rb#L72-L98 | train |
sds/scss-lint | lib/scss_lint/linter/empty_line_between_blocks.rb | SCSSLint.Linter::EmptyLineBetweenBlocks.check_preceding_node | def check_preceding_node(node, type)
case prev_node(node)
when
nil,
Sass::Tree::FunctionNode,
Sass::Tree::MixinNode,
Sass::Tree::MixinDefNode,
Sass::Tree::RuleNode,
Sass::Tree::CommentNode
# Ignore
nil
else
unless engine.lines[nod... | ruby | def check_preceding_node(node, type)
case prev_node(node)
when
nil,
Sass::Tree::FunctionNode,
Sass::Tree::MixinNode,
Sass::Tree::MixinDefNode,
Sass::Tree::RuleNode,
Sass::Tree::CommentNode
# Ignore
nil
else
unless engine.lines[nod... | [
"def",
"check_preceding_node",
"(",
"node",
",",
"type",
")",
"case",
"prev_node",
"(",
"node",
")",
"when",
"nil",
",",
"Sass",
"::",
"Tree",
"::",
"FunctionNode",
",",
"Sass",
"::",
"Tree",
"::",
"MixinNode",
",",
"Sass",
"::",
"Tree",
"::",
"MixinDefN... | In cases where the previous node is not a block declaration, we won't
have run any checks against it, so we need to check here if the previous
line is an empty line | [
"In",
"cases",
"where",
"the",
"previous",
"node",
"is",
"not",
"a",
"block",
"declaration",
"we",
"won",
"t",
"have",
"run",
"any",
"checks",
"against",
"it",
"so",
"we",
"need",
"to",
"check",
"here",
"if",
"the",
"previous",
"line",
"is",
"an",
"emp... | e99afe4ede041a431a06e585c12ce82f6ad50116 | https://github.com/sds/scss-lint/blob/e99afe4ede041a431a06e585c12ce82f6ad50116/lib/scss_lint/linter/empty_line_between_blocks.rb#L80-L96 | train |
sds/scss-lint | lib/scss_lint/linter/space_after_property_colon.rb | SCSSLint.Linter::SpaceAfterPropertyColon.value_offset | def value_offset(prop)
src_range = prop.name_source_range
src_range.start_pos.offset +
(src_range.end_pos.offset - src_range.start_pos.offset) +
whitespace_after_colon(prop).take_while { |w| w == ' ' }.size
end | ruby | def value_offset(prop)
src_range = prop.name_source_range
src_range.start_pos.offset +
(src_range.end_pos.offset - src_range.start_pos.offset) +
whitespace_after_colon(prop).take_while { |w| w == ' ' }.size
end | [
"def",
"value_offset",
"(",
"prop",
")",
"src_range",
"=",
"prop",
".",
"name_source_range",
"src_range",
".",
"start_pos",
".",
"offset",
"+",
"(",
"src_range",
".",
"end_pos",
".",
"offset",
"-",
"src_range",
".",
"start_pos",
".",
"offset",
")",
"+",
"w... | Offset of value for property | [
"Offset",
"of",
"value",
"for",
"property"
] | e99afe4ede041a431a06e585c12ce82f6ad50116 | https://github.com/sds/scss-lint/blob/e99afe4ede041a431a06e585c12ce82f6ad50116/lib/scss_lint/linter/space_after_property_colon.rb#L75-L80 | train |
Subsets and Splits
SQL Console for semeru/code-text-ruby
Retrieves 20,000 non-null code samples labeled as Ruby, providing a basic overview of the dataset but without deeper analysis.