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 |
|---|---|---|---|---|---|---|---|---|---|---|---|
movitto/reterm | lib/reterm/window.rb | RETerm.Window.erase | def erase
children.each { |c|
c.erase
}
@win.werase if @win
component.component.erase if cdk? && component? && component.init?
end | ruby | def erase
children.each { |c|
c.erase
}
@win.werase if @win
component.component.erase if cdk? && component? && component.init?
end | [
"def",
"erase",
"children",
".",
"each",
"{",
"|",
"c",
"|",
"c",
".",
"erase",
"}",
"@win",
".",
"werase",
"if",
"@win",
"component",
".",
"component",
".",
"erase",
"if",
"cdk?",
"&&",
"component?",
"&&",
"component",
".",
"init?",
"end"
] | Erase window drawing area | [
"Erase",
"window",
"drawing",
"area"
] | 3e78c64e677f69b22f00dc89c2b515b9188c5e15 | https://github.com/movitto/reterm/blob/3e78c64e677f69b22f00dc89c2b515b9188c5e15/lib/reterm/window.rb#L381-L389 | train |
movitto/reterm | lib/reterm/window.rb | RETerm.Window.no_border! | def no_border!
@win.border(' '.ord, ' '.ord, ' '.ord, ' '.ord, ' '.ord, ' '.ord, ' '.ord, ' '.ord)
end | ruby | def no_border!
@win.border(' '.ord, ' '.ord, ' '.ord, ' '.ord, ' '.ord, ' '.ord, ' '.ord, ' '.ord)
end | [
"def",
"no_border!",
"@win",
".",
"border",
"(",
"' '",
".",
"ord",
",",
"' '",
".",
"ord",
",",
"' '",
".",
"ord",
",",
"' '",
".",
"ord",
",",
"' '",
".",
"ord",
",",
"' '",
".",
"ord",
",",
"' '",
".",
"ord",
",",
"' '",
".",
"ord",
")",
... | Remove Border around window | [
"Remove",
"Border",
"around",
"window"
] | 3e78c64e677f69b22f00dc89c2b515b9188c5e15 | https://github.com/movitto/reterm/blob/3e78c64e677f69b22f00dc89c2b515b9188c5e15/lib/reterm/window.rb#L418-L420 | train |
movitto/reterm | lib/reterm/window.rb | RETerm.Window.sync_getch | def sync_getch
return self.getch unless sync_enabled?
c = -1
while c == -1 && !shutdown?
c = self.getch
run_sync!
end
c
end | ruby | def sync_getch
return self.getch unless sync_enabled?
c = -1
while c == -1 && !shutdown?
c = self.getch
run_sync!
end
c
end | [
"def",
"sync_getch",
"return",
"self",
".",
"getch",
"unless",
"sync_enabled?",
"c",
"=",
"-",
"1",
"while",
"c",
"==",
"-",
"1",
"&&",
"!",
"shutdown?",
"c",
"=",
"self",
".",
"getch",
"run_sync!",
"end",
"c",
"end"
] | Normal getch unless sync enabled in which case,
timeout will be checked & components synchronized | [
"Normal",
"getch",
"unless",
"sync",
"enabled",
"in",
"which",
"case",
"timeout",
"will",
"be",
"checked",
"&",
"components",
"synchronized"
] | 3e78c64e677f69b22f00dc89c2b515b9188c5e15 | https://github.com/movitto/reterm/blob/3e78c64e677f69b22f00dc89c2b515b9188c5e15/lib/reterm/window.rb#L434-L444 | train |
movitto/reterm | lib/reterm/window.rb | RETerm.Window.colors= | def colors=(c)
@colors = c.is_a?(ColorPair) ? c : ColorPair.for(c).first
@win.bkgd(Ncurses.COLOR_PAIR(@colors.id)) unless @win.nil?
component.colors = @colors if component?
children.each { |ch|
ch.colors = c
}
end | ruby | def colors=(c)
@colors = c.is_a?(ColorPair) ? c : ColorPair.for(c).first
@win.bkgd(Ncurses.COLOR_PAIR(@colors.id)) unless @win.nil?
component.colors = @colors if component?
children.each { |ch|
ch.colors = c
}
end | [
"def",
"colors",
"=",
"(",
"c",
")",
"@colors",
"=",
"c",
".",
"is_a?",
"(",
"ColorPair",
")",
"?",
"c",
":",
"ColorPair",
".",
"for",
"(",
"c",
")",
".",
"first",
"@win",
".",
"bkgd",
"(",
"Ncurses",
".",
"COLOR_PAIR",
"(",
"@colors",
".",
"id",... | Set window color | [
"Set",
"window",
"color"
] | 3e78c64e677f69b22f00dc89c2b515b9188c5e15 | https://github.com/movitto/reterm/blob/3e78c64e677f69b22f00dc89c2b515b9188c5e15/lib/reterm/window.rb#L493-L502 | train |
movitto/reterm | lib/reterm/window.rb | RETerm.Window.dimensions | def dimensions
rows = []
cols = []
@win.getmaxyx(rows, cols)
rows = rows.first
cols = cols.first
[rows, cols]
end | ruby | def dimensions
rows = []
cols = []
@win.getmaxyx(rows, cols)
rows = rows.first
cols = cols.first
[rows, cols]
end | [
"def",
"dimensions",
"rows",
"=",
"[",
"]",
"cols",
"=",
"[",
"]",
"@win",
".",
"getmaxyx",
"(",
"rows",
",",
"cols",
")",
"rows",
"=",
"rows",
".",
"first",
"cols",
"=",
"cols",
".",
"first",
"[",
"rows",
",",
"cols",
"]",
"end"
] | Return window dimensions as an array containing rows & cols | [
"Return",
"window",
"dimensions",
"as",
"an",
"array",
"containing",
"rows",
"&",
"cols"
] | 3e78c64e677f69b22f00dc89c2b515b9188c5e15 | https://github.com/movitto/reterm/blob/3e78c64e677f69b22f00dc89c2b515b9188c5e15/lib/reterm/window.rb#L505-L512 | train |
chef-workflow/chef-workflow | lib/chef-workflow/support/ip.rb | ChefWorkflow.IPSupport.next_ip | def next_ip(arg)
octets = arg.split(/\./, 4).map(&:to_i)
octets[3] += 1
raise "out of ips!" if octets[3] > 255
return octets.map(&:to_s).join(".")
end | ruby | def next_ip(arg)
octets = arg.split(/\./, 4).map(&:to_i)
octets[3] += 1
raise "out of ips!" if octets[3] > 255
return octets.map(&:to_s).join(".")
end | [
"def",
"next_ip",
"(",
"arg",
")",
"octets",
"=",
"arg",
".",
"split",
"(",
"/",
"\\.",
"/",
",",
"4",
")",
".",
"map",
"(",
"&",
":to_i",
")",
"octets",
"[",
"3",
"]",
"+=",
"1",
"raise",
"\"out of ips!\"",
"if",
"octets",
"[",
"3",
"]",
">",
... | Gets the next unallocated IP, given an IP to start with. | [
"Gets",
"the",
"next",
"unallocated",
"IP",
"given",
"an",
"IP",
"to",
"start",
"with",
"."
] | 956c8f6cd694dacc25dfa405d70b05b12b7c1691 | https://github.com/chef-workflow/chef-workflow/blob/956c8f6cd694dacc25dfa405d70b05b12b7c1691/lib/chef-workflow/support/ip.rb#L44-L49 | train |
devp/sanitize_attributes | lib/sanitize_attributes/instance_methods.rb | SanitizeAttributes.InstanceMethods.sanitize! | def sanitize!
self.class.sanitizable_attributes.each do |attr_name|
cleaned_text = process_text_via_sanitization_method(self.send(attr_name), attr_name)
self.send((attr_name.to_s + '='), cleaned_text)
end
end | ruby | def sanitize!
self.class.sanitizable_attributes.each do |attr_name|
cleaned_text = process_text_via_sanitization_method(self.send(attr_name), attr_name)
self.send((attr_name.to_s + '='), cleaned_text)
end
end | [
"def",
"sanitize!",
"self",
".",
"class",
".",
"sanitizable_attributes",
".",
"each",
"do",
"|",
"attr_name",
"|",
"cleaned_text",
"=",
"process_text_via_sanitization_method",
"(",
"self",
".",
"send",
"(",
"attr_name",
")",
",",
"attr_name",
")",
"self",
".",
... | sanitize! is the method that is called when a model is saved.
It can be called to manually sanitize attributes. | [
"sanitize!",
"is",
"the",
"method",
"that",
"is",
"called",
"when",
"a",
"model",
"is",
"saved",
".",
"It",
"can",
"be",
"called",
"to",
"manually",
"sanitize",
"attributes",
"."
] | 75f482b58d0b82a84b70658dd752d4c5b6ea9f02 | https://github.com/devp/sanitize_attributes/blob/75f482b58d0b82a84b70658dd752d4c5b6ea9f02/lib/sanitize_attributes/instance_methods.rb#L6-L11 | train |
kevgo/active_cucumber | lib/active_cucumber/creator.rb | ActiveCucumber.Creator.factorygirl_attributes | def factorygirl_attributes
symbolize_attributes!
@attributes.each do |key, value|
next unless respond_to?(method = method_name(key))
if (result = send method, value) || value.nil?
@attributes[key] = result if @attributes.key? key
else
@attributes.delete key
... | ruby | def factorygirl_attributes
symbolize_attributes!
@attributes.each do |key, value|
next unless respond_to?(method = method_name(key))
if (result = send method, value) || value.nil?
@attributes[key] = result if @attributes.key? key
else
@attributes.delete key
... | [
"def",
"factorygirl_attributes",
"symbolize_attributes!",
"@attributes",
".",
"each",
"do",
"|",
"key",
",",
"value",
"|",
"next",
"unless",
"respond_to?",
"(",
"method",
"=",
"method_name",
"(",
"key",
")",
")",
"if",
"(",
"result",
"=",
"send",
"method",
"... | Returns the FactoryGirl version of this Creator's attributes | [
"Returns",
"the",
"FactoryGirl",
"version",
"of",
"this",
"Creator",
"s",
"attributes"
] | 9f3609abbfe2c4c3534c2c64d2f638a6bb6347cf | https://github.com/kevgo/active_cucumber/blob/9f3609abbfe2c4c3534c2c64d2f638a6bb6347cf/lib/active_cucumber/creator.rb#L18-L28 | train |
jhass/configurate | lib/configurate/lookup_chain.rb | Configurate.LookupChain.add_provider | def add_provider(provider, *args)
unless provider.respond_to?(:instance_methods) && provider.instance_methods.include?(:lookup)
raise ArgumentError, "the given provider does not respond to lookup"
end
@provider << provider.new(*args)
end | ruby | def add_provider(provider, *args)
unless provider.respond_to?(:instance_methods) && provider.instance_methods.include?(:lookup)
raise ArgumentError, "the given provider does not respond to lookup"
end
@provider << provider.new(*args)
end | [
"def",
"add_provider",
"(",
"provider",
",",
"*",
"args",
")",
"unless",
"provider",
".",
"respond_to?",
"(",
":instance_methods",
")",
"&&",
"provider",
".",
"instance_methods",
".",
"include?",
"(",
":lookup",
")",
"raise",
"ArgumentError",
",",
"\"the given p... | Adds a provider to the chain. Providers are tried in the order
they are added, so the order is important.
@param provider [#lookup]
@param *args the arguments passed to the providers constructor
@raise [ArgumentError] if an invalid provider is given
@return [void] | [
"Adds",
"a",
"provider",
"to",
"the",
"chain",
".",
"Providers",
"are",
"tried",
"in",
"the",
"order",
"they",
"are",
"added",
"so",
"the",
"order",
"is",
"important",
"."
] | ace8ef4705d81d4623a144db289051c16da58978 | https://github.com/jhass/configurate/blob/ace8ef4705d81d4623a144db289051c16da58978/lib/configurate/lookup_chain.rb#L16-L22 | train |
jhass/configurate | lib/configurate/lookup_chain.rb | Configurate.LookupChain.lookup | def lookup(setting, *args)
setting = SettingPath.new setting if setting.is_a? String
@provider.each do |provider|
begin
return special_value_or_string(provider.lookup(setting.clone, *args))
rescue SettingNotFoundError; end
end
nil
end | ruby | def lookup(setting, *args)
setting = SettingPath.new setting if setting.is_a? String
@provider.each do |provider|
begin
return special_value_or_string(provider.lookup(setting.clone, *args))
rescue SettingNotFoundError; end
end
nil
end | [
"def",
"lookup",
"(",
"setting",
",",
"*",
"args",
")",
"setting",
"=",
"SettingPath",
".",
"new",
"setting",
"if",
"setting",
".",
"is_a?",
"String",
"@provider",
".",
"each",
"do",
"|",
"provider",
"|",
"begin",
"return",
"special_value_or_string",
"(",
... | Tries all providers in the order they were added to provide a response
for setting.
@param setting [SettingPath,String] nested settings as strings should
be separated by a dot
@param ... further args passed to the provider
@return [Array,Hash,String,Boolean,nil] whatever the responding
provider provides is c... | [
"Tries",
"all",
"providers",
"in",
"the",
"order",
"they",
"were",
"added",
"to",
"provide",
"a",
"response",
"for",
"setting",
"."
] | ace8ef4705d81d4623a144db289051c16da58978 | https://github.com/jhass/configurate/blob/ace8ef4705d81d4623a144db289051c16da58978/lib/configurate/lookup_chain.rb#L32-L41 | train |
holtrop/rscons | lib/rscons/environment.rb | Rscons.Environment.build_dir | def build_dir(src_dir, obj_dir)
if src_dir.is_a?(String)
src_dir = src_dir.gsub("\\", "/").sub(%r{/*$}, "")
end
@build_dirs.unshift([src_dir, obj_dir])
end | ruby | def build_dir(src_dir, obj_dir)
if src_dir.is_a?(String)
src_dir = src_dir.gsub("\\", "/").sub(%r{/*$}, "")
end
@build_dirs.unshift([src_dir, obj_dir])
end | [
"def",
"build_dir",
"(",
"src_dir",
",",
"obj_dir",
")",
"if",
"src_dir",
".",
"is_a?",
"(",
"String",
")",
"src_dir",
"=",
"src_dir",
".",
"gsub",
"(",
"\"\\\\\"",
",",
"\"/\"",
")",
".",
"sub",
"(",
"%r{",
"}",
",",
"\"\"",
")",
"end",
"@build_dirs... | Specify a build directory for this Environment.
Source files from src_dir will produce object files under obj_dir.
@param src_dir [String, Regexp]
Path to the source directory. If a Regexp is given, it will be matched
to source file names.
@param obj_dir [String]
Path to the object directory. If a Regexp ... | [
"Specify",
"a",
"build",
"directory",
"for",
"this",
"Environment",
"."
] | 4967f89a769a7b5c6ca91377526e3f53ceabd6a3 | https://github.com/holtrop/rscons/blob/4967f89a769a7b5c6ca91377526e3f53ceabd6a3/lib/rscons/environment.rb#L228-L233 | train |
holtrop/rscons | lib/rscons/environment.rb | Rscons.Environment.process | def process
cache = Cache.instance
failure = nil
begin
while @job_set.size > 0 or @threaded_commands.size > 0
if failure
@job_set.clear!
job = nil
else
targets_still_building = @threaded_commands.map do |tc|
tc.build_operat... | ruby | def process
cache = Cache.instance
failure = nil
begin
while @job_set.size > 0 or @threaded_commands.size > 0
if failure
@job_set.clear!
job = nil
else
targets_still_building = @threaded_commands.map do |tc|
tc.build_operat... | [
"def",
"process",
"cache",
"=",
"Cache",
".",
"instance",
"failure",
"=",
"nil",
"begin",
"while",
"@job_set",
".",
"size",
">",
"0",
"or",
"@threaded_commands",
".",
"size",
">",
"0",
"if",
"failure",
"@job_set",
".",
"clear!",
"job",
"=",
"nil",
"else"... | Build all build targets specified in the Environment.
When a block is passed to Environment.new, this method is automatically
called after the block returns.
@return [void] | [
"Build",
"all",
"build",
"targets",
"specified",
"in",
"the",
"Environment",
"."
] | 4967f89a769a7b5c6ca91377526e3f53ceabd6a3 | https://github.com/holtrop/rscons/blob/4967f89a769a7b5c6ca91377526e3f53ceabd6a3/lib/rscons/environment.rb#L305-L377 | train |
holtrop/rscons | lib/rscons/environment.rb | Rscons.Environment.expand_varref | def expand_varref(varref, extra_vars = nil)
vars = if extra_vars.nil?
@varset
else
@varset.merge(extra_vars)
end
lambda_args = [env: self, vars: vars]
vars.expand_varref(varref, lambda_args)
end | ruby | def expand_varref(varref, extra_vars = nil)
vars = if extra_vars.nil?
@varset
else
@varset.merge(extra_vars)
end
lambda_args = [env: self, vars: vars]
vars.expand_varref(varref, lambda_args)
end | [
"def",
"expand_varref",
"(",
"varref",
",",
"extra_vars",
"=",
"nil",
")",
"vars",
"=",
"if",
"extra_vars",
".",
"nil?",
"@varset",
"else",
"@varset",
".",
"merge",
"(",
"extra_vars",
")",
"end",
"lambda_args",
"=",
"[",
"env",
":",
"self",
",",
"vars",
... | Expand a construction variable reference.
@param varref [nil, String, Array, Proc, Symbol, TrueClass, FalseClass] Variable reference to expand.
@param extra_vars [Hash, VarSet]
Extra variables to use in addition to (or replace) the Environment's
construction variables when expanding the variable reference.
@... | [
"Expand",
"a",
"construction",
"variable",
"reference",
"."
] | 4967f89a769a7b5c6ca91377526e3f53ceabd6a3 | https://github.com/holtrop/rscons/blob/4967f89a769a7b5c6ca91377526e3f53ceabd6a3/lib/rscons/environment.rb#L394-L402 | train |
holtrop/rscons | lib/rscons/environment.rb | Rscons.Environment.execute | def execute(short_desc, command, options = {})
print_builder_run_message(short_desc, command)
env_args = options[:env] ? [options[:env]] : []
options_args = options[:options] ? [options[:options]] : []
system(*env_args, *Rscons.command_executer, *command, *options_args).tap do |result|
u... | ruby | def execute(short_desc, command, options = {})
print_builder_run_message(short_desc, command)
env_args = options[:env] ? [options[:env]] : []
options_args = options[:options] ? [options[:options]] : []
system(*env_args, *Rscons.command_executer, *command, *options_args).tap do |result|
u... | [
"def",
"execute",
"(",
"short_desc",
",",
"command",
",",
"options",
"=",
"{",
"}",
")",
"print_builder_run_message",
"(",
"short_desc",
",",
"command",
")",
"env_args",
"=",
"options",
"[",
":env",
"]",
"?",
"[",
"options",
"[",
":env",
"]",
"]",
":",
... | Execute a builder command.
@param short_desc [String] Message to print if the Environment's echo
mode is set to :short
@param command [Array] The command to execute.
@param options [Hash] Optional options, possible keys:
- :env - environment Hash to pass to Kernel#system.
- :options - options Hash to pass ... | [
"Execute",
"a",
"builder",
"command",
"."
] | 4967f89a769a7b5c6ca91377526e3f53ceabd6a3 | https://github.com/holtrop/rscons/blob/4967f89a769a7b5c6ca91377526e3f53ceabd6a3/lib/rscons/environment.rb#L415-L424 | train |
holtrop/rscons | lib/rscons/environment.rb | Rscons.Environment.method_missing | def method_missing(method, *args)
if @builders.has_key?(method.to_s)
target, sources, vars, *rest = args
vars ||= {}
unless vars.is_a?(Hash) or vars.is_a?(VarSet)
raise "Unexpected construction variable set: #{vars.inspect}"
end
builder = @builders[method.to_s]
... | ruby | def method_missing(method, *args)
if @builders.has_key?(method.to_s)
target, sources, vars, *rest = args
vars ||= {}
unless vars.is_a?(Hash) or vars.is_a?(VarSet)
raise "Unexpected construction variable set: #{vars.inspect}"
end
builder = @builders[method.to_s]
... | [
"def",
"method_missing",
"(",
"method",
",",
"*",
"args",
")",
"if",
"@builders",
".",
"has_key?",
"(",
"method",
".",
"to_s",
")",
"target",
",",
"sources",
",",
"vars",
",",
"*",
"rest",
"=",
"args",
"vars",
"||=",
"{",
"}",
"unless",
"vars",
".",
... | Define a build target.
@param method [Symbol] Method name.
@param args [Array] Method arguments.
@return [BuildTarget]
The {BuildTarget} object registered, if the method called is a
{Builder}. | [
"Define",
"a",
"build",
"target",
"."
] | 4967f89a769a7b5c6ca91377526e3f53ceabd6a3 | https://github.com/holtrop/rscons/blob/4967f89a769a7b5c6ca91377526e3f53ceabd6a3/lib/rscons/environment.rb#L434-L452 | train |
holtrop/rscons | lib/rscons/environment.rb | Rscons.Environment.depends | def depends(target, *user_deps)
target = expand_varref(target.to_s)
user_deps = user_deps.map {|ud| expand_varref(ud)}
@user_deps[target] ||= []
@user_deps[target] = (@user_deps[target] + user_deps).uniq
build_after(target, user_deps)
end | ruby | def depends(target, *user_deps)
target = expand_varref(target.to_s)
user_deps = user_deps.map {|ud| expand_varref(ud)}
@user_deps[target] ||= []
@user_deps[target] = (@user_deps[target] + user_deps).uniq
build_after(target, user_deps)
end | [
"def",
"depends",
"(",
"target",
",",
"*",
"user_deps",
")",
"target",
"=",
"expand_varref",
"(",
"target",
".",
"to_s",
")",
"user_deps",
"=",
"user_deps",
".",
"map",
"{",
"|",
"ud",
"|",
"expand_varref",
"(",
"ud",
")",
"}",
"@user_deps",
"[",
"targ... | Manually record a given target as depending on the specified files.
@param target [String,BuildTarget] Target file.
@param user_deps [Array<String>] Dependency files.
@return [void] | [
"Manually",
"record",
"a",
"given",
"target",
"as",
"depending",
"on",
"the",
"specified",
"files",
"."
] | 4967f89a769a7b5c6ca91377526e3f53ceabd6a3 | https://github.com/holtrop/rscons/blob/4967f89a769a7b5c6ca91377526e3f53ceabd6a3/lib/rscons/environment.rb#L460-L466 | train |
holtrop/rscons | lib/rscons/environment.rb | Rscons.Environment.build_sources | def build_sources(sources, suffixes, cache, vars)
sources.map do |source|
if source.end_with?(*suffixes)
source
else
converted = nil
suffixes.each do |suffix|
converted_fname = get_build_fname(source, suffix)
if builder = find_builder_for(conve... | ruby | def build_sources(sources, suffixes, cache, vars)
sources.map do |source|
if source.end_with?(*suffixes)
source
else
converted = nil
suffixes.each do |suffix|
converted_fname = get_build_fname(source, suffix)
if builder = find_builder_for(conve... | [
"def",
"build_sources",
"(",
"sources",
",",
"suffixes",
",",
"cache",
",",
"vars",
")",
"sources",
".",
"map",
"do",
"|",
"source",
"|",
"if",
"source",
".",
"end_with?",
"(",
"*",
"suffixes",
")",
"source",
"else",
"converted",
"=",
"nil",
"suffixes",
... | Build a list of source files into files containing one of the suffixes
given by suffixes.
This method is used internally by Rscons builders.
@deprecated Use {#register_builds} instead.
@param sources [Array<String>] List of source files to build.
@param suffixes [Array<String>]
List of suffixes to try to con... | [
"Build",
"a",
"list",
"of",
"source",
"files",
"into",
"files",
"containing",
"one",
"of",
"the",
"suffixes",
"given",
"by",
"suffixes",
"."
] | 4967f89a769a7b5c6ca91377526e3f53ceabd6a3 | https://github.com/holtrop/rscons/blob/4967f89a769a7b5c6ca91377526e3f53ceabd6a3/lib/rscons/environment.rb#L551-L568 | train |
holtrop/rscons | lib/rscons/environment.rb | Rscons.Environment.register_builds | def register_builds(target, sources, suffixes, vars, options = {})
options[:features] ||= []
@registered_build_dependencies[target] ||= Set.new
sources.map do |source|
if source.end_with?(*suffixes)
source
else
output_fname = nil
suffixes.each do |suffix|
... | ruby | def register_builds(target, sources, suffixes, vars, options = {})
options[:features] ||= []
@registered_build_dependencies[target] ||= Set.new
sources.map do |source|
if source.end_with?(*suffixes)
source
else
output_fname = nil
suffixes.each do |suffix|
... | [
"def",
"register_builds",
"(",
"target",
",",
"sources",
",",
"suffixes",
",",
"vars",
",",
"options",
"=",
"{",
"}",
")",
"options",
"[",
":features",
"]",
"||=",
"[",
"]",
"@registered_build_dependencies",
"[",
"target",
"]",
"||=",
"Set",
".",
"new",
... | Find and register builders to build source files into files containing
one of the suffixes given by suffixes.
This method is used internally by Rscons builders. It should be called
from the builder's #setup method.
@since 1.10.0
@param target [String]
The target that depends on these builds.
@param sources ... | [
"Find",
"and",
"register",
"builders",
"to",
"build",
"source",
"files",
"into",
"files",
"containing",
"one",
"of",
"the",
"suffixes",
"given",
"by",
"suffixes",
"."
] | 4967f89a769a7b5c6ca91377526e3f53ceabd6a3 | https://github.com/holtrop/rscons/blob/4967f89a769a7b5c6ca91377526e3f53ceabd6a3/lib/rscons/environment.rb#L596-L616 | train |
holtrop/rscons | lib/rscons/environment.rb | Rscons.Environment.run_builder | def run_builder(builder, target, sources, cache, vars, options = {})
vars = @varset.merge(vars)
build_operation = {
builder: builder,
target: target,
sources: sources,
cache: cache,
env: self,
vars: vars,
setup_info: options[:setup_info]
}
... | ruby | def run_builder(builder, target, sources, cache, vars, options = {})
vars = @varset.merge(vars)
build_operation = {
builder: builder,
target: target,
sources: sources,
cache: cache,
env: self,
vars: vars,
setup_info: options[:setup_info]
}
... | [
"def",
"run_builder",
"(",
"builder",
",",
"target",
",",
"sources",
",",
"cache",
",",
"vars",
",",
"options",
"=",
"{",
"}",
")",
"vars",
"=",
"@varset",
".",
"merge",
"(",
"vars",
")",
"build_operation",
"=",
"{",
"builder",
":",
"builder",
",",
"... | Invoke a builder to build the given target based on the given sources.
@param builder [Builder] The Builder to use.
@param target [String] The target output file.
@param sources [Array<String>] List of source files.
@param cache [Cache] The Cache.
@param vars [Hash] Extra variables to pass to the builder.
@param... | [
"Invoke",
"a",
"builder",
"to",
"build",
"the",
"given",
"target",
"based",
"on",
"the",
"given",
"sources",
"."
] | 4967f89a769a7b5c6ca91377526e3f53ceabd6a3 | https://github.com/holtrop/rscons/blob/4967f89a769a7b5c6ca91377526e3f53ceabd6a3/lib/rscons/environment.rb#L636-L686 | train |
holtrop/rscons | lib/rscons/environment.rb | Rscons.Environment.expand_path | def expand_path(path)
if Rscons.phony_target?(path)
path
elsif path.is_a?(Array)
path.map do |path|
expand_path(path)
end
else
path.sub(%r{^\^(?=[\\/])}, @build_root).gsub("\\", "/")
end
end | ruby | def expand_path(path)
if Rscons.phony_target?(path)
path
elsif path.is_a?(Array)
path.map do |path|
expand_path(path)
end
else
path.sub(%r{^\^(?=[\\/])}, @build_root).gsub("\\", "/")
end
end | [
"def",
"expand_path",
"(",
"path",
")",
"if",
"Rscons",
".",
"phony_target?",
"(",
"path",
")",
"path",
"elsif",
"path",
".",
"is_a?",
"(",
"Array",
")",
"path",
".",
"map",
"do",
"|",
"path",
"|",
"expand_path",
"(",
"path",
")",
"end",
"else",
"pat... | Expand a path to be relative to the Environment's build root.
Paths beginning with "^/" are expanded by replacing "^" with the
Environment's build root.
@param path [String, Array<String>]
The path(s) to expand.
@return [String, Array<String>]
The expanded path(s). | [
"Expand",
"a",
"path",
"to",
"be",
"relative",
"to",
"the",
"Environment",
"s",
"build",
"root",
"."
] | 4967f89a769a7b5c6ca91377526e3f53ceabd6a3 | https://github.com/holtrop/rscons/blob/4967f89a769a7b5c6ca91377526e3f53ceabd6a3/lib/rscons/environment.rb#L698-L708 | train |
holtrop/rscons | lib/rscons/environment.rb | Rscons.Environment.shell | def shell(command)
shell_cmd =
if self["SHELL"]
flag = self["SHELLFLAG"] || (self["SHELL"] == "cmd" ? "/c" : "-c")
[self["SHELL"], flag]
else
Rscons.get_system_shell
end
IO.popen([*shell_cmd, command]) do |io|
io.read
end
end | ruby | def shell(command)
shell_cmd =
if self["SHELL"]
flag = self["SHELLFLAG"] || (self["SHELL"] == "cmd" ? "/c" : "-c")
[self["SHELL"], flag]
else
Rscons.get_system_shell
end
IO.popen([*shell_cmd, command]) do |io|
io.read
end
end | [
"def",
"shell",
"(",
"command",
")",
"shell_cmd",
"=",
"if",
"self",
"[",
"\"SHELL\"",
"]",
"flag",
"=",
"self",
"[",
"\"SHELLFLAG\"",
"]",
"||",
"(",
"self",
"[",
"\"SHELL\"",
"]",
"==",
"\"cmd\"",
"?",
"\"/c\"",
":",
"\"-c\"",
")",
"[",
"self",
"["... | Execute a command using the system shell.
The shell is automatically determined but can be overridden by the SHELL
construction variable. If the SHELL construction variable is specified,
the flag to pass to the shell is automatically dtermined but can be
overridden by the SHELLFLAG construction variable.
@param ... | [
"Execute",
"a",
"command",
"using",
"the",
"system",
"shell",
"."
] | 4967f89a769a7b5c6ca91377526e3f53ceabd6a3 | https://github.com/holtrop/rscons/blob/4967f89a769a7b5c6ca91377526e3f53ceabd6a3/lib/rscons/environment.rb#L720-L731 | train |
holtrop/rscons | lib/rscons/environment.rb | Rscons.Environment.merge_flags | def merge_flags(flags)
flags.each_pair do |key, val|
if self[key].is_a?(Array) and val.is_a?(Array)
self[key] += val
else
self[key] = val
end
end
end | ruby | def merge_flags(flags)
flags.each_pair do |key, val|
if self[key].is_a?(Array) and val.is_a?(Array)
self[key] += val
else
self[key] = val
end
end
end | [
"def",
"merge_flags",
"(",
"flags",
")",
"flags",
".",
"each_pair",
"do",
"|",
"key",
",",
"val",
"|",
"if",
"self",
"[",
"key",
"]",
".",
"is_a?",
"(",
"Array",
")",
"and",
"val",
".",
"is_a?",
"(",
"Array",
")",
"self",
"[",
"key",
"]",
"+=",
... | Merge construction variable flags into this Environment's construction
variables.
This method does the same thing as {#append}, except that Array values in
+flags+ are appended to the end of Array construction variables instead
of replacing their contents.
@param flags [Hash]
Set of construction variables to ... | [
"Merge",
"construction",
"variable",
"flags",
"into",
"this",
"Environment",
"s",
"construction",
"variables",
"."
] | 4967f89a769a7b5c6ca91377526e3f53ceabd6a3 | https://github.com/holtrop/rscons/blob/4967f89a769a7b5c6ca91377526e3f53ceabd6a3/lib/rscons/environment.rb#L849-L857 | train |
holtrop/rscons | lib/rscons/environment.rb | Rscons.Environment.dump | def dump
varset_hash = @varset.to_h
varset_hash.keys.sort_by(&:to_s).each do |var|
var_str = var.is_a?(Symbol) ? var.inspect : var
Ansi.write($stdout, :cyan, var_str, :reset, " => #{varset_hash[var].inspect}\n")
end
end | ruby | def dump
varset_hash = @varset.to_h
varset_hash.keys.sort_by(&:to_s).each do |var|
var_str = var.is_a?(Symbol) ? var.inspect : var
Ansi.write($stdout, :cyan, var_str, :reset, " => #{varset_hash[var].inspect}\n")
end
end | [
"def",
"dump",
"varset_hash",
"=",
"@varset",
".",
"to_h",
"varset_hash",
".",
"keys",
".",
"sort_by",
"(",
"&",
":to_s",
")",
".",
"each",
"do",
"|",
"var",
"|",
"var_str",
"=",
"var",
".",
"is_a?",
"(",
"Symbol",
")",
"?",
"var",
".",
"inspect",
... | Print the Environment's construction variables for debugging. | [
"Print",
"the",
"Environment",
"s",
"construction",
"variables",
"for",
"debugging",
"."
] | 4967f89a769a7b5c6ca91377526e3f53ceabd6a3 | https://github.com/holtrop/rscons/blob/4967f89a769a7b5c6ca91377526e3f53ceabd6a3/lib/rscons/environment.rb#L860-L866 | train |
holtrop/rscons | lib/rscons/environment.rb | Rscons.Environment.print_builder_run_message | def print_builder_run_message(short_description, command)
case @echo
when :command
if command.is_a?(Array)
message = command_to_s(command)
elsif command.is_a?(String)
message = command
elsif short_description.is_a?(String)
message = short_description
... | ruby | def print_builder_run_message(short_description, command)
case @echo
when :command
if command.is_a?(Array)
message = command_to_s(command)
elsif command.is_a?(String)
message = command
elsif short_description.is_a?(String)
message = short_description
... | [
"def",
"print_builder_run_message",
"(",
"short_description",
",",
"command",
")",
"case",
"@echo",
"when",
":command",
"if",
"command",
".",
"is_a?",
"(",
"Array",
")",
"message",
"=",
"command_to_s",
"(",
"command",
")",
"elsif",
"command",
".",
"is_a?",
"("... | Print the builder run message, depending on the Environment's echo mode.
@param short_description [String]
Builder short description, printed if the echo mode is :short.
@param command [Array<String>]
Builder command, printed if the echo mode is :command.
@return [void] | [
"Print",
"the",
"builder",
"run",
"message",
"depending",
"on",
"the",
"Environment",
"s",
"echo",
"mode",
"."
] | 4967f89a769a7b5c6ca91377526e3f53ceabd6a3 | https://github.com/holtrop/rscons/blob/4967f89a769a7b5c6ca91377526e3f53ceabd6a3/lib/rscons/environment.rb#L885-L899 | train |
holtrop/rscons | lib/rscons/environment.rb | Rscons.Environment.add_target | def add_target(target, builder, sources, vars, args)
setup_info = builder.setup(
target: target,
sources: sources,
env: self,
vars: vars)
@job_set.add_job(
builder: builder,
target: target,
sources: sources,
vars: vars,
setup_info: setu... | ruby | def add_target(target, builder, sources, vars, args)
setup_info = builder.setup(
target: target,
sources: sources,
env: self,
vars: vars)
@job_set.add_job(
builder: builder,
target: target,
sources: sources,
vars: vars,
setup_info: setu... | [
"def",
"add_target",
"(",
"target",
",",
"builder",
",",
"sources",
",",
"vars",
",",
"args",
")",
"setup_info",
"=",
"builder",
".",
"setup",
"(",
"target",
":",
"target",
",",
"sources",
":",
"sources",
",",
"env",
":",
"self",
",",
"vars",
":",
"v... | Add a build target.
@param target [String] Build target file name.
@param builder [Builder] The {Builder} to use to build the target.
@param sources [Array<String>] Source file name(s).
@param vars [Hash] Construction variable overrides.
@param args [Object] Deprecated; unused.
@return [void] | [
"Add",
"a",
"build",
"target",
"."
] | 4967f89a769a7b5c6ca91377526e3f53ceabd6a3 | https://github.com/holtrop/rscons/blob/4967f89a769a7b5c6ca91377526e3f53ceabd6a3/lib/rscons/environment.rb#L922-L934 | train |
holtrop/rscons | lib/rscons/environment.rb | Rscons.Environment.start_threaded_command | def start_threaded_command(tc)
print_builder_run_message(tc.short_description, tc.command)
env_args = tc.system_env ? [tc.system_env] : []
options_args = tc.system_options ? [tc.system_options] : []
system_args = [*env_args, *Rscons.command_executer, *tc.command, *options_args]
tc.thread... | ruby | def start_threaded_command(tc)
print_builder_run_message(tc.short_description, tc.command)
env_args = tc.system_env ? [tc.system_env] : []
options_args = tc.system_options ? [tc.system_options] : []
system_args = [*env_args, *Rscons.command_executer, *tc.command, *options_args]
tc.thread... | [
"def",
"start_threaded_command",
"(",
"tc",
")",
"print_builder_run_message",
"(",
"tc",
".",
"short_description",
",",
"tc",
".",
"command",
")",
"env_args",
"=",
"tc",
".",
"system_env",
"?",
"[",
"tc",
".",
"system_env",
"]",
":",
"[",
"]",
"options_args"... | Start a threaded command in a new thread.
@param tc [ThreadedCommand]
The ThreadedCommand to start.
@return [void] | [
"Start",
"a",
"threaded",
"command",
"in",
"a",
"new",
"thread",
"."
] | 4967f89a769a7b5c6ca91377526e3f53ceabd6a3 | https://github.com/holtrop/rscons/blob/4967f89a769a7b5c6ca91377526e3f53ceabd6a3/lib/rscons/environment.rb#L942-L953 | train |
holtrop/rscons | lib/rscons/environment.rb | Rscons.Environment.wait_for_threaded_commands | def wait_for_threaded_commands(options = {})
options[:which] ||= @threaded_commands
threads = options[:which].map(&:thread)
if finished_thread = find_finished_thread(threads, options[:nonblock])
threaded_command = @threaded_commands.find do |tc|
tc.thread == finished_thread
e... | ruby | def wait_for_threaded_commands(options = {})
options[:which] ||= @threaded_commands
threads = options[:which].map(&:thread)
if finished_thread = find_finished_thread(threads, options[:nonblock])
threaded_command = @threaded_commands.find do |tc|
tc.thread == finished_thread
e... | [
"def",
"wait_for_threaded_commands",
"(",
"options",
"=",
"{",
"}",
")",
"options",
"[",
":which",
"]",
"||=",
"@threaded_commands",
"threads",
"=",
"options",
"[",
":which",
"]",
".",
"map",
"(",
"&",
":thread",
")",
"if",
"finished_thread",
"=",
"find_fini... | Wait for threaded commands to complete.
@param options [Hash]
Options.
@option options [Set<ThreadedCommand>, Array<ThreadedCommand>] :which
Which {ThreadedCommand} objects to wait for. If not specified, this
method will wait for any.
@option options [Boolean] :nonblock
Set to true to not block.
@retu... | [
"Wait",
"for",
"threaded",
"commands",
"to",
"complete",
"."
] | 4967f89a769a7b5c6ca91377526e3f53ceabd6a3 | https://github.com/holtrop/rscons/blob/4967f89a769a7b5c6ca91377526e3f53ceabd6a3/lib/rscons/environment.rb#L967-L977 | train |
holtrop/rscons | lib/rscons/environment.rb | Rscons.Environment.find_finished_thread | def find_finished_thread(threads, nonblock)
if nonblock
threads.find do |thread|
!thread.alive?
end
else
if threads.empty?
raise "No threads to wait for"
end
ThreadsWait.new(*threads).next_wait
end
end | ruby | def find_finished_thread(threads, nonblock)
if nonblock
threads.find do |thread|
!thread.alive?
end
else
if threads.empty?
raise "No threads to wait for"
end
ThreadsWait.new(*threads).next_wait
end
end | [
"def",
"find_finished_thread",
"(",
"threads",
",",
"nonblock",
")",
"if",
"nonblock",
"threads",
".",
"find",
"do",
"|",
"thread",
"|",
"!",
"thread",
".",
"alive?",
"end",
"else",
"if",
"threads",
".",
"empty?",
"raise",
"\"No threads to wait for\"",
"end",
... | Check if any of the requested threads are finished.
@param threads [Array<Thread>]
The threads to check.
@param nonblock [Boolean]
Whether to be non-blocking. If true, nil will be returned if no thread
is finished. If false, the method will wait until one of the threads
is finished.
@return [Thread, ni... | [
"Check",
"if",
"any",
"of",
"the",
"requested",
"threads",
"are",
"finished",
"."
] | 4967f89a769a7b5c6ca91377526e3f53ceabd6a3 | https://github.com/holtrop/rscons/blob/4967f89a769a7b5c6ca91377526e3f53ceabd6a3/lib/rscons/environment.rb#L990-L1001 | train |
holtrop/rscons | lib/rscons/environment.rb | Rscons.Environment.find_builder_for | def find_builder_for(target, source, features)
@builders.values.find do |builder|
features_met?(builder, features) and builder.produces?(target, source, self)
end
end | ruby | def find_builder_for(target, source, features)
@builders.values.find do |builder|
features_met?(builder, features) and builder.produces?(target, source, self)
end
end | [
"def",
"find_builder_for",
"(",
"target",
",",
"source",
",",
"features",
")",
"@builders",
".",
"values",
".",
"find",
"do",
"|",
"builder",
"|",
"features_met?",
"(",
"builder",
",",
"features",
")",
"and",
"builder",
".",
"produces?",
"(",
"target",
","... | Find a builder that meets the requested features and produces a target
of the requested name.
@param target [String]
Target file name.
@param source [String]
Source file name.
@param features [Array<String>]
See {#register_builds}.
@return [Builder, nil]
The builder found, if any. | [
"Find",
"a",
"builder",
"that",
"meets",
"the",
"requested",
"features",
"and",
"produces",
"a",
"target",
"of",
"the",
"requested",
"name",
"."
] | 4967f89a769a7b5c6ca91377526e3f53ceabd6a3 | https://github.com/holtrop/rscons/blob/4967f89a769a7b5c6ca91377526e3f53ceabd6a3/lib/rscons/environment.rb#L1040-L1044 | train |
holtrop/rscons | lib/rscons/environment.rb | Rscons.Environment.features_met? | def features_met?(builder, features)
builder_features = builder.features
features.all? do |feature|
want_feature = true
if feature =~ /^-(.*)$/
want_feature = false
feature = $1
end
builder_has_feature = builder_features.include?(feature)
want_feat... | ruby | def features_met?(builder, features)
builder_features = builder.features
features.all? do |feature|
want_feature = true
if feature =~ /^-(.*)$/
want_feature = false
feature = $1
end
builder_has_feature = builder_features.include?(feature)
want_feat... | [
"def",
"features_met?",
"(",
"builder",
",",
"features",
")",
"builder_features",
"=",
"builder",
".",
"features",
"features",
".",
"all?",
"do",
"|",
"feature",
"|",
"want_feature",
"=",
"true",
"if",
"feature",
"=~",
"/",
"/",
"want_feature",
"=",
"false",... | Determine if a builder meets the requested features.
@param builder [Builder]
The builder.
@param features [Array<String>]
See {#register_builds}.
@return [Boolean]
Whether the builder meets the requested features. | [
"Determine",
"if",
"a",
"builder",
"meets",
"the",
"requested",
"features",
"."
] | 4967f89a769a7b5c6ca91377526e3f53ceabd6a3 | https://github.com/holtrop/rscons/blob/4967f89a769a7b5c6ca91377526e3f53ceabd6a3/lib/rscons/environment.rb#L1055-L1066 | train |
puppetlabs/beaker-answers | lib/beaker-answers/answers.rb | BeakerAnswers.Answers.answer_for | def answer_for(options, q, default = nil)
case @format
when :bash
answer = DEFAULT_ANSWERS[q]
answers = options[:answers]
when :hiera
answer = DEFAULT_HIERA_ANSWERS[q]
answers = flatten_keys_to_joined_string(options[:answers]) if options[:answers]
else
rai... | ruby | def answer_for(options, q, default = nil)
case @format
when :bash
answer = DEFAULT_ANSWERS[q]
answers = options[:answers]
when :hiera
answer = DEFAULT_HIERA_ANSWERS[q]
answers = flatten_keys_to_joined_string(options[:answers]) if options[:answers]
else
rai... | [
"def",
"answer_for",
"(",
"options",
",",
"q",
",",
"default",
"=",
"nil",
")",
"case",
"@format",
"when",
":bash",
"answer",
"=",
"DEFAULT_ANSWERS",
"[",
"q",
"]",
"answers",
"=",
"options",
"[",
":answers",
"]",
"when",
":hiera",
"answer",
"=",
"DEFAUL... | The answer value for a provided question. Use the user answer when
available, otherwise return the default.
@param [Hash] options options for answer file
@option options [Symbol] :answers Contains a hash of user provided
question name and answer value pairs.
@param [String] default Should there be no user valu... | [
"The",
"answer",
"value",
"for",
"a",
"provided",
"question",
".",
"Use",
"the",
"user",
"answer",
"when",
"available",
"otherwise",
"return",
"the",
"default",
"."
] | 3193bf986fd1842f2c7d8940a88df36db4200f3f | https://github.com/puppetlabs/beaker-answers/blob/3193bf986fd1842f2c7d8940a88df36db4200f3f/lib/beaker-answers/answers.rb#L124-L145 | train |
chef-workflow/chef-workflow | lib/chef-workflow/support/knife.rb | ChefWorkflow.KnifeSupport.build_knife_config | def build_knife_config
FileUtils.mkdir_p(chef_config_path)
File.binwrite(knife_config_path, ERB.new(knife_config_template).result(binding))
end | ruby | def build_knife_config
FileUtils.mkdir_p(chef_config_path)
File.binwrite(knife_config_path, ERB.new(knife_config_template).result(binding))
end | [
"def",
"build_knife_config",
"FileUtils",
".",
"mkdir_p",
"(",
"chef_config_path",
")",
"File",
".",
"binwrite",
"(",
"knife_config_path",
",",
"ERB",
".",
"new",
"(",
"knife_config_template",
")",
".",
"result",
"(",
"binding",
")",
")",
"end"
] | Writes out a knife.rb based on the settings in this configuration. Uses the
`knife_config_path` and `chef_config_path` to determine where to write it. | [
"Writes",
"out",
"a",
"knife",
".",
"rb",
"based",
"on",
"the",
"settings",
"in",
"this",
"configuration",
".",
"Uses",
"the",
"knife_config_path",
"and",
"chef_config_path",
"to",
"determine",
"where",
"to",
"write",
"it",
"."
] | 956c8f6cd694dacc25dfa405d70b05b12b7c1691 | https://github.com/chef-workflow/chef-workflow/blob/956c8f6cd694dacc25dfa405d70b05b12b7c1691/lib/chef-workflow/support/knife.rb#L89-L92 | train |
itrp/itrp-client | lib/itrp/client/attachments.rb | Itrp.Attachments.upload_attachment | def upload_attachment(storage, attachment, raise_exceptions)
begin
# attachment is already a file or we need to open the file from disk
unless attachment.respond_to?(:path) && attachment.respond_to?(:read)
raise "file does not exist: #{attachment}" unless File.exists?(attachment)
... | ruby | def upload_attachment(storage, attachment, raise_exceptions)
begin
# attachment is already a file or we need to open the file from disk
unless attachment.respond_to?(:path) && attachment.respond_to?(:read)
raise "file does not exist: #{attachment}" unless File.exists?(attachment)
... | [
"def",
"upload_attachment",
"(",
"storage",
",",
"attachment",
",",
"raise_exceptions",
")",
"begin",
"unless",
"attachment",
".",
"respond_to?",
"(",
":path",
")",
"&&",
"attachment",
".",
"respond_to?",
"(",
":read",
")",
"raise",
"\"file does not exist: #{attachm... | upload a single attachment and return the data for the note_attachments
returns nil and provides an error in case the attachment upload failed | [
"upload",
"a",
"single",
"attachment",
"and",
"return",
"the",
"data",
"for",
"the",
"note_attachments",
"returns",
"nil",
"and",
"provides",
"an",
"error",
"in",
"case",
"the",
"attachment",
"upload",
"failed"
] | 80294aa93d7a64c1966d06d4f12ed24b606e3078 | https://github.com/itrp/itrp-client/blob/80294aa93d7a64c1966d06d4f12ed24b606e3078/lib/itrp/client/attachments.rb#L48-L68 | train |
itrp/itrp-client | lib/itrp/client/attachments.rb | Itrp.Attachments.itrp_upload | def itrp_upload(itrp, key_template, key, attachment)
uri = itrp[:upload_uri] =~ /\/v1/ ? itrp[:upload_uri] : itrp[:upload_uri].gsub('/attachments', '/v1/attachments')
response = send_file(uri, {file: attachment, key: key_template}, @client.send(:expand_header))
raise "ITRP upload to #{itrp[:upload_uri... | ruby | def itrp_upload(itrp, key_template, key, attachment)
uri = itrp[:upload_uri] =~ /\/v1/ ? itrp[:upload_uri] : itrp[:upload_uri].gsub('/attachments', '/v1/attachments')
response = send_file(uri, {file: attachment, key: key_template}, @client.send(:expand_header))
raise "ITRP upload to #{itrp[:upload_uri... | [
"def",
"itrp_upload",
"(",
"itrp",
",",
"key_template",
",",
"key",
",",
"attachment",
")",
"uri",
"=",
"itrp",
"[",
":upload_uri",
"]",
"=~",
"/",
"\\/",
"/",
"?",
"itrp",
"[",
":upload_uri",
"]",
":",
"itrp",
"[",
":upload_uri",
"]",
".",
"gsub",
"... | upload the file directly to ITRP | [
"upload",
"the",
"file",
"directly",
"to",
"ITRP"
] | 80294aa93d7a64c1966d06d4f12ed24b606e3078 | https://github.com/itrp/itrp-client/blob/80294aa93d7a64c1966d06d4f12ed24b606e3078/lib/itrp/client/attachments.rb#L93-L97 | train |
devp/sanitize_attributes | lib/sanitize_attributes/macros.rb | SanitizeAttributes.Macros.sanitize_attributes | def sanitize_attributes(*args, &block)
if (args.last && args.last.is_a?(Hash))
options = args.pop
end
options ||= {}
unless @sanitize_hook_already_defined
include InstanceMethods
extend ClassMethods
if options[:before_validation]
before_validation :sani... | ruby | def sanitize_attributes(*args, &block)
if (args.last && args.last.is_a?(Hash))
options = args.pop
end
options ||= {}
unless @sanitize_hook_already_defined
include InstanceMethods
extend ClassMethods
if options[:before_validation]
before_validation :sani... | [
"def",
"sanitize_attributes",
"(",
"*",
"args",
",",
"&",
"block",
")",
"if",
"(",
"args",
".",
"last",
"&&",
"args",
".",
"last",
".",
"is_a?",
"(",
"Hash",
")",
")",
"options",
"=",
"args",
".",
"pop",
"end",
"options",
"||=",
"{",
"}",
"unless",... | sanitize_attributes is used to define sanitizable attributes within a model definition. | [
"sanitize_attributes",
"is",
"used",
"to",
"define",
"sanitizable",
"attributes",
"within",
"a",
"model",
"definition",
"."
] | 75f482b58d0b82a84b70658dd752d4c5b6ea9f02 | https://github.com/devp/sanitize_attributes/blob/75f482b58d0b82a84b70658dd752d4c5b6ea9f02/lib/sanitize_attributes/macros.rb#L4-L39 | train |
vito/atomy | lib/atomy/locals.rb | Atomy.EvalLocalState.search_local | def search_local(name)
if variable = variables[name]
return variable.nested_reference
end
if variable = search_scopes(name)
variables[name] = variable
return variable.nested_reference
end
end | ruby | def search_local(name)
if variable = variables[name]
return variable.nested_reference
end
if variable = search_scopes(name)
variables[name] = variable
return variable.nested_reference
end
end | [
"def",
"search_local",
"(",
"name",
")",
"if",
"variable",
"=",
"variables",
"[",
"name",
"]",
"return",
"variable",
".",
"nested_reference",
"end",
"if",
"variable",
"=",
"search_scopes",
"(",
"name",
")",
"variables",
"[",
"name",
"]",
"=",
"variable",
"... | Returns a cached reference to a variable or searches all
surrounding scopes for a variable. If no variable is found,
it returns nil and a nested scope will create the variable
in itself. | [
"Returns",
"a",
"cached",
"reference",
"to",
"a",
"variable",
"or",
"searches",
"all",
"surrounding",
"scopes",
"for",
"a",
"variable",
".",
"If",
"no",
"variable",
"is",
"found",
"it",
"returns",
"nil",
"and",
"a",
"nested",
"scope",
"will",
"create",
"th... | 12a4a233722979e5e96567943df86e92a81d9343 | https://github.com/vito/atomy/blob/12a4a233722979e5e96567943df86e92a81d9343/lib/atomy/locals.rb#L33-L42 | train |
yas4891/stripe_invoice | app/helpers/stripe_invoice/invoices_helper.rb | StripeInvoice.InvoicesHelper.format_currency | def format_currency(amount, currency)
currency = currency.upcase()
# assuming that all currencies are split into 100 parts is probably wrong
# on an i18n scale but it works for USD, EUR and LBP
# TODO fix this maybe?
amount = amount / 100.0
options = {
# use comma for ... | ruby | def format_currency(amount, currency)
currency = currency.upcase()
# assuming that all currencies are split into 100 parts is probably wrong
# on an i18n scale but it works for USD, EUR and LBP
# TODO fix this maybe?
amount = amount / 100.0
options = {
# use comma for ... | [
"def",
"format_currency",
"(",
"amount",
",",
"currency",
")",
"currency",
"=",
"currency",
".",
"upcase",
"(",
")",
"amount",
"=",
"amount",
"/",
"100.0",
"options",
"=",
"{",
"separator",
":",
"currency",
"==",
"'EUR'",
"?",
"','",
":",
"'.'",
",",
"... | nicely formats the amount and currency | [
"nicely",
"formats",
"the",
"amount",
"and",
"currency"
] | 7b97dc0fb908e1648712fce69adb2fa689467c7a | https://github.com/yas4891/stripe_invoice/blob/7b97dc0fb908e1648712fce69adb2fa689467c7a/app/helpers/stripe_invoice/invoices_helper.rb#L5-L29 | train |
movitto/reterm | lib/reterm/color_pair.rb | RETerm.ColorPair.format | def format(win)
win.win.attron(nc)
yield
win.win.attroff(nc)
end | ruby | def format(win)
win.win.attron(nc)
yield
win.win.attroff(nc)
end | [
"def",
"format",
"(",
"win",
")",
"win",
".",
"win",
".",
"attron",
"(",
"nc",
")",
"yield",
"win",
".",
"win",
".",
"attroff",
"(",
"nc",
")",
"end"
] | Encapsulates window operation in color pair attribute | [
"Encapsulates",
"window",
"operation",
"in",
"color",
"pair",
"attribute"
] | 3e78c64e677f69b22f00dc89c2b515b9188c5e15 | https://github.com/movitto/reterm/blob/3e78c64e677f69b22f00dc89c2b515b9188c5e15/lib/reterm/color_pair.rb#L177-L181 | train |
chef-workflow/chef-workflow | lib/chef-workflow/support/scheduler.rb | ChefWorkflow.Scheduler.schedule_provision | def schedule_provision(group_name, provisioner, dependencies=[])
return nil if vm_groups[group_name]
provisioner = [provisioner] unless provisioner.kind_of?(Array)
provisioner.each { |x| x.name = group_name }
vm_groups[group_name] = provisioner
unless dependencies.all? { |x| vm_groups.has... | ruby | def schedule_provision(group_name, provisioner, dependencies=[])
return nil if vm_groups[group_name]
provisioner = [provisioner] unless provisioner.kind_of?(Array)
provisioner.each { |x| x.name = group_name }
vm_groups[group_name] = provisioner
unless dependencies.all? { |x| vm_groups.has... | [
"def",
"schedule_provision",
"(",
"group_name",
",",
"provisioner",
",",
"dependencies",
"=",
"[",
"]",
")",
"return",
"nil",
"if",
"vm_groups",
"[",
"group_name",
"]",
"provisioner",
"=",
"[",
"provisioner",
"]",
"unless",
"provisioner",
".",
"kind_of?",
"(",... | Schedule a group of VMs for provision. This takes a group name, which is a
string, an array of provisioner objects, and a list of string dependencies.
If anything in the dependencies list hasn't been pre-declared, it refuses
to continue.
This method will return nil if the server group is already provisioned. | [
"Schedule",
"a",
"group",
"of",
"VMs",
"for",
"provision",
".",
"This",
"takes",
"a",
"group",
"name",
"which",
"is",
"a",
"string",
"an",
"array",
"of",
"provisioner",
"objects",
"and",
"a",
"list",
"of",
"string",
"dependencies",
".",
"If",
"anything",
... | 956c8f6cd694dacc25dfa405d70b05b12b7c1691 | https://github.com/chef-workflow/chef-workflow/blob/956c8f6cd694dacc25dfa405d70b05b12b7c1691/lib/chef-workflow/support/scheduler.rb#L89-L103 | train |
chef-workflow/chef-workflow | lib/chef-workflow/support/scheduler.rb | ChefWorkflow.Scheduler.wait_for | def wait_for(*dependencies)
return nil if @serial
return nil if dependencies.empty?
dep_set = dependencies.to_set
until dep_set & solved == dep_set
sleep 1
@solver_thread.join unless @solver_thread.alive?
end
end | ruby | def wait_for(*dependencies)
return nil if @serial
return nil if dependencies.empty?
dep_set = dependencies.to_set
until dep_set & solved == dep_set
sleep 1
@solver_thread.join unless @solver_thread.alive?
end
end | [
"def",
"wait_for",
"(",
"*",
"dependencies",
")",
"return",
"nil",
"if",
"@serial",
"return",
"nil",
"if",
"dependencies",
".",
"empty?",
"dep_set",
"=",
"dependencies",
".",
"to_set",
"until",
"dep_set",
"&",
"solved",
"==",
"dep_set",
"sleep",
"1",
"@solve... | Sleep until this list of dependencies are resolved. In parallel mode, will
raise if an exeception occurred while waiting for these resources. In
serial mode, wait_for just returns nil. | [
"Sleep",
"until",
"this",
"list",
"of",
"dependencies",
"are",
"resolved",
".",
"In",
"parallel",
"mode",
"will",
"raise",
"if",
"an",
"exeception",
"occurred",
"while",
"waiting",
"for",
"these",
"resources",
".",
"In",
"serial",
"mode",
"wait_for",
"just",
... | 956c8f6cd694dacc25dfa405d70b05b12b7c1691 | https://github.com/chef-workflow/chef-workflow/blob/956c8f6cd694dacc25dfa405d70b05b12b7c1691/lib/chef-workflow/support/scheduler.rb#L110-L119 | train |
chef-workflow/chef-workflow | lib/chef-workflow/support/scheduler.rb | ChefWorkflow.Scheduler.with_timeout | def with_timeout(do_loop=true)
Timeout.timeout(10) do
dead_working = @working.values.reject(&:alive?)
if dead_working.size > 0
dead_working.map(&:join)
end
yield
end
rescue TimeoutError
retry if do_loop
end | ruby | def with_timeout(do_loop=true)
Timeout.timeout(10) do
dead_working = @working.values.reject(&:alive?)
if dead_working.size > 0
dead_working.map(&:join)
end
yield
end
rescue TimeoutError
retry if do_loop
end | [
"def",
"with_timeout",
"(",
"do_loop",
"=",
"true",
")",
"Timeout",
".",
"timeout",
"(",
"10",
")",
"do",
"dead_working",
"=",
"@working",
".",
"values",
".",
"reject",
"(",
"&",
":alive?",
")",
"if",
"dead_working",
".",
"size",
">",
"0",
"dead_working"... | Helper method for scheduling. Wraps items in a timeout and immediately
checks all running workers for exceptions, which are immediately bubbled up
if there are any. If do_loop is true, it will retry the timeout. | [
"Helper",
"method",
"for",
"scheduling",
".",
"Wraps",
"items",
"in",
"a",
"timeout",
"and",
"immediately",
"checks",
"all",
"running",
"workers",
"for",
"exceptions",
"which",
"are",
"immediately",
"bubbled",
"up",
"if",
"there",
"are",
"any",
".",
"If",
"d... | 956c8f6cd694dacc25dfa405d70b05b12b7c1691 | https://github.com/chef-workflow/chef-workflow/blob/956c8f6cd694dacc25dfa405d70b05b12b7c1691/lib/chef-workflow/support/scheduler.rb#L126-L137 | train |
chef-workflow/chef-workflow | lib/chef-workflow/support/scheduler.rb | ChefWorkflow.Scheduler.service_resolved_waiters | def service_resolved_waiters
@waiters_mutex.synchronize do
@waiters.replace(@waiters.to_set - (@working.keys.to_set + solved))
end
waiter_iteration = lambda do
@waiters.each do |group_name|
if (solved.to_set & vm_dependencies[group_name]).to_a == vm_dependencies[group_name]
... | ruby | def service_resolved_waiters
@waiters_mutex.synchronize do
@waiters.replace(@waiters.to_set - (@working.keys.to_set + solved))
end
waiter_iteration = lambda do
@waiters.each do |group_name|
if (solved.to_set & vm_dependencies[group_name]).to_a == vm_dependencies[group_name]
... | [
"def",
"service_resolved_waiters",
"@waiters_mutex",
".",
"synchronize",
"do",
"@waiters",
".",
"replace",
"(",
"@waiters",
".",
"to_set",
"-",
"(",
"@working",
".",
"keys",
".",
"to_set",
"+",
"solved",
")",
")",
"end",
"waiter_iteration",
"=",
"lambda",
"do"... | This method determines what 'waiters', or provisioners that cannot
provision yet because of unresolved dependencies, can be executed. | [
"This",
"method",
"determines",
"what",
"waiters",
"or",
"provisioners",
"that",
"cannot",
"provision",
"yet",
"because",
"of",
"unresolved",
"dependencies",
"can",
"be",
"executed",
"."
] | 956c8f6cd694dacc25dfa405d70b05b12b7c1691 | https://github.com/chef-workflow/chef-workflow/blob/956c8f6cd694dacc25dfa405d70b05b12b7c1691/lib/chef-workflow/support/scheduler.rb#L245-L291 | train |
movitto/reterm | lib/reterm/layout.rb | RETerm.Layout.layout_containing | def layout_containing(component)
return self if children.include?(component)
found = nil
children.each { |c|
next if found
if c.kind_of?(Layout)
found = c unless c.layout_containing(component).nil?
end
}
found
end | ruby | def layout_containing(component)
return self if children.include?(component)
found = nil
children.each { |c|
next if found
if c.kind_of?(Layout)
found = c unless c.layout_containing(component).nil?
end
}
found
end | [
"def",
"layout_containing",
"(",
"component",
")",
"return",
"self",
"if",
"children",
".",
"include?",
"(",
"component",
")",
"found",
"=",
"nil",
"children",
".",
"each",
"{",
"|",
"c",
"|",
"next",
"if",
"found",
"if",
"c",
".",
"kind_of?",
"(",
"La... | Return layout containing component
If coordinates are contained in a child in current layout | [
"Return",
"layout",
"containing",
"component",
"If",
"coordinates",
"are",
"contained",
"in",
"a",
"child",
"in",
"current",
"layout"
] | 3e78c64e677f69b22f00dc89c2b515b9188c5e15 | https://github.com/movitto/reterm/blob/3e78c64e677f69b22f00dc89c2b515b9188c5e15/lib/reterm/layout.rb#L73-L86 | train |
movitto/reterm | lib/reterm/layout.rb | RETerm.Layout.contains? | def contains?(child)
children.any? { |c|
(c.kind_of?(Layout) && c.contains?(child)) || c == child
}
end | ruby | def contains?(child)
children.any? { |c|
(c.kind_of?(Layout) && c.contains?(child)) || c == child
}
end | [
"def",
"contains?",
"(",
"child",
")",
"children",
".",
"any?",
"{",
"|",
"c",
"|",
"(",
"c",
".",
"kind_of?",
"(",
"Layout",
")",
"&&",
"c",
".",
"contains?",
"(",
"child",
")",
")",
"||",
"c",
"==",
"child",
"}",
"end"
] | Return boolean indicating if layout contains specified child | [
"Return",
"boolean",
"indicating",
"if",
"layout",
"contains",
"specified",
"child"
] | 3e78c64e677f69b22f00dc89c2b515b9188c5e15 | https://github.com/movitto/reterm/blob/3e78c64e677f69b22f00dc89c2b515b9188c5e15/lib/reterm/layout.rb#L89-L93 | train |
movitto/reterm | lib/reterm/layout.rb | RETerm.Layout.add_child | def add_child(h={})
c = nil
if h.key?(:component)
c = h[:component]
h = {:rows => c.requested_rows + c.extra_padding,
:cols => c.requested_cols + c.extra_padding}.merge(h)
end
raise ArgumentError, "must specify x/y" unless h.key?(:x) &&
... | ruby | def add_child(h={})
c = nil
if h.key?(:component)
c = h[:component]
h = {:rows => c.requested_rows + c.extra_padding,
:cols => c.requested_cols + c.extra_padding}.merge(h)
end
raise ArgumentError, "must specify x/y" unless h.key?(:x) &&
... | [
"def",
"add_child",
"(",
"h",
"=",
"{",
"}",
")",
"c",
"=",
"nil",
"if",
"h",
".",
"key?",
"(",
":component",
")",
"c",
"=",
"h",
"[",
":component",
"]",
"h",
"=",
"{",
":rows",
"=>",
"c",
".",
"requested_rows",
"+",
"c",
".",
"extra_padding",
... | Create new child window and add it to layout | [
"Create",
"new",
"child",
"window",
"and",
"add",
"it",
"to",
"layout"
] | 3e78c64e677f69b22f00dc89c2b515b9188c5e15 | https://github.com/movitto/reterm/blob/3e78c64e677f69b22f00dc89c2b515b9188c5e15/lib/reterm/layout.rb#L107-L158 | train |
mdub/lazily | lib/lazily/filtering.rb | Lazily.Enumerable.select | def select(&predicate)
filter("select") do |yielder|
each do |element|
yielder.call(element) if yield(element)
end
end
end | ruby | def select(&predicate)
filter("select") do |yielder|
each do |element|
yielder.call(element) if yield(element)
end
end
end | [
"def",
"select",
"(",
"&",
"predicate",
")",
"filter",
"(",
"\"select\"",
")",
"do",
"|",
"yielder",
"|",
"each",
"do",
"|",
"element",
"|",
"yielder",
".",
"call",
"(",
"element",
")",
"if",
"yield",
"(",
"element",
")",
"end",
"end",
"end"
] | Select elements using a predicate block.
@return [Enumerable] the elements that pass the predicate
@see ::Enumerable#select | [
"Select",
"elements",
"using",
"a",
"predicate",
"block",
"."
] | 8665e3532ea2d2ea3a41e6ec6a47088308979754 | https://github.com/mdub/lazily/blob/8665e3532ea2d2ea3a41e6ec6a47088308979754/lib/lazily/filtering.rb#L28-L34 | train |
mdub/lazily | lib/lazily/filtering.rb | Lazily.Enumerable.uniq | def uniq
filter("uniq") do |yielder|
seen = Set.new
each do |element|
key = if block_given?
yield element
else
element
end
yielder.call(element) if seen.add?(key)
end
end
end | ruby | def uniq
filter("uniq") do |yielder|
seen = Set.new
each do |element|
key = if block_given?
yield element
else
element
end
yielder.call(element) if seen.add?(key)
end
end
end | [
"def",
"uniq",
"filter",
"(",
"\"uniq\"",
")",
"do",
"|",
"yielder",
"|",
"seen",
"=",
"Set",
".",
"new",
"each",
"do",
"|",
"element",
"|",
"key",
"=",
"if",
"block_given?",
"yield",
"element",
"else",
"element",
"end",
"yielder",
".",
"call",
"(",
... | Remove duplicate values.
@return [Enumerable] elements which have not been previously encountered
@overload uniq
@overload uniq(&block)
@see ::Enumerable#uniq | [
"Remove",
"duplicate",
"values",
"."
] | 8665e3532ea2d2ea3a41e6ec6a47088308979754 | https://github.com/mdub/lazily/blob/8665e3532ea2d2ea3a41e6ec6a47088308979754/lib/lazily/filtering.rb#L63-L75 | train |
mdub/lazily | lib/lazily/filtering.rb | Lazily.Enumerable.take | def take(n)
filter("take") do |yielder, all_done|
if n > 0
each_with_index do |element, index|
yielder.call(element)
throw all_done if index + 1 == n
end
end
end
end | ruby | def take(n)
filter("take") do |yielder, all_done|
if n > 0
each_with_index do |element, index|
yielder.call(element)
throw all_done if index + 1 == n
end
end
end
end | [
"def",
"take",
"(",
"n",
")",
"filter",
"(",
"\"take\"",
")",
"do",
"|",
"yielder",
",",
"all_done",
"|",
"if",
"n",
">",
"0",
"each_with_index",
"do",
"|",
"element",
",",
"index",
"|",
"yielder",
".",
"call",
"(",
"element",
")",
"throw",
"all_done... | Select the first n elements.
@param n [Integer] the number of elements to take
@return [Enumerable] the first N elements
@see ::Enumerable#take | [
"Select",
"the",
"first",
"n",
"elements",
"."
] | 8665e3532ea2d2ea3a41e6ec6a47088308979754 | https://github.com/mdub/lazily/blob/8665e3532ea2d2ea3a41e6ec6a47088308979754/lib/lazily/filtering.rb#L84-L93 | train |
mdub/lazily | lib/lazily/filtering.rb | Lazily.Enumerable.take_while | def take_while(&predicate)
filter("take_while") do |yielder, all_done|
each do |element|
throw all_done unless yield(element)
yielder.call(element)
end
end
end | ruby | def take_while(&predicate)
filter("take_while") do |yielder, all_done|
each do |element|
throw all_done unless yield(element)
yielder.call(element)
end
end
end | [
"def",
"take_while",
"(",
"&",
"predicate",
")",
"filter",
"(",
"\"take_while\"",
")",
"do",
"|",
"yielder",
",",
"all_done",
"|",
"each",
"do",
"|",
"element",
"|",
"throw",
"all_done",
"unless",
"yield",
"(",
"element",
")",
"yielder",
".",
"call",
"("... | Select elements while a predicate returns true.
@return [Enumerable] all elements before the first that fails the predicate
@see ::Enumerable#take_while | [
"Select",
"elements",
"while",
"a",
"predicate",
"returns",
"true",
"."
] | 8665e3532ea2d2ea3a41e6ec6a47088308979754 | https://github.com/mdub/lazily/blob/8665e3532ea2d2ea3a41e6ec6a47088308979754/lib/lazily/filtering.rb#L101-L108 | train |
mdub/lazily | lib/lazily/filtering.rb | Lazily.Enumerable.drop | def drop(n)
filter("drop") do |yielder|
each_with_index do |element, index|
next if index < n
yielder.call(element)
end
end
end | ruby | def drop(n)
filter("drop") do |yielder|
each_with_index do |element, index|
next if index < n
yielder.call(element)
end
end
end | [
"def",
"drop",
"(",
"n",
")",
"filter",
"(",
"\"drop\"",
")",
"do",
"|",
"yielder",
"|",
"each_with_index",
"do",
"|",
"element",
",",
"index",
"|",
"next",
"if",
"index",
"<",
"n",
"yielder",
".",
"call",
"(",
"element",
")",
"end",
"end",
"end"
] | Ignore the first n elements.
@param n [Integer] the number of elements to drop
@return [Enumerable] elements after the first N
@see ::Enumerable#drop | [
"Ignore",
"the",
"first",
"n",
"elements",
"."
] | 8665e3532ea2d2ea3a41e6ec6a47088308979754 | https://github.com/mdub/lazily/blob/8665e3532ea2d2ea3a41e6ec6a47088308979754/lib/lazily/filtering.rb#L117-L124 | train |
mdub/lazily | lib/lazily/filtering.rb | Lazily.Enumerable.drop_while | def drop_while(&predicate)
filter("drop_while") do |yielder|
take = false
each do |element|
take ||= !yield(element)
yielder.call(element) if take
end
end
end | ruby | def drop_while(&predicate)
filter("drop_while") do |yielder|
take = false
each do |element|
take ||= !yield(element)
yielder.call(element) if take
end
end
end | [
"def",
"drop_while",
"(",
"&",
"predicate",
")",
"filter",
"(",
"\"drop_while\"",
")",
"do",
"|",
"yielder",
"|",
"take",
"=",
"false",
"each",
"do",
"|",
"element",
"|",
"take",
"||=",
"!",
"yield",
"(",
"element",
")",
"yielder",
".",
"call",
"(",
... | Reject elements while a predicate returns true.
@return [Enumerable] all elements including and after the first that fails the predicate
@see ::Enumerable#drop_while | [
"Reject",
"elements",
"while",
"a",
"predicate",
"returns",
"true",
"."
] | 8665e3532ea2d2ea3a41e6ec6a47088308979754 | https://github.com/mdub/lazily/blob/8665e3532ea2d2ea3a41e6ec6a47088308979754/lib/lazily/filtering.rb#L132-L140 | train |
mdub/lazily | lib/lazily/filtering.rb | Lazily.Enumerable.grep | def grep(pattern)
filter("grep") do |yielder|
each do |element|
if pattern === element
result = if block_given?
yield element
else
element
end
yielder.call(result)
end
end
end
end | ruby | def grep(pattern)
filter("grep") do |yielder|
each do |element|
if pattern === element
result = if block_given?
yield element
else
element
end
yielder.call(result)
end
end
end
end | [
"def",
"grep",
"(",
"pattern",
")",
"filter",
"(",
"\"grep\"",
")",
"do",
"|",
"yielder",
"|",
"each",
"do",
"|",
"element",
"|",
"if",
"pattern",
"===",
"element",
"result",
"=",
"if",
"block_given?",
"yield",
"element",
"else",
"element",
"end",
"yield... | Select elements matching a pattern.
@return [Enumerable] elements for which the pattern matches
@see ::Enumerable#grep | [
"Select",
"elements",
"matching",
"a",
"pattern",
"."
] | 8665e3532ea2d2ea3a41e6ec6a47088308979754 | https://github.com/mdub/lazily/blob/8665e3532ea2d2ea3a41e6ec6a47088308979754/lib/lazily/filtering.rb#L148-L161 | train |
mdub/lazily | lib/lazily/filtering.rb | Lazily.Enumerable.flatten | def flatten(level = 1)
filter("flatten") do |yielder|
each do |element|
if level > 0 && element.respond_to?(:each)
element.flatten(level - 1).each(&yielder)
else
yielder.call(element)
end
end
end
end | ruby | def flatten(level = 1)
filter("flatten") do |yielder|
each do |element|
if level > 0 && element.respond_to?(:each)
element.flatten(level - 1).each(&yielder)
else
yielder.call(element)
end
end
end
end | [
"def",
"flatten",
"(",
"level",
"=",
"1",
")",
"filter",
"(",
"\"flatten\"",
")",
"do",
"|",
"yielder",
"|",
"each",
"do",
"|",
"element",
"|",
"if",
"level",
">",
"0",
"&&",
"element",
".",
"respond_to?",
"(",
":each",
")",
"element",
".",
"flatten"... | Flatten the collection, such that Enumerable elements are included inline.
@return [Enumerable] elements of elements of the collection
@see ::Array#flatten | [
"Flatten",
"the",
"collection",
"such",
"that",
"Enumerable",
"elements",
"are",
"included",
"inline",
"."
] | 8665e3532ea2d2ea3a41e6ec6a47088308979754 | https://github.com/mdub/lazily/blob/8665e3532ea2d2ea3a41e6ec6a47088308979754/lib/lazily/filtering.rb#L169-L179 | train |
mdub/lazily | lib/lazily/filtering.rb | Lazily.Enumerable.compact | def compact
filter("compact") do |yielder|
each do |element|
yielder.call(element) unless element.nil?
end
end
end | ruby | def compact
filter("compact") do |yielder|
each do |element|
yielder.call(element) unless element.nil?
end
end
end | [
"def",
"compact",
"filter",
"(",
"\"compact\"",
")",
"do",
"|",
"yielder",
"|",
"each",
"do",
"|",
"element",
"|",
"yielder",
".",
"call",
"(",
"element",
")",
"unless",
"element",
".",
"nil?",
"end",
"end",
"end"
] | Ignore nil values.
@return [Enumerable] the elements that are not nil
@see ::Array#compact | [
"Ignore",
"nil",
"values",
"."
] | 8665e3532ea2d2ea3a41e6ec6a47088308979754 | https://github.com/mdub/lazily/blob/8665e3532ea2d2ea3a41e6ec6a47088308979754/lib/lazily/filtering.rb#L193-L199 | train |
movitto/reterm | lib/reterm/mixins/nav_input.rb | RETerm.NavInput.handle_input | def handle_input(from_parent=false)
@focus ||= 0
# focus on first component
ch = handle_focused unless nav_select
# Repeat until quit
until quit_nav?(ch)
# Navigate to the specified component (nav_select)
if self.nav_select
# it is a descendent of this one
... | ruby | def handle_input(from_parent=false)
@focus ||= 0
# focus on first component
ch = handle_focused unless nav_select
# Repeat until quit
until quit_nav?(ch)
# Navigate to the specified component (nav_select)
if self.nav_select
# it is a descendent of this one
... | [
"def",
"handle_input",
"(",
"from_parent",
"=",
"false",
")",
"@focus",
"||=",
"0",
"ch",
"=",
"handle_focused",
"unless",
"nav_select",
"until",
"quit_nav?",
"(",
"ch",
")",
"if",
"self",
".",
"nav_select",
"if",
"self",
".",
"contains?",
"(",
"self",
"."... | Helper to be internally invoked by navigation component
on activation | [
"Helper",
"to",
"be",
"internally",
"invoked",
"by",
"navigation",
"component",
"on",
"activation"
] | 3e78c64e677f69b22f00dc89c2b515b9188c5e15 | https://github.com/movitto/reterm/blob/3e78c64e677f69b22f00dc89c2b515b9188c5e15/lib/reterm/mixins/nav_input.rb#L37-L79 | train |
movitto/reterm | lib/reterm/mixins/nav_input.rb | RETerm.NavInput.handle_focused | def handle_focused
ch = nil
focused.dispatch :focused
update_focus
if focused.activate_focus?
focused.activate!
elsif focused.kind_of?(Layout)
ch = focused.handle_input(true)
elsif !deactivate? && !nav_select
ch = sync_getch
end
if self.ch_sel... | ruby | def handle_focused
ch = nil
focused.dispatch :focused
update_focus
if focused.activate_focus?
focused.activate!
elsif focused.kind_of?(Layout)
ch = focused.handle_input(true)
elsif !deactivate? && !nav_select
ch = sync_getch
end
if self.ch_sel... | [
"def",
"handle_focused",
"ch",
"=",
"nil",
"focused",
".",
"dispatch",
":focused",
"update_focus",
"if",
"focused",
".",
"activate_focus?",
"focused",
".",
"activate!",
"elsif",
"focused",
".",
"kind_of?",
"(",
"Layout",
")",
"ch",
"=",
"focused",
".",
"handle... | Internal helper, logic invoked when a component gains focus | [
"Internal",
"helper",
"logic",
"invoked",
"when",
"a",
"component",
"gains",
"focus"
] | 3e78c64e677f69b22f00dc89c2b515b9188c5e15 | https://github.com/movitto/reterm/blob/3e78c64e677f69b22f00dc89c2b515b9188c5e15/lib/reterm/mixins/nav_input.rb#L118-L140 | train |
movitto/reterm | lib/reterm/mixins/nav_input.rb | RETerm.NavInput.nav_to_selected | def nav_to_selected
# clear nav_select
ns = self.nav_select
self.nav_select = nil
# specified component is a direct child
if self.children.include?(ns)
remove_focus
@focus = focusable.index(ns)
#handle_focused
#update_focus
#focused.activate!
... | ruby | def nav_to_selected
# clear nav_select
ns = self.nav_select
self.nav_select = nil
# specified component is a direct child
if self.children.include?(ns)
remove_focus
@focus = focusable.index(ns)
#handle_focused
#update_focus
#focused.activate!
... | [
"def",
"nav_to_selected",
"ns",
"=",
"self",
".",
"nav_select",
"self",
".",
"nav_select",
"=",
"nil",
"if",
"self",
".",
"children",
".",
"include?",
"(",
"ns",
")",
"remove_focus",
"@focus",
"=",
"focusable",
".",
"index",
"(",
"ns",
")",
"else",
"chil... | Internal helper, navigate to selected component under current | [
"Internal",
"helper",
"navigate",
"to",
"selected",
"component",
"under",
"current"
] | 3e78c64e677f69b22f00dc89c2b515b9188c5e15 | https://github.com/movitto/reterm/blob/3e78c64e677f69b22f00dc89c2b515b9188c5e15/lib/reterm/mixins/nav_input.rb#L149-L169 | train |
bluegod/rint | lib/interface/helpers.rb | Interface.Helpers.must_implement | def must_implement(*args)
parsed_args(args).each do |method, arity|
raise_interface_error(method, arity) unless valid_method?(method, arity)
end
end | ruby | def must_implement(*args)
parsed_args(args).each do |method, arity|
raise_interface_error(method, arity) unless valid_method?(method, arity)
end
end | [
"def",
"must_implement",
"(",
"*",
"args",
")",
"parsed_args",
"(",
"args",
")",
".",
"each",
"do",
"|",
"method",
",",
"arity",
"|",
"raise_interface_error",
"(",
"method",
",",
"arity",
")",
"unless",
"valid_method?",
"(",
"method",
",",
"arity",
")",
... | Errors raised here identify the class_name that is not implementing or is
implemented with the wrong arity required by the Interface. | [
"Errors",
"raised",
"here",
"identify",
"the",
"class_name",
"that",
"is",
"not",
"implementing",
"or",
"is",
"implemented",
"with",
"the",
"wrong",
"arity",
"required",
"by",
"the",
"Interface",
"."
] | bbe04035fed22df6a14cfaef869b2b9fa8e97dc4 | https://github.com/bluegod/rint/blob/bbe04035fed22df6a14cfaef869b2b9fa8e97dc4/lib/interface/helpers.rb#L7-L11 | train |
bluegod/rint | lib/interface/helpers.rb | Interface.Helpers.parsed_args | def parsed_args(args)
args.inject({}) do |memo, method|
memo.merge(method.is_a?(Hash) ? method : { method => nil })
end
end | ruby | def parsed_args(args)
args.inject({}) do |memo, method|
memo.merge(method.is_a?(Hash) ? method : { method => nil })
end
end | [
"def",
"parsed_args",
"(",
"args",
")",
"args",
".",
"inject",
"(",
"{",
"}",
")",
"do",
"|",
"memo",
",",
"method",
"|",
"memo",
".",
"merge",
"(",
"method",
".",
"is_a?",
"(",
"Hash",
")",
"?",
"method",
":",
"{",
"method",
"=>",
"nil",
"}",
... | Transform symbol arguments to a hash of nil arity | [
"Transform",
"symbol",
"arguments",
"to",
"a",
"hash",
"of",
"nil",
"arity"
] | bbe04035fed22df6a14cfaef869b2b9fa8e97dc4 | https://github.com/bluegod/rint/blob/bbe04035fed22df6a14cfaef869b2b9fa8e97dc4/lib/interface/helpers.rb#L16-L20 | train |
actfong/apilayer | lib/apilayer/connection_helper.rb | Apilayer.ConnectionHelper.get_request | def get_request(slug, params={})
# calls connection method on the extended module
connection.get do |req|
req.url "api/#{slug}"
params.each_pair do |k,v|
req.params[k] = v
end
end
end | ruby | def get_request(slug, params={})
# calls connection method on the extended module
connection.get do |req|
req.url "api/#{slug}"
params.each_pair do |k,v|
req.params[k] = v
end
end
end | [
"def",
"get_request",
"(",
"slug",
",",
"params",
"=",
"{",
"}",
")",
"connection",
".",
"get",
"do",
"|",
"req",
"|",
"req",
".",
"url",
"\"api/#{slug}\"",
"params",
".",
"each_pair",
"do",
"|",
"k",
",",
"v",
"|",
"req",
".",
"params",
"[",
"k",
... | Makes a get-request to apilayer's service | [
"Makes",
"a",
"get",
"-",
"request",
"to",
"apilayer",
"s",
"service"
] | 976b2a6552247d0d345f312b804b72d17b618670 | https://github.com/actfong/apilayer/blob/976b2a6552247d0d345f312b804b72d17b618670/lib/apilayer/connection_helper.rb#L50-L58 | train |
infosimples/infosimples-data | lib/infosimples/data/client.rb | Infosimples::Data.Client.download_sites_urls | def download_sites_urls(response)
return [] if !response.is_a?(Hash) ||
(sites_urls = response.dig('receipt', 'sites_urls')).nil?
sites_urls.map do |url|
Infosimples::Data::HTTP.request(url: url, http_timeout: 30)
end
end | ruby | def download_sites_urls(response)
return [] if !response.is_a?(Hash) ||
(sites_urls = response.dig('receipt', 'sites_urls')).nil?
sites_urls.map do |url|
Infosimples::Data::HTTP.request(url: url, http_timeout: 30)
end
end | [
"def",
"download_sites_urls",
"(",
"response",
")",
"return",
"[",
"]",
"if",
"!",
"response",
".",
"is_a?",
"(",
"Hash",
")",
"||",
"(",
"sites_urls",
"=",
"response",
".",
"dig",
"(",
"'receipt'",
",",
"'sites_urls'",
")",
")",
".",
"nil?",
"sites_urls... | Download sites_urls from response.
@param [Hash] response Response returned by #automate.
@return [Array] HTML bodies from sites_urls. | [
"Download",
"sites_urls",
"from",
"response",
"."
] | 3712c76a12eb24d27340ee3aa5c98fb7b13f36e0 | https://github.com/infosimples/infosimples-data/blob/3712c76a12eb24d27340ee3aa5c98fb7b13f36e0/lib/infosimples/data/client.rb#L62-L68 | train |
infosimples/infosimples-data | lib/infosimples/data/client.rb | Infosimples::Data.Client.request | def request(service, method = :get, payload = {})
res = Infosimples::Data::HTTP.request(
url: BASE_URL.gsub(':service', service),
http_timeout: timeout,
method: method,
payload: payload.merge(
token: token,
timeout: timeout,
max_age: max_age,
... | ruby | def request(service, method = :get, payload = {})
res = Infosimples::Data::HTTP.request(
url: BASE_URL.gsub(':service', service),
http_timeout: timeout,
method: method,
payload: payload.merge(
token: token,
timeout: timeout,
max_age: max_age,
... | [
"def",
"request",
"(",
"service",
",",
"method",
"=",
":get",
",",
"payload",
"=",
"{",
"}",
")",
"res",
"=",
"Infosimples",
"::",
"Data",
"::",
"HTTP",
".",
"request",
"(",
"url",
":",
"BASE_URL",
".",
"gsub",
"(",
"':service'",
",",
"service",
")",... | Perform an HTTP request to the Infosimples Data API.
@param [String] service API method name.
@param [Symbol] method HTTP method (:get, :post, :multipart).
@param [Hash] payload Data to be sent through the HTTP request.
@return [Hash] Parsed JSON from the API response. | [
"Perform",
"an",
"HTTP",
"request",
"to",
"the",
"Infosimples",
"Data",
"API",
"."
] | 3712c76a12eb24d27340ee3aa5c98fb7b13f36e0 | https://github.com/infosimples/infosimples-data/blob/3712c76a12eb24d27340ee3aa5c98fb7b13f36e0/lib/infosimples/data/client.rb#L90-L103 | train |
yas4891/stripe_invoice | app/models/stripe_invoice/charge.rb | StripeInvoice.Charge.source_country | def source_country
# source can only be accessed via Customer
cus = Stripe::Customer.retrieve self.indifferent_json[:customer]
# TODO this is wrong, because there might be multiple sources and I
# just randomly select the first one - also some source types might NOT even
# have a country ... | ruby | def source_country
# source can only be accessed via Customer
cus = Stripe::Customer.retrieve self.indifferent_json[:customer]
# TODO this is wrong, because there might be multiple sources and I
# just randomly select the first one - also some source types might NOT even
# have a country ... | [
"def",
"source_country",
"cus",
"=",
"Stripe",
"::",
"Customer",
".",
"retrieve",
"self",
".",
"indifferent_json",
"[",
":customer",
"]",
"cus",
".",
"sources",
".",
"data",
"[",
"0",
"]",
".",
"country",
"end"
] | the country the source is registered in | [
"the",
"country",
"the",
"source",
"is",
"registered",
"in"
] | 7b97dc0fb908e1648712fce69adb2fa689467c7a | https://github.com/yas4891/stripe_invoice/blob/7b97dc0fb908e1648712fce69adb2fa689467c7a/app/models/stripe_invoice/charge.rb#L75-L82 | train |
shanebdavis/Babel-Bridge | lib/babel_bridge/shell.rb | BabelBridge.Shell.start | def start(options={},&block)
@stdout = options[:stdout] || $stdout
@stderr = options[:stdout] || @stdout
@stdin = options[:stdin] || $stdin
while line = @stdin == $stdin ? Readline.readline("> ", true) : @stdin.gets
line.strip!
next if line.length==0
parse_tree_node = parser.pars... | ruby | def start(options={},&block)
@stdout = options[:stdout] || $stdout
@stderr = options[:stdout] || @stdout
@stdin = options[:stdin] || $stdin
while line = @stdin == $stdin ? Readline.readline("> ", true) : @stdin.gets
line.strip!
next if line.length==0
parse_tree_node = parser.pars... | [
"def",
"start",
"(",
"options",
"=",
"{",
"}",
",",
"&",
"block",
")",
"@stdout",
"=",
"options",
"[",
":stdout",
"]",
"||",
"$stdout",
"@stderr",
"=",
"options",
"[",
":stdout",
"]",
"||",
"@stdout",
"@stdin",
"=",
"options",
"[",
":stdin",
"]",
"||... | Each line of input is parsed.
If parser fails, output explaination of why.
If parser succeeds, evaluate parse_tree_node, &block | [
"Each",
"line",
"of",
"input",
"is",
"parsed",
".",
"If",
"parser",
"fails",
"output",
"explaination",
"of",
"why",
".",
"If",
"parser",
"succeeds",
"evaluate",
"parse_tree_node",
"&block"
] | 415c6be1e3002b5eec96a8f1e3bcc7769eb29a57 | https://github.com/shanebdavis/Babel-Bridge/blob/415c6be1e3002b5eec96a8f1e3bcc7769eb29a57/lib/babel_bridge/shell.rb#L46-L60 | train |
platanus/negroku | lib/negroku/modes/env.rb | Negroku::Modes.Env.set_vars_to_stage | def set_vars_to_stage(stage, variables)
# convert to array using VAR=value
vars_array = variables.map{|k,v| "#{k}=#{v}" }
Capistrano::Application.invoke(stage)
Capistrano::Application.invoke("rbenv:vars:set", *vars_array)
end | ruby | def set_vars_to_stage(stage, variables)
# convert to array using VAR=value
vars_array = variables.map{|k,v| "#{k}=#{v}" }
Capistrano::Application.invoke(stage)
Capistrano::Application.invoke("rbenv:vars:set", *vars_array)
end | [
"def",
"set_vars_to_stage",
"(",
"stage",
",",
"variables",
")",
"vars_array",
"=",
"variables",
".",
"map",
"{",
"|",
"k",
",",
"v",
"|",
"\"#{k}=#{v}\"",
"}",
"Capistrano",
"::",
"Application",
".",
"invoke",
"(",
"stage",
")",
"Capistrano",
"::",
"Appli... | Sets the variables to the selected stage using cap rbenv set | [
"Sets",
"the",
"variables",
"to",
"the",
"selected",
"stage",
"using",
"cap",
"rbenv",
"set"
] | 7124973132de65026b30b66477678387a07dfa4d | https://github.com/platanus/negroku/blob/7124973132de65026b30b66477678387a07dfa4d/lib/negroku/modes/env.rb#L17-L22 | train |
platanus/negroku | lib/negroku/modes/env.rb | Negroku::Modes.Env.get_variables | def get_variables
return unless File.exists?(ENV_FILE)
File.open(ENV_FILE).each do |line|
var_name = line.split("=").first
yield var_name unless line =~ /^\#/
end
end | ruby | def get_variables
return unless File.exists?(ENV_FILE)
File.open(ENV_FILE).each do |line|
var_name = line.split("=").first
yield var_name unless line =~ /^\#/
end
end | [
"def",
"get_variables",
"return",
"unless",
"File",
".",
"exists?",
"(",
"ENV_FILE",
")",
"File",
".",
"open",
"(",
"ENV_FILE",
")",
".",
"each",
"do",
"|",
"line",
"|",
"var_name",
"=",
"line",
".",
"split",
"(",
"\"=\"",
")",
".",
"first",
"yield",
... | build a list of variables from ENV_FILE and yeilds it | [
"build",
"a",
"list",
"of",
"variables",
"from",
"ENV_FILE",
"and",
"yeilds",
"it"
] | 7124973132de65026b30b66477678387a07dfa4d | https://github.com/platanus/negroku/blob/7124973132de65026b30b66477678387a07dfa4d/lib/negroku/modes/env.rb#L25-L32 | train |
platanus/negroku | lib/negroku/modes/env.rb | Negroku::Modes.Env.select_variables | def select_variables
selection = {}
puts I18n.t(:ask_variables_message, scope: :negroku)
get_variables do |var_name|
selection[var_name] = Ask.input(var_name)
end
selection.reject {|key, value| value.empty? }
end | ruby | def select_variables
selection = {}
puts I18n.t(:ask_variables_message, scope: :negroku)
get_variables do |var_name|
selection[var_name] = Ask.input(var_name)
end
selection.reject {|key, value| value.empty? }
end | [
"def",
"select_variables",
"selection",
"=",
"{",
"}",
"puts",
"I18n",
".",
"t",
"(",
":ask_variables_message",
",",
"scope",
":",
":negroku",
")",
"get_variables",
"do",
"|",
"var_name",
"|",
"selection",
"[",
"var_name",
"]",
"=",
"Ask",
".",
"input",
"(... | Returns a hash of selected variables and values | [
"Returns",
"a",
"hash",
"of",
"selected",
"variables",
"and",
"values"
] | 7124973132de65026b30b66477678387a07dfa4d | https://github.com/platanus/negroku/blob/7124973132de65026b30b66477678387a07dfa4d/lib/negroku/modes/env.rb#L35-L42 | train |
holtrop/rscons | lib/rscons/varset.rb | Rscons.VarSet.[] | def [](key)
if @my_vars.include?(key)
@my_vars[key]
else
@coa_vars.each do |coa_vars|
if coa_vars.include?(key)
@my_vars[key] = deep_dup(coa_vars[key])
return @my_vars[key]
end
end
nil
end
end | ruby | def [](key)
if @my_vars.include?(key)
@my_vars[key]
else
@coa_vars.each do |coa_vars|
if coa_vars.include?(key)
@my_vars[key] = deep_dup(coa_vars[key])
return @my_vars[key]
end
end
nil
end
end | [
"def",
"[]",
"(",
"key",
")",
"if",
"@my_vars",
".",
"include?",
"(",
"key",
")",
"@my_vars",
"[",
"key",
"]",
"else",
"@coa_vars",
".",
"each",
"do",
"|",
"coa_vars",
"|",
"if",
"coa_vars",
".",
"include?",
"(",
"key",
")",
"@my_vars",
"[",
"key",
... | Create a VarSet.
@param vars [Hash] Optional initial variables.
Access the value of variable.
@param key [String, Symbol] The variable name.
@return [Object] The variable's value. | [
"Create",
"a",
"VarSet",
"."
] | 4967f89a769a7b5c6ca91377526e3f53ceabd6a3 | https://github.com/holtrop/rscons/blob/4967f89a769a7b5c6ca91377526e3f53ceabd6a3/lib/rscons/varset.rb#L19-L31 | train |
holtrop/rscons | lib/rscons/varset.rb | Rscons.VarSet.include? | def include?(key)
if @my_vars.include?(key)
true
else
@coa_vars.find do |coa_vars|
coa_vars.include?(key)
end
end
end | ruby | def include?(key)
if @my_vars.include?(key)
true
else
@coa_vars.find do |coa_vars|
coa_vars.include?(key)
end
end
end | [
"def",
"include?",
"(",
"key",
")",
"if",
"@my_vars",
".",
"include?",
"(",
"key",
")",
"true",
"else",
"@coa_vars",
".",
"find",
"do",
"|",
"coa_vars",
"|",
"coa_vars",
".",
"include?",
"(",
"key",
")",
"end",
"end",
"end"
] | Check if the VarSet contains a variable.
@param key [String, Symbol] The variable name.
@return [Boolean] Whether the VarSet contains the variable. | [
"Check",
"if",
"the",
"VarSet",
"contains",
"a",
"variable",
"."
] | 4967f89a769a7b5c6ca91377526e3f53ceabd6a3 | https://github.com/holtrop/rscons/blob/4967f89a769a7b5c6ca91377526e3f53ceabd6a3/lib/rscons/varset.rb#L47-L55 | train |
holtrop/rscons | lib/rscons/varset.rb | Rscons.VarSet.append | def append(values)
coa!
if values.is_a?(VarSet)
values.send(:coa!)
@coa_vars = values.instance_variable_get(:@coa_vars) + @coa_vars
else
@my_vars = deep_dup(values)
end
self
end | ruby | def append(values)
coa!
if values.is_a?(VarSet)
values.send(:coa!)
@coa_vars = values.instance_variable_get(:@coa_vars) + @coa_vars
else
@my_vars = deep_dup(values)
end
self
end | [
"def",
"append",
"(",
"values",
")",
"coa!",
"if",
"values",
".",
"is_a?",
"(",
"VarSet",
")",
"values",
".",
"send",
"(",
":coa!",
")",
"@coa_vars",
"=",
"values",
".",
"instance_variable_get",
"(",
":@coa_vars",
")",
"+",
"@coa_vars",
"else",
"@my_vars",... | Add or overwrite a set of variables.
@param values [VarSet, Hash] New set of variables.
@return [VarSet] Returns self. | [
"Add",
"or",
"overwrite",
"a",
"set",
"of",
"variables",
"."
] | 4967f89a769a7b5c6ca91377526e3f53ceabd6a3 | https://github.com/holtrop/rscons/blob/4967f89a769a7b5c6ca91377526e3f53ceabd6a3/lib/rscons/varset.rb#L62-L71 | train |
holtrop/rscons | lib/rscons/varset.rb | Rscons.VarSet.merge | def merge(other = {})
coa!
varset = self.class.new
varset.instance_variable_set(:@coa_vars, @coa_vars.dup)
varset.append(other)
end | ruby | def merge(other = {})
coa!
varset = self.class.new
varset.instance_variable_set(:@coa_vars, @coa_vars.dup)
varset.append(other)
end | [
"def",
"merge",
"(",
"other",
"=",
"{",
"}",
")",
"coa!",
"varset",
"=",
"self",
".",
"class",
".",
"new",
"varset",
".",
"instance_variable_set",
"(",
":@coa_vars",
",",
"@coa_vars",
".",
"dup",
")",
"varset",
".",
"append",
"(",
"other",
")",
"end"
] | Create a new VarSet object based on the first merged with other.
@param other [VarSet, Hash] Other variables to add or overwrite.
@return [VarSet] The newly created VarSet. | [
"Create",
"a",
"new",
"VarSet",
"object",
"based",
"on",
"the",
"first",
"merged",
"with",
"other",
"."
] | 4967f89a769a7b5c6ca91377526e3f53ceabd6a3 | https://github.com/holtrop/rscons/blob/4967f89a769a7b5c6ca91377526e3f53ceabd6a3/lib/rscons/varset.rb#L78-L83 | train |
holtrop/rscons | lib/rscons/varset.rb | Rscons.VarSet.to_h | def to_h
result = deep_dup(@my_vars)
@coa_vars.reduce(result) do |result, coa_vars|
coa_vars.each_pair do |key, value|
unless result.include?(key)
result[key] = deep_dup(value)
end
end
result
end
end | ruby | def to_h
result = deep_dup(@my_vars)
@coa_vars.reduce(result) do |result, coa_vars|
coa_vars.each_pair do |key, value|
unless result.include?(key)
result[key] = deep_dup(value)
end
end
result
end
end | [
"def",
"to_h",
"result",
"=",
"deep_dup",
"(",
"@my_vars",
")",
"@coa_vars",
".",
"reduce",
"(",
"result",
")",
"do",
"|",
"result",
",",
"coa_vars",
"|",
"coa_vars",
".",
"each_pair",
"do",
"|",
"key",
",",
"value",
"|",
"unless",
"result",
".",
"incl... | Return a Hash containing all variables in the VarSet.
@since 1.8.0
This method is not terribly efficient. It is intended to be used only by
debugging code to dump out a VarSet's variables.
@return [Hash] All variables in the VarSet. | [
"Return",
"a",
"Hash",
"containing",
"all",
"variables",
"in",
"the",
"VarSet",
"."
] | 4967f89a769a7b5c6ca91377526e3f53ceabd6a3 | https://github.com/holtrop/rscons/blob/4967f89a769a7b5c6ca91377526e3f53ceabd6a3/lib/rscons/varset.rb#L144-L154 | train |
holtrop/rscons | lib/rscons/varset.rb | Rscons.VarSet.deep_dup | def deep_dup(obj)
obj_class = obj.class
if obj_class == Hash
obj.reduce({}) do |result, (k, v)|
result[k] = deep_dup(v)
result
end
elsif obj_class == Array
obj.map { |v| deep_dup(v) }
elsif obj_class == String
obj.dup
else
obj
... | ruby | def deep_dup(obj)
obj_class = obj.class
if obj_class == Hash
obj.reduce({}) do |result, (k, v)|
result[k] = deep_dup(v)
result
end
elsif obj_class == Array
obj.map { |v| deep_dup(v) }
elsif obj_class == String
obj.dup
else
obj
... | [
"def",
"deep_dup",
"(",
"obj",
")",
"obj_class",
"=",
"obj",
".",
"class",
"if",
"obj_class",
"==",
"Hash",
"obj",
".",
"reduce",
"(",
"{",
"}",
")",
"do",
"|",
"result",
",",
"(",
"k",
",",
"v",
")",
"|",
"result",
"[",
"k",
"]",
"=",
"deep_du... | Create a deep copy of an object.
Only objects which are of type String, Array, or Hash are deep copied.
Any other object just has its referenced copied.
@param obj [Object] Object to deep copy.
@return [Object] Deep copied value. | [
"Create",
"a",
"deep",
"copy",
"of",
"an",
"object",
"."
] | 4967f89a769a7b5c6ca91377526e3f53ceabd6a3 | https://github.com/holtrop/rscons/blob/4967f89a769a7b5c6ca91377526e3f53ceabd6a3/lib/rscons/varset.rb#L196-L210 | train |
itrp/itrp-client | lib/itrp/client.rb | Itrp.Client.import | def import(csv, type, block_until_completed = false)
csv = File.open(csv, 'rb') unless csv.respond_to?(:path) && csv.respond_to?(:read)
data, headers = Itrp::Multipart::Post.prepare_query(type: type, file: csv)
request = Net::HTTP::Post.new(expand_path('/import'), expand_header(headers))
request... | ruby | def import(csv, type, block_until_completed = false)
csv = File.open(csv, 'rb') unless csv.respond_to?(:path) && csv.respond_to?(:read)
data, headers = Itrp::Multipart::Post.prepare_query(type: type, file: csv)
request = Net::HTTP::Post.new(expand_path('/import'), expand_header(headers))
request... | [
"def",
"import",
"(",
"csv",
",",
"type",
",",
"block_until_completed",
"=",
"false",
")",
"csv",
"=",
"File",
".",
"open",
"(",
"csv",
",",
"'rb'",
")",
"unless",
"csv",
".",
"respond_to?",
"(",
":path",
")",
"&&",
"csv",
".",
"respond_to?",
"(",
":... | upload a CSV file to import
@param csv: The CSV File or the location of the CSV file
@param type: The type, e.g. person, organization, people_contact_details
@raise Itrp::UploadFailed in case the file could was not accepted by ITRP and +block_until_completed+ is +true+
@raise Itrp::Exception in case the import prog... | [
"upload",
"a",
"CSV",
"file",
"to",
"import"
] | 80294aa93d7a64c1966d06d4f12ed24b606e3078 | https://github.com/itrp/itrp-client/blob/80294aa93d7a64c1966d06d4f12ed24b606e3078/lib/itrp/client.rb#L122-L148 | train |
itrp/itrp-client | lib/itrp/client.rb | Itrp.Client.export | def export(types, from = nil, block_until_completed = false, locale = nil)
data = {type: [types].flatten.join(',')}
data[:from] = from unless from.blank?
data[:locale] = locale unless locale.blank?
response = post('/export', data)
if response.valid?
if response.raw.code.to_s == '20... | ruby | def export(types, from = nil, block_until_completed = false, locale = nil)
data = {type: [types].flatten.join(',')}
data[:from] = from unless from.blank?
data[:locale] = locale unless locale.blank?
response = post('/export', data)
if response.valid?
if response.raw.code.to_s == '20... | [
"def",
"export",
"(",
"types",
",",
"from",
"=",
"nil",
",",
"block_until_completed",
"=",
"false",
",",
"locale",
"=",
"nil",
")",
"data",
"=",
"{",
"type",
":",
"[",
"types",
"]",
".",
"flatten",
".",
"join",
"(",
"','",
")",
"}",
"data",
"[",
... | Export CSV files
@param types: The types to export, e.g. person, organization, people_contact_details
@param from: Retrieve all files since a given data and time
@param block_until_completed: Set to true to monitor the export progress
@param locale: Required for translations export
@raise Itrp::Exception in case t... | [
"Export",
"CSV",
"files"
] | 80294aa93d7a64c1966d06d4f12ed24b606e3078 | https://github.com/itrp/itrp-client/blob/80294aa93d7a64c1966d06d4f12ed24b606e3078/lib/itrp/client.rb#L156-L187 | train |
itrp/itrp-client | lib/itrp/client.rb | Itrp.Client.expand_header | def expand_header(header = {})
header = DEFAULT_HEADER.merge(header)
header['X-ITRP-Account'] = option(:account) if option(:account)
header['AUTHORIZATION'] = 'Basic ' + ["#{option(:api_token)}:x"].pack('m*').gsub(/\s/, '')
if option(:source)
header['X-ITRP-Source'] = option(:source)
... | ruby | def expand_header(header = {})
header = DEFAULT_HEADER.merge(header)
header['X-ITRP-Account'] = option(:account) if option(:account)
header['AUTHORIZATION'] = 'Basic ' + ["#{option(:api_token)}:x"].pack('m*').gsub(/\s/, '')
if option(:source)
header['X-ITRP-Source'] = option(:source)
... | [
"def",
"expand_header",
"(",
"header",
"=",
"{",
"}",
")",
"header",
"=",
"DEFAULT_HEADER",
".",
"merge",
"(",
"header",
")",
"header",
"[",
"'X-ITRP-Account'",
"]",
"=",
"option",
"(",
":account",
")",
"if",
"option",
"(",
":account",
")",
"header",
"["... | Expand the given header with the default header | [
"Expand",
"the",
"given",
"header",
"with",
"the",
"default",
"header"
] | 80294aa93d7a64c1966d06d4f12ed24b606e3078 | https://github.com/itrp/itrp-client/blob/80294aa93d7a64c1966d06d4f12ed24b606e3078/lib/itrp/client.rb#L211-L220 | train |
itrp/itrp-client | lib/itrp/client.rb | Itrp.Client.typecast | def typecast(value, escape = true)
case value.class.name.to_sym
when :NilClass then ''
when :String then escape ? uri_escape(value) : value
when :TrueClass then 'true'
when :FalseClass then 'false'
when :DateTime then datetime = value.new_offset(0).iso8601; es... | ruby | def typecast(value, escape = true)
case value.class.name.to_sym
when :NilClass then ''
when :String then escape ? uri_escape(value) : value
when :TrueClass then 'true'
when :FalseClass then 'false'
when :DateTime then datetime = value.new_offset(0).iso8601; es... | [
"def",
"typecast",
"(",
"value",
",",
"escape",
"=",
"true",
")",
"case",
"value",
".",
"class",
".",
"name",
".",
"to_sym",
"when",
":NilClass",
"then",
"''",
"when",
":String",
"then",
"escape",
"?",
"uri_escape",
"(",
"value",
")",
":",
"value",
"wh... | Parameter value typecasting | [
"Parameter",
"value",
"typecasting"
] | 80294aa93d7a64c1966d06d4f12ed24b606e3078 | https://github.com/itrp/itrp-client/blob/80294aa93d7a64c1966d06d4f12ed24b606e3078/lib/itrp/client.rb#L247-L262 | train |
movitto/reterm | lib/reterm/mixins/cdk_component.rb | RETerm.CDKComponent.component | def component
enable_cdk!
@component ||= begin
c = _component
c.setBackgroundColor("</#{@colors.id}>") if colored?
c.timeout(SYNC_TIMEOUT) if sync_enabled? # XXX
c.title_attrib = @title_attrib if @title_attrib
c
end
end | ruby | def component
enable_cdk!
@component ||= begin
c = _component
c.setBackgroundColor("</#{@colors.id}>") if colored?
c.timeout(SYNC_TIMEOUT) if sync_enabled? # XXX
c.title_attrib = @title_attrib if @title_attrib
c
end
end | [
"def",
"component",
"enable_cdk!",
"@component",
"||=",
"begin",
"c",
"=",
"_component",
"c",
".",
"setBackgroundColor",
"(",
"\"</#{@colors.id}>\"",
")",
"if",
"colored?",
"c",
".",
"timeout",
"(",
"SYNC_TIMEOUT",
")",
"if",
"sync_enabled?",
"c",
".",
"title_at... | Return completely initialized CDK component | [
"Return",
"completely",
"initialized",
"CDK",
"component"
] | 3e78c64e677f69b22f00dc89c2b515b9188c5e15 | https://github.com/movitto/reterm/blob/3e78c64e677f69b22f00dc89c2b515b9188c5e15/lib/reterm/mixins/cdk_component.rb#L33-L42 | train |
movitto/reterm | lib/reterm/mixins/cdk_component.rb | RETerm.CDKComponent.activate! | def activate!(*input)
dispatch :activated
component.resetExitType
r = nil
while [:EARLY_EXIT, :NEVER_ACTIVATED, :TIMEOUT].include?(component.exit_type) &&
!shutdown?
r = component.activate(input)
run_sync! if sync_enabled?
end
dispatch :deactivated
... | ruby | def activate!(*input)
dispatch :activated
component.resetExitType
r = nil
while [:EARLY_EXIT, :NEVER_ACTIVATED, :TIMEOUT].include?(component.exit_type) &&
!shutdown?
r = component.activate(input)
run_sync! if sync_enabled?
end
dispatch :deactivated
... | [
"def",
"activate!",
"(",
"*",
"input",
")",
"dispatch",
":activated",
"component",
".",
"resetExitType",
"r",
"=",
"nil",
"while",
"[",
":EARLY_EXIT",
",",
":NEVER_ACTIVATED",
",",
":TIMEOUT",
"]",
".",
"include?",
"(",
"component",
".",
"exit_type",
")",
"&... | Invoke CDK activation routine | [
"Invoke",
"CDK",
"activation",
"routine"
] | 3e78c64e677f69b22f00dc89c2b515b9188c5e15 | https://github.com/movitto/reterm/blob/3e78c64e677f69b22f00dc89c2b515b9188c5e15/lib/reterm/mixins/cdk_component.rb#L81-L95 | train |
movitto/reterm | lib/reterm/mixins/cdk_component.rb | RETerm.CDKComponent.bind_key | def bind_key(key, kcb=nil, &bl)
kcb = bl if kcb.nil? && !bl.nil?
cb = lambda do |cdktype, widget, component, key|
kcb.call component, key
end
component.bind(:ENTRY, key, cb, self)
end | ruby | def bind_key(key, kcb=nil, &bl)
kcb = bl if kcb.nil? && !bl.nil?
cb = lambda do |cdktype, widget, component, key|
kcb.call component, key
end
component.bind(:ENTRY, key, cb, self)
end | [
"def",
"bind_key",
"(",
"key",
",",
"kcb",
"=",
"nil",
",",
"&",
"bl",
")",
"kcb",
"=",
"bl",
"if",
"kcb",
".",
"nil?",
"&&",
"!",
"bl",
".",
"nil?",
"cb",
"=",
"lambda",
"do",
"|",
"cdktype",
",",
"widget",
",",
"component",
",",
"key",
"|",
... | Override bind_key to use cdk bindings mechanism | [
"Override",
"bind_key",
"to",
"use",
"cdk",
"bindings",
"mechanism"
] | 3e78c64e677f69b22f00dc89c2b515b9188c5e15 | https://github.com/movitto/reterm/blob/3e78c64e677f69b22f00dc89c2b515b9188c5e15/lib/reterm/mixins/cdk_component.rb#L108-L116 | train |
platanus/negroku | lib/negroku/modes/app.rb | Negroku::Modes.App.ask_name | def ask_name
question = I18n.t :application_name, scope: :negroku
Ask.input question, default: File.basename(Dir.getwd)
end | ruby | def ask_name
question = I18n.t :application_name, scope: :negroku
Ask.input question, default: File.basename(Dir.getwd)
end | [
"def",
"ask_name",
"question",
"=",
"I18n",
".",
"t",
":application_name",
",",
"scope",
":",
":negroku",
"Ask",
".",
"input",
"question",
",",
"default",
":",
"File",
".",
"basename",
"(",
"Dir",
".",
"getwd",
")",
"end"
] | Ask the application name | [
"Ask",
"the",
"application",
"name"
] | 7124973132de65026b30b66477678387a07dfa4d | https://github.com/platanus/negroku/blob/7124973132de65026b30b66477678387a07dfa4d/lib/negroku/modes/app.rb#L74-L77 | train |
platanus/negroku | lib/negroku/modes/app.rb | Negroku::Modes.App.select_repo | def select_repo
remote_urls = %x(git remote -v 2> /dev/null | awk '{print $2}' | uniq).split("\n")
remote_urls << (I18n.t :other, scope: :negroku)
question = I18n.t :choose_repo_url, scope: :negroku
selected_idx = Ask.list question, remote_urls
if selected_idx == remote_urls.length - 1
... | ruby | def select_repo
remote_urls = %x(git remote -v 2> /dev/null | awk '{print $2}' | uniq).split("\n")
remote_urls << (I18n.t :other, scope: :negroku)
question = I18n.t :choose_repo_url, scope: :negroku
selected_idx = Ask.list question, remote_urls
if selected_idx == remote_urls.length - 1
... | [
"def",
"select_repo",
"remote_urls",
"=",
"%x(",
")",
".",
"split",
"(",
"\"\\n\"",
")",
"remote_urls",
"<<",
"(",
"I18n",
".",
"t",
":other",
",",
"scope",
":",
":negroku",
")",
"question",
"=",
"I18n",
".",
"t",
":choose_repo_url",
",",
"scope",
":",
... | Get git remotes from current git and ask to select one | [
"Get",
"git",
"remotes",
"from",
"current",
"git",
"and",
"ask",
"to",
"select",
"one"
] | 7124973132de65026b30b66477678387a07dfa4d | https://github.com/platanus/negroku/blob/7124973132de65026b30b66477678387a07dfa4d/lib/negroku/modes/app.rb#L93-L104 | train |
shanebdavis/Babel-Bridge | lib/babel_bridge/rule_variant.rb | BabelBridge.RuleVariant.pattern_elements | def pattern_elements
@pattern_elements||=pattern.collect { |match| [PatternElement.new(match, :rule_variant => self, :pattern_element => true), delimiter_pattern] }.flatten[0..-2]
end | ruby | def pattern_elements
@pattern_elements||=pattern.collect { |match| [PatternElement.new(match, :rule_variant => self, :pattern_element => true), delimiter_pattern] }.flatten[0..-2]
end | [
"def",
"pattern_elements",
"@pattern_elements",
"||=",
"pattern",
".",
"collect",
"{",
"|",
"match",
"|",
"[",
"PatternElement",
".",
"new",
"(",
"match",
",",
":rule_variant",
"=>",
"self",
",",
":pattern_element",
"=>",
"true",
")",
",",
"delimiter_pattern",
... | convert the pattern into a set of lamba functions | [
"convert",
"the",
"pattern",
"into",
"a",
"set",
"of",
"lamba",
"functions"
] | 415c6be1e3002b5eec96a8f1e3bcc7769eb29a57 | https://github.com/shanebdavis/Babel-Bridge/blob/415c6be1e3002b5eec96a8f1e3bcc7769eb29a57/lib/babel_bridge/rule_variant.rb#L36-L38 | train |
shanebdavis/Babel-Bridge | lib/babel_bridge/rule_variant.rb | BabelBridge.RuleVariant.parse | def parse(parent_node)
#return parse_nongreedy_optional(src,offset,parent_node) # nongreedy optionals break standard PEG
node = variant_node_class.new(parent_node, delimiter_pattern)
node.match parser.delimiter_pattern if root_rule?
pattern_elements.each do |pe|
return unless node.match(pe)
... | ruby | def parse(parent_node)
#return parse_nongreedy_optional(src,offset,parent_node) # nongreedy optionals break standard PEG
node = variant_node_class.new(parent_node, delimiter_pattern)
node.match parser.delimiter_pattern if root_rule?
pattern_elements.each do |pe|
return unless node.match(pe)
... | [
"def",
"parse",
"(",
"parent_node",
")",
"node",
"=",
"variant_node_class",
".",
"new",
"(",
"parent_node",
",",
"delimiter_pattern",
")",
"node",
".",
"match",
"parser",
".",
"delimiter_pattern",
"if",
"root_rule?",
"pattern_elements",
".",
"each",
"do",
"|",
... | returns a Node object if it matches, nil otherwise | [
"returns",
"a",
"Node",
"object",
"if",
"it",
"matches",
"nil",
"otherwise"
] | 415c6be1e3002b5eec96a8f1e3bcc7769eb29a57 | https://github.com/shanebdavis/Babel-Bridge/blob/415c6be1e3002b5eec96a8f1e3bcc7769eb29a57/lib/babel_bridge/rule_variant.rb#L41-L55 | train |
holtrop/rscons | lib/rscons/cache.rb | Rscons.Cache.write | def write
@cache["version"] = VERSION
File.open(CACHE_FILE, "w") do |fh|
fh.puts(JSON.dump(@cache))
end
end | ruby | def write
@cache["version"] = VERSION
File.open(CACHE_FILE, "w") do |fh|
fh.puts(JSON.dump(@cache))
end
end | [
"def",
"write",
"@cache",
"[",
"\"version\"",
"]",
"=",
"VERSION",
"File",
".",
"open",
"(",
"CACHE_FILE",
",",
"\"w\"",
")",
"do",
"|",
"fh",
"|",
"fh",
".",
"puts",
"(",
"JSON",
".",
"dump",
"(",
"@cache",
")",
")",
"end",
"end"
] | Write the cache to disk.
@return [void] | [
"Write",
"the",
"cache",
"to",
"disk",
"."
] | 4967f89a769a7b5c6ca91377526e3f53ceabd6a3 | https://github.com/holtrop/rscons/blob/4967f89a769a7b5c6ca91377526e3f53ceabd6a3/lib/rscons/cache.rb#L91-L96 | train |
holtrop/rscons | lib/rscons/cache.rb | Rscons.Cache.mkdir_p | def mkdir_p(path)
parts = path.split(/[\\\/]/)
parts.each_index do |i|
next if parts[i] == ""
subpath = File.join(*parts[0, i + 1])
unless File.exists?(subpath)
FileUtils.mkdir_p(subpath)
@cache["directories"][subpath] = true
end
end
end | ruby | def mkdir_p(path)
parts = path.split(/[\\\/]/)
parts.each_index do |i|
next if parts[i] == ""
subpath = File.join(*parts[0, i + 1])
unless File.exists?(subpath)
FileUtils.mkdir_p(subpath)
@cache["directories"][subpath] = true
end
end
end | [
"def",
"mkdir_p",
"(",
"path",
")",
"parts",
"=",
"path",
".",
"split",
"(",
"/",
"\\\\",
"\\/",
"/",
")",
"parts",
".",
"each_index",
"do",
"|",
"i",
"|",
"next",
"if",
"parts",
"[",
"i",
"]",
"==",
"\"\"",
"subpath",
"=",
"File",
".",
"join",
... | Make any needed directories and record the ones that are created for
removal upon a "clean" operation.
@param path [String] Directory to create.
@return [void] | [
"Make",
"any",
"needed",
"directories",
"and",
"record",
"the",
"ones",
"that",
"are",
"created",
"for",
"removal",
"upon",
"a",
"clean",
"operation",
"."
] | 4967f89a769a7b5c6ca91377526e3f53ceabd6a3 | https://github.com/holtrop/rscons/blob/4967f89a769a7b5c6ca91377526e3f53ceabd6a3/lib/rscons/cache.rb#L265-L275 | train |
holtrop/rscons | lib/rscons/cache.rb | Rscons.Cache.calculate_checksum | def calculate_checksum(file)
@lookup_checksums[file] = Digest::MD5.hexdigest(File.read(file, mode: "rb")) rescue ""
end | ruby | def calculate_checksum(file)
@lookup_checksums[file] = Digest::MD5.hexdigest(File.read(file, mode: "rb")) rescue ""
end | [
"def",
"calculate_checksum",
"(",
"file",
")",
"@lookup_checksums",
"[",
"file",
"]",
"=",
"Digest",
"::",
"MD5",
".",
"hexdigest",
"(",
"File",
".",
"read",
"(",
"file",
",",
"mode",
":",
"\"rb\"",
")",
")",
"rescue",
"\"\"",
"end"
] | Calculate and return a file's checksum.
@param file [String] The file name.
@return [String] The file's checksum. | [
"Calculate",
"and",
"return",
"a",
"file",
"s",
"checksum",
"."
] | 4967f89a769a7b5c6ca91377526e3f53ceabd6a3 | https://github.com/holtrop/rscons/blob/4967f89a769a7b5c6ca91377526e3f53ceabd6a3/lib/rscons/cache.rb#L330-L332 | train |
reset/chozo | lib/chozo/mixin/from_file.rb | Chozo::Mixin.FromFile.from_file | def from_file(filename)
filename = filename.to_s
if File.exists?(filename) && File.readable?(filename)
self.instance_eval(IO.read(filename), filename, 1)
self
else
raise IOError, "Could not open or read: '#{filename}'"
end
end | ruby | def from_file(filename)
filename = filename.to_s
if File.exists?(filename) && File.readable?(filename)
self.instance_eval(IO.read(filename), filename, 1)
self
else
raise IOError, "Could not open or read: '#{filename}'"
end
end | [
"def",
"from_file",
"(",
"filename",
")",
"filename",
"=",
"filename",
".",
"to_s",
"if",
"File",
".",
"exists?",
"(",
"filename",
")",
"&&",
"File",
".",
"readable?",
"(",
"filename",
")",
"self",
".",
"instance_eval",
"(",
"IO",
".",
"read",
"(",
"fi... | Loads the contents of a file within the context of the current object
@param [#to_s] filename
path to the file to load
@raise [IOError] if the file does not exist or cannot be read | [
"Loads",
"the",
"contents",
"of",
"a",
"file",
"within",
"the",
"context",
"of",
"the",
"current",
"object"
] | ba88aff29bef4b2f56090a8ad1a4ba5a165786e8 | https://github.com/reset/chozo/blob/ba88aff29bef4b2f56090a8ad1a4ba5a165786e8/lib/chozo/mixin/from_file.rb#L26-L35 | train |
reset/chozo | lib/chozo/mixin/from_file.rb | Chozo::Mixin.FromFile.class_from_file | def class_from_file(filename)
filename = filename.to_s
if File.exists?(filename) && File.readable?(filename)
self.class_eval(IO.read(filename), filename, 1)
self
else
raise IOError, "Could not open or read: '#{filename}'"
end
end | ruby | def class_from_file(filename)
filename = filename.to_s
if File.exists?(filename) && File.readable?(filename)
self.class_eval(IO.read(filename), filename, 1)
self
else
raise IOError, "Could not open or read: '#{filename}'"
end
end | [
"def",
"class_from_file",
"(",
"filename",
")",
"filename",
"=",
"filename",
".",
"to_s",
"if",
"File",
".",
"exists?",
"(",
"filename",
")",
"&&",
"File",
".",
"readable?",
"(",
"filename",
")",
"self",
".",
"class_eval",
"(",
"IO",
".",
"read",
"(",
... | Loads the contents of a file within the context of the current object's class
@param [#to_s] filename
path to the file to load
@raise [IOError] if the file does not exist or cannot be read | [
"Loads",
"the",
"contents",
"of",
"a",
"file",
"within",
"the",
"context",
"of",
"the",
"current",
"object",
"s",
"class"
] | ba88aff29bef4b2f56090a8ad1a4ba5a165786e8 | https://github.com/reset/chozo/blob/ba88aff29bef4b2f56090a8ad1a4ba5a165786e8/lib/chozo/mixin/from_file.rb#L43-L52 | train |
shanebdavis/Babel-Bridge | lib/babel_bridge/pattern_element.rb | BabelBridge.PatternElement.parse | def parse(parent_node)
# run element parser
begin
parent_node.parser.matching_negative if negative
match = parser.call(parent_node)
ensure
parent_node.parser.unmatching_negative if negative
end
# Negative patterns (PEG: !element)
match = match ? nil : EmptyNode.new(parent_nod... | ruby | def parse(parent_node)
# run element parser
begin
parent_node.parser.matching_negative if negative
match = parser.call(parent_node)
ensure
parent_node.parser.unmatching_negative if negative
end
# Negative patterns (PEG: !element)
match = match ? nil : EmptyNode.new(parent_nod... | [
"def",
"parse",
"(",
"parent_node",
")",
"begin",
"parent_node",
".",
"parser",
".",
"matching_negative",
"if",
"negative",
"match",
"=",
"parser",
".",
"call",
"(",
"parent_node",
")",
"ensure",
"parent_node",
".",
"parser",
".",
"unmatching_negative",
"if",
... | attempt to match the pattern defined in self.parser in parent_node.src starting at offset parent_node.next | [
"attempt",
"to",
"match",
"the",
"pattern",
"defined",
"in",
"self",
".",
"parser",
"in",
"parent_node",
".",
"src",
"starting",
"at",
"offset",
"parent_node",
".",
"next"
] | 415c6be1e3002b5eec96a8f1e3bcc7769eb29a57 | https://github.com/shanebdavis/Babel-Bridge/blob/415c6be1e3002b5eec96a8f1e3bcc7769eb29a57/lib/babel_bridge/pattern_element.rb#L54-L82 | train |
shanebdavis/Babel-Bridge | lib/babel_bridge/pattern_element.rb | BabelBridge.PatternElement.init_rule | def init_rule(rule_name)
rule_name.to_s[/^([^?!]*)([?!])?$/]
rule_name = $1.to_sym
option = $2
match_rule = rules[rule_name]
raise "no rule for #{rule_name}" unless match_rule
self.parser = lambda {|parent_node| match_rule.parse(parent_node)}
self.name ||= rule_name
case option
when... | ruby | def init_rule(rule_name)
rule_name.to_s[/^([^?!]*)([?!])?$/]
rule_name = $1.to_sym
option = $2
match_rule = rules[rule_name]
raise "no rule for #{rule_name}" unless match_rule
self.parser = lambda {|parent_node| match_rule.parse(parent_node)}
self.name ||= rule_name
case option
when... | [
"def",
"init_rule",
"(",
"rule_name",
")",
"rule_name",
".",
"to_s",
"[",
"/",
"/",
"]",
"rule_name",
"=",
"$1",
".",
"to_sym",
"option",
"=",
"$2",
"match_rule",
"=",
"rules",
"[",
"rule_name",
"]",
"raise",
"\"no rule for #{rule_name}\"",
"unless",
"match_... | initialize PatternElement as a parser that matches a named sub-rule | [
"initialize",
"PatternElement",
"as",
"a",
"parser",
"that",
"matches",
"a",
"named",
"sub",
"-",
"rule"
] | 415c6be1e3002b5eec96a8f1e3bcc7769eb29a57 | https://github.com/shanebdavis/Babel-Bridge/blob/415c6be1e3002b5eec96a8f1e3bcc7769eb29a57/lib/babel_bridge/pattern_element.rb#L120-L133 | train |
shanebdavis/Babel-Bridge | lib/babel_bridge/pattern_element.rb | BabelBridge.PatternElement.init_hash | def init_hash(hash)
if hash[:parser]
self.parser=hash[:parser]
elsif hash[:many]
init_many hash
elsif hash[:match]
init hash[:match]
elsif hash[:any]
init_any hash[:any]
else
raise "extended-options patterns (specified by a hash) must have either :parser=> or a :match=>... | ruby | def init_hash(hash)
if hash[:parser]
self.parser=hash[:parser]
elsif hash[:many]
init_many hash
elsif hash[:match]
init hash[:match]
elsif hash[:any]
init_any hash[:any]
else
raise "extended-options patterns (specified by a hash) must have either :parser=> or a :match=>... | [
"def",
"init_hash",
"(",
"hash",
")",
"if",
"hash",
"[",
":parser",
"]",
"self",
".",
"parser",
"=",
"hash",
"[",
":parser",
"]",
"elsif",
"hash",
"[",
":many",
"]",
"init_many",
"hash",
"elsif",
"hash",
"[",
":match",
"]",
"init",
"hash",
"[",
":mat... | initialize the PatternElement from hashed parameters | [
"initialize",
"the",
"PatternElement",
"from",
"hashed",
"parameters"
] | 415c6be1e3002b5eec96a8f1e3bcc7769eb29a57 | https://github.com/shanebdavis/Babel-Bridge/blob/415c6be1e3002b5eec96a8f1e3bcc7769eb29a57/lib/babel_bridge/pattern_element.rb#L159-L176 | train |
PRX/google_speech | lib/google_speech/chunk_factory.rb | GoogleSpeech.ChunkFactory.each | def each
pos = 0
while(pos < @original_duration) do
chunk = nil
begin
chunk = Chunk.new(@original_file, @original_duration, pos, (@chunk_duration + @overlap), @rate)
yield chunk
pos = pos + [chunk.duration, @chunk_duration].min
ensure
chunk.clo... | ruby | def each
pos = 0
while(pos < @original_duration) do
chunk = nil
begin
chunk = Chunk.new(@original_file, @original_duration, pos, (@chunk_duration + @overlap), @rate)
yield chunk
pos = pos + [chunk.duration, @chunk_duration].min
ensure
chunk.clo... | [
"def",
"each",
"pos",
"=",
"0",
"while",
"(",
"pos",
"<",
"@original_duration",
")",
"do",
"chunk",
"=",
"nil",
"begin",
"chunk",
"=",
"Chunk",
".",
"new",
"(",
"@original_file",
",",
"@original_duration",
",",
"pos",
",",
"(",
"@chunk_duration",
"+",
"@... | return temp file for each chunk | [
"return",
"temp",
"file",
"for",
"each",
"chunk"
] | a073bfcffc318013c740edd6e6e1de91a60a31bd | https://github.com/PRX/google_speech/blob/a073bfcffc318013c740edd6e6e1de91a60a31bd/lib/google_speech/chunk_factory.rb#L18-L30 | train |
chef-workflow/chef-workflow | lib/chef-workflow/support/ssh.rb | ChefWorkflow.SSHHelper.ssh_role_command | def ssh_role_command(role, command)
t = []
ChefWorkflow::IPSupport.get_role_ips(role).each do |ip|
t.push(
Thread.new do
ssh_command(ip, command)
end
)
end
t.each(&:join)
end | ruby | def ssh_role_command(role, command)
t = []
ChefWorkflow::IPSupport.get_role_ips(role).each do |ip|
t.push(
Thread.new do
ssh_command(ip, command)
end
)
end
t.each(&:join)
end | [
"def",
"ssh_role_command",
"(",
"role",
",",
"command",
")",
"t",
"=",
"[",
"]",
"ChefWorkflow",
"::",
"IPSupport",
".",
"get_role_ips",
"(",
"role",
")",
".",
"each",
"do",
"|",
"ip",
"|",
"t",
".",
"push",
"(",
"Thread",
".",
"new",
"do",
"ssh_comm... | run a command against a group of servers. These commands are run in
parallel, but the command itself does not complete until all the threads
have finished running. | [
"run",
"a",
"command",
"against",
"a",
"group",
"of",
"servers",
".",
"These",
"commands",
"are",
"run",
"in",
"parallel",
"but",
"the",
"command",
"itself",
"does",
"not",
"complete",
"until",
"all",
"the",
"threads",
"have",
"finished",
"running",
"."
] | 956c8f6cd694dacc25dfa405d70b05b12b7c1691 | https://github.com/chef-workflow/chef-workflow/blob/956c8f6cd694dacc25dfa405d70b05b12b7c1691/lib/chef-workflow/support/ssh.rb#L19-L29 | train |
chef-workflow/chef-workflow | lib/chef-workflow/support/ssh.rb | ChefWorkflow.SSHHelper.ssh_command | def ssh_command(ip, command)
configure_ssh_command(ip, command) do |ch, success|
return 1 unless success
if_debug(2) do
ch.on_data do |ch, data|
$stderr.puts data
end
end
ch.on_request("exit-status") do |ch, data|
return data.read_long
... | ruby | def ssh_command(ip, command)
configure_ssh_command(ip, command) do |ch, success|
return 1 unless success
if_debug(2) do
ch.on_data do |ch, data|
$stderr.puts data
end
end
ch.on_request("exit-status") do |ch, data|
return data.read_long
... | [
"def",
"ssh_command",
"(",
"ip",
",",
"command",
")",
"configure_ssh_command",
"(",
"ip",
",",
"command",
")",
"do",
"|",
"ch",
",",
"success",
"|",
"return",
"1",
"unless",
"success",
"if_debug",
"(",
"2",
")",
"do",
"ch",
".",
"on_data",
"do",
"|",
... | Run a command against a single IP. Returns the exit status. | [
"Run",
"a",
"command",
"against",
"a",
"single",
"IP",
".",
"Returns",
"the",
"exit",
"status",
"."
] | 956c8f6cd694dacc25dfa405d70b05b12b7c1691 | https://github.com/chef-workflow/chef-workflow/blob/956c8f6cd694dacc25dfa405d70b05b12b7c1691/lib/chef-workflow/support/ssh.rb#L70-L84 | train |
chef-workflow/chef-workflow | lib/chef-workflow/support/ssh.rb | ChefWorkflow.SSHHelper.ssh_capture | def ssh_capture(ip, command)
retval = ""
configure_ssh_command(ip, command) do |ch, success|
return "" unless success
ch.on_data do |ch, data|
retval << data
end
ch.on_request("exit-status") do |ch, data|
return retval
end
end
return... | ruby | def ssh_capture(ip, command)
retval = ""
configure_ssh_command(ip, command) do |ch, success|
return "" unless success
ch.on_data do |ch, data|
retval << data
end
ch.on_request("exit-status") do |ch, data|
return retval
end
end
return... | [
"def",
"ssh_capture",
"(",
"ip",
",",
"command",
")",
"retval",
"=",
"\"\"",
"configure_ssh_command",
"(",
"ip",
",",
"command",
")",
"do",
"|",
"ch",
",",
"success",
"|",
"return",
"\"\"",
"unless",
"success",
"ch",
".",
"on_data",
"do",
"|",
"ch",
",... | run a command, and instead of capturing the exit status, return the data
captured during the command run. | [
"run",
"a",
"command",
"and",
"instead",
"of",
"capturing",
"the",
"exit",
"status",
"return",
"the",
"data",
"captured",
"during",
"the",
"command",
"run",
"."
] | 956c8f6cd694dacc25dfa405d70b05b12b7c1691 | https://github.com/chef-workflow/chef-workflow/blob/956c8f6cd694dacc25dfa405d70b05b12b7c1691/lib/chef-workflow/support/ssh.rb#L90-L105 | train |
chef-workflow/chef-workflow | lib/chef-workflow/support/ec2.rb | ChefWorkflow.EC2Support.create_security_group | def create_security_group
aws_ec2 = ec2_obj
name = nil
loop do
name = 'chef-workflow-' + (0..rand(10).to_i).map { rand(0..9).to_s }.join("")
if_debug(3) do
$stderr.puts "Seeing if security group name #{name} is taken"
end
break unless aws_ec2.security_grou... | ruby | def create_security_group
aws_ec2 = ec2_obj
name = nil
loop do
name = 'chef-workflow-' + (0..rand(10).to_i).map { rand(0..9).to_s }.join("")
if_debug(3) do
$stderr.puts "Seeing if security group name #{name} is taken"
end
break unless aws_ec2.security_grou... | [
"def",
"create_security_group",
"aws_ec2",
"=",
"ec2_obj",
"name",
"=",
"nil",
"loop",
"do",
"name",
"=",
"'chef-workflow-'",
"+",
"(",
"0",
"..",
"rand",
"(",
"10",
")",
".",
"to_i",
")",
".",
"map",
"{",
"rand",
"(",
"0",
"..",
"9",
")",
".",
"to... | Creates a security group and saves it to the security_group_setting_path. | [
"Creates",
"a",
"security",
"group",
"and",
"saves",
"it",
"to",
"the",
"security_group_setting_path",
"."
] | 956c8f6cd694dacc25dfa405d70b05b12b7c1691 | https://github.com/chef-workflow/chef-workflow/blob/956c8f6cd694dacc25dfa405d70b05b12b7c1691/lib/chef-workflow/support/ec2.rb#L57-L86 | train |
chef-workflow/chef-workflow | lib/chef-workflow/support/ec2.rb | ChefWorkflow.EC2Support.assert_security_groups | def assert_security_groups
aws_ec2 = ec2_obj
if security_groups == :auto
loaded_groups = load_security_group
# this will make it hit the second block everytime from now on (and
# bootstrap it recursively)
if loaded_groups
self.security_groups loaded_groups
... | ruby | def assert_security_groups
aws_ec2 = ec2_obj
if security_groups == :auto
loaded_groups = load_security_group
# this will make it hit the second block everytime from now on (and
# bootstrap it recursively)
if loaded_groups
self.security_groups loaded_groups
... | [
"def",
"assert_security_groups",
"aws_ec2",
"=",
"ec2_obj",
"if",
"security_groups",
"==",
":auto",
"loaded_groups",
"=",
"load_security_group",
"if",
"loaded_groups",
"self",
".",
"security_groups",
"loaded_groups",
"assert_security_groups",
"else",
"self",
".",
"securit... | Ensures security groups exist.
If @security_groups is :auto, creates one and sets it up with the
security_group_open_ports on TCP and UDP.
If @security_groups is an array of group names or a single group name,
asserts they exist. If they do not exist, it raises. | [
"Ensures",
"security",
"groups",
"exist",
"."
] | 956c8f6cd694dacc25dfa405d70b05b12b7c1691 | https://github.com/chef-workflow/chef-workflow/blob/956c8f6cd694dacc25dfa405d70b05b12b7c1691/lib/chef-workflow/support/ec2.rb#L104-L136 | train |
itrp/itrp-client | lib/itrp/client/response.rb | Itrp.Response.json | def json
return @json if defined?(@json)
# no content, no JSON
if @response.code.to_s == '204'
data = {}
elsif @response.body.blank?
# no body, no json
data = {message: @response.message.blank? ? 'empty body' : @response.message.strip}
end
begin
data |... | ruby | def json
return @json if defined?(@json)
# no content, no JSON
if @response.code.to_s == '204'
data = {}
elsif @response.body.blank?
# no body, no json
data = {message: @response.message.blank? ? 'empty body' : @response.message.strip}
end
begin
data |... | [
"def",
"json",
"return",
"@json",
"if",
"defined?",
"(",
"@json",
")",
"if",
"@response",
".",
"code",
".",
"to_s",
"==",
"'204'",
"data",
"=",
"{",
"}",
"elsif",
"@response",
".",
"body",
".",
"blank?",
"data",
"=",
"{",
"message",
":",
"@response",
... | The JSON value, if single resource is queried this is a Hash, if multiple resources where queried it is an Array
If the response is not +valid?+ it is a Hash with 'message' and optionally 'errors' | [
"The",
"JSON",
"value",
"if",
"single",
"resource",
"is",
"queried",
"this",
"is",
"a",
"Hash",
"if",
"multiple",
"resources",
"where",
"queried",
"it",
"is",
"an",
"Array",
"If",
"the",
"response",
"is",
"not",
"+",
"valid?",
"+",
"it",
"is",
"a",
"Ha... | 80294aa93d7a64c1966d06d4f12ed24b606e3078 | https://github.com/itrp/itrp-client/blob/80294aa93d7a64c1966d06d4f12ed24b606e3078/lib/itrp/client/response.rb#L23-L44 | train |
itrp/itrp-client | lib/itrp/client/response.rb | Itrp.Response.[] | def[](*keys)
values = json.is_a?(Array) ? json : [json]
keys.each { |key| values = values.map{ |value| value.is_a?(Hash) ? value[key] : nil} }
json.is_a?(Array) ? values : values.first
end | ruby | def[](*keys)
values = json.is_a?(Array) ? json : [json]
keys.each { |key| values = values.map{ |value| value.is_a?(Hash) ? value[key] : nil} }
json.is_a?(Array) ? values : values.first
end | [
"def",
"[]",
"(",
"*",
"keys",
")",
"values",
"=",
"json",
".",
"is_a?",
"(",
"Array",
")",
"?",
"json",
":",
"[",
"json",
"]",
"keys",
".",
"each",
"{",
"|",
"key",
"|",
"values",
"=",
"values",
".",
"map",
"{",
"|",
"value",
"|",
"value",
"... | retrieve a value from the resource
if the JSON value is an Array a array with the value for each resource will be given
@param keys: a single key or a key-path separated by comma | [
"retrieve",
"a",
"value",
"from",
"the",
"resource",
"if",
"the",
"JSON",
"value",
"is",
"an",
"Array",
"a",
"array",
"with",
"the",
"value",
"for",
"each",
"resource",
"will",
"be",
"given"
] | 80294aa93d7a64c1966d06d4f12ed24b606e3078 | https://github.com/itrp/itrp-client/blob/80294aa93d7a64c1966d06d4f12ed24b606e3078/lib/itrp/client/response.rb#L65-L69 | train |
Subsets and Splits
No community queries yet
The top public SQL queries from the community will appear here once available.