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 |
|---|---|---|---|---|---|---|---|---|---|---|---|
dorack/jiralicious | lib/jiralicious/session.rb | Jiralicious.Session.request | def request(method, *options)
response_handler = if options.last.is_a?(Hash) && options.last[:handler]
options.last.delete(:handler)
else
handler
end
self.class.base_uri Jiralicious.uri
before_requ... | ruby | def request(method, *options)
response_handler = if options.last.is_a?(Hash) && options.last[:handler]
options.last.delete(:handler)
else
handler
end
self.class.base_uri Jiralicious.uri
before_requ... | [
"def",
"request",
"(",
"method",
",",
"*",
"options",
")",
"response_handler",
"=",
"if",
"options",
".",
"last",
".",
"is_a?",
"(",
"Hash",
")",
"&&",
"options",
".",
"last",
"[",
":handler",
"]",
"options",
".",
"last",
".",
"delete",
"(",
":handler"... | Main access method to request data from the Jira API
[Arguments]
:method (required) http method type
:options (required) request specific options | [
"Main",
"access",
"method",
"to",
"request",
"data",
"from",
"the",
"Jira",
"API"
] | e907cba8618fb15893b62666e195a5288a9899d8 | https://github.com/dorack/jiralicious/blob/e907cba8618fb15893b62666e195a5288a9899d8/lib/jiralicious/session.rb#L25-L38 | train |
theforeman/staypuft | app/models/staypuft/deployment.rb | Staypuft.Deployment.update_hostgroup_list | def update_hostgroup_list
old_deployment_role_hostgroups = deployment_role_hostgroups.to_a
new_deployment_role_hostgroups = layout.layout_roles.map do |layout_role|
deployment_role_hostgroup = deployment_role_hostgroups.where(:role_id => layout_role.role).first_or_initialize do |drh|
drh.h... | ruby | def update_hostgroup_list
old_deployment_role_hostgroups = deployment_role_hostgroups.to_a
new_deployment_role_hostgroups = layout.layout_roles.map do |layout_role|
deployment_role_hostgroup = deployment_role_hostgroups.where(:role_id => layout_role.role).first_or_initialize do |drh|
drh.h... | [
"def",
"update_hostgroup_list",
"old_deployment_role_hostgroups",
"=",
"deployment_role_hostgroups",
".",
"to_a",
"new_deployment_role_hostgroups",
"=",
"layout",
".",
"layout_roles",
".",
"map",
"do",
"|",
"layout_role",
"|",
"deployment_role_hostgroup",
"=",
"deployment_rol... | After setting or changing layout, update the set of child hostgroups,
adding groups for any roles not already represented, and removing others
no longer needed. | [
"After",
"setting",
"or",
"changing",
"layout",
"update",
"the",
"set",
"of",
"child",
"hostgroups",
"adding",
"groups",
"for",
"any",
"roles",
"not",
"already",
"represented",
"and",
"removing",
"others",
"no",
"longer",
"needed",
"."
] | 58b0dec6a027bb6fb10c5db4dc5e4430faba8e6f | https://github.com/theforeman/staypuft/blob/58b0dec6a027bb6fb10c5db4dc5e4430faba8e6f/app/models/staypuft/deployment.rb#L353-L374 | train |
dorack/jiralicious | lib/jiralicious/versions.rb | Jiralicious.Version.update | def update(details)
details.each do |k, v|
send("#{k}=", v)
end
self.class.update(version_key, details)
end | ruby | def update(details)
details.each do |k, v|
send("#{k}=", v)
end
self.class.update(version_key, details)
end | [
"def",
"update",
"(",
"details",
")",
"details",
".",
"each",
"do",
"|",
"k",
",",
"v",
"|",
"send",
"(",
"\"#{k}=\"",
",",
"v",
")",
"end",
"self",
".",
"class",
".",
"update",
"(",
"version_key",
",",
"details",
")",
"end"
] | Updates a version
[Arguments]
:details (required) Details of the version to be updated | [
"Updates",
"a",
"version"
] | e907cba8618fb15893b62666e195a5288a9899d8 | https://github.com/dorack/jiralicious/blob/e907cba8618fb15893b62666e195a5288a9899d8/lib/jiralicious/versions.rb#L136-L141 | train |
dorack/jiralicious | lib/jiralicious/oauth_session.rb | Jiralicious.OauthSession.get_secret | def get_secret
if Jiralicious.oauth_secret.nil?
IO.read(Jiralicious.config_path + Jiralicious.oauth_secret_filename)
else
Jiralicious.oauth_secret
end
end | ruby | def get_secret
if Jiralicious.oauth_secret.nil?
IO.read(Jiralicious.config_path + Jiralicious.oauth_secret_filename)
else
Jiralicious.oauth_secret
end
end | [
"def",
"get_secret",
"if",
"Jiralicious",
".",
"oauth_secret",
".",
"nil?",
"IO",
".",
"read",
"(",
"Jiralicious",
".",
"config_path",
"+",
"Jiralicious",
".",
"oauth_secret_filename",
")",
"else",
"Jiralicious",
".",
"oauth_secret",
"end",
"end"
] | returns the oauth_secret parameter or the file | [
"returns",
"the",
"oauth_secret",
"parameter",
"or",
"the",
"file"
] | e907cba8618fb15893b62666e195a5288a9899d8 | https://github.com/dorack/jiralicious/blob/e907cba8618fb15893b62666e195a5288a9899d8/lib/jiralicious/oauth_session.rb#L102-L108 | train |
dorack/jiralicious | lib/jiralicious/oauth_session.rb | Jiralicious.OauthSession.handler | def handler
proc do |response|
case response.code
when 200..204
response
else
message = response.body
message = message["errorMessages"].join('\n') if message.is_a?(Hash)
Jiralicious::JiraError.new(message)
end
end
end | ruby | def handler
proc do |response|
case response.code
when 200..204
response
else
message = response.body
message = message["errorMessages"].join('\n') if message.is_a?(Hash)
Jiralicious::JiraError.new(message)
end
end
end | [
"def",
"handler",
"proc",
"do",
"|",
"response",
"|",
"case",
"response",
".",
"code",
"when",
"200",
"..",
"204",
"response",
"else",
"message",
"=",
"response",
".",
"body",
"message",
"=",
"message",
"[",
"\"errorMessages\"",
"]",
".",
"join",
"(",
"'... | Configures the default handler. This can be overridden in
the child class to provide additional error handling. | [
"Configures",
"the",
"default",
"handler",
".",
"This",
"can",
"be",
"overridden",
"in",
"the",
"child",
"class",
"to",
"provide",
"additional",
"error",
"handling",
"."
] | e907cba8618fb15893b62666e195a5288a9899d8 | https://github.com/dorack/jiralicious/blob/e907cba8618fb15893b62666e195a5288a9899d8/lib/jiralicious/oauth_session.rb#L114-L125 | train |
dorack/jiralicious | lib/jiralicious/cookie_session.rb | Jiralicious.CookieSession.after_request | def after_request(response)
unless @authenticating
if captcha_required(response) # rubocop:disable Style/GuardClause
raise Jiralicious::CaptchaRequired, "Captacha is required. Try logging into Jira via the web interface"
elsif cookie_invalid(response)
# Can usually be fixed by ... | ruby | def after_request(response)
unless @authenticating
if captcha_required(response) # rubocop:disable Style/GuardClause
raise Jiralicious::CaptchaRequired, "Captacha is required. Try logging into Jira via the web interface"
elsif cookie_invalid(response)
# Can usually be fixed by ... | [
"def",
"after_request",
"(",
"response",
")",
"unless",
"@authenticating",
"if",
"captcha_required",
"(",
"response",
")",
"raise",
"Jiralicious",
"::",
"CaptchaRequired",
",",
"\"Captacha is required. Try logging into Jira via the web interface\"",
"elsif",
"cookie_invalid",
... | Handles the response from the request | [
"Handles",
"the",
"response",
"from",
"the",
"request"
] | e907cba8618fb15893b62666e195a5288a9899d8 | https://github.com/dorack/jiralicious/blob/e907cba8618fb15893b62666e195a5288a9899d8/lib/jiralicious/cookie_session.rb#L24-L35 | train |
dorack/jiralicious | lib/jiralicious/cookie_session.rb | Jiralicious.CookieSession.login | def login
@authenticating = true
handler = proc do |response|
if response.code == 200
@session = response["session"]
@login_info = response["loginInfo"]
self.class.cookies(session["name"] => session["value"])
else
clear_session
case response.... | ruby | def login
@authenticating = true
handler = proc do |response|
if response.code == 200
@session = response["session"]
@login_info = response["loginInfo"]
self.class.cookies(session["name"] => session["value"])
else
clear_session
case response.... | [
"def",
"login",
"@authenticating",
"=",
"true",
"handler",
"=",
"proc",
"do",
"|",
"response",
"|",
"if",
"response",
".",
"code",
"==",
"200",
"@session",
"=",
"response",
"[",
"\"session\"",
"]",
"@login_info",
"=",
"response",
"[",
"\"loginInfo\"",
"]",
... | Authenticates the login | [
"Authenticates",
"the",
"login"
] | e907cba8618fb15893b62666e195a5288a9899d8 | https://github.com/dorack/jiralicious/blob/e907cba8618fb15893b62666e195a5288a9899d8/lib/jiralicious/cookie_session.rb#L38-L67 | train |
dorack/jiralicious | lib/jiralicious/cookie_session.rb | Jiralicious.CookieSession.logout | def logout
handler = proc do
if response.code == 204
clear_session
else
case response.code
when 401 then
raise Jiralicious::NotLoggedIn, "Not logged in"
else
# Give Net::HTTP reason
raise Jiralicious::JiraError, response
... | ruby | def logout
handler = proc do
if response.code == 204
clear_session
else
case response.code
when 401 then
raise Jiralicious::NotLoggedIn, "Not logged in"
else
# Give Net::HTTP reason
raise Jiralicious::JiraError, response
... | [
"def",
"logout",
"handler",
"=",
"proc",
"do",
"if",
"response",
".",
"code",
"==",
"204",
"clear_session",
"else",
"case",
"response",
".",
"code",
"when",
"401",
"then",
"raise",
"Jiralicious",
"::",
"NotLoggedIn",
",",
"\"Not logged in\"",
"else",
"raise",
... | Logs out of the API | [
"Logs",
"out",
"of",
"the",
"API"
] | e907cba8618fb15893b62666e195a5288a9899d8 | https://github.com/dorack/jiralicious/blob/e907cba8618fb15893b62666e195a5288a9899d8/lib/jiralicious/cookie_session.rb#L70-L86 | train |
dorack/jiralicious | lib/jiralicious/issue.rb | Jiralicious.Issue.save | def save
if loaded?
self.class.update(@fields.format_for_update, jira_key)
else
response = self.class.create(@fields.format_for_create)
self.jira_key = response.parsed_response["key"]
end
jira_key
end | ruby | def save
if loaded?
self.class.update(@fields.format_for_update, jira_key)
else
response = self.class.create(@fields.format_for_create)
self.jira_key = response.parsed_response["key"]
end
jira_key
end | [
"def",
"save",
"if",
"loaded?",
"self",
".",
"class",
".",
"update",
"(",
"@fields",
".",
"format_for_update",
",",
"jira_key",
")",
"else",
"response",
"=",
"self",
".",
"class",
".",
"create",
"(",
"@fields",
".",
"format_for_create",
")",
"self",
".",
... | Saves the current Issue but does not update itself. | [
"Saves",
"the",
"current",
"Issue",
"but",
"does",
"not",
"update",
"itself",
"."
] | e907cba8618fb15893b62666e195a5288a9899d8 | https://github.com/dorack/jiralicious/blob/e907cba8618fb15893b62666e195a5288a9899d8/lib/jiralicious/issue.rb#L253-L261 | train |
leonhartX/danger-eslint | lib/eslint/plugin.rb | Danger.DangerEslint.lint_results | def lint_results
bin = eslint_path
raise 'eslint is not installed' unless bin
return run_lint(bin, '.') unless filtering
((git.modified_files - git.deleted_files) + git.added_files)
.select { |f| f.end_with? '.js' }
.map { |f| f.gsub("#{Dir.pwd}/", '') }
.map { |f| run_li... | ruby | def lint_results
bin = eslint_path
raise 'eslint is not installed' unless bin
return run_lint(bin, '.') unless filtering
((git.modified_files - git.deleted_files) + git.added_files)
.select { |f| f.end_with? '.js' }
.map { |f| f.gsub("#{Dir.pwd}/", '') }
.map { |f| run_li... | [
"def",
"lint_results",
"bin",
"=",
"eslint_path",
"raise",
"'eslint is not installed'",
"unless",
"bin",
"return",
"run_lint",
"(",
"bin",
",",
"'.'",
")",
"unless",
"filtering",
"(",
"(",
"git",
".",
"modified_files",
"-",
"git",
".",
"deleted_files",
")",
"+... | Get lint result regards the filtering option
return [Hash] | [
"Get",
"lint",
"result",
"regards",
"the",
"filtering",
"option"
] | f51dca105e8c87326b35a27e9a349cd486e7a5e2 | https://github.com/leonhartX/danger-eslint/blob/f51dca105e8c87326b35a27e9a349cd486e7a5e2/lib/eslint/plugin.rb#L55-L63 | train |
leonhartX/danger-eslint | lib/eslint/plugin.rb | Danger.DangerEslint.send_comment | def send_comment(results)
dir = "#{Dir.pwd}/"
results['messages'].each do |r|
filename = results['filePath'].gsub(dir, '')
method = r['severity'] > 1 ? 'fail' : 'warn'
send(method, r['message'], file: filename, line: r['line'])
end
end | ruby | def send_comment(results)
dir = "#{Dir.pwd}/"
results['messages'].each do |r|
filename = results['filePath'].gsub(dir, '')
method = r['severity'] > 1 ? 'fail' : 'warn'
send(method, r['message'], file: filename, line: r['line'])
end
end | [
"def",
"send_comment",
"(",
"results",
")",
"dir",
"=",
"\"#{Dir.pwd}/\"",
"results",
"[",
"'messages'",
"]",
".",
"each",
"do",
"|",
"r",
"|",
"filename",
"=",
"results",
"[",
"'filePath'",
"]",
".",
"gsub",
"(",
"dir",
",",
"''",
")",
"method",
"=",
... | Send comment with danger's warn or fail method.
@return [void] | [
"Send",
"comment",
"with",
"danger",
"s",
"warn",
"or",
"fail",
"method",
"."
] | f51dca105e8c87326b35a27e9a349cd486e7a5e2 | https://github.com/leonhartX/danger-eslint/blob/f51dca105e8c87326b35a27e9a349cd486e7a5e2/lib/eslint/plugin.rb#L85-L92 | train |
dorack/jiralicious | lib/jiralicious/component.rb | Jiralicious.Component.update | def update(details)
details.each do |k, v|
send("#{k}=", v)
end
self.class.update(component_key, details)
end | ruby | def update(details)
details.each do |k, v|
send("#{k}=", v)
end
self.class.update(component_key, details)
end | [
"def",
"update",
"(",
"details",
")",
"details",
".",
"each",
"do",
"|",
"k",
",",
"v",
"|",
"send",
"(",
"\"#{k}=\"",
",",
"v",
")",
"end",
"self",
".",
"class",
".",
"update",
"(",
"component_key",
",",
"details",
")",
"end"
] | Updates a component
[Arguments]
:details (required) Details of the component to be updated | [
"Updates",
"a",
"component"
] | e907cba8618fb15893b62666e195a5288a9899d8 | https://github.com/dorack/jiralicious/blob/e907cba8618fb15893b62666e195a5288a9899d8/lib/jiralicious/component.rb#L94-L99 | train |
dorack/jiralicious | lib/jiralicious/base.rb | Jiralicious.Base.method_missing | def method_missing(meth, *args, &block)
if !loaded?
self.loaded = true
reload
send(meth, *args, &block)
else
super
end
end | ruby | def method_missing(meth, *args, &block)
if !loaded?
self.loaded = true
reload
send(meth, *args, &block)
else
super
end
end | [
"def",
"method_missing",
"(",
"meth",
",",
"*",
"args",
",",
"&",
"block",
")",
"if",
"!",
"loaded?",
"self",
".",
"loaded",
"=",
"true",
"reload",
"send",
"(",
"meth",
",",
"*",
"args",
",",
"&",
"block",
")",
"else",
"super",
"end",
"end"
] | Overrides the default method_missing check. This override is used in lazy
loading to ensure that the requested field or method is truly unavailable.
[Arguments]
:meth (system)
:args (system)
:block (system) | [
"Overrides",
"the",
"default",
"method_missing",
"check",
".",
"This",
"override",
"is",
"used",
"in",
"lazy",
"loading",
"to",
"ensure",
"that",
"the",
"requested",
"field",
"or",
"method",
"is",
"truly",
"unavailable",
"."
] | e907cba8618fb15893b62666e195a5288a9899d8 | https://github.com/dorack/jiralicious/blob/e907cba8618fb15893b62666e195a5288a9899d8/lib/jiralicious/base.rb#L212-L220 | train |
dorack/jiralicious | lib/jiralicious/configuration.rb | Jiralicious.Configuration.options | def options
VALID_OPTIONS.inject({}) do |option, key|
option.merge!(key => send(key))
end
end | ruby | def options
VALID_OPTIONS.inject({}) do |option, key|
option.merge!(key => send(key))
end
end | [
"def",
"options",
"VALID_OPTIONS",
".",
"inject",
"(",
"{",
"}",
")",
"do",
"|",
"option",
",",
"key",
"|",
"option",
".",
"merge!",
"(",
"key",
"=>",
"send",
"(",
"key",
")",
")",
"end",
"end"
] | Pass options to set the values | [
"Pass",
"options",
"to",
"set",
"the",
"values"
] | e907cba8618fb15893b62666e195a5288a9899d8 | https://github.com/dorack/jiralicious/blob/e907cba8618fb15893b62666e195a5288a9899d8/lib/jiralicious/configuration.rb#L44-L48 | train |
dorack/jiralicious | lib/jiralicious/configuration.rb | Jiralicious.Configuration.reset | def reset
self.username = DEFAULT_USERNAME
self.password = DEFAULT_PASSWORD
self.uri = DEFAULT_URI
self.api_version = DEFAULT_API_VERSION
self.auth_type = DEFAULT_AUTH_TYPE
self.project = nil
self.oauth_secret = nil
self.oauth_secret_filename = nil
self.oauth_pass_p... | ruby | def reset
self.username = DEFAULT_USERNAME
self.password = DEFAULT_PASSWORD
self.uri = DEFAULT_URI
self.api_version = DEFAULT_API_VERSION
self.auth_type = DEFAULT_AUTH_TYPE
self.project = nil
self.oauth_secret = nil
self.oauth_secret_filename = nil
self.oauth_pass_p... | [
"def",
"reset",
"self",
".",
"username",
"=",
"DEFAULT_USERNAME",
"self",
".",
"password",
"=",
"DEFAULT_PASSWORD",
"self",
".",
"uri",
"=",
"DEFAULT_URI",
"self",
".",
"api_version",
"=",
"DEFAULT_API_VERSION",
"self",
".",
"auth_type",
"=",
"DEFAULT_AUTH_TYPE",
... | Resets all attributes to default values | [
"Resets",
"all",
"attributes",
"to",
"default",
"values"
] | e907cba8618fb15893b62666e195a5288a9899d8 | https://github.com/dorack/jiralicious/blob/e907cba8618fb15893b62666e195a5288a9899d8/lib/jiralicious/configuration.rb#L53-L65 | train |
dorack/jiralicious | lib/jiralicious/configuration.rb | Jiralicious.Configuration.load_yml | def load_yml(yml_file, mode = nil)
if File.exist?(yml_file)
yml_cfg = OpenStruct.new(YAML.load_file(yml_file))
if mode.nil? || mode =~ /production/i
yml_cfg.jira.each do |k, v|
instance_variable_set("@#{k}", v)
end
else
yml_cfg.send(mode).each do |... | ruby | def load_yml(yml_file, mode = nil)
if File.exist?(yml_file)
yml_cfg = OpenStruct.new(YAML.load_file(yml_file))
if mode.nil? || mode =~ /production/i
yml_cfg.jira.each do |k, v|
instance_variable_set("@#{k}", v)
end
else
yml_cfg.send(mode).each do |... | [
"def",
"load_yml",
"(",
"yml_file",
",",
"mode",
"=",
"nil",
")",
"if",
"File",
".",
"exist?",
"(",
"yml_file",
")",
"yml_cfg",
"=",
"OpenStruct",
".",
"new",
"(",
"YAML",
".",
"load_file",
"(",
"yml_file",
")",
")",
"if",
"mode",
".",
"nil?",
"||",
... | Loads the provided YML file.
Can provide either direct or relational path to the file.
It is recommended to send a direct path due to dynamic
loading and/or different file locations due to different deployment methods.
[Direct Path] /usr/project/somepath_to_file/jira.yml
[Relational Path] Rails.root.to_s + "/co... | [
"Loads",
"the",
"provided",
"YML",
"file",
"."
] | e907cba8618fb15893b62666e195a5288a9899d8 | https://github.com/dorack/jiralicious/blob/e907cba8618fb15893b62666e195a5288a9899d8/lib/jiralicious/configuration.rb#L85-L100 | train |
theforeman/staypuft | app/models/staypuft/interface_assigner.rb | Staypuft.InterfaceAssigner.unassign_physical | def unassign_physical(interface)
interface.ip = nil if interface.subnet.ipam?
interface.subnet_id = nil
unless interface.save
@errors.push(interface.errors.full_messages)
end
end | ruby | def unassign_physical(interface)
interface.ip = nil if interface.subnet.ipam?
interface.subnet_id = nil
unless interface.save
@errors.push(interface.errors.full_messages)
end
end | [
"def",
"unassign_physical",
"(",
"interface",
")",
"interface",
".",
"ip",
"=",
"nil",
"if",
"interface",
".",
"subnet",
".",
"ipam?",
"interface",
".",
"subnet_id",
"=",
"nil",
"unless",
"interface",
".",
"save",
"@errors",
".",
"push",
"(",
"interface",
... | if subnet has IP suggesting enabled we also clear the IP that was suggested
this IP will be used for another interface | [
"if",
"subnet",
"has",
"IP",
"suggesting",
"enabled",
"we",
"also",
"clear",
"the",
"IP",
"that",
"was",
"suggested",
"this",
"IP",
"will",
"be",
"used",
"for",
"another",
"interface"
] | 58b0dec6a027bb6fb10c5db4dc5e4430faba8e6f | https://github.com/theforeman/staypuft/blob/58b0dec6a027bb6fb10c5db4dc5e4430faba8e6f/app/models/staypuft/interface_assigner.rb#L120-L126 | train |
localytics/humidifier | lib/humidifier/loader.rb | Humidifier.Loader.load | def load
parsed = JSON.parse(File.read(SPECPATH))
structs = StructureContainer.new(parsed['PropertyTypes'])
parsed['ResourceTypes'].each do |key, spec|
match = key.match(/\A(\w+)::(\w+)::(\w+)\z/)
register(match[1], match[2], match[3], spec, structs.search(key))
end
end | ruby | def load
parsed = JSON.parse(File.read(SPECPATH))
structs = StructureContainer.new(parsed['PropertyTypes'])
parsed['ResourceTypes'].each do |key, spec|
match = key.match(/\A(\w+)::(\w+)::(\w+)\z/)
register(match[1], match[2], match[3], spec, structs.search(key))
end
end | [
"def",
"load",
"parsed",
"=",
"JSON",
".",
"parse",
"(",
"File",
".",
"read",
"(",
"SPECPATH",
")",
")",
"structs",
"=",
"StructureContainer",
".",
"new",
"(",
"parsed",
"[",
"'PropertyTypes'",
"]",
")",
"parsed",
"[",
"'ResourceTypes'",
"]",
".",
"each"... | loop through the specs and register each class | [
"loop",
"through",
"the",
"specs",
"and",
"register",
"each",
"class"
] | 143c2fd9a411278988e8b40bd7598ac80f419c20 | https://github.com/localytics/humidifier/blob/143c2fd9a411278988e8b40bd7598ac80f419c20/lib/humidifier/loader.rb#L44-L53 | train |
toy/progress | lib/progress/active_record.rb | ActiveRecord.Base.find_each_with_progress | def find_each_with_progress(options = {})
Progress.start(name.tableize, count(options)) do
find_each do |model|
Progress.step do
yield model
end
end
end
end | ruby | def find_each_with_progress(options = {})
Progress.start(name.tableize, count(options)) do
find_each do |model|
Progress.step do
yield model
end
end
end
end | [
"def",
"find_each_with_progress",
"(",
"options",
"=",
"{",
"}",
")",
"Progress",
".",
"start",
"(",
"name",
".",
"tableize",
",",
"count",
"(",
"options",
")",
")",
"do",
"find_each",
"do",
"|",
"model",
"|",
"Progress",
".",
"step",
"do",
"yield",
"m... | run `find_each` with progress | [
"run",
"find_each",
"with",
"progress"
] | 1a3db7805fc95ef1412b3c21a19b87504933ac3d | https://github.com/toy/progress/blob/1a3db7805fc95ef1412b3c21a19b87504933ac3d/lib/progress/active_record.rb#L8-L16 | train |
toy/progress | lib/progress/active_record.rb | ActiveRecord.Base.find_in_batches_with_progress | def find_in_batches_with_progress(options = {})
Progress.start(name.tableize, count(options)) do
find_in_batches do |batch|
Progress.step batch.length do
yield batch
end
end
end
end | ruby | def find_in_batches_with_progress(options = {})
Progress.start(name.tableize, count(options)) do
find_in_batches do |batch|
Progress.step batch.length do
yield batch
end
end
end
end | [
"def",
"find_in_batches_with_progress",
"(",
"options",
"=",
"{",
"}",
")",
"Progress",
".",
"start",
"(",
"name",
".",
"tableize",
",",
"count",
"(",
"options",
")",
")",
"do",
"find_in_batches",
"do",
"|",
"batch",
"|",
"Progress",
".",
"step",
"batch",
... | run `find_in_batches` with progress | [
"run",
"find_in_batches",
"with",
"progress"
] | 1a3db7805fc95ef1412b3c21a19b87504933ac3d | https://github.com/toy/progress/blob/1a3db7805fc95ef1412b3c21a19b87504933ac3d/lib/progress/active_record.rb#L19-L27 | train |
localytics/humidifier | lib/humidifier/resource.rb | Humidifier.Resource.method_missing | def method_missing(name, *args)
if !valid_accessor?(name)
super
elsif self.class.prop?(name.to_s)
self.class.build_property_reader(name)
send(name)
else
self.class.build_property_writer(name)
send(name, args.first)
end
end | ruby | def method_missing(name, *args)
if !valid_accessor?(name)
super
elsif self.class.prop?(name.to_s)
self.class.build_property_reader(name)
send(name)
else
self.class.build_property_writer(name)
send(name, args.first)
end
end | [
"def",
"method_missing",
"(",
"name",
",",
"*",
"args",
")",
"if",
"!",
"valid_accessor?",
"(",
"name",
")",
"super",
"elsif",
"self",
".",
"class",
".",
"prop?",
"(",
"name",
".",
"to_s",
")",
"self",
".",
"class",
".",
"build_property_reader",
"(",
"... | Patches method_missing to include property accessors
After the first method call, builds the accessor methods to get a speed
boost | [
"Patches",
"method_missing",
"to",
"include",
"property",
"accessors",
"After",
"the",
"first",
"method",
"call",
"builds",
"the",
"accessor",
"methods",
"to",
"get",
"a",
"speed",
"boost"
] | 143c2fd9a411278988e8b40bd7598ac80f419c20 | https://github.com/localytics/humidifier/blob/143c2fd9a411278988e8b40bd7598ac80f419c20/lib/humidifier/resource.rb#L21-L31 | train |
localytics/humidifier | lib/humidifier/resource.rb | Humidifier.Resource.update | def update(properties, raw = false)
properties.each do |property, value|
update_property(property, value, raw)
end
end | ruby | def update(properties, raw = false)
properties.each do |property, value|
update_property(property, value, raw)
end
end | [
"def",
"update",
"(",
"properties",
",",
"raw",
"=",
"false",
")",
"properties",
".",
"each",
"do",
"|",
"property",
",",
"value",
"|",
"update_property",
"(",
"property",
",",
"value",
",",
"raw",
")",
"end",
"end"
] | Update a set of properties defined by the given properties hash | [
"Update",
"a",
"set",
"of",
"properties",
"defined",
"by",
"the",
"given",
"properties",
"hash"
] | 143c2fd9a411278988e8b40bd7598ac80f419c20 | https://github.com/localytics/humidifier/blob/143c2fd9a411278988e8b40bd7598ac80f419c20/lib/humidifier/resource.rb#L52-L56 | train |
localytics/humidifier | lib/humidifier/resource.rb | Humidifier.Resource.update_property | def update_property(property, value, raw = false)
property = property.to_s
property = validate_property(property, raw)
value = validate_value(property, value, raw)
properties[property] = value
end | ruby | def update_property(property, value, raw = false)
property = property.to_s
property = validate_property(property, raw)
value = validate_value(property, value, raw)
properties[property] = value
end | [
"def",
"update_property",
"(",
"property",
",",
"value",
",",
"raw",
"=",
"false",
")",
"property",
"=",
"property",
".",
"to_s",
"property",
"=",
"validate_property",
"(",
"property",
",",
"raw",
")",
"value",
"=",
"validate_value",
"(",
"property",
",",
... | Update an individual property on this resource | [
"Update",
"an",
"individual",
"property",
"on",
"this",
"resource"
] | 143c2fd9a411278988e8b40bd7598ac80f419c20 | https://github.com/localytics/humidifier/blob/143c2fd9a411278988e8b40bd7598ac80f419c20/lib/humidifier/resource.rb#L70-L75 | train |
pandastream/panda_gem | lib/panda/proxies/scope.rb | Panda.Scope.find_by_path | def find_by_path(url, map={})
object = find_object_by_path(url, map)
if object.is_a?(Array)
object.map{|o| klass.new(o.merge('cloud_id' => cloud.id))}
elsif object['id']
klass.new(object.merge('cloud_id' => cloud.id))
else
raise APIError.new(object)
end
end | ruby | def find_by_path(url, map={})
object = find_object_by_path(url, map)
if object.is_a?(Array)
object.map{|o| klass.new(o.merge('cloud_id' => cloud.id))}
elsif object['id']
klass.new(object.merge('cloud_id' => cloud.id))
else
raise APIError.new(object)
end
end | [
"def",
"find_by_path",
"(",
"url",
",",
"map",
"=",
"{",
"}",
")",
"object",
"=",
"find_object_by_path",
"(",
"url",
",",
"map",
")",
"if",
"object",
".",
"is_a?",
"(",
"Array",
")",
"object",
".",
"map",
"{",
"|",
"o",
"|",
"klass",
".",
"new",
... | Overide the function to set the cloud_id as the same as the scope | [
"Overide",
"the",
"function",
"to",
"set",
"the",
"cloud_id",
"as",
"the",
"same",
"as",
"the",
"scope"
] | 5c242b5b7b32d1d11e5cc9d031eeea4dbae60476 | https://github.com/pandastream/panda_gem/blob/5c242b5b7b32d1d11e5cc9d031eeea4dbae60476/lib/panda/proxies/scope.rb#L24-L34 | train |
colinmarc/impala-ruby | lib/impala/connection.rb | Impala.Connection.open | def open
return if @connected
socket = Thrift::Socket.new(@host, @port, @options[:timeout])
if @options[:kerberos]
@transport = SASLTransport.new(socket, :GSSAPI, @options[:kerberos])
elsif @options[:sasl]
@transport = SASLTransport.new(socket, :PLAIN, @options[:sasl])
el... | ruby | def open
return if @connected
socket = Thrift::Socket.new(@host, @port, @options[:timeout])
if @options[:kerberos]
@transport = SASLTransport.new(socket, :GSSAPI, @options[:kerberos])
elsif @options[:sasl]
@transport = SASLTransport.new(socket, :PLAIN, @options[:sasl])
el... | [
"def",
"open",
"return",
"if",
"@connected",
"socket",
"=",
"Thrift",
"::",
"Socket",
".",
"new",
"(",
"@host",
",",
"@port",
",",
"@options",
"[",
":timeout",
"]",
")",
"if",
"@options",
"[",
":kerberos",
"]",
"@transport",
"=",
"SASLTransport",
".",
"n... | Open the connection if it's currently closed. | [
"Open",
"the",
"connection",
"if",
"it",
"s",
"currently",
"closed",
"."
] | 1b5b2c228a4feac43c1b1cb889b27838a253e2ea | https://github.com/colinmarc/impala-ruby/blob/1b5b2c228a4feac43c1b1cb889b27838a253e2ea/lib/impala/connection.rb#L21-L39 | train |
colinmarc/impala-ruby | lib/impala/connection.rb | Impala.Connection.execute | def execute(query, query_options = {})
raise ConnectionError.new("Connection closed") unless open?
handle = send_query(query, query_options)
check_result(handle)
Cursor.new(handle, @service)
end | ruby | def execute(query, query_options = {})
raise ConnectionError.new("Connection closed") unless open?
handle = send_query(query, query_options)
check_result(handle)
Cursor.new(handle, @service)
end | [
"def",
"execute",
"(",
"query",
",",
"query_options",
"=",
"{",
"}",
")",
"raise",
"ConnectionError",
".",
"new",
"(",
"\"Connection closed\"",
")",
"unless",
"open?",
"handle",
"=",
"send_query",
"(",
"query",
",",
"query_options",
")",
"check_result",
"(",
... | Perform a query and return a cursor for iterating over the results.
@param [String] query the query you want to run
@param [Hash] query_options the options to set user and configuration
except for :user, see TImpalaQueryOptions in ImpalaService.thrift
@option query_options [String] :user the user runs the query
... | [
"Perform",
"a",
"query",
"and",
"return",
"a",
"cursor",
"for",
"iterating",
"over",
"the",
"results",
"."
] | 1b5b2c228a4feac43c1b1cb889b27838a253e2ea | https://github.com/colinmarc/impala-ruby/blob/1b5b2c228a4feac43c1b1cb889b27838a253e2ea/lib/impala/connection.rb#L78-L84 | train |
localytics/humidifier | lib/humidifier/stack.rb | Humidifier.Stack.add | def add(name, resource, attributes = {})
resources[name] = resource
resource.update_attributes(attributes) if attributes.any?
resource
end | ruby | def add(name, resource, attributes = {})
resources[name] = resource
resource.update_attributes(attributes) if attributes.any?
resource
end | [
"def",
"add",
"(",
"name",
",",
"resource",
",",
"attributes",
"=",
"{",
"}",
")",
"resources",
"[",
"name",
"]",
"=",
"resource",
"resource",
".",
"update_attributes",
"(",
"attributes",
")",
"if",
"attributes",
".",
"any?",
"resource",
"end"
] | Add a resource to the stack and optionally set its attributes | [
"Add",
"a",
"resource",
"to",
"the",
"stack",
"and",
"optionally",
"set",
"its",
"attributes"
] | 143c2fd9a411278988e8b40bd7598ac80f419c20 | https://github.com/localytics/humidifier/blob/143c2fd9a411278988e8b40bd7598ac80f419c20/lib/humidifier/stack.rb#L32-L36 | train |
localytics/humidifier | lib/humidifier/stack.rb | Humidifier.Stack.to_cf | def to_cf(serializer = :json)
resources = static_resources.merge(enumerable_resources)
case serializer
when :json then JSON.pretty_generate(resources)
when :yaml then YAML.dump(resources)
end
end | ruby | def to_cf(serializer = :json)
resources = static_resources.merge(enumerable_resources)
case serializer
when :json then JSON.pretty_generate(resources)
when :yaml then YAML.dump(resources)
end
end | [
"def",
"to_cf",
"(",
"serializer",
"=",
":json",
")",
"resources",
"=",
"static_resources",
".",
"merge",
"(",
"enumerable_resources",
")",
"case",
"serializer",
"when",
":json",
"then",
"JSON",
".",
"pretty_generate",
"(",
"resources",
")",
"when",
":yaml",
"... | A string representation of the stack that's valid for CFN | [
"A",
"string",
"representation",
"of",
"the",
"stack",
"that",
"s",
"valid",
"for",
"CFN"
] | 143c2fd9a411278988e8b40bd7598ac80f419c20 | https://github.com/localytics/humidifier/blob/143c2fd9a411278988e8b40bd7598ac80f419c20/lib/humidifier/stack.rb#L45-L52 | train |
grange-insurance/cuke_slicer | lib/cuke_slicer/slicer.rb | CukeSlicer.Slicer.slice | def slice(target, filters = {}, format, &block)
validate_target(target)
validate_filters(filters)
validate_format(format)
begin
target = File.directory?(target) ? CukeModeler::Directory.new(target) : CukeModeler::FeatureFile.new(target)
rescue => e
if e.message =~ /lexing|... | ruby | def slice(target, filters = {}, format, &block)
validate_target(target)
validate_filters(filters)
validate_format(format)
begin
target = File.directory?(target) ? CukeModeler::Directory.new(target) : CukeModeler::FeatureFile.new(target)
rescue => e
if e.message =~ /lexing|... | [
"def",
"slice",
"(",
"target",
",",
"filters",
"=",
"{",
"}",
",",
"format",
",",
"&",
"block",
")",
"validate_target",
"(",
"target",
")",
"validate_filters",
"(",
"filters",
")",
"validate_format",
"(",
"format",
")",
"begin",
"target",
"=",
"File",
".... | Slices up the given location into individual test cases.
The location chosen for slicing can be a file or directory path. Optional filters can be provided in order to
ignore certain kinds of test cases. See #known_filters for the available option types. Most options are either a
string or regular expression, althou... | [
"Slices",
"up",
"the",
"given",
"location",
"into",
"individual",
"test",
"cases",
"."
] | 8a31914fae2458c26ec268d9b2c0ea554a7c510c | https://github.com/grange-insurance/cuke_slicer/blob/8a31914fae2458c26ec268d9b2c0ea554a7c510c/lib/cuke_slicer/slicer.rb#L27-L50 | train |
iiif-prezi/osullivan | lib/iiif/ordered_hash.rb | IIIF.OrderedHash.insert | def insert(index, key, value)
tmp = IIIF::OrderedHash.new
index = self.length + 1 + index if index < 0
if index < 0
m = "Index #{index} is too small for current length (#{length})"
raise IndexError, m
end
if index > 0
i=0
self.each do |k,v|
tmp[k] ... | ruby | def insert(index, key, value)
tmp = IIIF::OrderedHash.new
index = self.length + 1 + index if index < 0
if index < 0
m = "Index #{index} is too small for current length (#{length})"
raise IndexError, m
end
if index > 0
i=0
self.each do |k,v|
tmp[k] ... | [
"def",
"insert",
"(",
"index",
",",
"key",
",",
"value",
")",
"tmp",
"=",
"IIIF",
"::",
"OrderedHash",
".",
"new",
"index",
"=",
"self",
".",
"length",
"+",
"1",
"+",
"index",
"if",
"index",
"<",
"0",
"if",
"index",
"<",
"0",
"m",
"=",
"\"Index #... | Insert a new key and value at the suppplied index.
Note that this is slightly different from Array#insert in that new
entries must be added one at a time, i.e. insert(n, k, v, k, v...) is
not supported.
@param [Integer] index
@param [Object] key
@param [Object] value | [
"Insert",
"a",
"new",
"key",
"and",
"value",
"at",
"the",
"suppplied",
"index",
"."
] | d659b736a19ea6283761cf417dcad78470da0978 | https://github.com/iiif-prezi/osullivan/blob/d659b736a19ea6283761cf417dcad78470da0978/lib/iiif/ordered_hash.rb#L15-L36 | train |
iiif-prezi/osullivan | lib/iiif/ordered_hash.rb | IIIF.OrderedHash.remove_empties | def remove_empties
self.keys.each do |key|
if (self[key].kind_of?(Array) && self[key].empty?) || self[key].nil?
self.delete(key)
end
end
end | ruby | def remove_empties
self.keys.each do |key|
if (self[key].kind_of?(Array) && self[key].empty?) || self[key].nil?
self.delete(key)
end
end
end | [
"def",
"remove_empties",
"self",
".",
"keys",
".",
"each",
"do",
"|",
"key",
"|",
"if",
"(",
"self",
"[",
"key",
"]",
".",
"kind_of?",
"(",
"Array",
")",
"&&",
"self",
"[",
"key",
"]",
".",
"empty?",
")",
"||",
"self",
"[",
"key",
"]",
".",
"ni... | Delete any keys that are empty arrays | [
"Delete",
"any",
"keys",
"that",
"are",
"empty",
"arrays"
] | d659b736a19ea6283761cf417dcad78470da0978 | https://github.com/iiif-prezi/osullivan/blob/d659b736a19ea6283761cf417dcad78470da0978/lib/iiif/ordered_hash.rb#L79-L85 | train |
iiif-prezi/osullivan | lib/iiif/ordered_hash.rb | IIIF.OrderedHash.camelize_keys | def camelize_keys
self.keys.each_with_index do |key, i|
if key != key.camelize(:lower)
self.insert(i, key.camelize(:lower), self[key])
self.delete(key)
end
end
self
end | ruby | def camelize_keys
self.keys.each_with_index do |key, i|
if key != key.camelize(:lower)
self.insert(i, key.camelize(:lower), self[key])
self.delete(key)
end
end
self
end | [
"def",
"camelize_keys",
"self",
".",
"keys",
".",
"each_with_index",
"do",
"|",
"key",
",",
"i",
"|",
"if",
"key",
"!=",
"key",
".",
"camelize",
"(",
":lower",
")",
"self",
".",
"insert",
"(",
"i",
",",
"key",
".",
"camelize",
"(",
":lower",
")",
"... | Covert snake_case keys to camelCase | [
"Covert",
"snake_case",
"keys",
"to",
"camelCase"
] | d659b736a19ea6283761cf417dcad78470da0978 | https://github.com/iiif-prezi/osullivan/blob/d659b736a19ea6283761cf417dcad78470da0978/lib/iiif/ordered_hash.rb#L88-L96 | train |
iiif-prezi/osullivan | lib/iiif/ordered_hash.rb | IIIF.OrderedHash.snakeize_keys | def snakeize_keys
self.keys.each_with_index do |key, i|
if key != key.underscore
self.insert(i, key.underscore, self[key])
self.delete(key)
end
end
self
end | ruby | def snakeize_keys
self.keys.each_with_index do |key, i|
if key != key.underscore
self.insert(i, key.underscore, self[key])
self.delete(key)
end
end
self
end | [
"def",
"snakeize_keys",
"self",
".",
"keys",
".",
"each_with_index",
"do",
"|",
"key",
",",
"i",
"|",
"if",
"key",
"!=",
"key",
".",
"underscore",
"self",
".",
"insert",
"(",
"i",
",",
"key",
".",
"underscore",
",",
"self",
"[",
"key",
"]",
")",
"s... | Covert camelCase keys to snake_case | [
"Covert",
"camelCase",
"keys",
"to",
"snake_case"
] | d659b736a19ea6283761cf417dcad78470da0978 | https://github.com/iiif-prezi/osullivan/blob/d659b736a19ea6283761cf417dcad78470da0978/lib/iiif/ordered_hash.rb#L99-L107 | train |
salesking/king_dtaus | lib/king_dta/dtazv.rb | KingDta.Dtazv.add_z | def add_z(bookings)
data3 = '0256'
data3 += 'Z'
sum = 0
bookings.each do |b|
sum += b.value.divmod(100)[0]
end
data3 += '%015i' % sum
data3 += '%015i' % bookings.count
data3 += '%0221s' % ''
raise "DTAUS: Längenfehler Z (#{data3.size} <> 256)\n" if dat... | ruby | def add_z(bookings)
data3 = '0256'
data3 += 'Z'
sum = 0
bookings.each do |b|
sum += b.value.divmod(100)[0]
end
data3 += '%015i' % sum
data3 += '%015i' % bookings.count
data3 += '%0221s' % ''
raise "DTAUS: Längenfehler Z (#{data3.size} <> 256)\n" if dat... | [
"def",
"add_z",
"(",
"bookings",
")",
"data3",
"=",
"'0256'",
"data3",
"+=",
"'Z'",
"sum",
"=",
"0",
"bookings",
".",
"each",
"do",
"|",
"b",
"|",
"sum",
"+=",
"b",
".",
"value",
".",
"divmod",
"(",
"100",
")",
"[",
"0",
"]",
"end",
"data3",
"+... | THE MAGICAL Z SEGMENT | [
"THE",
"MAGICAL",
"Z",
"SEGMENT"
] | 84a72f2f0476b6fae5253aa7a139cfc639eace08 | https://github.com/salesking/king_dtaus/blob/84a72f2f0476b6fae5253aa7a139cfc639eace08/lib/king_dta/dtazv.rb#L275-L287 | train |
iiif-prezi/osullivan | lib/iiif/hash_behaviours.rb | IIIF.HashBehaviours.select | def select
new_instance = self.class.new
if block_given?
@data.each { |k,v| new_instance.data[k] = v if yield(k,v) }
end
return new_instance
end | ruby | def select
new_instance = self.class.new
if block_given?
@data.each { |k,v| new_instance.data[k] = v if yield(k,v) }
end
return new_instance
end | [
"def",
"select",
"new_instance",
"=",
"self",
".",
"class",
".",
"new",
"if",
"block_given?",
"@data",
".",
"each",
"{",
"|",
"k",
",",
"v",
"|",
"new_instance",
".",
"data",
"[",
"k",
"]",
"=",
"v",
"if",
"yield",
"(",
"k",
",",
"v",
")",
"}",
... | Returns a new instance consisting of entries for which the block returns
true. Not that an enumerator is not available for the OrderedHash'
implementation | [
"Returns",
"a",
"new",
"instance",
"consisting",
"of",
"entries",
"for",
"which",
"the",
"block",
"returns",
"true",
".",
"Not",
"that",
"an",
"enumerator",
"is",
"not",
"available",
"for",
"the",
"OrderedHash",
"implementation"
] | d659b736a19ea6283761cf417dcad78470da0978 | https://github.com/iiif-prezi/osullivan/blob/d659b736a19ea6283761cf417dcad78470da0978/lib/iiif/hash_behaviours.rb#L123-L129 | train |
salesking/king_dtaus | lib/king_dta/account.rb | KingDta.Account.bank_account_number= | def bank_account_number=(number)
raise ArgumentError.new('Bank account number cannot be nil') if number.nil?
nr_str = "#{number}".gsub(/\s/,'')
raise ArgumentError.new('Bank account number too long, max 10 allowed') if nr_str.length > 10
raise ArgumentError.new('Bank account number cannot be 0')... | ruby | def bank_account_number=(number)
raise ArgumentError.new('Bank account number cannot be nil') if number.nil?
nr_str = "#{number}".gsub(/\s/,'')
raise ArgumentError.new('Bank account number too long, max 10 allowed') if nr_str.length > 10
raise ArgumentError.new('Bank account number cannot be 0')... | [
"def",
"bank_account_number",
"=",
"(",
"number",
")",
"raise",
"ArgumentError",
".",
"new",
"(",
"'Bank account number cannot be nil'",
")",
"if",
"number",
".",
"nil?",
"nr_str",
"=",
"\"#{number}\"",
".",
"gsub",
"(",
"/",
"\\s",
"/",
",",
"''",
")",
"rai... | Cast given account number to integer. Strips spaces and leading zeros
from the bank account number.
DTA relies on integers for checksums and field values.
@param [String|Integer] number | [
"Cast",
"given",
"account",
"number",
"to",
"integer",
".",
"Strips",
"spaces",
"and",
"leading",
"zeros",
"from",
"the",
"bank",
"account",
"number",
".",
"DTA",
"relies",
"on",
"integers",
"for",
"checksums",
"and",
"field",
"values",
"."
] | 84a72f2f0476b6fae5253aa7a139cfc639eace08 | https://github.com/salesking/king_dtaus/blob/84a72f2f0476b6fae5253aa7a139cfc639eace08/lib/king_dta/account.rb#L49-L56 | train |
ssoroka/scheduler_daemon | lib/scheduler_daemon/base.rb | Scheduler.Base.time | def time
if Time.respond_to?(:zone) && Time.zone
self.class.send(:define_method, :time) { Time.zone.now.to_s }
else
self.class.send(:define_method, :time) { Time.now.to_s }
end
time
end | ruby | def time
if Time.respond_to?(:zone) && Time.zone
self.class.send(:define_method, :time) { Time.zone.now.to_s }
else
self.class.send(:define_method, :time) { Time.now.to_s }
end
time
end | [
"def",
"time",
"if",
"Time",
".",
"respond_to?",
"(",
":zone",
")",
"&&",
"Time",
".",
"zone",
"self",
".",
"class",
".",
"send",
"(",
":define_method",
",",
":time",
")",
"{",
"Time",
".",
"zone",
".",
"now",
".",
"to_s",
"}",
"else",
"self",
".",... | time redefines itself with a faster implementation, since it gets called a lot. | [
"time",
"redefines",
"itself",
"with",
"a",
"faster",
"implementation",
"since",
"it",
"gets",
"called",
"a",
"lot",
"."
] | dc52046eb0002ba8529a3f6cc8cea3f327020020 | https://github.com/ssoroka/scheduler_daemon/blob/dc52046eb0002ba8529a3f6cc8cea3f327020020/lib/scheduler_daemon/base.rb#L69-L76 | train |
bmuller/bandit | lib/bandit/storage/redis.rb | Bandit.RedisStorage.init | def init(key, value)
with_failure_grace(value) {
@redis.set(key, value) if get(key, nil).nil?
}
end | ruby | def init(key, value)
with_failure_grace(value) {
@redis.set(key, value) if get(key, nil).nil?
}
end | [
"def",
"init",
"(",
"key",
",",
"value",
")",
"with_failure_grace",
"(",
"value",
")",
"{",
"@redis",
".",
"set",
"(",
"key",
",",
"value",
")",
"if",
"get",
"(",
"key",
",",
"nil",
")",
".",
"nil?",
"}",
"end"
] | initialize key if not set | [
"initialize",
"key",
"if",
"not",
"set"
] | 4c2528adee6ed761b3298f5b8889819ed9e04483 | https://github.com/bmuller/bandit/blob/4c2528adee6ed761b3298f5b8889819ed9e04483/lib/bandit/storage/redis.rb#L28-L32 | train |
bmuller/bandit | lib/bandit/storage/redis.rb | Bandit.RedisStorage.get | def get(key, default=0)
with_failure_grace(default) {
val = @redis.get(key)
return default if val.nil?
val.numeric? ? val.to_i : val
}
end | ruby | def get(key, default=0)
with_failure_grace(default) {
val = @redis.get(key)
return default if val.nil?
val.numeric? ? val.to_i : val
}
end | [
"def",
"get",
"(",
"key",
",",
"default",
"=",
"0",
")",
"with_failure_grace",
"(",
"default",
")",
"{",
"val",
"=",
"@redis",
".",
"get",
"(",
"key",
")",
"return",
"default",
"if",
"val",
".",
"nil?",
"val",
".",
"numeric?",
"?",
"val",
".",
"to_... | get key if exists, otherwise 0 | [
"get",
"key",
"if",
"exists",
"otherwise",
"0"
] | 4c2528adee6ed761b3298f5b8889819ed9e04483 | https://github.com/bmuller/bandit/blob/4c2528adee6ed761b3298f5b8889819ed9e04483/lib/bandit/storage/redis.rb#L35-L41 | train |
bmuller/bandit | lib/bandit/extensions/view_concerns.rb | Bandit.ViewConcerns.bandit_session_choose | def bandit_session_choose(exp)
name = "bandit_#{exp}".intern
# choose url param with preference
value = params[name].nil? ? cookies.signed[name] : params[name]
# choose with default, and set cookie
cookies.signed[name] = Bandit.get_experiment(exp).choose(value)
end | ruby | def bandit_session_choose(exp)
name = "bandit_#{exp}".intern
# choose url param with preference
value = params[name].nil? ? cookies.signed[name] : params[name]
# choose with default, and set cookie
cookies.signed[name] = Bandit.get_experiment(exp).choose(value)
end | [
"def",
"bandit_session_choose",
"(",
"exp",
")",
"name",
"=",
"\"bandit_#{exp}\"",
".",
"intern",
"value",
"=",
"params",
"[",
"name",
"]",
".",
"nil?",
"?",
"cookies",
".",
"signed",
"[",
"name",
"]",
":",
"params",
"[",
"name",
"]",
"cookies",
".",
"... | stick to one alternative for the entire browser session | [
"stick",
"to",
"one",
"alternative",
"for",
"the",
"entire",
"browser",
"session"
] | 4c2528adee6ed761b3298f5b8889819ed9e04483 | https://github.com/bmuller/bandit/blob/4c2528adee6ed761b3298f5b8889819ed9e04483/lib/bandit/extensions/view_concerns.rb#L18-L24 | train |
bmuller/bandit | lib/bandit/extensions/view_concerns.rb | Bandit.ViewConcerns.bandit_sticky_choose | def bandit_sticky_choose(exp)
name = "bandit_#{exp}".intern
# choose url param with preference
value = params[name].nil? ? cookies.signed[name] : params[name]
# sticky choice may outlast a given alternative
alternative = if Bandit.get_experiment(exp).alternatives.include?(value)
... | ruby | def bandit_sticky_choose(exp)
name = "bandit_#{exp}".intern
# choose url param with preference
value = params[name].nil? ? cookies.signed[name] : params[name]
# sticky choice may outlast a given alternative
alternative = if Bandit.get_experiment(exp).alternatives.include?(value)
... | [
"def",
"bandit_sticky_choose",
"(",
"exp",
")",
"name",
"=",
"\"bandit_#{exp}\"",
".",
"intern",
"value",
"=",
"params",
"[",
"name",
"]",
".",
"nil?",
"?",
"cookies",
".",
"signed",
"[",
"name",
"]",
":",
"params",
"[",
"name",
"]",
"alternative",
"=",
... | stick to one alternative until user deletes cookies or changes browser | [
"stick",
"to",
"one",
"alternative",
"until",
"user",
"deletes",
"cookies",
"or",
"changes",
"browser"
] | 4c2528adee6ed761b3298f5b8889819ed9e04483 | https://github.com/bmuller/bandit/blob/4c2528adee6ed761b3298f5b8889819ed9e04483/lib/bandit/extensions/view_concerns.rb#L27-L39 | train |
shinesolutions/ruby_aem | lib/ruby_aem.rb | RubyAem.Aem.sanitise_conf | def sanitise_conf(conf)
conf[:username] ||= 'admin'
conf[:password] ||= 'admin'
conf[:protocol] ||= 'http'
conf[:host] ||= 'localhost'
conf[:port] ||= 4502
conf[:timeout] ||= 300
# handle custom configuration value being passed as a String
# e.g. when the values are passe... | ruby | def sanitise_conf(conf)
conf[:username] ||= 'admin'
conf[:password] ||= 'admin'
conf[:protocol] ||= 'http'
conf[:host] ||= 'localhost'
conf[:port] ||= 4502
conf[:timeout] ||= 300
# handle custom configuration value being passed as a String
# e.g. when the values are passe... | [
"def",
"sanitise_conf",
"(",
"conf",
")",
"conf",
"[",
":username",
"]",
"||=",
"'admin'",
"conf",
"[",
":password",
"]",
"||=",
"'admin'",
"conf",
"[",
":protocol",
"]",
"||=",
"'http'",
"conf",
"[",
":host",
"]",
"||=",
"'localhost'",
"conf",
"[",
":po... | Initialise a Ruby AEM instance.
@param conf configuration hash of the following configuration values:
- username: username used to authenticate to AEM instance, default: 'admin'
- password: password used to authenticate to AEM instance, default: 'admin'
- protocol: AEM instance protocol (http or https), default: '... | [
"Initialise",
"a",
"Ruby",
"AEM",
"instance",
"."
] | 96e9d491486f09e044ea5d05c433e53a37a08120 | https://github.com/shinesolutions/ruby_aem/blob/96e9d491486f09e044ea5d05c433e53a37a08120/lib/ruby_aem.rb#L82-L95 | train |
shinesolutions/ruby_aem | lib/ruby_aem.rb | RubyAem.Aem.config_property | def config_property(name, type, value)
RubyAem::Resources::ConfigProperty.new(@client, name, type, value)
end | ruby | def config_property(name, type, value)
RubyAem::Resources::ConfigProperty.new(@client, name, type, value)
end | [
"def",
"config_property",
"(",
"name",
",",
"type",
",",
"value",
")",
"RubyAem",
"::",
"Resources",
"::",
"ConfigProperty",
".",
"new",
"(",
"@client",
",",
"name",
",",
"type",
",",
"value",
")",
"end"
] | Create a config property instance.
@param name the property's name
@param type the property's type, e.g. Boolean
@param value the property's value, e.g. true
@return new RubyAem::Resources::ConfigProperty instance | [
"Create",
"a",
"config",
"property",
"instance",
"."
] | 96e9d491486f09e044ea5d05c433e53a37a08120 | https://github.com/shinesolutions/ruby_aem/blob/96e9d491486f09e044ea5d05c433e53a37a08120/lib/ruby_aem.rb#L136-L138 | train |
shinesolutions/ruby_aem | lib/ruby_aem.rb | RubyAem.Aem.package | def package(group_name, package_name, package_version)
RubyAem::Resources::Package.new(@client, group_name, package_name, package_version)
end | ruby | def package(group_name, package_name, package_version)
RubyAem::Resources::Package.new(@client, group_name, package_name, package_version)
end | [
"def",
"package",
"(",
"group_name",
",",
"package_name",
",",
"package_version",
")",
"RubyAem",
"::",
"Resources",
"::",
"Package",
".",
"new",
"(",
"@client",
",",
"group_name",
",",
"package_name",
",",
"package_version",
")",
"end"
] | Create a package instance.
@param group_name the group name of the package, e.g. somepackagegroup
@param package_name the name of the package, e.g. somepackage
@param package_version the version of the package, e.g. 1.2.3
@return new RubyAem::Resources::Package instance | [
"Create",
"a",
"package",
"instance",
"."
] | 96e9d491486f09e044ea5d05c433e53a37a08120 | https://github.com/shinesolutions/ruby_aem/blob/96e9d491486f09e044ea5d05c433e53a37a08120/lib/ruby_aem.rb#L180-L182 | train |
bmuller/bandit | lib/bandit/storage/base.rb | Bandit.BaseStorage.part_key | def part_key(exp, alt, date_hour=nil)
parts = [ "participants", exp.name, alt ]
parts += [ date_hour.date, date_hour.hour ] unless date_hour.nil?
make_key parts
end | ruby | def part_key(exp, alt, date_hour=nil)
parts = [ "participants", exp.name, alt ]
parts += [ date_hour.date, date_hour.hour ] unless date_hour.nil?
make_key parts
end | [
"def",
"part_key",
"(",
"exp",
",",
"alt",
",",
"date_hour",
"=",
"nil",
")",
"parts",
"=",
"[",
"\"participants\"",
",",
"exp",
".",
"name",
",",
"alt",
"]",
"parts",
"+=",
"[",
"date_hour",
".",
"date",
",",
"date_hour",
".",
"hour",
"]",
"unless",... | if date_hour is nil, create key for total
otherwise, create key for hourly based | [
"if",
"date_hour",
"is",
"nil",
"create",
"key",
"for",
"total",
"otherwise",
"create",
"key",
"for",
"hourly",
"based"
] | 4c2528adee6ed761b3298f5b8889819ed9e04483 | https://github.com/bmuller/bandit/blob/4c2528adee6ed761b3298f5b8889819ed9e04483/lib/bandit/storage/base.rb#L105-L109 | train |
notEthan/oauthenticator | lib/oauthenticator/rack_authenticator.rb | OAuthenticator.RackAuthenticator.unauthenticated_response | def unauthenticated_response(errors)
# default to a blank realm, I suppose
realm = @options[:realm] || ''
response_headers = {"WWW-Authenticate" => %Q(OAuth realm="#{realm}"), 'Content-Type' => 'application/json'}
body = {'errors' => errors}
error_message = begin
error_values = er... | ruby | def unauthenticated_response(errors)
# default to a blank realm, I suppose
realm = @options[:realm] || ''
response_headers = {"WWW-Authenticate" => %Q(OAuth realm="#{realm}"), 'Content-Type' => 'application/json'}
body = {'errors' => errors}
error_message = begin
error_values = er... | [
"def",
"unauthenticated_response",
"(",
"errors",
")",
"realm",
"=",
"@options",
"[",
":realm",
"]",
"||",
"''",
"response_headers",
"=",
"{",
"\"WWW-Authenticate\"",
"=>",
"%Q(OAuth realm=\"#{realm}\")",
",",
"'Content-Type'",
"=>",
"'application/json'",
"}",
"body",... | the response for an unauthenticated request. the argument will be a hash with the key 'errors', whose
value is a hash with string keys indicating attributes with errors, and values being arrays of strings
indicating error messages on the attribute key. | [
"the",
"response",
"for",
"an",
"unauthenticated",
"request",
".",
"the",
"argument",
"will",
"be",
"a",
"hash",
"with",
"the",
"key",
"errors",
"whose",
"value",
"is",
"a",
"hash",
"with",
"string",
"keys",
"indicating",
"attributes",
"with",
"errors",
"and... | f462501e4d3e79086855ad5c6f95104de3c2ec07 | https://github.com/notEthan/oauthenticator/blob/f462501e4d3e79086855ad5c6f95104de3c2ec07/lib/oauthenticator/rack_authenticator.rb#L65-L83 | train |
bmuller/bandit | lib/bandit/extensions/controller_concerns.rb | Bandit.ControllerConcerns.bandit_simple_convert! | def bandit_simple_convert!(exp, alt, count=1)
Bandit.get_experiment(exp).convert!(alt, count)
end | ruby | def bandit_simple_convert!(exp, alt, count=1)
Bandit.get_experiment(exp).convert!(alt, count)
end | [
"def",
"bandit_simple_convert!",
"(",
"exp",
",",
"alt",
",",
"count",
"=",
"1",
")",
"Bandit",
".",
"get_experiment",
"(",
"exp",
")",
".",
"convert!",
"(",
"alt",
",",
"count",
")",
"end"
] | look mum, no cookies | [
"look",
"mum",
"no",
"cookies"
] | 4c2528adee6ed761b3298f5b8889819ed9e04483 | https://github.com/bmuller/bandit/blob/4c2528adee6ed761b3298f5b8889819ed9e04483/lib/bandit/extensions/controller_concerns.rb#L13-L15 | train |
bmuller/bandit | lib/bandit/extensions/controller_concerns.rb | Bandit.ControllerConcerns.bandit_session_convert! | def bandit_session_convert!(exp, alt=nil, count=1)
cookiename = "bandit_#{exp}".intern
cookiename_converted = "bandit_#{exp}_converted".intern
alt ||= cookies.signed[cookiename]
unless alt.nil? or cookies.signed[cookiename_converted]
Bandit.get_experiment(exp).convert!(alt, count)
... | ruby | def bandit_session_convert!(exp, alt=nil, count=1)
cookiename = "bandit_#{exp}".intern
cookiename_converted = "bandit_#{exp}_converted".intern
alt ||= cookies.signed[cookiename]
unless alt.nil? or cookies.signed[cookiename_converted]
Bandit.get_experiment(exp).convert!(alt, count)
... | [
"def",
"bandit_session_convert!",
"(",
"exp",
",",
"alt",
"=",
"nil",
",",
"count",
"=",
"1",
")",
"cookiename",
"=",
"\"bandit_#{exp}\"",
".",
"intern",
"cookiename_converted",
"=",
"\"bandit_#{exp}_converted\"",
".",
"intern",
"alt",
"||=",
"cookies",
".",
"si... | expects a session cookie, deletes it, will convert again | [
"expects",
"a",
"session",
"cookie",
"deletes",
"it",
"will",
"convert",
"again"
] | 4c2528adee6ed761b3298f5b8889819ed9e04483 | https://github.com/bmuller/bandit/blob/4c2528adee6ed761b3298f5b8889819ed9e04483/lib/bandit/extensions/controller_concerns.rb#L18-L26 | train |
bmuller/bandit | lib/bandit/extensions/controller_concerns.rb | Bandit.ControllerConcerns.bandit_sticky_convert! | def bandit_sticky_convert!(exp, alt=nil, count=1)
cookiename = "bandit_#{exp}".intern
cookiename_converted = "bandit_#{exp}_converted".intern
alt ||= cookies.signed[cookiename]
unless alt.nil? or cookies.signed[cookiename_converted]
cookies.permanent.signed[cookiename_converted] = "true"... | ruby | def bandit_sticky_convert!(exp, alt=nil, count=1)
cookiename = "bandit_#{exp}".intern
cookiename_converted = "bandit_#{exp}_converted".intern
alt ||= cookies.signed[cookiename]
unless alt.nil? or cookies.signed[cookiename_converted]
cookies.permanent.signed[cookiename_converted] = "true"... | [
"def",
"bandit_sticky_convert!",
"(",
"exp",
",",
"alt",
"=",
"nil",
",",
"count",
"=",
"1",
")",
"cookiename",
"=",
"\"bandit_#{exp}\"",
".",
"intern",
"cookiename_converted",
"=",
"\"bandit_#{exp}_converted\"",
".",
"intern",
"alt",
"||=",
"cookies",
".",
"sig... | creates a _converted cookie, prevents multiple conversions | [
"creates",
"a",
"_converted",
"cookie",
"prevents",
"multiple",
"conversions"
] | 4c2528adee6ed761b3298f5b8889819ed9e04483 | https://github.com/bmuller/bandit/blob/4c2528adee6ed761b3298f5b8889819ed9e04483/lib/bandit/extensions/controller_concerns.rb#L29-L37 | train |
david942j/rbelftools | lib/elftools/dynamic.rb | ELFTools.Dynamic.each_tags | def each_tags(&block)
return enum_for(:each_tags) unless block_given?
arr = []
0.step do |i|
tag = tag_at(i).tap(&block)
arr << tag
break if tag.header.d_tag == ELFTools::Constants::DT_NULL
end
arr
end | ruby | def each_tags(&block)
return enum_for(:each_tags) unless block_given?
arr = []
0.step do |i|
tag = tag_at(i).tap(&block)
arr << tag
break if tag.header.d_tag == ELFTools::Constants::DT_NULL
end
arr
end | [
"def",
"each_tags",
"(",
"&",
"block",
")",
"return",
"enum_for",
"(",
":each_tags",
")",
"unless",
"block_given?",
"arr",
"=",
"[",
"]",
"0",
".",
"step",
"do",
"|",
"i",
"|",
"tag",
"=",
"tag_at",
"(",
"i",
")",
".",
"tap",
"(",
"&",
"block",
"... | Iterate all tags.
@note
This method assume the following methods already exist:
header
tag_start
@yieldparam [ELFTools::Dynamic::Tag] tag
@return [Enumerator<ELFTools::Dynamic::Tag>, Array<ELFTools::Dynamic::Tag>]
If block is not given, an enumerator will be returned.
Otherwise, return array of t... | [
"Iterate",
"all",
"tags",
"."
] | 9a453ac31d72eae3b8b99d5dbd361c101577d58e | https://github.com/david942j/rbelftools/blob/9a453ac31d72eae3b8b99d5dbd361c101577d58e/lib/elftools/dynamic.rb#L19-L29 | train |
david942j/rbelftools | lib/elftools/dynamic.rb | ELFTools.Dynamic.tag_at | def tag_at(n)
return if n < 0
@tag_at_map ||= {}
return @tag_at_map[n] if @tag_at_map[n]
dyn = Structs::ELF_Dyn.new(endian: endian)
dyn.elf_class = header.elf_class
stream.pos = tag_start + n * dyn.num_bytes
dyn.offset = stream.pos
@tag_at_map[n] = Tag.new(dyn.read(stre... | ruby | def tag_at(n)
return if n < 0
@tag_at_map ||= {}
return @tag_at_map[n] if @tag_at_map[n]
dyn = Structs::ELF_Dyn.new(endian: endian)
dyn.elf_class = header.elf_class
stream.pos = tag_start + n * dyn.num_bytes
dyn.offset = stream.pos
@tag_at_map[n] = Tag.new(dyn.read(stre... | [
"def",
"tag_at",
"(",
"n",
")",
"return",
"if",
"n",
"<",
"0",
"@tag_at_map",
"||=",
"{",
"}",
"return",
"@tag_at_map",
"[",
"n",
"]",
"if",
"@tag_at_map",
"[",
"n",
"]",
"dyn",
"=",
"Structs",
"::",
"ELF_Dyn",
".",
"new",
"(",
"endian",
":",
"endi... | Get the +n+-th tag.
Tags are lazy loaded.
@note
This method assume the following methods already exist:
header
tag_start
@note
We cannot do bound checking of +n+ here since the only way to get size
of tags is calling +tags.size+.
@param [Integer] n The index.
@return [ELFTools::Dynamic::Tag] Th... | [
"Get",
"the",
"+",
"n",
"+",
"-",
"th",
"tag",
"."
] | 9a453ac31d72eae3b8b99d5dbd361c101577d58e | https://github.com/david942j/rbelftools/blob/9a453ac31d72eae3b8b99d5dbd361c101577d58e/lib/elftools/dynamic.rb#L91-L102 | train |
david942j/rbelftools | lib/elftools/elf_file.rb | ELFTools.ELFFile.build_id | def build_id
section = section_by_name('.note.gnu.build-id')
return nil if section.nil?
note = section.notes.first
return nil if note.nil?
note.desc.unpack('H*').first
end | ruby | def build_id
section = section_by_name('.note.gnu.build-id')
return nil if section.nil?
note = section.notes.first
return nil if note.nil?
note.desc.unpack('H*').first
end | [
"def",
"build_id",
"section",
"=",
"section_by_name",
"(",
"'.note.gnu.build-id'",
")",
"return",
"nil",
"if",
"section",
".",
"nil?",
"note",
"=",
"section",
".",
"notes",
".",
"first",
"return",
"nil",
"if",
"note",
".",
"nil?",
"note",
".",
"desc",
".",... | Return the BuildID of ELF.
@return [String, nil]
BuildID in hex form will be returned.
+nil+ is returned if the .note.gnu.build-id section
is not found.
@example
elf.build_id
#=> '73ab62cb7bc9959ce053c2b711322158708cdc07' | [
"Return",
"the",
"BuildID",
"of",
"ELF",
"."
] | 9a453ac31d72eae3b8b99d5dbd361c101577d58e | https://github.com/david942j/rbelftools/blob/9a453ac31d72eae3b8b99d5dbd361c101577d58e/lib/elftools/elf_file.rb#L50-L58 | train |
david942j/rbelftools | lib/elftools/elf_file.rb | ELFTools.ELFFile.each_sections | def each_sections(&block)
return enum_for(:each_sections) unless block_given?
Array.new(num_sections) do |i|
section_at(i).tap(&block)
end
end | ruby | def each_sections(&block)
return enum_for(:each_sections) unless block_given?
Array.new(num_sections) do |i|
section_at(i).tap(&block)
end
end | [
"def",
"each_sections",
"(",
"&",
"block",
")",
"return",
"enum_for",
"(",
":each_sections",
")",
"unless",
"block_given?",
"Array",
".",
"new",
"(",
"num_sections",
")",
"do",
"|",
"i",
"|",
"section_at",
"(",
"i",
")",
".",
"tap",
"(",
"&",
"block",
... | Iterate all sections.
All sections are lazy loading, the section
only be created whenever accessing it.
This method is useful for {#section_by_name}
since not all sections need to be created.
@yieldparam [ELFTools::Sections::Section] section A section.
@yieldreturn [void]
@return [Enumerator<ELFTools::Sections:... | [
"Iterate",
"all",
"sections",
"."
] | 9a453ac31d72eae3b8b99d5dbd361c101577d58e | https://github.com/david942j/rbelftools/blob/9a453ac31d72eae3b8b99d5dbd361c101577d58e/lib/elftools/elf_file.rb#L120-L126 | train |
david942j/rbelftools | lib/elftools/elf_file.rb | ELFTools.ELFFile.sections_by_type | def sections_by_type(type, &block)
type = Util.to_constant(Constants::SHT, type)
Util.select_by_type(each_sections, type, &block)
end | ruby | def sections_by_type(type, &block)
type = Util.to_constant(Constants::SHT, type)
Util.select_by_type(each_sections, type, &block)
end | [
"def",
"sections_by_type",
"(",
"type",
",",
"&",
"block",
")",
"type",
"=",
"Util",
".",
"to_constant",
"(",
"Constants",
"::",
"SHT",
",",
"type",
")",
"Util",
".",
"select_by_type",
"(",
"each_sections",
",",
"type",
",",
"&",
"block",
")",
"end"
] | Fetch all sections with specific type.
The available types are listed in {ELFTools::Constants::PT}.
This method accept giving block.
@param [Integer, Symbol, String] type
The type needed, similar format as {#segment_by_type}.
@yieldparam [ELFTools::Sections::Section] section A section in specific type.
@yieldr... | [
"Fetch",
"all",
"sections",
"with",
"specific",
"type",
"."
] | 9a453ac31d72eae3b8b99d5dbd361c101577d58e | https://github.com/david942j/rbelftools/blob/9a453ac31d72eae3b8b99d5dbd361c101577d58e/lib/elftools/elf_file.rb#L161-L164 | train |
david942j/rbelftools | lib/elftools/elf_file.rb | ELFTools.ELFFile.each_segments | def each_segments(&block)
return enum_for(:each_segments) unless block_given?
Array.new(num_segments) do |i|
segment_at(i).tap(&block)
end
end | ruby | def each_segments(&block)
return enum_for(:each_segments) unless block_given?
Array.new(num_segments) do |i|
segment_at(i).tap(&block)
end
end | [
"def",
"each_segments",
"(",
"&",
"block",
")",
"return",
"enum_for",
"(",
":each_segments",
")",
"unless",
"block_given?",
"Array",
".",
"new",
"(",
"num_segments",
")",
"do",
"|",
"i",
"|",
"segment_at",
"(",
"i",
")",
".",
"tap",
"(",
"&",
"block",
... | Iterate all segments.
All segments are lazy loading, the segment
only be created whenever accessing it.
This method is useful for {#segment_by_type}
since not all segments need to be created.
@yieldparam [ELFTools::Segments::Segment] segment A segment.
@yieldreturn [void]
@return [Array<ELFTools::Segments::Segm... | [
"Iterate",
"all",
"segments",
"."
] | 9a453ac31d72eae3b8b99d5dbd361c101577d58e | https://github.com/david942j/rbelftools/blob/9a453ac31d72eae3b8b99d5dbd361c101577d58e/lib/elftools/elf_file.rb#L193-L199 | train |
david942j/rbelftools | lib/elftools/elf_file.rb | ELFTools.ELFFile.segments_by_type | def segments_by_type(type, &block)
type = Util.to_constant(Constants::PT, type)
Util.select_by_type(each_segments, type, &block)
end | ruby | def segments_by_type(type, &block)
type = Util.to_constant(Constants::PT, type)
Util.select_by_type(each_segments, type, &block)
end | [
"def",
"segments_by_type",
"(",
"type",
",",
"&",
"block",
")",
"type",
"=",
"Util",
".",
"to_constant",
"(",
"Constants",
"::",
"PT",
",",
"type",
")",
"Util",
".",
"select_by_type",
"(",
"each_segments",
",",
"type",
",",
"&",
"block",
")",
"end"
] | Fetch all segments with specific type.
If you want to find only one segment,
use {#segment_by_type} instead.
This method accept giving block.
@param [Integer, Symbol, String] type
The type needed, same format as {#segment_by_type}.
@yieldparam [ELFTools::Segments::Segment] segment A segment in specific type.
... | [
"Fetch",
"all",
"segments",
"with",
"specific",
"type",
"."
] | 9a453ac31d72eae3b8b99d5dbd361c101577d58e | https://github.com/david942j/rbelftools/blob/9a453ac31d72eae3b8b99d5dbd361c101577d58e/lib/elftools/elf_file.rb#L264-L267 | train |
david942j/rbelftools | lib/elftools/elf_file.rb | ELFTools.ELFFile.offset_from_vma | def offset_from_vma(vma, size = 0)
segments_by_type(:load) do |seg|
return seg.vma_to_offset(vma) if seg.vma_in?(vma, size)
end
end | ruby | def offset_from_vma(vma, size = 0)
segments_by_type(:load) do |seg|
return seg.vma_to_offset(vma) if seg.vma_in?(vma, size)
end
end | [
"def",
"offset_from_vma",
"(",
"vma",
",",
"size",
"=",
"0",
")",
"segments_by_type",
"(",
":load",
")",
"do",
"|",
"seg",
"|",
"return",
"seg",
".",
"vma_to_offset",
"(",
"vma",
")",
"if",
"seg",
".",
"vma_in?",
"(",
"vma",
",",
"size",
")",
"end",
... | Get the offset related to file, given virtual memory address.
This method should work no matter ELF is a PIE or not.
This method refers from (actually equals to) binutils/readelf.c#offset_from_vma.
@param [Integer] vma The virtual address to be queried.
@return [Integer] Related file offset.
@example
elf = ELF... | [
"Get",
"the",
"offset",
"related",
"to",
"file",
"given",
"virtual",
"memory",
"address",
"."
] | 9a453ac31d72eae3b8b99d5dbd361c101577d58e | https://github.com/david942j/rbelftools/blob/9a453ac31d72eae3b8b99d5dbd361c101577d58e/lib/elftools/elf_file.rb#L291-L295 | train |
david942j/rbelftools | lib/elftools/elf_file.rb | ELFTools.ELFFile.patches | def patches
patch = {}
loaded_headers.each do |header|
header.patches.each do |key, val|
patch[key + header.offset] = val
end
end
patch
end | ruby | def patches
patch = {}
loaded_headers.each do |header|
header.patches.each do |key, val|
patch[key + header.offset] = val
end
end
patch
end | [
"def",
"patches",
"patch",
"=",
"{",
"}",
"loaded_headers",
".",
"each",
"do",
"|",
"header",
"|",
"header",
".",
"patches",
".",
"each",
"do",
"|",
"key",
",",
"val",
"|",
"patch",
"[",
"key",
"+",
"header",
".",
"offset",
"]",
"=",
"val",
"end",
... | The patch status.
@return [Hash{Integer => String}] | [
"The",
"patch",
"status",
"."
] | 9a453ac31d72eae3b8b99d5dbd361c101577d58e | https://github.com/david942j/rbelftools/blob/9a453ac31d72eae3b8b99d5dbd361c101577d58e/lib/elftools/elf_file.rb#L299-L307 | train |
david942j/rbelftools | lib/elftools/elf_file.rb | ELFTools.ELFFile.save | def save(filename)
stream.pos = 0
all = stream.read.force_encoding('ascii-8bit')
patches.each do |pos, val|
all[pos, val.size] = val
end
IO.binwrite(filename, all)
end | ruby | def save(filename)
stream.pos = 0
all = stream.read.force_encoding('ascii-8bit')
patches.each do |pos, val|
all[pos, val.size] = val
end
IO.binwrite(filename, all)
end | [
"def",
"save",
"(",
"filename",
")",
"stream",
".",
"pos",
"=",
"0",
"all",
"=",
"stream",
".",
"read",
".",
"force_encoding",
"(",
"'ascii-8bit'",
")",
"patches",
".",
"each",
"do",
"|",
"pos",
",",
"val",
"|",
"all",
"[",
"pos",
",",
"val",
".",
... | Apply patches and save as +filename+.
@param [String] filename
@return [void] | [
"Apply",
"patches",
"and",
"save",
"as",
"+",
"filename",
"+",
"."
] | 9a453ac31d72eae3b8b99d5dbd361c101577d58e | https://github.com/david942j/rbelftools/blob/9a453ac31d72eae3b8b99d5dbd361c101577d58e/lib/elftools/elf_file.rb#L313-L320 | train |
david942j/rbelftools | lib/elftools/elf_file.rb | ELFTools.ELFFile.loaded_headers | def loaded_headers
explore = lambda do |obj|
return obj if obj.is_a?(::ELFTools::Structs::ELFStruct)
return obj.map(&explore) if obj.is_a?(Array)
obj.instance_variables.map do |s|
explore.call(obj.instance_variable_get(s))
end
end
explore.call(self).flatten
... | ruby | def loaded_headers
explore = lambda do |obj|
return obj if obj.is_a?(::ELFTools::Structs::ELFStruct)
return obj.map(&explore) if obj.is_a?(Array)
obj.instance_variables.map do |s|
explore.call(obj.instance_variable_get(s))
end
end
explore.call(self).flatten
... | [
"def",
"loaded_headers",
"explore",
"=",
"lambda",
"do",
"|",
"obj",
"|",
"return",
"obj",
"if",
"obj",
".",
"is_a?",
"(",
"::",
"ELFTools",
"::",
"Structs",
"::",
"ELFStruct",
")",
"return",
"obj",
".",
"map",
"(",
"&",
"explore",
")",
"if",
"obj",
... | bad idea.. | [
"bad",
"idea",
".."
] | 9a453ac31d72eae3b8b99d5dbd361c101577d58e | https://github.com/david942j/rbelftools/blob/9a453ac31d72eae3b8b99d5dbd361c101577d58e/lib/elftools/elf_file.rb#L325-L335 | train |
cotag/http-parser | lib/http-parser/parser.rb | HttpParser.Parser.parse | def parse(inst, data)
::HttpParser.http_parser_execute(inst, @settings, data, data.length)
return inst.error?
end | ruby | def parse(inst, data)
::HttpParser.http_parser_execute(inst, @settings, data, data.length)
return inst.error?
end | [
"def",
"parse",
"(",
"inst",
",",
"data",
")",
"::",
"HttpParser",
".",
"http_parser_execute",
"(",
"inst",
",",
"@settings",
",",
"data",
",",
"data",
".",
"length",
")",
"return",
"inst",
".",
"error?",
"end"
] | Parses data.
@param [HttpParser::Instance] inst
The state so far of the request / response being processed.
@param [String] data
The data to parse against the instance specified.
@return [Boolean]
Returns true if the data was parsed successfully. | [
"Parses",
"data",
"."
] | 9a202b38945e9ad66ca113947860267411efc6f2 | https://github.com/cotag/http-parser/blob/9a202b38945e9ad66ca113947860267411efc6f2/lib/http-parser/parser.rb#L221-L224 | train |
shinesolutions/ruby_aem | lib/ruby_aem/client.rb | RubyAem.Client.call | def call(clazz, action, call_params)
resource_name = clazz.name.downcase.sub('rubyaem::resources::', '')
resource = @spec[resource_name]
action_spec = resource['actions'][action]
api = @apis[action_spec['api'].to_sym]
operation = action_spec['operation']
params = []
required_... | ruby | def call(clazz, action, call_params)
resource_name = clazz.name.downcase.sub('rubyaem::resources::', '')
resource = @spec[resource_name]
action_spec = resource['actions'][action]
api = @apis[action_spec['api'].to_sym]
operation = action_spec['operation']
params = []
required_... | [
"def",
"call",
"(",
"clazz",
",",
"action",
",",
"call_params",
")",
"resource_name",
"=",
"clazz",
".",
"name",
".",
"downcase",
".",
"sub",
"(",
"'rubyaem::resources::'",
",",
"''",
")",
"resource",
"=",
"@spec",
"[",
"resource_name",
"]",
"action_spec",
... | Initialise a client.
@param apis a hash of Swagger AEM client's API instances
@param spec ruby_aem specification
@return new RubyAem::Client instance
Make an API call using the relevant Swagger AEM API client.
Clazz and action parameters are used to identify the action, API, and params
from ruby_aem specificatio... | [
"Initialise",
"a",
"client",
"."
] | 96e9d491486f09e044ea5d05c433e53a37a08120 | https://github.com/shinesolutions/ruby_aem/blob/96e9d491486f09e044ea5d05c433e53a37a08120/lib/ruby_aem/client.rb#L49-L80 | train |
shinesolutions/ruby_aem | lib/ruby_aem/client.rb | RubyAem.Client.add_optional_param | def add_optional_param(key, value, params, call_params)
# if there is no value in optional param spec,
# then only add optional param that is set in call parameters
if !value
params[-1][key.to_sym] = call_params[key.to_sym] if call_params.key? key.to_sym
# if value is provided in optiona... | ruby | def add_optional_param(key, value, params, call_params)
# if there is no value in optional param spec,
# then only add optional param that is set in call parameters
if !value
params[-1][key.to_sym] = call_params[key.to_sym] if call_params.key? key.to_sym
# if value is provided in optiona... | [
"def",
"add_optional_param",
"(",
"key",
",",
"value",
",",
"params",
",",
"call_params",
")",
"if",
"!",
"value",
"params",
"[",
"-",
"1",
"]",
"[",
"key",
".",
"to_sym",
"]",
"=",
"call_params",
"[",
"key",
".",
"to_sym",
"]",
"if",
"call_params",
... | Add optional param into params list.
@param key optional param key
@param value optional param value
@param params combined list of required and optional parameters
@param call_params API call parameters | [
"Add",
"optional",
"param",
"into",
"params",
"list",
"."
] | 96e9d491486f09e044ea5d05c433e53a37a08120 | https://github.com/shinesolutions/ruby_aem/blob/96e9d491486f09e044ea5d05c433e53a37a08120/lib/ruby_aem/client.rb#L88-L117 | train |
shinesolutions/ruby_aem | lib/ruby_aem/client.rb | RubyAem.Client.handle | def handle(response, responses_spec, call_params)
if responses_spec.key?(response.status_code)
response_spec = responses_spec[response.status_code]
handler = response_spec['handler']
Handlers.send(handler, response, response_spec, call_params)
else
message = "Unexpected respo... | ruby | def handle(response, responses_spec, call_params)
if responses_spec.key?(response.status_code)
response_spec = responses_spec[response.status_code]
handler = response_spec['handler']
Handlers.send(handler, response, response_spec, call_params)
else
message = "Unexpected respo... | [
"def",
"handle",
"(",
"response",
",",
"responses_spec",
",",
"call_params",
")",
"if",
"responses_spec",
".",
"key?",
"(",
"response",
".",
"status_code",
")",
"response_spec",
"=",
"responses_spec",
"[",
"response",
".",
"status_code",
"]",
"handler",
"=",
"... | Handle a response based on status code and a given list of response specifications.
If none of the response specifications contains the status code, a failure result
will then be returned.
@param response response containing HTTP status code, body, and headers
@param responses_spec a list of response specification... | [
"Handle",
"a",
"response",
"based",
"on",
"status",
"code",
"and",
"a",
"given",
"list",
"of",
"response",
"specifications",
".",
"If",
"none",
"of",
"the",
"response",
"specifications",
"contains",
"the",
"status",
"code",
"a",
"failure",
"result",
"will",
... | 96e9d491486f09e044ea5d05c433e53a37a08120 | https://github.com/shinesolutions/ruby_aem/blob/96e9d491486f09e044ea5d05c433e53a37a08120/lib/ruby_aem/client.rb#L128-L138 | train |
daddyz/evercookie | lib/evercookie/controller.rb | Evercookie.EvercookieController.save | def save
if data = session[Evercookie.hash_name_for_get]
if data[:key] && cookies[data[:key]]
session[Evercookie.hash_name_for_saved] =
{ data[:key] => cookies[data[:key]] }
end
end
render nothing: true
end | ruby | def save
if data = session[Evercookie.hash_name_for_get]
if data[:key] && cookies[data[:key]]
session[Evercookie.hash_name_for_saved] =
{ data[:key] => cookies[data[:key]] }
end
end
render nothing: true
end | [
"def",
"save",
"if",
"data",
"=",
"session",
"[",
"Evercookie",
".",
"hash_name_for_get",
"]",
"if",
"data",
"[",
":key",
"]",
"&&",
"cookies",
"[",
"data",
"[",
":key",
"]",
"]",
"session",
"[",
"Evercookie",
".",
"hash_name_for_saved",
"]",
"=",
"{",
... | Saves current evercookie value to session | [
"Saves",
"current",
"evercookie",
"value",
"to",
"session"
] | 887c607e43865caf2ce7c649fc5e531653024cbe | https://github.com/daddyz/evercookie/blob/887c607e43865caf2ce7c649fc5e531653024cbe/lib/evercookie/controller.rb#L60-L68 | train |
daddyz/evercookie | lib/evercookie/controller.rb | Evercookie.EvercookieController.ec_png | def ec_png
if not cookies[Evercookie.cookie_png].present?
render :nothing => true, :status => 304
return true
end
response.headers["Content-Type"] = "image/png"
response.headers["Last-Modified"] = "Wed, 30 Jun 2010 21:36:48 GMT"
response.headers["Expires"] = "Tue, 31 Dec 2... | ruby | def ec_png
if not cookies[Evercookie.cookie_png].present?
render :nothing => true, :status => 304
return true
end
response.headers["Content-Type"] = "image/png"
response.headers["Last-Modified"] = "Wed, 30 Jun 2010 21:36:48 GMT"
response.headers["Expires"] = "Tue, 31 Dec 2... | [
"def",
"ec_png",
"if",
"not",
"cookies",
"[",
"Evercookie",
".",
"cookie_png",
"]",
".",
"present?",
"render",
":nothing",
"=>",
"true",
",",
":status",
"=>",
"304",
"return",
"true",
"end",
"response",
".",
"headers",
"[",
"\"Content-Type\"",
"]",
"=",
"\... | Renders png image with encoded evercookie value in it | [
"Renders",
"png",
"image",
"with",
"encoded",
"evercookie",
"value",
"in",
"it"
] | 887c607e43865caf2ce7c649fc5e531653024cbe | https://github.com/daddyz/evercookie/blob/887c607e43865caf2ce7c649fc5e531653024cbe/lib/evercookie/controller.rb#L71-L83 | train |
daddyz/evercookie | lib/evercookie/controller.rb | Evercookie.EvercookieController.ec_etag | def ec_etag
if not cookies[Evercookie.cookie_etag].present?
render :text => request.headers['If-None-Match'] || '', :status => 304
return true
end
puts "cache value (#{Evercookie.cookie_etag}): #{cookies[Evercookie.cookie_etag]}"
response.headers["Etag"] = cookies[Evercookie.co... | ruby | def ec_etag
if not cookies[Evercookie.cookie_etag].present?
render :text => request.headers['If-None-Match'] || '', :status => 304
return true
end
puts "cache value (#{Evercookie.cookie_etag}): #{cookies[Evercookie.cookie_etag]}"
response.headers["Etag"] = cookies[Evercookie.co... | [
"def",
"ec_etag",
"if",
"not",
"cookies",
"[",
"Evercookie",
".",
"cookie_etag",
"]",
".",
"present?",
"render",
":text",
"=>",
"request",
".",
"headers",
"[",
"'If-None-Match'",
"]",
"||",
"''",
",",
":status",
"=>",
"304",
"return",
"true",
"end",
"puts"... | Renders page with etag header for evercookie js script | [
"Renders",
"page",
"with",
"etag",
"header",
"for",
"evercookie",
"js",
"script"
] | 887c607e43865caf2ce7c649fc5e531653024cbe | https://github.com/daddyz/evercookie/blob/887c607e43865caf2ce7c649fc5e531653024cbe/lib/evercookie/controller.rb#L86-L96 | train |
daddyz/evercookie | lib/evercookie/controller.rb | Evercookie.EvercookieController.ec_cache | def ec_cache
if not cookies[Evercookie.cookie_cache].present?
render :nothing => true, :status => 304
return true
end
puts "cache value (#{Evercookie.cookie_cache}): #{cookies[Evercookie.cookie_cache]}"
response.headers["Content-Type"] = "text/html"
response.headers["Last... | ruby | def ec_cache
if not cookies[Evercookie.cookie_cache].present?
render :nothing => true, :status => 304
return true
end
puts "cache value (#{Evercookie.cookie_cache}): #{cookies[Evercookie.cookie_cache]}"
response.headers["Content-Type"] = "text/html"
response.headers["Last... | [
"def",
"ec_cache",
"if",
"not",
"cookies",
"[",
"Evercookie",
".",
"cookie_cache",
"]",
".",
"present?",
"render",
":nothing",
"=>",
"true",
",",
":status",
"=>",
"304",
"return",
"true",
"end",
"puts",
"\"cache value (#{Evercookie.cookie_cache}): #{cookies[Evercookie... | Renders page with cache header for evercookie js script | [
"Renders",
"page",
"with",
"cache",
"header",
"for",
"evercookie",
"js",
"script"
] | 887c607e43865caf2ce7c649fc5e531653024cbe | https://github.com/daddyz/evercookie/blob/887c607e43865caf2ce7c649fc5e531653024cbe/lib/evercookie/controller.rb#L99-L113 | train |
david942j/rbelftools | lib/elftools/note.rb | ELFTools.Note.each_notes | def each_notes
return enum_for(:each_notes) unless block_given?
@notes_offset_map ||= {}
cur = note_start
notes = []
while cur < note_start + note_total_size
stream.pos = cur
@notes_offset_map[cur] ||= create_note(cur)
note = @notes_offset_map[cur]
# name a... | ruby | def each_notes
return enum_for(:each_notes) unless block_given?
@notes_offset_map ||= {}
cur = note_start
notes = []
while cur < note_start + note_total_size
stream.pos = cur
@notes_offset_map[cur] ||= create_note(cur)
note = @notes_offset_map[cur]
# name a... | [
"def",
"each_notes",
"return",
"enum_for",
"(",
":each_notes",
")",
"unless",
"block_given?",
"@notes_offset_map",
"||=",
"{",
"}",
"cur",
"=",
"note_start",
"notes",
"=",
"[",
"]",
"while",
"cur",
"<",
"note_start",
"+",
"note_total_size",
"stream",
".",
"pos... | Iterate all notes in a note section or segment.
Structure of notes are:
+---------------+
| Note 1 header |
+---------------+
| Note 1 name |
+---------------+
| Note 1 desc |
+---------------+
| Note 2 header |
+---------------+
| ... |
+---------------+
@note
This... | [
"Iterate",
"all",
"notes",
"in",
"a",
"note",
"section",
"or",
"segment",
"."
] | 9a453ac31d72eae3b8b99d5dbd361c101577d58e | https://github.com/david942j/rbelftools/blob/9a453ac31d72eae3b8b99d5dbd361c101577d58e/lib/elftools/note.rb#L42-L60 | train |
notEthan/oauthenticator | lib/oauthenticator/signed_request.rb | OAuthenticator.SignedRequest.config_method_not_implemented | def config_method_not_implemented
caller_name = caller[0].match(%r(in `(.*?)'))[1]
using_middleware = caller.any? { |l| l =~ %r(oauthenticator/rack_authenticator.rb:.*`call') }
message = "method \##{caller_name} must be implemented on a module of oauth config methods, which is " + begin
if usi... | ruby | def config_method_not_implemented
caller_name = caller[0].match(%r(in `(.*?)'))[1]
using_middleware = caller.any? { |l| l =~ %r(oauthenticator/rack_authenticator.rb:.*`call') }
message = "method \##{caller_name} must be implemented on a module of oauth config methods, which is " + begin
if usi... | [
"def",
"config_method_not_implemented",
"caller_name",
"=",
"caller",
"[",
"0",
"]",
".",
"match",
"(",
"%r(",
")",
")",
"[",
"1",
"]",
"using_middleware",
"=",
"caller",
".",
"any?",
"{",
"|",
"l",
"|",
"l",
"=~",
"%r(",
")",
"}",
"message",
"=",
"\... | raise a nice error message for a method that needs to be implemented on a module of config methods | [
"raise",
"a",
"nice",
"error",
"message",
"for",
"a",
"method",
"that",
"needs",
"to",
"be",
"implemented",
"on",
"a",
"module",
"of",
"config",
"methods"
] | f462501e4d3e79086855ad5c6f95104de3c2ec07 | https://github.com/notEthan/oauthenticator/blob/f462501e4d3e79086855ad5c6f95104de3c2ec07/lib/oauthenticator/signed_request.rb#L245-L256 | train |
cotag/http-parser | lib/http-parser/types.rb | HttpParser.Instance.error | def error
error = (self[:error_upgrade] & 0b1111111)
return nil if error == 0
err = ::HttpParser.err_name(error)[4..-1] # HPE_ is at the start of all these errors
klass = ERRORS[err.to_sym]
err = "#{::HttpParser.err_desc(error)} (#{err})"
return k... | ruby | def error
error = (self[:error_upgrade] & 0b1111111)
return nil if error == 0
err = ::HttpParser.err_name(error)[4..-1] # HPE_ is at the start of all these errors
klass = ERRORS[err.to_sym]
err = "#{::HttpParser.err_desc(error)} (#{err})"
return k... | [
"def",
"error",
"error",
"=",
"(",
"self",
"[",
":error_upgrade",
"]",
"&",
"0b1111111",
")",
"return",
"nil",
"if",
"error",
"==",
"0",
"err",
"=",
"::",
"HttpParser",
".",
"err_name",
"(",
"error",
")",
"[",
"4",
"..",
"-",
"1",
"]",
"klass",
"="... | Returns the error that occurred during processing.
@return [StandarError]
Returns the error that occurred. | [
"Returns",
"the",
"error",
"that",
"occurred",
"during",
"processing",
"."
] | 9a202b38945e9ad66ca113947860267411efc6f2 | https://github.com/cotag/http-parser/blob/9a202b38945e9ad66ca113947860267411efc6f2/lib/http-parser/types.rb#L241-L249 | train |
notEthan/oauthenticator | lib/oauthenticator/faraday_signer.rb | OAuthenticator.FaradaySigner.call | def call(request_env)
media_type = Rack::Request.new('CONTENT_TYPE' => request_env[:request_headers]['Content-Type']).media_type
request_attributes = {
:request_method => request_env[:method],
:uri => request_env[:url],
:media_type => media_type,
:body => request_env[:body]
... | ruby | def call(request_env)
media_type = Rack::Request.new('CONTENT_TYPE' => request_env[:request_headers]['Content-Type']).media_type
request_attributes = {
:request_method => request_env[:method],
:uri => request_env[:url],
:media_type => media_type,
:body => request_env[:body]
... | [
"def",
"call",
"(",
"request_env",
")",
"media_type",
"=",
"Rack",
"::",
"Request",
".",
"new",
"(",
"'CONTENT_TYPE'",
"=>",
"request_env",
"[",
":request_headers",
"]",
"[",
"'Content-Type'",
"]",
")",
".",
"media_type",
"request_attributes",
"=",
"{",
":requ... | do the thing | [
"do",
"the",
"thing"
] | f462501e4d3e79086855ad5c6f95104de3c2ec07 | https://github.com/notEthan/oauthenticator/blob/f462501e4d3e79086855ad5c6f95104de3c2ec07/lib/oauthenticator/faraday_signer.rb#L56-L74 | train |
notEthan/oauthenticator | lib/oauthenticator/signable_request.rb | OAuthenticator.SignableRequest.signature_base | def signature_base
parts = [normalized_request_method, base_string_uri, normalized_request_params_string]
parts.map { |v| OAuthenticator.escape(v) }.join('&')
end | ruby | def signature_base
parts = [normalized_request_method, base_string_uri, normalized_request_params_string]
parts.map { |v| OAuthenticator.escape(v) }.join('&')
end | [
"def",
"signature_base",
"parts",
"=",
"[",
"normalized_request_method",
",",
"base_string_uri",
",",
"normalized_request_params_string",
"]",
"parts",
".",
"map",
"{",
"|",
"v",
"|",
"OAuthenticator",
".",
"escape",
"(",
"v",
")",
"}",
".",
"join",
"(",
"'&'"... | signature base string for signing. section 3.4.1
@return [String] | [
"signature",
"base",
"string",
"for",
"signing",
".",
"section",
"3",
".",
"4",
".",
"1"
] | f462501e4d3e79086855ad5c6f95104de3c2ec07 | https://github.com/notEthan/oauthenticator/blob/f462501e4d3e79086855ad5c6f95104de3c2ec07/lib/oauthenticator/signable_request.rb#L170-L173 | train |
notEthan/oauthenticator | lib/oauthenticator/signable_request.rb | OAuthenticator.SignableRequest.base_string_uri | def base_string_uri
Addressable::URI.parse(@attributes['uri'].to_s).tap do |uri|
uri.scheme = uri.scheme.downcase if uri.scheme
uri.host = uri.host.downcase if uri.host
uri.normalize!
uri.fragment = nil
uri.query = nil
end.to_s
end | ruby | def base_string_uri
Addressable::URI.parse(@attributes['uri'].to_s).tap do |uri|
uri.scheme = uri.scheme.downcase if uri.scheme
uri.host = uri.host.downcase if uri.host
uri.normalize!
uri.fragment = nil
uri.query = nil
end.to_s
end | [
"def",
"base_string_uri",
"Addressable",
"::",
"URI",
".",
"parse",
"(",
"@attributes",
"[",
"'uri'",
"]",
".",
"to_s",
")",
".",
"tap",
"do",
"|",
"uri",
"|",
"uri",
".",
"scheme",
"=",
"uri",
".",
"scheme",
".",
"downcase",
"if",
"uri",
".",
"schem... | section 3.4.1.2
@return [String] | [
"section",
"3",
".",
"4",
".",
"1",
".",
"2"
] | f462501e4d3e79086855ad5c6f95104de3c2ec07 | https://github.com/notEthan/oauthenticator/blob/f462501e4d3e79086855ad5c6f95104de3c2ec07/lib/oauthenticator/signable_request.rb#L178-L186 | train |
notEthan/oauthenticator | lib/oauthenticator/signable_request.rb | OAuthenticator.SignableRequest.normalized_request_params_string | def normalized_request_params_string
normalized_request_params.map { |kv| kv.map { |v| OAuthenticator.escape(v) } }.sort.map { |p| p.join('=') }.join('&')
end | ruby | def normalized_request_params_string
normalized_request_params.map { |kv| kv.map { |v| OAuthenticator.escape(v) } }.sort.map { |p| p.join('=') }.join('&')
end | [
"def",
"normalized_request_params_string",
"normalized_request_params",
".",
"map",
"{",
"|",
"kv",
"|",
"kv",
".",
"map",
"{",
"|",
"v",
"|",
"OAuthenticator",
".",
"escape",
"(",
"v",
")",
"}",
"}",
".",
"sort",
".",
"map",
"{",
"|",
"p",
"|",
"p",
... | section 3.4.1.3.2
@return [String] | [
"section",
"3",
".",
"4",
".",
"1",
".",
"3",
".",
"2"
] | f462501e4d3e79086855ad5c6f95104de3c2ec07 | https://github.com/notEthan/oauthenticator/blob/f462501e4d3e79086855ad5c6f95104de3c2ec07/lib/oauthenticator/signable_request.rb#L198-L200 | train |
notEthan/oauthenticator | lib/oauthenticator/signable_request.rb | OAuthenticator.SignableRequest.normalized_request_params | def normalized_request_params
query_params + protocol_params.reject { |k,v| %w(realm oauth_signature).include?(k) }.to_a + entity_params
end | ruby | def normalized_request_params
query_params + protocol_params.reject { |k,v| %w(realm oauth_signature).include?(k) }.to_a + entity_params
end | [
"def",
"normalized_request_params",
"query_params",
"+",
"protocol_params",
".",
"reject",
"{",
"|",
"k",
",",
"v",
"|",
"%w(",
"realm",
"oauth_signature",
")",
".",
"include?",
"(",
"k",
")",
"}",
".",
"to_a",
"+",
"entity_params",
"end"
] | section 3.4.1.3
@return [Array<Array<String> (size 2)>] | [
"section",
"3",
".",
"4",
".",
"1",
".",
"3"
] | f462501e4d3e79086855ad5c6f95104de3c2ec07 | https://github.com/notEthan/oauthenticator/blob/f462501e4d3e79086855ad5c6f95104de3c2ec07/lib/oauthenticator/signable_request.rb#L205-L207 | train |
notEthan/oauthenticator | lib/oauthenticator/signable_request.rb | OAuthenticator.SignableRequest.parse_form_encoded | def parse_form_encoded(data)
data.split(/[&;]/).map do |pair|
key, value = pair.split('=', 2).map { |v| CGI::unescape(v) }
[key, value] unless [nil, ''].include?(key)
end.compact
end | ruby | def parse_form_encoded(data)
data.split(/[&;]/).map do |pair|
key, value = pair.split('=', 2).map { |v| CGI::unescape(v) }
[key, value] unless [nil, ''].include?(key)
end.compact
end | [
"def",
"parse_form_encoded",
"(",
"data",
")",
"data",
".",
"split",
"(",
"/",
"/",
")",
".",
"map",
"do",
"|",
"pair",
"|",
"key",
",",
"value",
"=",
"pair",
".",
"split",
"(",
"'='",
",",
"2",
")",
".",
"map",
"{",
"|",
"v",
"|",
"CGI",
"::... | like CGI.parse but it keeps keys without any value. doesn't keep blank keys though.
@return [Array<Array<String, nil> (size 2)>] | [
"like",
"CGI",
".",
"parse",
"but",
"it",
"keeps",
"keys",
"without",
"any",
"value",
".",
"doesn",
"t",
"keep",
"blank",
"keys",
"though",
"."
] | f462501e4d3e79086855ad5c6f95104de3c2ec07 | https://github.com/notEthan/oauthenticator/blob/f462501e4d3e79086855ad5c6f95104de3c2ec07/lib/oauthenticator/signable_request.rb#L236-L241 | train |
notEthan/oauthenticator | lib/oauthenticator/signable_request.rb | OAuthenticator.SignableRequest.read_body | def read_body
body = @attributes['body']
if body.nil?
''
elsif body.is_a?(String)
body
elsif body.respond_to?(:read) && body.respond_to?(:rewind)
body.rewind
body.read.tap do
body.rewind
end
else
raise TypeError, "Body must be a Str... | ruby | def read_body
body = @attributes['body']
if body.nil?
''
elsif body.is_a?(String)
body
elsif body.respond_to?(:read) && body.respond_to?(:rewind)
body.rewind
body.read.tap do
body.rewind
end
else
raise TypeError, "Body must be a Str... | [
"def",
"read_body",
"body",
"=",
"@attributes",
"[",
"'body'",
"]",
"if",
"body",
".",
"nil?",
"''",
"elsif",
"body",
".",
"is_a?",
"(",
"String",
")",
"body",
"elsif",
"body",
".",
"respond_to?",
"(",
":read",
")",
"&&",
"body",
".",
"respond_to?",
"(... | reads the request body, be it String or IO
@return [String] request body | [
"reads",
"the",
"request",
"body",
"be",
"it",
"String",
"or",
"IO"
] | f462501e4d3e79086855ad5c6f95104de3c2ec07 | https://github.com/notEthan/oauthenticator/blob/f462501e4d3e79086855ad5c6f95104de3c2ec07/lib/oauthenticator/signable_request.rb#L253-L268 | train |
notEthan/oauthenticator | lib/oauthenticator/signable_request.rb | OAuthenticator.SignableRequest.rsa_sha1_signature | def rsa_sha1_signature
private_key = OpenSSL::PKey::RSA.new(@attributes['consumer_secret'])
Base64.encode64(private_key.sign(OpenSSL::Digest::SHA1.new, signature_base)).gsub(/\n/, '')
end | ruby | def rsa_sha1_signature
private_key = OpenSSL::PKey::RSA.new(@attributes['consumer_secret'])
Base64.encode64(private_key.sign(OpenSSL::Digest::SHA1.new, signature_base)).gsub(/\n/, '')
end | [
"def",
"rsa_sha1_signature",
"private_key",
"=",
"OpenSSL",
"::",
"PKey",
"::",
"RSA",
".",
"new",
"(",
"@attributes",
"[",
"'consumer_secret'",
"]",
")",
"Base64",
".",
"encode64",
"(",
"private_key",
".",
"sign",
"(",
"OpenSSL",
"::",
"Digest",
"::",
"SHA1... | signature, with method RSA-SHA1. section 3.4.3
@return [String] | [
"signature",
"with",
"method",
"RSA",
"-",
"SHA1",
".",
"section",
"3",
".",
"4",
".",
"3"
] | f462501e4d3e79086855ad5c6f95104de3c2ec07 | https://github.com/notEthan/oauthenticator/blob/f462501e4d3e79086855ad5c6f95104de3c2ec07/lib/oauthenticator/signable_request.rb#L298-L301 | train |
notEthan/oauthenticator | lib/oauthenticator/signable_request.rb | OAuthenticator.SignableRequest.hmac_sha1_signature | def hmac_sha1_signature
# hmac secret is same as plaintext signature
secret = plaintext_signature
Base64.encode64(OpenSSL::HMAC.digest(OpenSSL::Digest::SHA1.new, secret, signature_base)).gsub(/\n/, '')
end | ruby | def hmac_sha1_signature
# hmac secret is same as plaintext signature
secret = plaintext_signature
Base64.encode64(OpenSSL::HMAC.digest(OpenSSL::Digest::SHA1.new, secret, signature_base)).gsub(/\n/, '')
end | [
"def",
"hmac_sha1_signature",
"secret",
"=",
"plaintext_signature",
"Base64",
".",
"encode64",
"(",
"OpenSSL",
"::",
"HMAC",
".",
"digest",
"(",
"OpenSSL",
"::",
"Digest",
"::",
"SHA1",
".",
"new",
",",
"secret",
",",
"signature_base",
")",
")",
".",
"gsub",... | signature, with method HMAC-SHA1. section 3.4.2
@return [String] | [
"signature",
"with",
"method",
"HMAC",
"-",
"SHA1",
".",
"section",
"3",
".",
"4",
".",
"2"
] | f462501e4d3e79086855ad5c6f95104de3c2ec07 | https://github.com/notEthan/oauthenticator/blob/f462501e4d3e79086855ad5c6f95104de3c2ec07/lib/oauthenticator/signable_request.rb#L306-L310 | train |
moio/tetra | lib/tetra/facades/bash.rb | Tetra.Bash.bash | def bash(command = nil)
Tempfile.open("tetra-history") do |history_file|
Tempfile.open("tetra-bashrc") do |bashrc_file|
kit = Tetra::Kit.new(@project)
ant_path = kit.find_executable("ant")
ant_in_kit = ant_path != nil
ant_commandline = Tetra::Ant.commandline(@projec... | ruby | def bash(command = nil)
Tempfile.open("tetra-history") do |history_file|
Tempfile.open("tetra-bashrc") do |bashrc_file|
kit = Tetra::Kit.new(@project)
ant_path = kit.find_executable("ant")
ant_in_kit = ant_path != nil
ant_commandline = Tetra::Ant.commandline(@projec... | [
"def",
"bash",
"(",
"command",
"=",
"nil",
")",
"Tempfile",
".",
"open",
"(",
"\"tetra-history\"",
")",
"do",
"|",
"history_file",
"|",
"Tempfile",
".",
"open",
"(",
"\"tetra-bashrc\"",
")",
"do",
"|",
"bashrc_file",
"|",
"kit",
"=",
"Tetra",
"::",
"Kit"... | runs bash in a subshell, returns list of
commands that were run in the session | [
"runs",
"bash",
"in",
"a",
"subshell",
"returns",
"list",
"of",
"commands",
"that",
"were",
"run",
"in",
"the",
"session"
] | de06d766502b885bd62bd7cd9dc8da678abd7cb0 | https://github.com/moio/tetra/blob/de06d766502b885bd62bd7cd9dc8da678abd7cb0/lib/tetra/facades/bash.rb#L15-L47 | train |
jantman/serverspec-extended-types | lib/serverspec_extended_types/bitlbee.rb | Serverspec.Type.bitlbee | def bitlbee(port, nick, password, use_ssl=false)
Bitlbee.new(port, nick, password, use_ssl)
end | ruby | def bitlbee(port, nick, password, use_ssl=false)
Bitlbee.new(port, nick, password, use_ssl)
end | [
"def",
"bitlbee",
"(",
"port",
",",
"nick",
",",
"password",
",",
"use_ssl",
"=",
"false",
")",
"Bitlbee",
".",
"new",
"(",
"port",
",",
"nick",
",",
"password",
",",
"use_ssl",
")",
"end"
] | Serverspec Type method for Bitlbee
@example
describe bitlbee(6697, 'myuser', 'mypass') do
# tests here
end
@api public
@param port [Integer] the port to connect to
@param nick [String] the nick to connect as
@param password [String] the password for nick
@param use_ssl [Boolean] whether to connect w... | [
"Serverspec",
"Type",
"method",
"for",
"Bitlbee"
] | 28437dcccc403ab71abe8bf481ec4d22d4eed395 | https://github.com/jantman/serverspec-extended-types/blob/28437dcccc403ab71abe8bf481ec4d22d4eed395/lib/serverspec_extended_types/bitlbee.rb#L198-L200 | train |
moio/tetra | lib/tetra/facades/git.rb | Tetra.Git.commit_directories | def commit_directories(directories, message)
log.debug "committing with message: #{message}"
Dir.chdir(@directory) do
directories.each do |directory|
run("git rm -r --cached --ignore-unmatch #{directory}")
run("git add #{directory}")
end
run("git commit --allow-e... | ruby | def commit_directories(directories, message)
log.debug "committing with message: #{message}"
Dir.chdir(@directory) do
directories.each do |directory|
run("git rm -r --cached --ignore-unmatch #{directory}")
run("git add #{directory}")
end
run("git commit --allow-e... | [
"def",
"commit_directories",
"(",
"directories",
",",
"message",
")",
"log",
".",
"debug",
"\"committing with message: #{message}\"",
"Dir",
".",
"chdir",
"(",
"@directory",
")",
"do",
"directories",
".",
"each",
"do",
"|",
"directory",
"|",
"run",
"(",
"\"git r... | adds all files in the specified directories,
removes all files not in the specified directories,
commits with message | [
"adds",
"all",
"files",
"in",
"the",
"specified",
"directories",
"removes",
"all",
"files",
"not",
"in",
"the",
"specified",
"directories",
"commits",
"with",
"message"
] | de06d766502b885bd62bd7cd9dc8da678abd7cb0 | https://github.com/moio/tetra/blob/de06d766502b885bd62bd7cd9dc8da678abd7cb0/lib/tetra/facades/git.rb#L49-L59 | train |
moio/tetra | lib/tetra/facades/git.rb | Tetra.Git.commit_file | def commit_file(path, message)
Dir.chdir(@directory) do
log.debug "committing path #{path} with message: #{message}"
run("git add #{path}")
run("git commit --allow-empty -F -", false, message)
end
end | ruby | def commit_file(path, message)
Dir.chdir(@directory) do
log.debug "committing path #{path} with message: #{message}"
run("git add #{path}")
run("git commit --allow-empty -F -", false, message)
end
end | [
"def",
"commit_file",
"(",
"path",
",",
"message",
")",
"Dir",
".",
"chdir",
"(",
"@directory",
")",
"do",
"log",
".",
"debug",
"\"committing path #{path} with message: #{message}\"",
"run",
"(",
"\"git add #{path}\"",
")",
"run",
"(",
"\"git commit --allow-empty -F -... | commits one single file | [
"commits",
"one",
"single",
"file"
] | de06d766502b885bd62bd7cd9dc8da678abd7cb0 | https://github.com/moio/tetra/blob/de06d766502b885bd62bd7cd9dc8da678abd7cb0/lib/tetra/facades/git.rb#L62-L68 | train |
moio/tetra | lib/tetra/facades/git.rb | Tetra.Git.revert_directories | def revert_directories(directories, id)
Dir.chdir(@directory) do
directories.each do |directory|
# reverts added and modified files, both in index and working tree
run("git checkout -f #{id} -- #{directory}")
# compute the list of deleted files
files_in_commit = ru... | ruby | def revert_directories(directories, id)
Dir.chdir(@directory) do
directories.each do |directory|
# reverts added and modified files, both in index and working tree
run("git checkout -f #{id} -- #{directory}")
# compute the list of deleted files
files_in_commit = ru... | [
"def",
"revert_directories",
"(",
"directories",
",",
"id",
")",
"Dir",
".",
"chdir",
"(",
"@directory",
")",
"do",
"directories",
".",
"each",
"do",
"|",
"directory",
"|",
"run",
"(",
"\"git checkout -f #{id} -- #{directory}\"",
")",
"files_in_commit",
"=",
"ru... | reverts multiple directories' contents as per specified id | [
"reverts",
"multiple",
"directories",
"contents",
"as",
"per",
"specified",
"id"
] | de06d766502b885bd62bd7cd9dc8da678abd7cb0 | https://github.com/moio/tetra/blob/de06d766502b885bd62bd7cd9dc8da678abd7cb0/lib/tetra/facades/git.rb#L71-L88 | train |
moio/tetra | lib/tetra/facades/git.rb | Tetra.Git.disable_special_files | def disable_special_files(path)
Dir.chdir(File.join(@directory, path)) do
Find.find(".") do |file|
next unless file =~ /\.git(ignore)?$/
FileUtils.mv(file, "#{file}_disabled_by_tetra")
end
end
end | ruby | def disable_special_files(path)
Dir.chdir(File.join(@directory, path)) do
Find.find(".") do |file|
next unless file =~ /\.git(ignore)?$/
FileUtils.mv(file, "#{file}_disabled_by_tetra")
end
end
end | [
"def",
"disable_special_files",
"(",
"path",
")",
"Dir",
".",
"chdir",
"(",
"File",
".",
"join",
"(",
"@directory",
",",
"path",
")",
")",
"do",
"Find",
".",
"find",
"(",
"\".\"",
")",
"do",
"|",
"file",
"|",
"next",
"unless",
"file",
"=~",
"/",
"\... | renames git special files to 'disable' them | [
"renames",
"git",
"special",
"files",
"to",
"disable",
"them"
] | de06d766502b885bd62bd7cd9dc8da678abd7cb0 | https://github.com/moio/tetra/blob/de06d766502b885bd62bd7cd9dc8da678abd7cb0/lib/tetra/facades/git.rb#L99-L107 | train |
moio/tetra | lib/tetra/facades/git.rb | Tetra.Git.merge_with_id | def merge_with_id(path, new_path, id)
Dir.chdir(@directory) do
run("git show #{id}:#{path} > #{path}.old_version")
conflict_count = 0
begin
run("git merge-file #{path} #{path}.old_version #{new_path} \
-L \"newly generated\" \
-L \"previously gene... | ruby | def merge_with_id(path, new_path, id)
Dir.chdir(@directory) do
run("git show #{id}:#{path} > #{path}.old_version")
conflict_count = 0
begin
run("git merge-file #{path} #{path}.old_version #{new_path} \
-L \"newly generated\" \
-L \"previously gene... | [
"def",
"merge_with_id",
"(",
"path",
",",
"new_path",
",",
"id",
")",
"Dir",
".",
"chdir",
"(",
"@directory",
")",
"do",
"run",
"(",
"\"git show #{id}:#{path} > #{path}.old_version\"",
")",
"conflict_count",
"=",
"0",
"begin",
"run",
"(",
"\"git merge-file #{path}... | 3-way merges the git file at path with the one in new_path
assuming they have a common ancestor at the specified id
returns the conflict count | [
"3",
"-",
"way",
"merges",
"the",
"git",
"file",
"at",
"path",
"with",
"the",
"one",
"in",
"new_path",
"assuming",
"they",
"have",
"a",
"common",
"ancestor",
"at",
"the",
"specified",
"id",
"returns",
"the",
"conflict",
"count"
] | de06d766502b885bd62bd7cd9dc8da678abd7cb0 | https://github.com/moio/tetra/blob/de06d766502b885bd62bd7cd9dc8da678abd7cb0/lib/tetra/facades/git.rb#L112-L132 | train |
moio/tetra | lib/tetra/facades/git.rb | Tetra.Git.changed_files | def changed_files(directory, id)
Dir.chdir(@directory) do
tracked_files = []
begin
tracked_files += run("git diff-index --name-only #{id} -- #{directory}").split
rescue ExecutionFailed => e
raise e if e.status != 1 # status 1 is normal
end
untracked_fil... | ruby | def changed_files(directory, id)
Dir.chdir(@directory) do
tracked_files = []
begin
tracked_files += run("git diff-index --name-only #{id} -- #{directory}").split
rescue ExecutionFailed => e
raise e if e.status != 1 # status 1 is normal
end
untracked_fil... | [
"def",
"changed_files",
"(",
"directory",
",",
"id",
")",
"Dir",
".",
"chdir",
"(",
"@directory",
")",
"do",
"tracked_files",
"=",
"[",
"]",
"begin",
"tracked_files",
"+=",
"run",
"(",
"\"git diff-index --name-only #{id} -- #{directory}\"",
")",
".",
"split",
"r... | returns the list of files changed from since_id
including changes in the working tree and staging
area | [
"returns",
"the",
"list",
"of",
"files",
"changed",
"from",
"since_id",
"including",
"changes",
"in",
"the",
"working",
"tree",
"and",
"staging",
"area"
] | de06d766502b885bd62bd7cd9dc8da678abd7cb0 | https://github.com/moio/tetra/blob/de06d766502b885bd62bd7cd9dc8da678abd7cb0/lib/tetra/facades/git.rb#L137-L149 | train |
moio/tetra | lib/tetra/facades/git.rb | Tetra.Git.archive | def archive(directory, id, destination_path)
Dir.chdir(@directory) do
FileUtils.mkdir_p(File.dirname(destination_path))
run("git archive --format=tar #{id} -- #{directory} | xz -9e > #{destination_path}")
end
destination_path
end | ruby | def archive(directory, id, destination_path)
Dir.chdir(@directory) do
FileUtils.mkdir_p(File.dirname(destination_path))
run("git archive --format=tar #{id} -- #{directory} | xz -9e > #{destination_path}")
end
destination_path
end | [
"def",
"archive",
"(",
"directory",
",",
"id",
",",
"destination_path",
")",
"Dir",
".",
"chdir",
"(",
"@directory",
")",
"do",
"FileUtils",
".",
"mkdir_p",
"(",
"File",
".",
"dirname",
"(",
"destination_path",
")",
")",
"run",
"(",
"\"git archive --format=t... | archives version id of directory in destination_path | [
"archives",
"version",
"id",
"of",
"directory",
"in",
"destination_path"
] | de06d766502b885bd62bd7cd9dc8da678abd7cb0 | https://github.com/moio/tetra/blob/de06d766502b885bd62bd7cd9dc8da678abd7cb0/lib/tetra/facades/git.rb#L152-L158 | train |
moio/tetra | lib/tetra/ui/subcommand.rb | Tetra.Subcommand.configure_log_level | def configure_log_level(v, vv, vvv)
if vvv
log.level = ::Logger::DEBUG
elsif vv
log.level = ::Logger::INFO
elsif v
log.level = ::Logger::WARN
else
log.level = ::Logger::ERROR
end
end | ruby | def configure_log_level(v, vv, vvv)
if vvv
log.level = ::Logger::DEBUG
elsif vv
log.level = ::Logger::INFO
elsif v
log.level = ::Logger::WARN
else
log.level = ::Logger::ERROR
end
end | [
"def",
"configure_log_level",
"(",
"v",
",",
"vv",
",",
"vvv",
")",
"if",
"vvv",
"log",
".",
"level",
"=",
"::",
"Logger",
"::",
"DEBUG",
"elsif",
"vv",
"log",
".",
"level",
"=",
"::",
"Logger",
"::",
"INFO",
"elsif",
"v",
"log",
".",
"level",
"=",... | maps verbosity options to log level | [
"maps",
"verbosity",
"options",
"to",
"log",
"level"
] | de06d766502b885bd62bd7cd9dc8da678abd7cb0 | https://github.com/moio/tetra/blob/de06d766502b885bd62bd7cd9dc8da678abd7cb0/lib/tetra/ui/subcommand.rb#L27-L37 | train |
moio/tetra | lib/tetra/ui/subcommand.rb | Tetra.Subcommand.bypass_parsing | def bypass_parsing(args)
log.level = ::Logger::WARN if args.delete "--verbose"
log.level = ::Logger::INFO if args.delete "--very-verbose"
log.level = ::Logger::DEBUG if args.delete "--very-very-verbose"
@options = args
end | ruby | def bypass_parsing(args)
log.level = ::Logger::WARN if args.delete "--verbose"
log.level = ::Logger::INFO if args.delete "--very-verbose"
log.level = ::Logger::DEBUG if args.delete "--very-very-verbose"
@options = args
end | [
"def",
"bypass_parsing",
"(",
"args",
")",
"log",
".",
"level",
"=",
"::",
"Logger",
"::",
"WARN",
"if",
"args",
".",
"delete",
"\"--verbose\"",
"log",
".",
"level",
"=",
"::",
"Logger",
"::",
"INFO",
"if",
"args",
".",
"delete",
"\"--very-verbose\"",
"l... | override default option parsing to pass options to other commands | [
"override",
"default",
"option",
"parsing",
"to",
"pass",
"options",
"to",
"other",
"commands"
] | de06d766502b885bd62bd7cd9dc8da678abd7cb0 | https://github.com/moio/tetra/blob/de06d766502b885bd62bd7cd9dc8da678abd7cb0/lib/tetra/ui/subcommand.rb#L40-L46 | train |
moio/tetra | lib/tetra/ui/subcommand.rb | Tetra.Subcommand.format_path | def format_path(path, project)
full_path = (
if Pathname.new(path).relative?
File.join(project.full_path, path)
else
path
end
)
Pathname.new(full_path).relative_path_from(Pathname.new(Dir.pwd))
end | ruby | def format_path(path, project)
full_path = (
if Pathname.new(path).relative?
File.join(project.full_path, path)
else
path
end
)
Pathname.new(full_path).relative_path_from(Pathname.new(Dir.pwd))
end | [
"def",
"format_path",
"(",
"path",
",",
"project",
")",
"full_path",
"=",
"(",
"if",
"Pathname",
".",
"new",
"(",
"path",
")",
".",
"relative?",
"File",
".",
"join",
"(",
"project",
".",
"full_path",
",",
"path",
")",
"else",
"path",
"end",
")",
"Pat... | generates a version of path relative to the current directory | [
"generates",
"a",
"version",
"of",
"path",
"relative",
"to",
"the",
"current",
"directory"
] | de06d766502b885bd62bd7cd9dc8da678abd7cb0 | https://github.com/moio/tetra/blob/de06d766502b885bd62bd7cd9dc8da678abd7cb0/lib/tetra/ui/subcommand.rb#L77-L86 | train |
moio/tetra | lib/tetra/ui/subcommand.rb | Tetra.Subcommand.checking_exceptions | def checking_exceptions
yield
rescue Errno::EACCES => e
$stderr.puts e
rescue Errno::ENOENT => e
$stderr.puts e
rescue Errno::EEXIST => e
$stderr.puts e
rescue NoProjectDirectoryError => e
$stderr.puts "#{e.directory} is not a tetra project directory, see \"tetra init\""
... | ruby | def checking_exceptions
yield
rescue Errno::EACCES => e
$stderr.puts e
rescue Errno::ENOENT => e
$stderr.puts e
rescue Errno::EEXIST => e
$stderr.puts e
rescue NoProjectDirectoryError => e
$stderr.puts "#{e.directory} is not a tetra project directory, see \"tetra init\""
... | [
"def",
"checking_exceptions",
"yield",
"rescue",
"Errno",
"::",
"EACCES",
"=>",
"e",
"$stderr",
".",
"puts",
"e",
"rescue",
"Errno",
"::",
"ENOENT",
"=>",
"e",
"$stderr",
".",
"puts",
"e",
"rescue",
"Errno",
"::",
"EEXIST",
"=>",
"e",
"$stderr",
".",
"pu... | handles most fatal exceptions | [
"handles",
"most",
"fatal",
"exceptions"
] | de06d766502b885bd62bd7cd9dc8da678abd7cb0 | https://github.com/moio/tetra/blob/de06d766502b885bd62bd7cd9dc8da678abd7cb0/lib/tetra/ui/subcommand.rb#L89-L105 | train |
buildkite/buildbox-agent-ruby | lib/buildbox/canceler.rb | Buildbox.Canceler.process_map | def process_map
output = `ps -eo ppid,pid`
processes = {}
output.split("\n").each do |line|
if result = line.match(/(\d+)\s(\d+)/)
parent = result[1].to_i
child = result[2].to_i
processes[parent] ||= []
processes[parent] << child
end
... | ruby | def process_map
output = `ps -eo ppid,pid`
processes = {}
output.split("\n").each do |line|
if result = line.match(/(\d+)\s(\d+)/)
parent = result[1].to_i
child = result[2].to_i
processes[parent] ||= []
processes[parent] << child
end
... | [
"def",
"process_map",
"output",
"=",
"`",
"`",
"processes",
"=",
"{",
"}",
"output",
".",
"split",
"(",
"\"\\n\"",
")",
".",
"each",
"do",
"|",
"line",
"|",
"if",
"result",
"=",
"line",
".",
"match",
"(",
"/",
"\\d",
"\\s",
"\\d",
"/",
")",
"pare... | Generates a map of parent process and child processes. This method
will currently only work on unix. | [
"Generates",
"a",
"map",
"of",
"parent",
"process",
"and",
"child",
"processes",
".",
"This",
"method",
"will",
"currently",
"only",
"work",
"on",
"unix",
"."
] | cff8c7dec6eb120c6d36eb5907c556cb5d483c86 | https://github.com/buildkite/buildbox-agent-ruby/blob/cff8c7dec6eb120c6d36eb5907c556cb5d483c86/lib/buildbox/canceler.rb#L63-L78 | train |
buildkite/buildbox-agent-ruby | lib/buildbox/command.rb | Buildbox.Command.read_io | def read_io(io)
data = ""
while true
begin
if Platform.windows?
# Windows doesn't support non-blocking reads on
# file descriptors or pipes so we have to get
# a bit more creative.
# Check if data is actually ready on this IO device.
... | ruby | def read_io(io)
data = ""
while true
begin
if Platform.windows?
# Windows doesn't support non-blocking reads on
# file descriptors or pipes so we have to get
# a bit more creative.
# Check if data is actually ready on this IO device.
... | [
"def",
"read_io",
"(",
"io",
")",
"data",
"=",
"\"\"",
"while",
"true",
"begin",
"if",
"Platform",
".",
"windows?",
"results",
"=",
"IO",
".",
"select",
"(",
"[",
"io",
"]",
",",
"nil",
",",
"nil",
",",
"0.1",
")",
"break",
"if",
"!",
"results",
... | Reads data from an IO object while it can, returning the data it reads.
When it encounters a case when it can't read anymore, it returns the
data.
@return [String] | [
"Reads",
"data",
"from",
"an",
"IO",
"object",
"while",
"it",
"can",
"returning",
"the",
"data",
"it",
"reads",
".",
"When",
"it",
"encounters",
"a",
"case",
"when",
"it",
"can",
"t",
"read",
"anymore",
"it",
"returns",
"the",
"data",
"."
] | cff8c7dec6eb120c6d36eb5907c556cb5d483c86 | https://github.com/buildkite/buildbox-agent-ruby/blob/cff8c7dec6eb120c6d36eb5907c556cb5d483c86/lib/buildbox/command.rb#L164-L218 | train |
jantman/serverspec-extended-types | lib/serverspec_extended_types/virtualenv.rb | Serverspec::Type.Virtualenv.virtualenv? | def virtualenv?
pip_path = ::File.join(@name, 'bin', 'pip')
python_path = ::File.join(@name, 'bin', 'python')
act_path = ::File.join(@name, 'bin', 'activate')
cmd = "grep -q 'export VIRTUAL_ENV' #{act_path}"
@runner.check_file_is_executable(pip_path, 'owner') and
@runner.check_file... | ruby | def virtualenv?
pip_path = ::File.join(@name, 'bin', 'pip')
python_path = ::File.join(@name, 'bin', 'python')
act_path = ::File.join(@name, 'bin', 'activate')
cmd = "grep -q 'export VIRTUAL_ENV' #{act_path}"
@runner.check_file_is_executable(pip_path, 'owner') and
@runner.check_file... | [
"def",
"virtualenv?",
"pip_path",
"=",
"::",
"File",
".",
"join",
"(",
"@name",
",",
"'bin'",
",",
"'pip'",
")",
"python_path",
"=",
"::",
"File",
".",
"join",
"(",
"@name",
",",
"'bin'",
",",
"'python'",
")",
"act_path",
"=",
"::",
"File",
".",
"joi... | Test whether this appears to be a working venv
Tests performed:
- venv_path/bin/pip executable by owner?
- venv_path/bin/python executable by owner?
- venv_path/bin/activate readable by owner?
- 'export VIRTUAL_ENV' in venv_path/bin/activate?
@example
describe virtualenv('/path/to/venv') do
it { should ... | [
"Test",
"whether",
"this",
"appears",
"to",
"be",
"a",
"working",
"venv"
] | 28437dcccc403ab71abe8bf481ec4d22d4eed395 | https://github.com/jantman/serverspec-extended-types/blob/28437dcccc403ab71abe8bf481ec4d22d4eed395/lib/serverspec_extended_types/virtualenv.rb#L30-L39 | train |
moio/tetra | lib/tetra/facades/process_runner.rb | Tetra.ProcessRunner.run_interactive | def run_interactive(command)
log.debug "running `#{command}`"
success = system({}, command)
log.debug "`#{command}` exited with success #{success}"
fail ExecutionFailed.new(command, $CHILD_STATUS, nil, nil) unless success
end | ruby | def run_interactive(command)
log.debug "running `#{command}`"
success = system({}, command)
log.debug "`#{command}` exited with success #{success}"
fail ExecutionFailed.new(command, $CHILD_STATUS, nil, nil) unless success
end | [
"def",
"run_interactive",
"(",
"command",
")",
"log",
".",
"debug",
"\"running `#{command}`\"",
"success",
"=",
"system",
"(",
"{",
"}",
",",
"command",
")",
"log",
".",
"debug",
"\"`#{command}` exited with success #{success}\"",
"fail",
"ExecutionFailed",
".",
"new... | runs an interactive executable in a subshell | [
"runs",
"an",
"interactive",
"executable",
"in",
"a",
"subshell"
] | de06d766502b885bd62bd7cd9dc8da678abd7cb0 | https://github.com/moio/tetra/blob/de06d766502b885bd62bd7cd9dc8da678abd7cb0/lib/tetra/facades/process_runner.rb#L38-L43 | train |
moio/tetra | lib/tetra/project.rb | Tetra.Project.merge_new_content | def merge_new_content(new_content, path, comment, kind)
from_directory do
log.debug "merging new content to #{path} of kind #{kind}"
already_existing = File.exist?(path)
generated_comment = "tetra: generated-#{kind}"
whole_comment = [comment, generated_comment].join("\n\n")
... | ruby | def merge_new_content(new_content, path, comment, kind)
from_directory do
log.debug "merging new content to #{path} of kind #{kind}"
already_existing = File.exist?(path)
generated_comment = "tetra: generated-#{kind}"
whole_comment = [comment, generated_comment].join("\n\n")
... | [
"def",
"merge_new_content",
"(",
"new_content",
",",
"path",
",",
"comment",
",",
"kind",
")",
"from_directory",
"do",
"log",
".",
"debug",
"\"merging new content to #{path} of kind #{kind}\"",
"already_existing",
"=",
"File",
".",
"exist?",
"(",
"path",
")",
"gener... | replaces content in path with new_content, commits using
comment and 3-way merges new and old content with the previous
version of file of the same kind, if it exists.
returns the number of conflicts | [
"replaces",
"content",
"in",
"path",
"with",
"new_content",
"commits",
"using",
"comment",
"and",
"3",
"-",
"way",
"merges",
"new",
"and",
"old",
"content",
"with",
"the",
"previous",
"version",
"of",
"file",
"of",
"the",
"same",
"kind",
"if",
"it",
"exist... | de06d766502b885bd62bd7cd9dc8da678abd7cb0 | https://github.com/moio/tetra/blob/de06d766502b885bd62bd7cd9dc8da678abd7cb0/lib/tetra/project.rb#L110-L144 | train |
moio/tetra | lib/tetra/project.rb | Tetra.Project.src_archive | def src_archive
from_directory do
Find.find(File.join("packages", name)) do |file|
if File.file?(file) && file.match(/\.(spec)|(sh)|(patch)$/).nil?
return File.basename(file)
end
end
nil
end
end | ruby | def src_archive
from_directory do
Find.find(File.join("packages", name)) do |file|
if File.file?(file) && file.match(/\.(spec)|(sh)|(patch)$/).nil?
return File.basename(file)
end
end
nil
end
end | [
"def",
"src_archive",
"from_directory",
"do",
"Find",
".",
"find",
"(",
"File",
".",
"join",
"(",
"\"packages\"",
",",
"name",
")",
")",
"do",
"|",
"file",
"|",
"if",
"File",
".",
"file?",
"(",
"file",
")",
"&&",
"file",
".",
"match",
"(",
"/",
"\\... | returns the name of the source archive file, if any | [
"returns",
"the",
"name",
"of",
"the",
"source",
"archive",
"file",
"if",
"any"
] | de06d766502b885bd62bd7cd9dc8da678abd7cb0 | https://github.com/moio/tetra/blob/de06d766502b885bd62bd7cd9dc8da678abd7cb0/lib/tetra/project.rb#L186-L195 | train |
mikejmoore/docker-swarm-sdk | lib/docker-swarm.rb | Docker.Swarm.authenticate! | def authenticate!(options = {}, connection = self.connection)
creds = options.to_json
connection.post('/auth', {}, :body => creds)
@creds = creds
true
rescue Docker::Error::ServerError, Docker::Error::UnauthorizedError
raise Docker::Error::AuthenticationError
end | ruby | def authenticate!(options = {}, connection = self.connection)
creds = options.to_json
connection.post('/auth', {}, :body => creds)
@creds = creds
true
rescue Docker::Error::ServerError, Docker::Error::UnauthorizedError
raise Docker::Error::AuthenticationError
end | [
"def",
"authenticate!",
"(",
"options",
"=",
"{",
"}",
",",
"connection",
"=",
"self",
".",
"connection",
")",
"creds",
"=",
"options",
".",
"to_json",
"connection",
".",
"post",
"(",
"'/auth'",
",",
"{",
"}",
",",
":body",
"=>",
"creds",
")",
"@creds"... | Login to the Docker registry. | [
"Login",
"to",
"the",
"Docker",
"registry",
"."
] | 7f69f295900af880211d6a3a830eff0458df5526 | https://github.com/mikejmoore/docker-swarm-sdk/blob/7f69f295900af880211d6a3a830eff0458df5526/lib/docker-swarm.rb#L116-L123 | train |
Subsets and Splits
No community queries yet
The top public SQL queries from the community will appear here once available.