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
sequence | docstring
stringlengths 8
16k
| docstring_tokens
sequence | sha
stringlengths 40
40
| url
stringlengths 94
266
| partition
stringclasses 1
value |
---|---|---|---|---|---|---|---|---|---|---|---|
arangamani/jenkins_api_client | lib/jenkins_api_client/client.rb | JenkinsApi.Client.get_config | def get_config(url_prefix)
request = Net::HTTP::Get.new("#{@jenkins_path}#{url_prefix}/config.xml")
@logger.debug "GET #{url_prefix}/config.xml"
response = make_http_request(request)
handle_exception(response, "body")
end | ruby | def get_config(url_prefix)
request = Net::HTTP::Get.new("#{@jenkins_path}#{url_prefix}/config.xml")
@logger.debug "GET #{url_prefix}/config.xml"
response = make_http_request(request)
handle_exception(response, "body")
end | [
"def",
"get_config",
"(",
"url_prefix",
")",
"request",
"=",
"Net",
"::",
"HTTP",
"::",
"Get",
".",
"new",
"(",
"\"#{@jenkins_path}#{url_prefix}/config.xml\"",
")",
"@logger",
".",
"debug",
"\"GET #{url_prefix}/config.xml\"",
"response",
"=",
"make_http_request",
"(",
"request",
")",
"handle_exception",
"(",
"response",
",",
"\"body\"",
")",
"end"
] | Obtains the configuration of a component from the Jenkins CI server
@param [String] url_prefix The prefix to be used in the URL
@return [String] XML configuration obtained from Jenkins | [
"Obtains",
"the",
"configuration",
"of",
"a",
"component",
"from",
"the",
"Jenkins",
"CI",
"server"
] | 72f49f2e7ef12d58a0e33856ca91962b2e27709b | https://github.com/arangamani/jenkins_api_client/blob/72f49f2e7ef12d58a0e33856ca91962b2e27709b/lib/jenkins_api_client/client.rb#L486-L491 | train |
arangamani/jenkins_api_client | lib/jenkins_api_client/client.rb | JenkinsApi.Client.exec_cli | def exec_cli(command, args = [])
base_dir = File.dirname(__FILE__)
server_url = "http://#{@server_ip}:#{@server_port}/#{@jenkins_path}"
cmd = "java -jar #{base_dir}/../../java_deps/jenkins-cli.jar -s #{server_url}"
cmd << " -i #{@identity_file}" if @identity_file && !@identity_file.empty?
cmd << " #{command}"
cmd << " --username #{@username} --password #{@password}" if @identity_file.nil? || @identity_file.empty?
cmd << ' '
cmd << args.join(' ')
java_cmd = Mixlib::ShellOut.new(cmd)
# Run the command
java_cmd.run_command
if java_cmd.stderr.empty?
java_cmd.stdout.chomp
else
# The stderr has a stack trace of the Java program. We'll already have
# a stack trace for Ruby. So just display a descriptive message for the
# error thrown by the CLI.
raise Exceptions::CLIException.new(
@logger,
java_cmd.stderr.split("\n").first
)
end
end | ruby | def exec_cli(command, args = [])
base_dir = File.dirname(__FILE__)
server_url = "http://#{@server_ip}:#{@server_port}/#{@jenkins_path}"
cmd = "java -jar #{base_dir}/../../java_deps/jenkins-cli.jar -s #{server_url}"
cmd << " -i #{@identity_file}" if @identity_file && !@identity_file.empty?
cmd << " #{command}"
cmd << " --username #{@username} --password #{@password}" if @identity_file.nil? || @identity_file.empty?
cmd << ' '
cmd << args.join(' ')
java_cmd = Mixlib::ShellOut.new(cmd)
# Run the command
java_cmd.run_command
if java_cmd.stderr.empty?
java_cmd.stdout.chomp
else
# The stderr has a stack trace of the Java program. We'll already have
# a stack trace for Ruby. So just display a descriptive message for the
# error thrown by the CLI.
raise Exceptions::CLIException.new(
@logger,
java_cmd.stderr.split("\n").first
)
end
end | [
"def",
"exec_cli",
"(",
"command",
",",
"args",
"=",
"[",
"]",
")",
"base_dir",
"=",
"File",
".",
"dirname",
"(",
"__FILE__",
")",
"server_url",
"=",
"\"http://#{@server_ip}:#{@server_port}/#{@jenkins_path}\"",
"cmd",
"=",
"\"java -jar #{base_dir}/../../java_deps/jenkins-cli.jar -s #{server_url}\"",
"cmd",
"<<",
"\" -i #{@identity_file}\"",
"if",
"@identity_file",
"&&",
"!",
"@identity_file",
".",
"empty?",
"cmd",
"<<",
"\" #{command}\"",
"cmd",
"<<",
"\" --username #{@username} --password #{@password}\"",
"if",
"@identity_file",
".",
"nil?",
"||",
"@identity_file",
".",
"empty?",
"cmd",
"<<",
"' '",
"cmd",
"<<",
"args",
".",
"join",
"(",
"' '",
")",
"java_cmd",
"=",
"Mixlib",
"::",
"ShellOut",
".",
"new",
"(",
"cmd",
")",
"# Run the command",
"java_cmd",
".",
"run_command",
"if",
"java_cmd",
".",
"stderr",
".",
"empty?",
"java_cmd",
".",
"stdout",
".",
"chomp",
"else",
"# The stderr has a stack trace of the Java program. We'll already have",
"# a stack trace for Ruby. So just display a descriptive message for the",
"# error thrown by the CLI.",
"raise",
"Exceptions",
"::",
"CLIException",
".",
"new",
"(",
"@logger",
",",
"java_cmd",
".",
"stderr",
".",
"split",
"(",
"\"\\n\"",
")",
".",
"first",
")",
"end",
"end"
] | Execute the Jenkins CLI
@param command [String] command name
@param args [Array] the arguments for the command
@return [String] command output from the CLI
@raise [Exceptions::CLIException] if there are issues in running the
commands using CLI | [
"Execute",
"the",
"Jenkins",
"CLI"
] | 72f49f2e7ef12d58a0e33856ca91962b2e27709b | https://github.com/arangamani/jenkins_api_client/blob/72f49f2e7ef12d58a0e33856ca91962b2e27709b/lib/jenkins_api_client/client.rb#L669-L693 | train |
arangamani/jenkins_api_client | lib/jenkins_api_client/client.rb | JenkinsApi.Client.symbolize_keys | def symbolize_keys(hash)
hash.inject({}){|result, (key, value)|
new_key = case key
when String then key.to_sym
else key
end
new_value = case value
when Hash then symbolize_keys(value)
else value
end
result[new_key] = new_value
result
}
end | ruby | def symbolize_keys(hash)
hash.inject({}){|result, (key, value)|
new_key = case key
when String then key.to_sym
else key
end
new_value = case value
when Hash then symbolize_keys(value)
else value
end
result[new_key] = new_value
result
}
end | [
"def",
"symbolize_keys",
"(",
"hash",
")",
"hash",
".",
"inject",
"(",
"{",
"}",
")",
"{",
"|",
"result",
",",
"(",
"key",
",",
"value",
")",
"|",
"new_key",
"=",
"case",
"key",
"when",
"String",
"then",
"key",
".",
"to_sym",
"else",
"key",
"end",
"new_value",
"=",
"case",
"value",
"when",
"Hash",
"then",
"symbolize_keys",
"(",
"value",
")",
"else",
"value",
"end",
"result",
"[",
"new_key",
"]",
"=",
"new_value",
"result",
"}",
"end"
] | Private method. Converts keys passed in as strings into symbols.
@param hash [Hash] Hash containing arguments to login to jenkins. | [
"Private",
"method",
".",
"Converts",
"keys",
"passed",
"in",
"as",
"strings",
"into",
"symbols",
"."
] | 72f49f2e7ef12d58a0e33856ca91962b2e27709b | https://github.com/arangamani/jenkins_api_client/blob/72f49f2e7ef12d58a0e33856ca91962b2e27709b/lib/jenkins_api_client/client.rb#L763-L776 | train |
arangamani/jenkins_api_client | lib/jenkins_api_client/client.rb | JenkinsApi.Client.handle_exception | def handle_exception(response, to_send = "code", send_json = false)
msg = "HTTP Code: #{response.code}, Response Body: #{response.body}"
@logger.debug msg
case response.code.to_i
# As of Jenkins version 1.519, the job builds return a 201 status code
# with a Location HTTP header with the pointing the URL of the item in
# the queue.
when 200, 201, 302
if to_send == "body" && send_json
return JSON.parse(response.body)
elsif to_send == "body"
return response.body
elsif to_send == "code"
return response.code
elsif to_send == "raw"
return response
end
when 400
matched = response.body.match(/<p>(.*)<\/p>/)
api_message = matched[1] unless matched.nil?
@logger.debug "API message: #{api_message}"
case api_message
when /A job already exists with the name/
raise Exceptions::JobAlreadyExists.new(@logger, api_message)
when /A view already exists with the name/
raise Exceptions::ViewAlreadyExists.new(@logger, api_message)
when /Slave called .* already exists/
raise Exceptions::NodeAlreadyExists.new(@logger, api_message)
when /Nothing is submitted/
raise Exceptions::NothingSubmitted.new(@logger, api_message)
else
raise Exceptions::ApiException.new(@logger, api_message)
end
when 401
raise Exceptions::Unauthorized.new @logger
when 403
raise Exceptions::Forbidden.new @logger
when 404
raise Exceptions::NotFound.new @logger
when 500
matched = response.body.match(/Exception: (.*)<br>/)
api_message = matched[1] unless matched.nil?
@logger.debug "API message: #{api_message}"
raise Exceptions::InternalServerError.new(@logger, api_message)
when 503
raise Exceptions::ServiceUnavailable.new @logger
else
raise Exceptions::ApiException.new(
@logger,
"Error code #{response.code}"
)
end
end | ruby | def handle_exception(response, to_send = "code", send_json = false)
msg = "HTTP Code: #{response.code}, Response Body: #{response.body}"
@logger.debug msg
case response.code.to_i
# As of Jenkins version 1.519, the job builds return a 201 status code
# with a Location HTTP header with the pointing the URL of the item in
# the queue.
when 200, 201, 302
if to_send == "body" && send_json
return JSON.parse(response.body)
elsif to_send == "body"
return response.body
elsif to_send == "code"
return response.code
elsif to_send == "raw"
return response
end
when 400
matched = response.body.match(/<p>(.*)<\/p>/)
api_message = matched[1] unless matched.nil?
@logger.debug "API message: #{api_message}"
case api_message
when /A job already exists with the name/
raise Exceptions::JobAlreadyExists.new(@logger, api_message)
when /A view already exists with the name/
raise Exceptions::ViewAlreadyExists.new(@logger, api_message)
when /Slave called .* already exists/
raise Exceptions::NodeAlreadyExists.new(@logger, api_message)
when /Nothing is submitted/
raise Exceptions::NothingSubmitted.new(@logger, api_message)
else
raise Exceptions::ApiException.new(@logger, api_message)
end
when 401
raise Exceptions::Unauthorized.new @logger
when 403
raise Exceptions::Forbidden.new @logger
when 404
raise Exceptions::NotFound.new @logger
when 500
matched = response.body.match(/Exception: (.*)<br>/)
api_message = matched[1] unless matched.nil?
@logger.debug "API message: #{api_message}"
raise Exceptions::InternalServerError.new(@logger, api_message)
when 503
raise Exceptions::ServiceUnavailable.new @logger
else
raise Exceptions::ApiException.new(
@logger,
"Error code #{response.code}"
)
end
end | [
"def",
"handle_exception",
"(",
"response",
",",
"to_send",
"=",
"\"code\"",
",",
"send_json",
"=",
"false",
")",
"msg",
"=",
"\"HTTP Code: #{response.code}, Response Body: #{response.body}\"",
"@logger",
".",
"debug",
"msg",
"case",
"response",
".",
"code",
".",
"to_i",
"# As of Jenkins version 1.519, the job builds return a 201 status code",
"# with a Location HTTP header with the pointing the URL of the item in",
"# the queue.",
"when",
"200",
",",
"201",
",",
"302",
"if",
"to_send",
"==",
"\"body\"",
"&&",
"send_json",
"return",
"JSON",
".",
"parse",
"(",
"response",
".",
"body",
")",
"elsif",
"to_send",
"==",
"\"body\"",
"return",
"response",
".",
"body",
"elsif",
"to_send",
"==",
"\"code\"",
"return",
"response",
".",
"code",
"elsif",
"to_send",
"==",
"\"raw\"",
"return",
"response",
"end",
"when",
"400",
"matched",
"=",
"response",
".",
"body",
".",
"match",
"(",
"/",
"\\/",
"/",
")",
"api_message",
"=",
"matched",
"[",
"1",
"]",
"unless",
"matched",
".",
"nil?",
"@logger",
".",
"debug",
"\"API message: #{api_message}\"",
"case",
"api_message",
"when",
"/",
"/",
"raise",
"Exceptions",
"::",
"JobAlreadyExists",
".",
"new",
"(",
"@logger",
",",
"api_message",
")",
"when",
"/",
"/",
"raise",
"Exceptions",
"::",
"ViewAlreadyExists",
".",
"new",
"(",
"@logger",
",",
"api_message",
")",
"when",
"/",
"/",
"raise",
"Exceptions",
"::",
"NodeAlreadyExists",
".",
"new",
"(",
"@logger",
",",
"api_message",
")",
"when",
"/",
"/",
"raise",
"Exceptions",
"::",
"NothingSubmitted",
".",
"new",
"(",
"@logger",
",",
"api_message",
")",
"else",
"raise",
"Exceptions",
"::",
"ApiException",
".",
"new",
"(",
"@logger",
",",
"api_message",
")",
"end",
"when",
"401",
"raise",
"Exceptions",
"::",
"Unauthorized",
".",
"new",
"@logger",
"when",
"403",
"raise",
"Exceptions",
"::",
"Forbidden",
".",
"new",
"@logger",
"when",
"404",
"raise",
"Exceptions",
"::",
"NotFound",
".",
"new",
"@logger",
"when",
"500",
"matched",
"=",
"response",
".",
"body",
".",
"match",
"(",
"/",
"/",
")",
"api_message",
"=",
"matched",
"[",
"1",
"]",
"unless",
"matched",
".",
"nil?",
"@logger",
".",
"debug",
"\"API message: #{api_message}\"",
"raise",
"Exceptions",
"::",
"InternalServerError",
".",
"new",
"(",
"@logger",
",",
"api_message",
")",
"when",
"503",
"raise",
"Exceptions",
"::",
"ServiceUnavailable",
".",
"new",
"@logger",
"else",
"raise",
"Exceptions",
"::",
"ApiException",
".",
"new",
"(",
"@logger",
",",
"\"Error code #{response.code}\"",
")",
"end",
"end"
] | Private method that handles the exception and raises with proper error
message with the type of exception and returns the required values if no
exceptions are raised.
@param [Net::HTTP::Response] response Response from Jenkins
@param [String] to_send What should be returned as a response. Allowed
values: "code", "body", and "raw".
@param [Boolean] send_json Boolean value used to determine whether to
load the JSON or send the response as is.
@return [String, Hash] Response returned whether loaded JSON or raw
string
@raise [Exceptions::Unauthorized] When invalid credentials are
provided to connect to Jenkins
@raise [Exceptions::NotFound] When the requested page on Jenkins is not
found
@raise [Exceptions::InternalServerError] When Jenkins returns a 500
Internal Server Error
@raise [Exceptions::ApiException] Any other exception returned from
Jenkins that are not categorized in the API Client. | [
"Private",
"method",
"that",
"handles",
"the",
"exception",
"and",
"raises",
"with",
"proper",
"error",
"message",
"with",
"the",
"type",
"of",
"exception",
"and",
"returns",
"the",
"required",
"values",
"if",
"no",
"exceptions",
"are",
"raised",
"."
] | 72f49f2e7ef12d58a0e33856ca91962b2e27709b | https://github.com/arangamani/jenkins_api_client/blob/72f49f2e7ef12d58a0e33856ca91962b2e27709b/lib/jenkins_api_client/client.rb#L800-L852 | train |
bugsnag/bugsnag-ruby | lib/bugsnag/report.rb | Bugsnag.Report.add_tab | def add_tab(name, value)
return if name.nil?
if value.is_a? Hash
meta_data[name] ||= {}
meta_data[name].merge! value
else
meta_data["custom"] = {} unless meta_data["custom"]
meta_data["custom"][name.to_s] = value
end
end | ruby | def add_tab(name, value)
return if name.nil?
if value.is_a? Hash
meta_data[name] ||= {}
meta_data[name].merge! value
else
meta_data["custom"] = {} unless meta_data["custom"]
meta_data["custom"][name.to_s] = value
end
end | [
"def",
"add_tab",
"(",
"name",
",",
"value",
")",
"return",
"if",
"name",
".",
"nil?",
"if",
"value",
".",
"is_a?",
"Hash",
"meta_data",
"[",
"name",
"]",
"||=",
"{",
"}",
"meta_data",
"[",
"name",
"]",
".",
"merge!",
"value",
"else",
"meta_data",
"[",
"\"custom\"",
"]",
"=",
"{",
"}",
"unless",
"meta_data",
"[",
"\"custom\"",
"]",
"meta_data",
"[",
"\"custom\"",
"]",
"[",
"name",
".",
"to_s",
"]",
"=",
"value",
"end",
"end"
] | Initializes a new report from an exception.
Add a new metadata tab to this notification. | [
"Initializes",
"a",
"new",
"report",
"from",
"an",
"exception",
"."
] | eaef01ab04392f362e14848edb5f29d7a3df2ae0 | https://github.com/bugsnag/bugsnag-ruby/blob/eaef01ab04392f362e14848edb5f29d7a3df2ae0/lib/bugsnag/report.rb#L67-L78 | train |
bugsnag/bugsnag-ruby | lib/bugsnag/report.rb | Bugsnag.Report.as_json | def as_json
# Build the payload's exception event
payload_event = {
app: {
version: app_version,
releaseStage: release_stage,
type: app_type
},
context: context,
device: {
hostname: hostname
},
exceptions: exceptions,
groupingHash: grouping_hash,
session: session,
severity: severity,
severityReason: severity_reason,
unhandled: @unhandled,
user: user
}
# cleanup character encodings
payload_event = Bugsnag::Cleaner.clean_object_encoding(payload_event)
# filter out sensitive values in (and cleanup encodings) metaData
filter_cleaner = Bugsnag::Cleaner.new(configuration.meta_data_filters)
payload_event[:metaData] = filter_cleaner.clean_object(meta_data)
payload_event[:breadcrumbs] = breadcrumbs.map do |breadcrumb|
breadcrumb_hash = breadcrumb.to_h
breadcrumb_hash[:metaData] = filter_cleaner.clean_object(breadcrumb_hash[:metaData])
breadcrumb_hash
end
payload_event.reject! {|k,v| v.nil? }
# return the payload hash
{
:apiKey => api_key,
:notifier => {
:name => NOTIFIER_NAME,
:version => NOTIFIER_VERSION,
:url => NOTIFIER_URL
},
:events => [payload_event]
}
end | ruby | def as_json
# Build the payload's exception event
payload_event = {
app: {
version: app_version,
releaseStage: release_stage,
type: app_type
},
context: context,
device: {
hostname: hostname
},
exceptions: exceptions,
groupingHash: grouping_hash,
session: session,
severity: severity,
severityReason: severity_reason,
unhandled: @unhandled,
user: user
}
# cleanup character encodings
payload_event = Bugsnag::Cleaner.clean_object_encoding(payload_event)
# filter out sensitive values in (and cleanup encodings) metaData
filter_cleaner = Bugsnag::Cleaner.new(configuration.meta_data_filters)
payload_event[:metaData] = filter_cleaner.clean_object(meta_data)
payload_event[:breadcrumbs] = breadcrumbs.map do |breadcrumb|
breadcrumb_hash = breadcrumb.to_h
breadcrumb_hash[:metaData] = filter_cleaner.clean_object(breadcrumb_hash[:metaData])
breadcrumb_hash
end
payload_event.reject! {|k,v| v.nil? }
# return the payload hash
{
:apiKey => api_key,
:notifier => {
:name => NOTIFIER_NAME,
:version => NOTIFIER_VERSION,
:url => NOTIFIER_URL
},
:events => [payload_event]
}
end | [
"def",
"as_json",
"# Build the payload's exception event",
"payload_event",
"=",
"{",
"app",
":",
"{",
"version",
":",
"app_version",
",",
"releaseStage",
":",
"release_stage",
",",
"type",
":",
"app_type",
"}",
",",
"context",
":",
"context",
",",
"device",
":",
"{",
"hostname",
":",
"hostname",
"}",
",",
"exceptions",
":",
"exceptions",
",",
"groupingHash",
":",
"grouping_hash",
",",
"session",
":",
"session",
",",
"severity",
":",
"severity",
",",
"severityReason",
":",
"severity_reason",
",",
"unhandled",
":",
"@unhandled",
",",
"user",
":",
"user",
"}",
"# cleanup character encodings",
"payload_event",
"=",
"Bugsnag",
"::",
"Cleaner",
".",
"clean_object_encoding",
"(",
"payload_event",
")",
"# filter out sensitive values in (and cleanup encodings) metaData",
"filter_cleaner",
"=",
"Bugsnag",
"::",
"Cleaner",
".",
"new",
"(",
"configuration",
".",
"meta_data_filters",
")",
"payload_event",
"[",
":metaData",
"]",
"=",
"filter_cleaner",
".",
"clean_object",
"(",
"meta_data",
")",
"payload_event",
"[",
":breadcrumbs",
"]",
"=",
"breadcrumbs",
".",
"map",
"do",
"|",
"breadcrumb",
"|",
"breadcrumb_hash",
"=",
"breadcrumb",
".",
"to_h",
"breadcrumb_hash",
"[",
":metaData",
"]",
"=",
"filter_cleaner",
".",
"clean_object",
"(",
"breadcrumb_hash",
"[",
":metaData",
"]",
")",
"breadcrumb_hash",
"end",
"payload_event",
".",
"reject!",
"{",
"|",
"k",
",",
"v",
"|",
"v",
".",
"nil?",
"}",
"# return the payload hash",
"{",
":apiKey",
"=>",
"api_key",
",",
":notifier",
"=>",
"{",
":name",
"=>",
"NOTIFIER_NAME",
",",
":version",
"=>",
"NOTIFIER_VERSION",
",",
":url",
"=>",
"NOTIFIER_URL",
"}",
",",
":events",
"=>",
"[",
"payload_event",
"]",
"}",
"end"
] | Builds and returns the exception payload for this notification. | [
"Builds",
"and",
"returns",
"the",
"exception",
"payload",
"for",
"this",
"notification",
"."
] | eaef01ab04392f362e14848edb5f29d7a3df2ae0 | https://github.com/bugsnag/bugsnag-ruby/blob/eaef01ab04392f362e14848edb5f29d7a3df2ae0/lib/bugsnag/report.rb#L90-L135 | train |
bugsnag/bugsnag-ruby | lib/bugsnag/report.rb | Bugsnag.Report.summary | def summary
# Guard against the exceptions array being removed/changed or emptied here
if exceptions.respond_to?(:first) && exceptions.first
{
:error_class => exceptions.first[:errorClass],
:message => exceptions.first[:message],
:severity => severity
}
else
{
:error_class => "Unknown",
:severity => severity
}
end
end | ruby | def summary
# Guard against the exceptions array being removed/changed or emptied here
if exceptions.respond_to?(:first) && exceptions.first
{
:error_class => exceptions.first[:errorClass],
:message => exceptions.first[:message],
:severity => severity
}
else
{
:error_class => "Unknown",
:severity => severity
}
end
end | [
"def",
"summary",
"# Guard against the exceptions array being removed/changed or emptied here",
"if",
"exceptions",
".",
"respond_to?",
"(",
":first",
")",
"&&",
"exceptions",
".",
"first",
"{",
":error_class",
"=>",
"exceptions",
".",
"first",
"[",
":errorClass",
"]",
",",
":message",
"=>",
"exceptions",
".",
"first",
"[",
":message",
"]",
",",
":severity",
"=>",
"severity",
"}",
"else",
"{",
":error_class",
"=>",
"\"Unknown\"",
",",
":severity",
"=>",
"severity",
"}",
"end",
"end"
] | Generates a summary to be attached as a breadcrumb
@return [Hash] a Hash containing the report's error class, error message, and severity | [
"Generates",
"a",
"summary",
"to",
"be",
"attached",
"as",
"a",
"breadcrumb"
] | eaef01ab04392f362e14848edb5f29d7a3df2ae0 | https://github.com/bugsnag/bugsnag-ruby/blob/eaef01ab04392f362e14848edb5f29d7a3df2ae0/lib/bugsnag/report.rb#L169-L183 | train |
bugsnag/bugsnag-ruby | lib/bugsnag/breadcrumbs/validator.rb | Bugsnag::Breadcrumbs.Validator.valid_meta_data_type? | def valid_meta_data_type?(value)
value.nil? || value.is_a?(String) || value.is_a?(Numeric) || value.is_a?(FalseClass) || value.is_a?(TrueClass)
end | ruby | def valid_meta_data_type?(value)
value.nil? || value.is_a?(String) || value.is_a?(Numeric) || value.is_a?(FalseClass) || value.is_a?(TrueClass)
end | [
"def",
"valid_meta_data_type?",
"(",
"value",
")",
"value",
".",
"nil?",
"||",
"value",
".",
"is_a?",
"(",
"String",
")",
"||",
"value",
".",
"is_a?",
"(",
"Numeric",
")",
"||",
"value",
".",
"is_a?",
"(",
"FalseClass",
")",
"||",
"value",
".",
"is_a?",
"(",
"TrueClass",
")",
"end"
] | Tests whether the meta_data types are non-complex objects.
Acceptable types are String, Numeric, TrueClass, FalseClass, and nil.
@param value [Object] the object to be type checked | [
"Tests",
"whether",
"the",
"meta_data",
"types",
"are",
"non",
"-",
"complex",
"objects",
"."
] | eaef01ab04392f362e14848edb5f29d7a3df2ae0 | https://github.com/bugsnag/bugsnag-ruby/blob/eaef01ab04392f362e14848edb5f29d7a3df2ae0/lib/bugsnag/breadcrumbs/validator.rb#L55-L57 | train |
bugsnag/bugsnag-ruby | lib/bugsnag/integrations/rack.rb | Bugsnag.Rack.call | def call(env)
# Set the request data for bugsnag middleware to use
Bugsnag.configuration.set_request_data(:rack_env, env)
if Bugsnag.configuration.auto_capture_sessions
Bugsnag.start_session
end
begin
response = @app.call(env)
rescue Exception => raised
# Notify bugsnag of rack exceptions
Bugsnag.notify(raised, true) do |report|
report.severity = "error"
report.severity_reason = {
:type => Bugsnag::Report::UNHANDLED_EXCEPTION_MIDDLEWARE,
:attributes => Bugsnag::Rack::FRAMEWORK_ATTRIBUTES
}
end
# Re-raise the exception
raise
end
# Notify bugsnag of rack exceptions
if env["rack.exception"]
Bugsnag.notify(env["rack.exception"], true) do |report|
report.severity = "error"
report.severity_reason = {
:type => Bugsnag::Report::UNHANDLED_EXCEPTION_MIDDLEWARE,
:attributes => FRAMEWORK_ATTRIBUTES
}
end
end
response
ensure
# Clear per-request data after processing the each request
Bugsnag.configuration.clear_request_data
end | ruby | def call(env)
# Set the request data for bugsnag middleware to use
Bugsnag.configuration.set_request_data(:rack_env, env)
if Bugsnag.configuration.auto_capture_sessions
Bugsnag.start_session
end
begin
response = @app.call(env)
rescue Exception => raised
# Notify bugsnag of rack exceptions
Bugsnag.notify(raised, true) do |report|
report.severity = "error"
report.severity_reason = {
:type => Bugsnag::Report::UNHANDLED_EXCEPTION_MIDDLEWARE,
:attributes => Bugsnag::Rack::FRAMEWORK_ATTRIBUTES
}
end
# Re-raise the exception
raise
end
# Notify bugsnag of rack exceptions
if env["rack.exception"]
Bugsnag.notify(env["rack.exception"], true) do |report|
report.severity = "error"
report.severity_reason = {
:type => Bugsnag::Report::UNHANDLED_EXCEPTION_MIDDLEWARE,
:attributes => FRAMEWORK_ATTRIBUTES
}
end
end
response
ensure
# Clear per-request data after processing the each request
Bugsnag.configuration.clear_request_data
end | [
"def",
"call",
"(",
"env",
")",
"# Set the request data for bugsnag middleware to use",
"Bugsnag",
".",
"configuration",
".",
"set_request_data",
"(",
":rack_env",
",",
"env",
")",
"if",
"Bugsnag",
".",
"configuration",
".",
"auto_capture_sessions",
"Bugsnag",
".",
"start_session",
"end",
"begin",
"response",
"=",
"@app",
".",
"call",
"(",
"env",
")",
"rescue",
"Exception",
"=>",
"raised",
"# Notify bugsnag of rack exceptions",
"Bugsnag",
".",
"notify",
"(",
"raised",
",",
"true",
")",
"do",
"|",
"report",
"|",
"report",
".",
"severity",
"=",
"\"error\"",
"report",
".",
"severity_reason",
"=",
"{",
":type",
"=>",
"Bugsnag",
"::",
"Report",
"::",
"UNHANDLED_EXCEPTION_MIDDLEWARE",
",",
":attributes",
"=>",
"Bugsnag",
"::",
"Rack",
"::",
"FRAMEWORK_ATTRIBUTES",
"}",
"end",
"# Re-raise the exception",
"raise",
"end",
"# Notify bugsnag of rack exceptions",
"if",
"env",
"[",
"\"rack.exception\"",
"]",
"Bugsnag",
".",
"notify",
"(",
"env",
"[",
"\"rack.exception\"",
"]",
",",
"true",
")",
"do",
"|",
"report",
"|",
"report",
".",
"severity",
"=",
"\"error\"",
"report",
".",
"severity_reason",
"=",
"{",
":type",
"=>",
"Bugsnag",
"::",
"Report",
"::",
"UNHANDLED_EXCEPTION_MIDDLEWARE",
",",
":attributes",
"=>",
"FRAMEWORK_ATTRIBUTES",
"}",
"end",
"end",
"response",
"ensure",
"# Clear per-request data after processing the each request",
"Bugsnag",
".",
"configuration",
".",
"clear_request_data",
"end"
] | Wraps a call to the application with error capturing | [
"Wraps",
"a",
"call",
"to",
"the",
"application",
"with",
"error",
"capturing"
] | eaef01ab04392f362e14848edb5f29d7a3df2ae0 | https://github.com/bugsnag/bugsnag-ruby/blob/eaef01ab04392f362e14848edb5f29d7a3df2ae0/lib/bugsnag/integrations/rack.rb#L38-L76 | train |
bugsnag/bugsnag-ruby | lib/bugsnag/session_tracker.rb | Bugsnag.SessionTracker.start_session | def start_session
return unless Bugsnag.configuration.enable_sessions
start_delivery_thread
start_time = Time.now().utc().strftime('%Y-%m-%dT%H:%M:00')
new_session = {
:id => SecureRandom.uuid,
:startedAt => start_time,
:events => {
:handled => 0,
:unhandled => 0
}
}
SessionTracker.set_current_session(new_session)
add_session(start_time)
end | ruby | def start_session
return unless Bugsnag.configuration.enable_sessions
start_delivery_thread
start_time = Time.now().utc().strftime('%Y-%m-%dT%H:%M:00')
new_session = {
:id => SecureRandom.uuid,
:startedAt => start_time,
:events => {
:handled => 0,
:unhandled => 0
}
}
SessionTracker.set_current_session(new_session)
add_session(start_time)
end | [
"def",
"start_session",
"return",
"unless",
"Bugsnag",
".",
"configuration",
".",
"enable_sessions",
"start_delivery_thread",
"start_time",
"=",
"Time",
".",
"now",
"(",
")",
".",
"utc",
"(",
")",
".",
"strftime",
"(",
"'%Y-%m-%dT%H:%M:00'",
")",
"new_session",
"=",
"{",
":id",
"=>",
"SecureRandom",
".",
"uuid",
",",
":startedAt",
"=>",
"start_time",
",",
":events",
"=>",
"{",
":handled",
"=>",
"0",
",",
":unhandled",
"=>",
"0",
"}",
"}",
"SessionTracker",
".",
"set_current_session",
"(",
"new_session",
")",
"add_session",
"(",
"start_time",
")",
"end"
] | Initializes the session tracker.
Starts a new session, storing it on the current thread.
This allows Bugsnag to track error rates for a release. | [
"Initializes",
"the",
"session",
"tracker",
"."
] | eaef01ab04392f362e14848edb5f29d7a3df2ae0 | https://github.com/bugsnag/bugsnag-ruby/blob/eaef01ab04392f362e14848edb5f29d7a3df2ae0/lib/bugsnag/session_tracker.rb#L37-L51 | train |
bugsnag/bugsnag-ruby | lib/bugsnag/session_tracker.rb | Bugsnag.SessionTracker.send_sessions | def send_sessions
sessions = []
counts = @session_counts
@session_counts = Concurrent::Hash.new(0)
counts.each do |min, count|
sessions << {
:startedAt => min,
:sessionsStarted => count
}
end
deliver(sessions)
end | ruby | def send_sessions
sessions = []
counts = @session_counts
@session_counts = Concurrent::Hash.new(0)
counts.each do |min, count|
sessions << {
:startedAt => min,
:sessionsStarted => count
}
end
deliver(sessions)
end | [
"def",
"send_sessions",
"sessions",
"=",
"[",
"]",
"counts",
"=",
"@session_counts",
"@session_counts",
"=",
"Concurrent",
"::",
"Hash",
".",
"new",
"(",
"0",
")",
"counts",
".",
"each",
"do",
"|",
"min",
",",
"count",
"|",
"sessions",
"<<",
"{",
":startedAt",
"=>",
"min",
",",
":sessionsStarted",
"=>",
"count",
"}",
"end",
"deliver",
"(",
"sessions",
")",
"end"
] | Delivers the current session_counts lists to the session endpoint. | [
"Delivers",
"the",
"current",
"session_counts",
"lists",
"to",
"the",
"session",
"endpoint",
"."
] | eaef01ab04392f362e14848edb5f29d7a3df2ae0 | https://github.com/bugsnag/bugsnag-ruby/blob/eaef01ab04392f362e14848edb5f29d7a3df2ae0/lib/bugsnag/session_tracker.rb#L57-L68 | train |
bugsnag/bugsnag-ruby | lib/bugsnag/integrations/railtie.rb | Bugsnag.Railtie.event_subscription | def event_subscription(event)
ActiveSupport::Notifications.subscribe(event[:id]) do |*, event_id, data|
filtered_data = data.slice(*event[:allowed_data])
filtered_data[:event_name] = event[:id]
filtered_data[:event_id] = event_id
if event[:id] == "sql.active_record"
binds = data[:binds].each_with_object({}) { |bind, output| output[bind.name] = '?' if defined?(bind.name) }
filtered_data[:binds] = JSON.dump(binds) unless binds.empty?
end
Bugsnag.leave_breadcrumb(
event[:message],
filtered_data,
event[:type],
:auto
)
end
end | ruby | def event_subscription(event)
ActiveSupport::Notifications.subscribe(event[:id]) do |*, event_id, data|
filtered_data = data.slice(*event[:allowed_data])
filtered_data[:event_name] = event[:id]
filtered_data[:event_id] = event_id
if event[:id] == "sql.active_record"
binds = data[:binds].each_with_object({}) { |bind, output| output[bind.name] = '?' if defined?(bind.name) }
filtered_data[:binds] = JSON.dump(binds) unless binds.empty?
end
Bugsnag.leave_breadcrumb(
event[:message],
filtered_data,
event[:type],
:auto
)
end
end | [
"def",
"event_subscription",
"(",
"event",
")",
"ActiveSupport",
"::",
"Notifications",
".",
"subscribe",
"(",
"event",
"[",
":id",
"]",
")",
"do",
"|",
"*",
",",
"event_id",
",",
"data",
"|",
"filtered_data",
"=",
"data",
".",
"slice",
"(",
"event",
"[",
":allowed_data",
"]",
")",
"filtered_data",
"[",
":event_name",
"]",
"=",
"event",
"[",
":id",
"]",
"filtered_data",
"[",
":event_id",
"]",
"=",
"event_id",
"if",
"event",
"[",
":id",
"]",
"==",
"\"sql.active_record\"",
"binds",
"=",
"data",
"[",
":binds",
"]",
".",
"each_with_object",
"(",
"{",
"}",
")",
"{",
"|",
"bind",
",",
"output",
"|",
"output",
"[",
"bind",
".",
"name",
"]",
"=",
"'?'",
"if",
"defined?",
"(",
"bind",
".",
"name",
")",
"}",
"filtered_data",
"[",
":binds",
"]",
"=",
"JSON",
".",
"dump",
"(",
"binds",
")",
"unless",
"binds",
".",
"empty?",
"end",
"Bugsnag",
".",
"leave_breadcrumb",
"(",
"event",
"[",
":message",
"]",
",",
"filtered_data",
",",
"event",
"[",
":type",
"]",
",",
":auto",
")",
"end",
"end"
] | Subscribes to an ActiveSupport event, leaving a breadcrumb when it triggers
@api private
@param event [Hash] details of the event to subscribe to | [
"Subscribes",
"to",
"an",
"ActiveSupport",
"event",
"leaving",
"a",
"breadcrumb",
"when",
"it",
"triggers"
] | eaef01ab04392f362e14848edb5f29d7a3df2ae0 | https://github.com/bugsnag/bugsnag-ruby/blob/eaef01ab04392f362e14848edb5f29d7a3df2ae0/lib/bugsnag/integrations/railtie.rb#L76-L92 | train |
bugsnag/bugsnag-ruby | lib/bugsnag/integrations/resque.rb | Bugsnag.Resque.save | def save
Bugsnag.notify(exception, true) do |report|
report.severity = "error"
report.severity_reason = {
:type => Bugsnag::Report::UNHANDLED_EXCEPTION_MIDDLEWARE,
:attributes => FRAMEWORK_ATTRIBUTES
}
context = "#{payload['class']}@#{queue}"
report.meta_data.merge!({:context => context, :payload => payload})
report.context = context
end
end | ruby | def save
Bugsnag.notify(exception, true) do |report|
report.severity = "error"
report.severity_reason = {
:type => Bugsnag::Report::UNHANDLED_EXCEPTION_MIDDLEWARE,
:attributes => FRAMEWORK_ATTRIBUTES
}
context = "#{payload['class']}@#{queue}"
report.meta_data.merge!({:context => context, :payload => payload})
report.context = context
end
end | [
"def",
"save",
"Bugsnag",
".",
"notify",
"(",
"exception",
",",
"true",
")",
"do",
"|",
"report",
"|",
"report",
".",
"severity",
"=",
"\"error\"",
"report",
".",
"severity_reason",
"=",
"{",
":type",
"=>",
"Bugsnag",
"::",
"Report",
"::",
"UNHANDLED_EXCEPTION_MIDDLEWARE",
",",
":attributes",
"=>",
"FRAMEWORK_ATTRIBUTES",
"}",
"context",
"=",
"\"#{payload['class']}@#{queue}\"",
"report",
".",
"meta_data",
".",
"merge!",
"(",
"{",
":context",
"=>",
"context",
",",
":payload",
"=>",
"payload",
"}",
")",
"report",
".",
"context",
"=",
"context",
"end",
"end"
] | Notifies Bugsnag of a raised exception. | [
"Notifies",
"Bugsnag",
"of",
"a",
"raised",
"exception",
"."
] | eaef01ab04392f362e14848edb5f29d7a3df2ae0 | https://github.com/bugsnag/bugsnag-ruby/blob/eaef01ab04392f362e14848edb5f29d7a3df2ae0/lib/bugsnag/integrations/resque.rb#L39-L51 | train |
bugsnag/bugsnag-ruby | lib/bugsnag/middleware_stack.rb | Bugsnag.MiddlewareStack.insert_after | def insert_after(after, new_middleware)
@mutex.synchronize do
return if @disabled_middleware.include?(new_middleware)
return if @middlewares.include?(new_middleware)
if after.is_a? Array
index = @middlewares.rindex {|el| after.include?(el)}
else
index = @middlewares.rindex(after)
end
if index.nil?
@middlewares << new_middleware
else
@middlewares.insert index + 1, new_middleware
end
end
end | ruby | def insert_after(after, new_middleware)
@mutex.synchronize do
return if @disabled_middleware.include?(new_middleware)
return if @middlewares.include?(new_middleware)
if after.is_a? Array
index = @middlewares.rindex {|el| after.include?(el)}
else
index = @middlewares.rindex(after)
end
if index.nil?
@middlewares << new_middleware
else
@middlewares.insert index + 1, new_middleware
end
end
end | [
"def",
"insert_after",
"(",
"after",
",",
"new_middleware",
")",
"@mutex",
".",
"synchronize",
"do",
"return",
"if",
"@disabled_middleware",
".",
"include?",
"(",
"new_middleware",
")",
"return",
"if",
"@middlewares",
".",
"include?",
"(",
"new_middleware",
")",
"if",
"after",
".",
"is_a?",
"Array",
"index",
"=",
"@middlewares",
".",
"rindex",
"{",
"|",
"el",
"|",
"after",
".",
"include?",
"(",
"el",
")",
"}",
"else",
"index",
"=",
"@middlewares",
".",
"rindex",
"(",
"after",
")",
"end",
"if",
"index",
".",
"nil?",
"@middlewares",
"<<",
"new_middleware",
"else",
"@middlewares",
".",
"insert",
"index",
"+",
"1",
",",
"new_middleware",
"end",
"end",
"end"
] | Inserts a new middleware to use after a given middleware already added.
Will return early if given middleware is disabled or already added.
New middleware will be inserted last if the existing middleware is not already included. | [
"Inserts",
"a",
"new",
"middleware",
"to",
"use",
"after",
"a",
"given",
"middleware",
"already",
"added",
"."
] | eaef01ab04392f362e14848edb5f29d7a3df2ae0 | https://github.com/bugsnag/bugsnag-ruby/blob/eaef01ab04392f362e14848edb5f29d7a3df2ae0/lib/bugsnag/middleware_stack.rb#L29-L46 | train |
bugsnag/bugsnag-ruby | lib/bugsnag/middleware_stack.rb | Bugsnag.MiddlewareStack.insert_before | def insert_before(before, new_middleware)
@mutex.synchronize do
return if @disabled_middleware.include?(new_middleware)
return if @middlewares.include?(new_middleware)
if before.is_a? Array
index = @middlewares.index {|el| before.include?(el)}
else
index = @middlewares.index(before)
end
@middlewares.insert index || @middlewares.length, new_middleware
end
end | ruby | def insert_before(before, new_middleware)
@mutex.synchronize do
return if @disabled_middleware.include?(new_middleware)
return if @middlewares.include?(new_middleware)
if before.is_a? Array
index = @middlewares.index {|el| before.include?(el)}
else
index = @middlewares.index(before)
end
@middlewares.insert index || @middlewares.length, new_middleware
end
end | [
"def",
"insert_before",
"(",
"before",
",",
"new_middleware",
")",
"@mutex",
".",
"synchronize",
"do",
"return",
"if",
"@disabled_middleware",
".",
"include?",
"(",
"new_middleware",
")",
"return",
"if",
"@middlewares",
".",
"include?",
"(",
"new_middleware",
")",
"if",
"before",
".",
"is_a?",
"Array",
"index",
"=",
"@middlewares",
".",
"index",
"{",
"|",
"el",
"|",
"before",
".",
"include?",
"(",
"el",
")",
"}",
"else",
"index",
"=",
"@middlewares",
".",
"index",
"(",
"before",
")",
"end",
"@middlewares",
".",
"insert",
"index",
"||",
"@middlewares",
".",
"length",
",",
"new_middleware",
"end",
"end"
] | Inserts a new middleware to use before a given middleware already added.
Will return early if given middleware is disabled or already added.
New middleware will be inserted last if the existing middleware is not already included. | [
"Inserts",
"a",
"new",
"middleware",
"to",
"use",
"before",
"a",
"given",
"middleware",
"already",
"added",
"."
] | eaef01ab04392f362e14848edb5f29d7a3df2ae0 | https://github.com/bugsnag/bugsnag-ruby/blob/eaef01ab04392f362e14848edb5f29d7a3df2ae0/lib/bugsnag/middleware_stack.rb#L53-L66 | train |
bugsnag/bugsnag-ruby | lib/bugsnag/middleware_stack.rb | Bugsnag.MiddlewareStack.run | def run(report)
# The final lambda is the termination of the middleware stack. It calls deliver on the notification
lambda_has_run = false
notify_lambda = lambda do |notif|
lambda_has_run = true
yield if block_given?
end
begin
# We reverse them, so we can call "call" on the first middleware
middleware_procs.reverse.inject(notify_lambda) { |n,e| e.call(n) }.call(report)
rescue StandardError => e
# KLUDGE: Since we don't re-raise middleware exceptions, this breaks rspec
raise if e.class.to_s == "RSpec::Expectations::ExpectationNotMetError"
# We dont notify, as we dont want to loop forever in the case of really broken middleware, we will
# still send this notify
Bugsnag.configuration.warn "Bugsnag middleware error: #{e}"
Bugsnag.configuration.warn "Middleware error stacktrace: #{e.backtrace.inspect}"
end
# Ensure that the deliver has been performed, and no middleware has botched it
notify_lambda.call(report) unless lambda_has_run
end | ruby | def run(report)
# The final lambda is the termination of the middleware stack. It calls deliver on the notification
lambda_has_run = false
notify_lambda = lambda do |notif|
lambda_has_run = true
yield if block_given?
end
begin
# We reverse them, so we can call "call" on the first middleware
middleware_procs.reverse.inject(notify_lambda) { |n,e| e.call(n) }.call(report)
rescue StandardError => e
# KLUDGE: Since we don't re-raise middleware exceptions, this breaks rspec
raise if e.class.to_s == "RSpec::Expectations::ExpectationNotMetError"
# We dont notify, as we dont want to loop forever in the case of really broken middleware, we will
# still send this notify
Bugsnag.configuration.warn "Bugsnag middleware error: #{e}"
Bugsnag.configuration.warn "Middleware error stacktrace: #{e.backtrace.inspect}"
end
# Ensure that the deliver has been performed, and no middleware has botched it
notify_lambda.call(report) unless lambda_has_run
end | [
"def",
"run",
"(",
"report",
")",
"# The final lambda is the termination of the middleware stack. It calls deliver on the notification",
"lambda_has_run",
"=",
"false",
"notify_lambda",
"=",
"lambda",
"do",
"|",
"notif",
"|",
"lambda_has_run",
"=",
"true",
"yield",
"if",
"block_given?",
"end",
"begin",
"# We reverse them, so we can call \"call\" on the first middleware",
"middleware_procs",
".",
"reverse",
".",
"inject",
"(",
"notify_lambda",
")",
"{",
"|",
"n",
",",
"e",
"|",
"e",
".",
"call",
"(",
"n",
")",
"}",
".",
"call",
"(",
"report",
")",
"rescue",
"StandardError",
"=>",
"e",
"# KLUDGE: Since we don't re-raise middleware exceptions, this breaks rspec",
"raise",
"if",
"e",
".",
"class",
".",
"to_s",
"==",
"\"RSpec::Expectations::ExpectationNotMetError\"",
"# We dont notify, as we dont want to loop forever in the case of really broken middleware, we will",
"# still send this notify",
"Bugsnag",
".",
"configuration",
".",
"warn",
"\"Bugsnag middleware error: #{e}\"",
"Bugsnag",
".",
"configuration",
".",
"warn",
"\"Middleware error stacktrace: #{e.backtrace.inspect}\"",
"end",
"# Ensure that the deliver has been performed, and no middleware has botched it",
"notify_lambda",
".",
"call",
"(",
"report",
")",
"unless",
"lambda_has_run",
"end"
] | Runs the middleware stack. | [
"Runs",
"the",
"middleware",
"stack",
"."
] | eaef01ab04392f362e14848edb5f29d7a3df2ae0 | https://github.com/bugsnag/bugsnag-ruby/blob/eaef01ab04392f362e14848edb5f29d7a3df2ae0/lib/bugsnag/middleware_stack.rb#L84-L107 | train |
bugsnag/bugsnag-ruby | lib/bugsnag/integrations/mongo.rb | Bugsnag.MongoBreadcrumbSubscriber.leave_mongo_breadcrumb | def leave_mongo_breadcrumb(event_name, event)
message = MONGO_MESSAGE_PREFIX + event_name
meta_data = {
:event_name => MONGO_EVENT_PREFIX + event_name,
:command_name => event.command_name,
:database_name => event.database_name,
:operation_id => event.operation_id,
:request_id => event.request_id,
:duration => event.duration
}
if (command = pop_command(event.request_id))
collection_key = event.command_name == "getMore" ? "collection" : event.command_name
meta_data[:collection] = command[collection_key]
unless command["filter"].nil?
filter = sanitize_filter_hash(command["filter"])
meta_data[:filter] = JSON.dump(filter)
end
end
meta_data[:message] = event.message if defined?(event.message)
Bugsnag.leave_breadcrumb(message, meta_data, Bugsnag::Breadcrumbs::PROCESS_BREADCRUMB_TYPE, :auto)
end | ruby | def leave_mongo_breadcrumb(event_name, event)
message = MONGO_MESSAGE_PREFIX + event_name
meta_data = {
:event_name => MONGO_EVENT_PREFIX + event_name,
:command_name => event.command_name,
:database_name => event.database_name,
:operation_id => event.operation_id,
:request_id => event.request_id,
:duration => event.duration
}
if (command = pop_command(event.request_id))
collection_key = event.command_name == "getMore" ? "collection" : event.command_name
meta_data[:collection] = command[collection_key]
unless command["filter"].nil?
filter = sanitize_filter_hash(command["filter"])
meta_data[:filter] = JSON.dump(filter)
end
end
meta_data[:message] = event.message if defined?(event.message)
Bugsnag.leave_breadcrumb(message, meta_data, Bugsnag::Breadcrumbs::PROCESS_BREADCRUMB_TYPE, :auto)
end | [
"def",
"leave_mongo_breadcrumb",
"(",
"event_name",
",",
"event",
")",
"message",
"=",
"MONGO_MESSAGE_PREFIX",
"+",
"event_name",
"meta_data",
"=",
"{",
":event_name",
"=>",
"MONGO_EVENT_PREFIX",
"+",
"event_name",
",",
":command_name",
"=>",
"event",
".",
"command_name",
",",
":database_name",
"=>",
"event",
".",
"database_name",
",",
":operation_id",
"=>",
"event",
".",
"operation_id",
",",
":request_id",
"=>",
"event",
".",
"request_id",
",",
":duration",
"=>",
"event",
".",
"duration",
"}",
"if",
"(",
"command",
"=",
"pop_command",
"(",
"event",
".",
"request_id",
")",
")",
"collection_key",
"=",
"event",
".",
"command_name",
"==",
"\"getMore\"",
"?",
"\"collection\"",
":",
"event",
".",
"command_name",
"meta_data",
"[",
":collection",
"]",
"=",
"command",
"[",
"collection_key",
"]",
"unless",
"command",
"[",
"\"filter\"",
"]",
".",
"nil?",
"filter",
"=",
"sanitize_filter_hash",
"(",
"command",
"[",
"\"filter\"",
"]",
")",
"meta_data",
"[",
":filter",
"]",
"=",
"JSON",
".",
"dump",
"(",
"filter",
")",
"end",
"end",
"meta_data",
"[",
":message",
"]",
"=",
"event",
".",
"message",
"if",
"defined?",
"(",
"event",
".",
"message",
")",
"Bugsnag",
".",
"leave_breadcrumb",
"(",
"message",
",",
"meta_data",
",",
"Bugsnag",
"::",
"Breadcrumbs",
"::",
"PROCESS_BREADCRUMB_TYPE",
",",
":auto",
")",
"end"
] | Generates breadcrumb data from an event
@param event_name [String] the type of event
@param event [Mongo::Event::Base] the mongo_ruby_driver generated event | [
"Generates",
"breadcrumb",
"data",
"from",
"an",
"event"
] | eaef01ab04392f362e14848edb5f29d7a3df2ae0 | https://github.com/bugsnag/bugsnag-ruby/blob/eaef01ab04392f362e14848edb5f29d7a3df2ae0/lib/bugsnag/integrations/mongo.rb#L46-L67 | train |
bugsnag/bugsnag-ruby | lib/bugsnag/integrations/mongo.rb | Bugsnag.MongoBreadcrumbSubscriber.sanitize_filter_hash | def sanitize_filter_hash(filter_hash, depth = 0)
filter_hash.each_with_object({}) do |(key, value), output|
output[key] = sanitize_filter_value(value, depth)
end
end | ruby | def sanitize_filter_hash(filter_hash, depth = 0)
filter_hash.each_with_object({}) do |(key, value), output|
output[key] = sanitize_filter_value(value, depth)
end
end | [
"def",
"sanitize_filter_hash",
"(",
"filter_hash",
",",
"depth",
"=",
"0",
")",
"filter_hash",
".",
"each_with_object",
"(",
"{",
"}",
")",
"do",
"|",
"(",
"key",
",",
"value",
")",
",",
"output",
"|",
"output",
"[",
"key",
"]",
"=",
"sanitize_filter_value",
"(",
"value",
",",
"depth",
")",
"end",
"end"
] | Removes values from filter hashes, replacing them with '?'
@param filter_hash [Hash] the filter hash for the mongo transaction
@param depth [Integer] the current filter depth
@return [Hash] the filtered hash | [
"Removes",
"values",
"from",
"filter",
"hashes",
"replacing",
"them",
"with",
"?"
] | eaef01ab04392f362e14848edb5f29d7a3df2ae0 | https://github.com/bugsnag/bugsnag-ruby/blob/eaef01ab04392f362e14848edb5f29d7a3df2ae0/lib/bugsnag/integrations/mongo.rb#L76-L80 | train |
bugsnag/bugsnag-ruby | lib/bugsnag/integrations/mongo.rb | Bugsnag.MongoBreadcrumbSubscriber.sanitize_filter_value | def sanitize_filter_value(value, depth)
depth += 1
if depth >= MAX_FILTER_DEPTH
'[MAX_FILTER_DEPTH_REACHED]'
elsif value.is_a?(Array)
value.map { |array_value| sanitize_filter_value(array_value, depth) }
elsif value.is_a?(Hash)
sanitize_filter_hash(value, depth)
else
'?'
end
end | ruby | def sanitize_filter_value(value, depth)
depth += 1
if depth >= MAX_FILTER_DEPTH
'[MAX_FILTER_DEPTH_REACHED]'
elsif value.is_a?(Array)
value.map { |array_value| sanitize_filter_value(array_value, depth) }
elsif value.is_a?(Hash)
sanitize_filter_hash(value, depth)
else
'?'
end
end | [
"def",
"sanitize_filter_value",
"(",
"value",
",",
"depth",
")",
"depth",
"+=",
"1",
"if",
"depth",
">=",
"MAX_FILTER_DEPTH",
"'[MAX_FILTER_DEPTH_REACHED]'",
"elsif",
"value",
".",
"is_a?",
"(",
"Array",
")",
"value",
".",
"map",
"{",
"|",
"array_value",
"|",
"sanitize_filter_value",
"(",
"array_value",
",",
"depth",
")",
"}",
"elsif",
"value",
".",
"is_a?",
"(",
"Hash",
")",
"sanitize_filter_hash",
"(",
"value",
",",
"depth",
")",
"else",
"'?'",
"end",
"end"
] | Transforms a value element into a useful, redacted, version
@param value [Object] the filter value
@param depth [Integer] the current filter depth
@return [Array, Hash, String] the sanitized value | [
"Transforms",
"a",
"value",
"element",
"into",
"a",
"useful",
"redacted",
"version"
] | eaef01ab04392f362e14848edb5f29d7a3df2ae0 | https://github.com/bugsnag/bugsnag-ruby/blob/eaef01ab04392f362e14848edb5f29d7a3df2ae0/lib/bugsnag/integrations/mongo.rb#L89-L100 | train |
bugsnag/bugsnag-ruby | lib/bugsnag/configuration.rb | Bugsnag.Configuration.parse_proxy | def parse_proxy(uri)
proxy = URI.parse(uri)
self.proxy_host = proxy.host
self.proxy_port = proxy.port
self.proxy_user = proxy.user
self.proxy_password = proxy.password
end | ruby | def parse_proxy(uri)
proxy = URI.parse(uri)
self.proxy_host = proxy.host
self.proxy_port = proxy.port
self.proxy_user = proxy.user
self.proxy_password = proxy.password
end | [
"def",
"parse_proxy",
"(",
"uri",
")",
"proxy",
"=",
"URI",
".",
"parse",
"(",
"uri",
")",
"self",
".",
"proxy_host",
"=",
"proxy",
".",
"host",
"self",
".",
"proxy_port",
"=",
"proxy",
".",
"port",
"self",
".",
"proxy_user",
"=",
"proxy",
".",
"user",
"self",
".",
"proxy_password",
"=",
"proxy",
".",
"password",
"end"
] | Parses and sets proxy from a uri | [
"Parses",
"and",
"sets",
"proxy",
"from",
"a",
"uri"
] | eaef01ab04392f362e14848edb5f29d7a3df2ae0 | https://github.com/bugsnag/bugsnag-ruby/blob/eaef01ab04392f362e14848edb5f29d7a3df2ae0/lib/bugsnag/configuration.rb#L227-L233 | train |
bugsnag/bugsnag-ruby | lib/bugsnag/integrations/mailman.rb | Bugsnag.Mailman.call | def call(mail)
begin
Bugsnag.configuration.set_request_data :mailman_msg, mail.to_s
yield
rescue Exception => ex
Bugsnag.notify(ex, true) do |report|
report.severity = "error"
report.severity_reason = {
:type => Bugsnag::Report::UNHANDLED_EXCEPTION_MIDDLEWARE,
:attributes => FRAMEWORK_ATTRIBUTES
}
end
raise
ensure
Bugsnag.configuration.clear_request_data
end
end | ruby | def call(mail)
begin
Bugsnag.configuration.set_request_data :mailman_msg, mail.to_s
yield
rescue Exception => ex
Bugsnag.notify(ex, true) do |report|
report.severity = "error"
report.severity_reason = {
:type => Bugsnag::Report::UNHANDLED_EXCEPTION_MIDDLEWARE,
:attributes => FRAMEWORK_ATTRIBUTES
}
end
raise
ensure
Bugsnag.configuration.clear_request_data
end
end | [
"def",
"call",
"(",
"mail",
")",
"begin",
"Bugsnag",
".",
"configuration",
".",
"set_request_data",
":mailman_msg",
",",
"mail",
".",
"to_s",
"yield",
"rescue",
"Exception",
"=>",
"ex",
"Bugsnag",
".",
"notify",
"(",
"ex",
",",
"true",
")",
"do",
"|",
"report",
"|",
"report",
".",
"severity",
"=",
"\"error\"",
"report",
".",
"severity_reason",
"=",
"{",
":type",
"=>",
"Bugsnag",
"::",
"Report",
"::",
"UNHANDLED_EXCEPTION_MIDDLEWARE",
",",
":attributes",
"=>",
"FRAMEWORK_ATTRIBUTES",
"}",
"end",
"raise",
"ensure",
"Bugsnag",
".",
"configuration",
".",
"clear_request_data",
"end",
"end"
] | Calls the mailman middleware. | [
"Calls",
"the",
"mailman",
"middleware",
"."
] | eaef01ab04392f362e14848edb5f29d7a3df2ae0 | https://github.com/bugsnag/bugsnag-ruby/blob/eaef01ab04392f362e14848edb5f29d7a3df2ae0/lib/bugsnag/integrations/mailman.rb#L19-L35 | train |
codeplant/simple-navigation | lib/simple_navigation/helpers.rb | SimpleNavigation.Helpers.render_navigation | def render_navigation(options = {}, &block)
container = active_navigation_item_container(options, &block)
container && container.render(options)
end | ruby | def render_navigation(options = {}, &block)
container = active_navigation_item_container(options, &block)
container && container.render(options)
end | [
"def",
"render_navigation",
"(",
"options",
"=",
"{",
"}",
",",
"&",
"block",
")",
"container",
"=",
"active_navigation_item_container",
"(",
"options",
",",
"block",
")",
"container",
"&&",
"container",
".",
"render",
"(",
"options",
")",
"end"
] | Renders the navigation according to the specified options-hash.
The following options are supported:
* <tt>:level</tt> - defaults to :all which renders the the sub_navigation
for an active primary_navigation inside that active
primary_navigation item.
Specify a specific level to only render that level of navigation
(e.g. level: 1 for primary_navigation, etc).
Specifiy a Range of levels to render only those specific levels
(e.g. level: 1..2 to render both your first and second levels, maybe
you want to render your third level somewhere else on the page)
* <tt>:expand_all</tt> - defaults to false. If set to true the all
specified levels will be rendered as a fully expanded
tree (always open). This is useful for javascript menus like Superfish.
* <tt>:context</tt> - specifies the context for which you would render
the navigation. Defaults to :default which loads the default
navigation.rb (i.e. config/navigation.rb).
If you specify a context then the plugin tries to load the configuration
file for that context, e.g. if you call
<tt>render_navigation(context: :admin)</tt> the file
config/admin_navigation.rb will be loaded and used for rendering
the navigation.
* <tt>:items</tt> - you can specify the items directly (e.g. if items are
dynamically generated from database).
See SimpleNavigation::ItemsProvider for documentation on what to
provide as items.
* <tt>:renderer</tt> - specify the renderer to be used for rendering the
navigation. Either provide the Class or a symbol matching a registered
renderer. Defaults to :list (html list renderer).
Instead of using the <tt>:items</tt> option, a block can be passed to
specify the items dynamically
==== Examples
render_navigation do |menu|
menu.item :posts, "Posts", posts_path
end | [
"Renders",
"the",
"navigation",
"according",
"to",
"the",
"specified",
"options",
"-",
"hash",
"."
] | ed5b99744754b8f3dfca44c885df5aa938730b64 | https://github.com/codeplant/simple-navigation/blob/ed5b99744754b8f3dfca44c885df5aa938730b64/lib/simple_navigation/helpers.rb#L86-L89 | train |
codeplant/simple-navigation | lib/simple_navigation/helpers.rb | SimpleNavigation.Helpers.active_navigation_item | def active_navigation_item(options = {}, value_for_nil = nil)
if options[:level].nil? || options[:level] == :all
options[:level] = :leaves
end
container = active_navigation_item_container(options)
if container && (item = container.selected_item)
block_given? ? yield(item) : item
else
value_for_nil
end
end | ruby | def active_navigation_item(options = {}, value_for_nil = nil)
if options[:level].nil? || options[:level] == :all
options[:level] = :leaves
end
container = active_navigation_item_container(options)
if container && (item = container.selected_item)
block_given? ? yield(item) : item
else
value_for_nil
end
end | [
"def",
"active_navigation_item",
"(",
"options",
"=",
"{",
"}",
",",
"value_for_nil",
"=",
"nil",
")",
"if",
"options",
"[",
":level",
"]",
".",
"nil?",
"||",
"options",
"[",
":level",
"]",
"==",
":all",
"options",
"[",
":level",
"]",
"=",
":leaves",
"end",
"container",
"=",
"active_navigation_item_container",
"(",
"options",
")",
"if",
"container",
"&&",
"(",
"item",
"=",
"container",
".",
"selected_item",
")",
"block_given?",
"?",
"yield",
"(",
"item",
")",
":",
"item",
"else",
"value_for_nil",
"end",
"end"
] | Returns the currently active navigation item belonging to the specified
level.
The following options are supported:
* <tt>:level</tt> - defaults to :all which returns the
most specific/deepest selected item (the leaf).
Specify a specific level to only look for the selected item in the
specified level of navigation
(e.g. level: 1 for primary_navigation, etc).
* <tt>:context</tt> - specifies the context for which you would like to
find the active navigation item. Defaults to :default which loads the
default navigation.rb (i.e. config/navigation.rb).
If you specify a context then the plugin tries to load the configuration
file for that context, e.g. if you call
<tt>active_navigation_item_name(context: :admin)</tt> the file
config/admin_navigation.rb will be loaded and used for searching the
active item.
* <tt>:items</tt> - you can specify the items directly (e.g. if items are
dynamically generated from database).
See SimpleNavigation::ItemsProvider for documentation on what to provide
as items.
Returns the supplied <tt>value_for_nil</tt> object (<tt>nil</tt>
by default) if no active item can be found for the specified
options | [
"Returns",
"the",
"currently",
"active",
"navigation",
"item",
"belonging",
"to",
"the",
"specified",
"level",
"."
] | ed5b99744754b8f3dfca44c885df5aa938730b64 | https://github.com/codeplant/simple-navigation/blob/ed5b99744754b8f3dfca44c885df5aa938730b64/lib/simple_navigation/helpers.rb#L140-L150 | train |
codeplant/simple-navigation | lib/simple_navigation/helpers.rb | SimpleNavigation.Helpers.active_navigation_item_container | def active_navigation_item_container(options = {}, &block)
options = SimpleNavigation::Helpers.apply_defaults(options)
SimpleNavigation::Helpers.load_config(options, self, &block)
SimpleNavigation.active_item_container_for(options[:level])
end | ruby | def active_navigation_item_container(options = {}, &block)
options = SimpleNavigation::Helpers.apply_defaults(options)
SimpleNavigation::Helpers.load_config(options, self, &block)
SimpleNavigation.active_item_container_for(options[:level])
end | [
"def",
"active_navigation_item_container",
"(",
"options",
"=",
"{",
"}",
",",
"&",
"block",
")",
"options",
"=",
"SimpleNavigation",
"::",
"Helpers",
".",
"apply_defaults",
"(",
"options",
")",
"SimpleNavigation",
"::",
"Helpers",
".",
"load_config",
"(",
"options",
",",
"self",
",",
"block",
")",
"SimpleNavigation",
".",
"active_item_container_for",
"(",
"options",
"[",
":level",
"]",
")",
"end"
] | Returns the currently active item container belonging to the specified
level.
The following options are supported:
* <tt>:level</tt> - defaults to :all which returns the
least specific/shallowest selected item.
Specify a specific level to only look for the selected item in the
specified level of navigation
(e.g. level: 1 for primary_navigation, etc).
* <tt>:context</tt> - specifies the context for which you would like to
find the active navigation item. Defaults to :default which loads the
default navigation.rb (i.e. config/navigation.rb).
If you specify a context then the plugin tries to load the configuration
file for that context, e.g. if you call
<tt>active_navigation_item_name(context: :admin)</tt> the file
config/admin_navigation.rb will be loaded and used for searching the
active item.
* <tt>:items</tt> - you can specify the items directly (e.g. if items are
dynamically generated from database).
See SimpleNavigation::ItemsProvider for documentation on what to provide
as items.
Returns <tt>nil</tt> if no active item container can be found | [
"Returns",
"the",
"currently",
"active",
"item",
"container",
"belonging",
"to",
"the",
"specified",
"level",
"."
] | ed5b99744754b8f3dfca44c885df5aa938730b64 | https://github.com/codeplant/simple-navigation/blob/ed5b99744754b8f3dfca44c885df5aa938730b64/lib/simple_navigation/helpers.rb#L175-L179 | train |
codeplant/simple-navigation | lib/simple_navigation/item.rb | SimpleNavigation.Item.html_options | def html_options
html_opts = options.fetch(:html) { Hash.new }
html_opts[:id] ||= autogenerated_item_id
classes = [html_opts[:class], selected_class, active_leaf_class]
classes = classes.flatten.compact.join(' ')
html_opts[:class] = classes if classes && !classes.empty?
html_opts
end | ruby | def html_options
html_opts = options.fetch(:html) { Hash.new }
html_opts[:id] ||= autogenerated_item_id
classes = [html_opts[:class], selected_class, active_leaf_class]
classes = classes.flatten.compact.join(' ')
html_opts[:class] = classes if classes && !classes.empty?
html_opts
end | [
"def",
"html_options",
"html_opts",
"=",
"options",
".",
"fetch",
"(",
":html",
")",
"{",
"Hash",
".",
"new",
"}",
"html_opts",
"[",
":id",
"]",
"||=",
"autogenerated_item_id",
"classes",
"=",
"[",
"html_opts",
"[",
":class",
"]",
",",
"selected_class",
",",
"active_leaf_class",
"]",
"classes",
"=",
"classes",
".",
"flatten",
".",
"compact",
".",
"join",
"(",
"' '",
")",
"html_opts",
"[",
":class",
"]",
"=",
"classes",
"if",
"classes",
"&&",
"!",
"classes",
".",
"empty?",
"html_opts",
"end"
] | Returns the html-options hash for the item, i.e. the options specified
for this item in the config-file.
It also adds the 'selected' class to the list of classes if necessary. | [
"Returns",
"the",
"html",
"-",
"options",
"hash",
"for",
"the",
"item",
"i",
".",
"e",
".",
"the",
"options",
"specified",
"for",
"this",
"item",
"in",
"the",
"config",
"-",
"file",
".",
"It",
"also",
"adds",
"the",
"selected",
"class",
"to",
"the",
"list",
"of",
"classes",
"if",
"necessary",
"."
] | ed5b99744754b8f3dfca44c885df5aa938730b64 | https://github.com/codeplant/simple-navigation/blob/ed5b99744754b8f3dfca44c885df5aa938730b64/lib/simple_navigation/item.rb#L51-L60 | train |
codeplant/simple-navigation | lib/simple_navigation/item_container.rb | SimpleNavigation.ItemContainer.item | def item(key, name, url = nil, options = {}, &block)
return unless should_add_item?(options)
item = Item.new(self, key, name, url, options, &block)
add_item item, options
end | ruby | def item(key, name, url = nil, options = {}, &block)
return unless should_add_item?(options)
item = Item.new(self, key, name, url, options, &block)
add_item item, options
end | [
"def",
"item",
"(",
"key",
",",
"name",
",",
"url",
"=",
"nil",
",",
"options",
"=",
"{",
"}",
",",
"&",
"block",
")",
"return",
"unless",
"should_add_item?",
"(",
"options",
")",
"item",
"=",
"Item",
".",
"new",
"(",
"self",
",",
"key",
",",
"name",
",",
"url",
",",
"options",
",",
"block",
")",
"add_item",
"item",
",",
"options",
"end"
] | Creates a new navigation item.
The <tt>key</tt> is a symbol which uniquely defines your navigation item
in the scope of the primary_navigation or the sub_navigation.
The <tt>name</tt> will be displayed in the rendered navigation.
This can also be a call to your I18n-framework.
The <tt>url</tt> is the address that the generated item points to.
You can also use url_helpers (named routes, restful routes helper,
url_for, etc). <tt>url</tt> is optional - items without URLs should not
be rendered as links.
The <tt>options</tt> can be used to specify the following things:
* <tt>any html_attributes</tt> - will be included in the rendered
navigation item (e.g. id, class etc.)
* <tt>:if</tt> - Specifies a proc to call to determine if the item should
be rendered (e.g. <tt>if: Proc.new { current_user.admin? }</tt>). The
proc should evaluate to a true or false value and is evaluated
in the context of the view.
* <tt>:unless</tt> - Specifies a proc to call to determine if the item
should not be rendered
(e.g. <tt>unless: Proc.new { current_user.admin? }</tt>).
The proc should evaluate to a true or false value and is evaluated in
the context of the view.
* <tt>:method</tt> - Specifies the http-method for the generated link -
default is :get.
* <tt>:highlights_on</tt> - if autohighlighting is turned off and/or you
want to explicitly specify when the item should be highlighted, you can
set a regexp which is matched againstthe current URI.
The <tt>block</tt> - if specified - will hold the item's sub_navigation. | [
"Creates",
"a",
"new",
"navigation",
"item",
"."
] | ed5b99744754b8f3dfca44c885df5aa938730b64 | https://github.com/codeplant/simple-navigation/blob/ed5b99744754b8f3dfca44c885df5aa938730b64/lib/simple_navigation/item_container.rb#L64-L68 | train |
codeplant/simple-navigation | lib/simple_navigation/item_container.rb | SimpleNavigation.ItemContainer.level_for_item | def level_for_item(navi_key)
return level if self[navi_key]
items.each do |item|
next unless item.sub_navigation
level = item.sub_navigation.level_for_item(navi_key)
return level if level
end
return nil
end | ruby | def level_for_item(navi_key)
return level if self[navi_key]
items.each do |item|
next unless item.sub_navigation
level = item.sub_navigation.level_for_item(navi_key)
return level if level
end
return nil
end | [
"def",
"level_for_item",
"(",
"navi_key",
")",
"return",
"level",
"if",
"self",
"[",
"navi_key",
"]",
"items",
".",
"each",
"do",
"|",
"item",
"|",
"next",
"unless",
"item",
".",
"sub_navigation",
"level",
"=",
"item",
".",
"sub_navigation",
".",
"level_for_item",
"(",
"navi_key",
")",
"return",
"level",
"if",
"level",
"end",
"return",
"nil",
"end"
] | Returns the level of the item specified by navi_key.
Recursively works its way down the item's sub_navigations if the desired
item is not found directly in this container's items.
Returns nil if item cannot be found. | [
"Returns",
"the",
"level",
"of",
"the",
"item",
"specified",
"by",
"navi_key",
".",
"Recursively",
"works",
"its",
"way",
"down",
"the",
"item",
"s",
"sub_navigations",
"if",
"the",
"desired",
"item",
"is",
"not",
"found",
"directly",
"in",
"this",
"container",
"s",
"items",
".",
"Returns",
"nil",
"if",
"item",
"cannot",
"be",
"found",
"."
] | ed5b99744754b8f3dfca44c885df5aa938730b64 | https://github.com/codeplant/simple-navigation/blob/ed5b99744754b8f3dfca44c885df5aa938730b64/lib/simple_navigation/item_container.rb#L89-L98 | train |
ueno/ruby-gpgme | lib/gpgme/key_common.rb | GPGME.KeyCommon.usable_for? | def usable_for?(purposes)
unless purposes.kind_of? Array
purposes = [purposes]
end
return false if [:revoked, :expired, :disabled, :invalid].include? trust
return (purposes - capability).empty?
end | ruby | def usable_for?(purposes)
unless purposes.kind_of? Array
purposes = [purposes]
end
return false if [:revoked, :expired, :disabled, :invalid].include? trust
return (purposes - capability).empty?
end | [
"def",
"usable_for?",
"(",
"purposes",
")",
"unless",
"purposes",
".",
"kind_of?",
"Array",
"purposes",
"=",
"[",
"purposes",
"]",
"end",
"return",
"false",
"if",
"[",
":revoked",
",",
":expired",
",",
":disabled",
",",
":invalid",
"]",
".",
"include?",
"trust",
"return",
"(",
"purposes",
"-",
"capability",
")",
".",
"empty?",
"end"
] | Checks if the key is capable of all of these actions. If empty array
is passed then will return true.
Returns false if the keys trust has been invalidated. | [
"Checks",
"if",
"the",
"key",
"is",
"capable",
"of",
"all",
"of",
"these",
"actions",
".",
"If",
"empty",
"array",
"is",
"passed",
"then",
"will",
"return",
"true",
"."
] | e84f42e2e8d956940c2430e5ccfbba9e989e3370 | https://github.com/ueno/ruby-gpgme/blob/e84f42e2e8d956940c2430e5ccfbba9e989e3370/lib/gpgme/key_common.rb#L31-L37 | train |
ueno/ruby-gpgme | lib/gpgme/data.rb | GPGME.Data.read | def read(length = nil)
if length
GPGME::gpgme_data_read(self, length)
else
buf = String.new
loop do
s = GPGME::gpgme_data_read(self, BLOCK_SIZE)
break unless s
buf << s
end
buf
end
end | ruby | def read(length = nil)
if length
GPGME::gpgme_data_read(self, length)
else
buf = String.new
loop do
s = GPGME::gpgme_data_read(self, BLOCK_SIZE)
break unless s
buf << s
end
buf
end
end | [
"def",
"read",
"(",
"length",
"=",
"nil",
")",
"if",
"length",
"GPGME",
"::",
"gpgme_data_read",
"(",
"self",
",",
"length",
")",
"else",
"buf",
"=",
"String",
".",
"new",
"loop",
"do",
"s",
"=",
"GPGME",
"::",
"gpgme_data_read",
"(",
"self",
",",
"BLOCK_SIZE",
")",
"break",
"unless",
"s",
"buf",
"<<",
"s",
"end",
"buf",
"end",
"end"
] | class << self
Read at most +length+ bytes from the data object, or to the end
of file if +length+ is omitted or is +nil+.
@example
data = GPGME::Data.new("From a string")
data.read # => "From a string"
@example
data = GPGME::Data.new("From a string")
data.read(4) # => "From" | [
"class",
"<<",
"self",
"Read",
"at",
"most",
"+",
"length",
"+",
"bytes",
"from",
"the",
"data",
"object",
"or",
"to",
"the",
"end",
"of",
"file",
"if",
"+",
"length",
"+",
"is",
"omitted",
"or",
"is",
"+",
"nil",
"+",
"."
] | e84f42e2e8d956940c2430e5ccfbba9e989e3370 | https://github.com/ueno/ruby-gpgme/blob/e84f42e2e8d956940c2430e5ccfbba9e989e3370/lib/gpgme/data.rb#L112-L124 | train |
ueno/ruby-gpgme | lib/gpgme/data.rb | GPGME.Data.seek | def seek(offset, whence = IO::SEEK_SET)
GPGME::gpgme_data_seek(self, offset, IO::SEEK_SET)
end | ruby | def seek(offset, whence = IO::SEEK_SET)
GPGME::gpgme_data_seek(self, offset, IO::SEEK_SET)
end | [
"def",
"seek",
"(",
"offset",
",",
"whence",
"=",
"IO",
"::",
"SEEK_SET",
")",
"GPGME",
"::",
"gpgme_data_seek",
"(",
"self",
",",
"offset",
",",
"IO",
"::",
"SEEK_SET",
")",
"end"
] | Seek to a given +offset+ in the data object according to the
value of +whence+.
@example going to the beginning of the buffer after writing something
data = GPGME::Data.new("Some data")
data.read # => "Some data"
data.read # => ""
data.seek 0
data.read # => "Some data" | [
"Seek",
"to",
"a",
"given",
"+",
"offset",
"+",
"in",
"the",
"data",
"object",
"according",
"to",
"the",
"value",
"of",
"+",
"whence",
"+",
"."
] | e84f42e2e8d956940c2430e5ccfbba9e989e3370 | https://github.com/ueno/ruby-gpgme/blob/e84f42e2e8d956940c2430e5ccfbba9e989e3370/lib/gpgme/data.rb#L137-L139 | train |
ueno/ruby-gpgme | lib/gpgme/data.rb | GPGME.Data.file_name= | def file_name=(file_name)
err = GPGME::gpgme_data_set_file_name(self, file_name)
exc = GPGME::error_to_exception(err)
raise exc if exc
file_name
end | ruby | def file_name=(file_name)
err = GPGME::gpgme_data_set_file_name(self, file_name)
exc = GPGME::error_to_exception(err)
raise exc if exc
file_name
end | [
"def",
"file_name",
"=",
"(",
"file_name",
")",
"err",
"=",
"GPGME",
"::",
"gpgme_data_set_file_name",
"(",
"self",
",",
"file_name",
")",
"exc",
"=",
"GPGME",
"::",
"error_to_exception",
"(",
"err",
")",
"raise",
"exc",
"if",
"exc",
"file_name",
"end"
] | Sets the file name for this buffer.
@raise [GPGME::Error::InvalidValue] if the value isn't accepted. | [
"Sets",
"the",
"file",
"name",
"for",
"this",
"buffer",
"."
] | e84f42e2e8d956940c2430e5ccfbba9e989e3370 | https://github.com/ueno/ruby-gpgme/blob/e84f42e2e8d956940c2430e5ccfbba9e989e3370/lib/gpgme/data.rb#L197-L202 | train |
ueno/ruby-gpgme | lib/gpgme/key.rb | GPGME.Key.delete! | def delete!(allow_secret = false)
GPGME::Ctx.new do |ctx|
ctx.delete_key self, allow_secret
end
end | ruby | def delete!(allow_secret = false)
GPGME::Ctx.new do |ctx|
ctx.delete_key self, allow_secret
end
end | [
"def",
"delete!",
"(",
"allow_secret",
"=",
"false",
")",
"GPGME",
"::",
"Ctx",
".",
"new",
"do",
"|",
"ctx",
"|",
"ctx",
".",
"delete_key",
"self",
",",
"allow_secret",
"end",
"end"
] | Delete this key. If it's public, and has a secret one it will fail unless
+allow_secret+ is specified as true. | [
"Delete",
"this",
"key",
".",
"If",
"it",
"s",
"public",
"and",
"has",
"a",
"secret",
"one",
"it",
"will",
"fail",
"unless",
"+",
"allow_secret",
"+",
"is",
"specified",
"as",
"true",
"."
] | e84f42e2e8d956940c2430e5ccfbba9e989e3370 | https://github.com/ueno/ruby-gpgme/blob/e84f42e2e8d956940c2430e5ccfbba9e989e3370/lib/gpgme/key.rb#L148-L152 | train |
ueno/ruby-gpgme | lib/gpgme/ctx.rb | GPGME.Ctx.protocol= | def protocol=(proto)
err = GPGME::gpgme_set_protocol(self, proto)
exc = GPGME::error_to_exception(err)
raise exc if exc
proto
end | ruby | def protocol=(proto)
err = GPGME::gpgme_set_protocol(self, proto)
exc = GPGME::error_to_exception(err)
raise exc if exc
proto
end | [
"def",
"protocol",
"=",
"(",
"proto",
")",
"err",
"=",
"GPGME",
"::",
"gpgme_set_protocol",
"(",
"self",
",",
"proto",
")",
"exc",
"=",
"GPGME",
"::",
"error_to_exception",
"(",
"err",
")",
"raise",
"exc",
"if",
"exc",
"proto",
"end"
] | Getters and setters
Set the +protocol+ used within this context. See {GPGME::Ctx.new} for
possible values. | [
"Getters",
"and",
"setters"
] | e84f42e2e8d956940c2430e5ccfbba9e989e3370 | https://github.com/ueno/ruby-gpgme/blob/e84f42e2e8d956940c2430e5ccfbba9e989e3370/lib/gpgme/ctx.rb#L108-L113 | train |
ueno/ruby-gpgme | lib/gpgme/ctx.rb | GPGME.Ctx.keylist_next | def keylist_next
rkey = []
err = GPGME::gpgme_op_keylist_next(self, rkey)
exc = GPGME::error_to_exception(err)
raise exc if exc
rkey[0]
end | ruby | def keylist_next
rkey = []
err = GPGME::gpgme_op_keylist_next(self, rkey)
exc = GPGME::error_to_exception(err)
raise exc if exc
rkey[0]
end | [
"def",
"keylist_next",
"rkey",
"=",
"[",
"]",
"err",
"=",
"GPGME",
"::",
"gpgme_op_keylist_next",
"(",
"self",
",",
"rkey",
")",
"exc",
"=",
"GPGME",
"::",
"error_to_exception",
"(",
"err",
")",
"raise",
"exc",
"if",
"exc",
"rkey",
"[",
"0",
"]",
"end"
] | Advance to the next key in the key listing operation.
Used by {GPGME::Ctx#each_key} | [
"Advance",
"to",
"the",
"next",
"key",
"in",
"the",
"key",
"listing",
"operation",
"."
] | e84f42e2e8d956940c2430e5ccfbba9e989e3370 | https://github.com/ueno/ruby-gpgme/blob/e84f42e2e8d956940c2430e5ccfbba9e989e3370/lib/gpgme/ctx.rb#L281-L287 | train |
ueno/ruby-gpgme | lib/gpgme/ctx.rb | GPGME.Ctx.keylist_end | def keylist_end
err = GPGME::gpgme_op_keylist_end(self)
exc = GPGME::error_to_exception(err)
raise exc if exc
end | ruby | def keylist_end
err = GPGME::gpgme_op_keylist_end(self)
exc = GPGME::error_to_exception(err)
raise exc if exc
end | [
"def",
"keylist_end",
"err",
"=",
"GPGME",
"::",
"gpgme_op_keylist_end",
"(",
"self",
")",
"exc",
"=",
"GPGME",
"::",
"error_to_exception",
"(",
"err",
")",
"raise",
"exc",
"if",
"exc",
"end"
] | End a pending key list operation.
Used by {GPGME::Ctx#each_key} | [
"End",
"a",
"pending",
"key",
"list",
"operation",
"."
] | e84f42e2e8d956940c2430e5ccfbba9e989e3370 | https://github.com/ueno/ruby-gpgme/blob/e84f42e2e8d956940c2430e5ccfbba9e989e3370/lib/gpgme/ctx.rb#L292-L296 | train |
ueno/ruby-gpgme | lib/gpgme/ctx.rb | GPGME.Ctx.each_key | def each_key(pattern = nil, secret_only = false, &block)
keylist_start(pattern, secret_only)
begin
loop { yield keylist_next }
rescue EOFError
# The last key in the list has already been returned.
ensure
keylist_end
end
end | ruby | def each_key(pattern = nil, secret_only = false, &block)
keylist_start(pattern, secret_only)
begin
loop { yield keylist_next }
rescue EOFError
# The last key in the list has already been returned.
ensure
keylist_end
end
end | [
"def",
"each_key",
"(",
"pattern",
"=",
"nil",
",",
"secret_only",
"=",
"false",
",",
"&",
"block",
")",
"keylist_start",
"(",
"pattern",
",",
"secret_only",
")",
"begin",
"loop",
"{",
"yield",
"keylist_next",
"}",
"rescue",
"EOFError",
"# The last key in the list has already been returned.",
"ensure",
"keylist_end",
"end",
"end"
] | Convenient method to iterate over keys.
If +pattern+ is +nil+, all available keys are returned. If +secret_only+
is +true+, only secret keys are returned.
See {GPGME::Key.find} for an example of how to use, or for an easier way
to use. | [
"Convenient",
"method",
"to",
"iterate",
"over",
"keys",
"."
] | e84f42e2e8d956940c2430e5ccfbba9e989e3370 | https://github.com/ueno/ruby-gpgme/blob/e84f42e2e8d956940c2430e5ccfbba9e989e3370/lib/gpgme/ctx.rb#L305-L314 | train |
ueno/ruby-gpgme | lib/gpgme/ctx.rb | GPGME.Ctx.keys | def keys(pattern = nil, secret_only = nil)
keys = []
each_key(pattern, secret_only) do |key|
keys << key
end
keys
end | ruby | def keys(pattern = nil, secret_only = nil)
keys = []
each_key(pattern, secret_only) do |key|
keys << key
end
keys
end | [
"def",
"keys",
"(",
"pattern",
"=",
"nil",
",",
"secret_only",
"=",
"nil",
")",
"keys",
"=",
"[",
"]",
"each_key",
"(",
"pattern",
",",
"secret_only",
")",
"do",
"|",
"key",
"|",
"keys",
"<<",
"key",
"end",
"keys",
"end"
] | Returns the keys that match the +pattern+, or all if +pattern+ is nil.
Returns only secret keys if +secret_only+ is true. | [
"Returns",
"the",
"keys",
"that",
"match",
"the",
"+",
"pattern",
"+",
"or",
"all",
"if",
"+",
"pattern",
"+",
"is",
"nil",
".",
"Returns",
"only",
"secret",
"keys",
"if",
"+",
"secret_only",
"+",
"is",
"true",
"."
] | e84f42e2e8d956940c2430e5ccfbba9e989e3370 | https://github.com/ueno/ruby-gpgme/blob/e84f42e2e8d956940c2430e5ccfbba9e989e3370/lib/gpgme/ctx.rb#L319-L325 | train |
ueno/ruby-gpgme | lib/gpgme/ctx.rb | GPGME.Ctx.get_key | def get_key(fingerprint, secret = false)
rkey = []
err = GPGME::gpgme_get_key(self, fingerprint, rkey, secret ? 1 : 0)
exc = GPGME::error_to_exception(err)
raise exc if exc
rkey[0]
end | ruby | def get_key(fingerprint, secret = false)
rkey = []
err = GPGME::gpgme_get_key(self, fingerprint, rkey, secret ? 1 : 0)
exc = GPGME::error_to_exception(err)
raise exc if exc
rkey[0]
end | [
"def",
"get_key",
"(",
"fingerprint",
",",
"secret",
"=",
"false",
")",
"rkey",
"=",
"[",
"]",
"err",
"=",
"GPGME",
"::",
"gpgme_get_key",
"(",
"self",
",",
"fingerprint",
",",
"rkey",
",",
"secret",
"?",
"1",
":",
"0",
")",
"exc",
"=",
"GPGME",
"::",
"error_to_exception",
"(",
"err",
")",
"raise",
"exc",
"if",
"exc",
"rkey",
"[",
"0",
"]",
"end"
] | Get the key with the +fingerprint+.
If +secret+ is +true+, secret key is returned. | [
"Get",
"the",
"key",
"with",
"the",
"+",
"fingerprint",
"+",
".",
"If",
"+",
"secret",
"+",
"is",
"+",
"true",
"+",
"secret",
"key",
"is",
"returned",
"."
] | e84f42e2e8d956940c2430e5ccfbba9e989e3370 | https://github.com/ueno/ruby-gpgme/blob/e84f42e2e8d956940c2430e5ccfbba9e989e3370/lib/gpgme/ctx.rb#L329-L335 | train |
ueno/ruby-gpgme | lib/gpgme/ctx.rb | GPGME.Ctx.import_keys | def import_keys(keydata)
err = GPGME::gpgme_op_import(self, keydata)
exc = GPGME::error_to_exception(err)
raise exc if exc
end | ruby | def import_keys(keydata)
err = GPGME::gpgme_op_import(self, keydata)
exc = GPGME::error_to_exception(err)
raise exc if exc
end | [
"def",
"import_keys",
"(",
"keydata",
")",
"err",
"=",
"GPGME",
"::",
"gpgme_op_import",
"(",
"self",
",",
"keydata",
")",
"exc",
"=",
"GPGME",
"::",
"error_to_exception",
"(",
"err",
")",
"raise",
"exc",
"if",
"exc",
"end"
] | Add the keys in the data buffer to the key ring. | [
"Add",
"the",
"keys",
"in",
"the",
"data",
"buffer",
"to",
"the",
"key",
"ring",
"."
] | e84f42e2e8d956940c2430e5ccfbba9e989e3370 | https://github.com/ueno/ruby-gpgme/blob/e84f42e2e8d956940c2430e5ccfbba9e989e3370/lib/gpgme/ctx.rb#L382-L386 | train |
ueno/ruby-gpgme | lib/gpgme/ctx.rb | GPGME.Ctx.delete_key | def delete_key(key, allow_secret = false)
err = GPGME::gpgme_op_delete(self, key, allow_secret ? 1 : 0)
exc = GPGME::error_to_exception(err)
raise exc if exc
end | ruby | def delete_key(key, allow_secret = false)
err = GPGME::gpgme_op_delete(self, key, allow_secret ? 1 : 0)
exc = GPGME::error_to_exception(err)
raise exc if exc
end | [
"def",
"delete_key",
"(",
"key",
",",
"allow_secret",
"=",
"false",
")",
"err",
"=",
"GPGME",
"::",
"gpgme_op_delete",
"(",
"self",
",",
"key",
",",
"allow_secret",
"?",
"1",
":",
"0",
")",
"exc",
"=",
"GPGME",
"::",
"error_to_exception",
"(",
"err",
")",
"raise",
"exc",
"if",
"exc",
"end"
] | Delete the key from the key ring.
If allow_secret is false, only public keys are deleted,
otherwise secret keys are deleted as well. | [
"Delete",
"the",
"key",
"from",
"the",
"key",
"ring",
".",
"If",
"allow_secret",
"is",
"false",
"only",
"public",
"keys",
"are",
"deleted",
"otherwise",
"secret",
"keys",
"are",
"deleted",
"as",
"well",
"."
] | e84f42e2e8d956940c2430e5ccfbba9e989e3370 | https://github.com/ueno/ruby-gpgme/blob/e84f42e2e8d956940c2430e5ccfbba9e989e3370/lib/gpgme/ctx.rb#L396-L400 | train |
ueno/ruby-gpgme | lib/gpgme/ctx.rb | GPGME.Ctx.edit_key | def edit_key(key, editfunc, hook_value = nil, out = Data.new)
err = GPGME::gpgme_op_edit(self, key, editfunc, hook_value, out)
exc = GPGME::error_to_exception(err)
raise exc if exc
end | ruby | def edit_key(key, editfunc, hook_value = nil, out = Data.new)
err = GPGME::gpgme_op_edit(self, key, editfunc, hook_value, out)
exc = GPGME::error_to_exception(err)
raise exc if exc
end | [
"def",
"edit_key",
"(",
"key",
",",
"editfunc",
",",
"hook_value",
"=",
"nil",
",",
"out",
"=",
"Data",
".",
"new",
")",
"err",
"=",
"GPGME",
"::",
"gpgme_op_edit",
"(",
"self",
",",
"key",
",",
"editfunc",
",",
"hook_value",
",",
"out",
")",
"exc",
"=",
"GPGME",
"::",
"error_to_exception",
"(",
"err",
")",
"raise",
"exc",
"if",
"exc",
"end"
] | Edit attributes of the key in the local key ring. | [
"Edit",
"attributes",
"of",
"the",
"key",
"in",
"the",
"local",
"key",
"ring",
"."
] | e84f42e2e8d956940c2430e5ccfbba9e989e3370 | https://github.com/ueno/ruby-gpgme/blob/e84f42e2e8d956940c2430e5ccfbba9e989e3370/lib/gpgme/ctx.rb#L404-L408 | train |
ueno/ruby-gpgme | lib/gpgme/ctx.rb | GPGME.Ctx.edit_card_key | def edit_card_key(key, editfunc, hook_value = nil, out = Data.new)
err = GPGME::gpgme_op_card_edit(self, key, editfunc, hook_value, out)
exc = GPGME::error_to_exception(err)
raise exc if exc
end | ruby | def edit_card_key(key, editfunc, hook_value = nil, out = Data.new)
err = GPGME::gpgme_op_card_edit(self, key, editfunc, hook_value, out)
exc = GPGME::error_to_exception(err)
raise exc if exc
end | [
"def",
"edit_card_key",
"(",
"key",
",",
"editfunc",
",",
"hook_value",
"=",
"nil",
",",
"out",
"=",
"Data",
".",
"new",
")",
"err",
"=",
"GPGME",
"::",
"gpgme_op_card_edit",
"(",
"self",
",",
"key",
",",
"editfunc",
",",
"hook_value",
",",
"out",
")",
"exc",
"=",
"GPGME",
"::",
"error_to_exception",
"(",
"err",
")",
"raise",
"exc",
"if",
"exc",
"end"
] | Edit attributes of the key on the card. | [
"Edit",
"attributes",
"of",
"the",
"key",
"on",
"the",
"card",
"."
] | e84f42e2e8d956940c2430e5ccfbba9e989e3370 | https://github.com/ueno/ruby-gpgme/blob/e84f42e2e8d956940c2430e5ccfbba9e989e3370/lib/gpgme/ctx.rb#L412-L416 | train |
ueno/ruby-gpgme | lib/gpgme/ctx.rb | GPGME.Ctx.verify | def verify(sig, signed_text = nil, plain = Data.new)
err = GPGME::gpgme_op_verify(self, sig, signed_text, plain)
exc = GPGME::error_to_exception(err)
raise exc if exc
plain
end | ruby | def verify(sig, signed_text = nil, plain = Data.new)
err = GPGME::gpgme_op_verify(self, sig, signed_text, plain)
exc = GPGME::error_to_exception(err)
raise exc if exc
plain
end | [
"def",
"verify",
"(",
"sig",
",",
"signed_text",
"=",
"nil",
",",
"plain",
"=",
"Data",
".",
"new",
")",
"err",
"=",
"GPGME",
"::",
"gpgme_op_verify",
"(",
"self",
",",
"sig",
",",
"signed_text",
",",
"plain",
")",
"exc",
"=",
"GPGME",
"::",
"error_to_exception",
"(",
"err",
")",
"raise",
"exc",
"if",
"exc",
"plain",
"end"
] | Verify that the signature in the data object is a valid signature. | [
"Verify",
"that",
"the",
"signature",
"in",
"the",
"data",
"object",
"is",
"a",
"valid",
"signature",
"."
] | e84f42e2e8d956940c2430e5ccfbba9e989e3370 | https://github.com/ueno/ruby-gpgme/blob/e84f42e2e8d956940c2430e5ccfbba9e989e3370/lib/gpgme/ctx.rb#L444-L449 | train |
ueno/ruby-gpgme | lib/gpgme/ctx.rb | GPGME.Ctx.add_signer | def add_signer(*keys)
keys.each do |key|
err = GPGME::gpgme_signers_add(self, key)
exc = GPGME::error_to_exception(err)
raise exc if exc
end
end | ruby | def add_signer(*keys)
keys.each do |key|
err = GPGME::gpgme_signers_add(self, key)
exc = GPGME::error_to_exception(err)
raise exc if exc
end
end | [
"def",
"add_signer",
"(",
"*",
"keys",
")",
"keys",
".",
"each",
"do",
"|",
"key",
"|",
"err",
"=",
"GPGME",
"::",
"gpgme_signers_add",
"(",
"self",
",",
"key",
")",
"exc",
"=",
"GPGME",
"::",
"error_to_exception",
"(",
"err",
")",
"raise",
"exc",
"if",
"exc",
"end",
"end"
] | Add _keys_ to the list of signers. | [
"Add",
"_keys_",
"to",
"the",
"list",
"of",
"signers",
"."
] | e84f42e2e8d956940c2430e5ccfbba9e989e3370 | https://github.com/ueno/ruby-gpgme/blob/e84f42e2e8d956940c2430e5ccfbba9e989e3370/lib/gpgme/ctx.rb#L461-L467 | train |
ueno/ruby-gpgme | lib/gpgme/ctx.rb | GPGME.Ctx.sign | def sign(plain, sig = Data.new, mode = GPGME::SIG_MODE_NORMAL)
err = GPGME::gpgme_op_sign(self, plain, sig, mode)
exc = GPGME::error_to_exception(err)
raise exc if exc
sig
end | ruby | def sign(plain, sig = Data.new, mode = GPGME::SIG_MODE_NORMAL)
err = GPGME::gpgme_op_sign(self, plain, sig, mode)
exc = GPGME::error_to_exception(err)
raise exc if exc
sig
end | [
"def",
"sign",
"(",
"plain",
",",
"sig",
"=",
"Data",
".",
"new",
",",
"mode",
"=",
"GPGME",
"::",
"SIG_MODE_NORMAL",
")",
"err",
"=",
"GPGME",
"::",
"gpgme_op_sign",
"(",
"self",
",",
"plain",
",",
"sig",
",",
"mode",
")",
"exc",
"=",
"GPGME",
"::",
"error_to_exception",
"(",
"err",
")",
"raise",
"exc",
"if",
"exc",
"sig",
"end"
] | Create a signature for the text.
+plain+ is a data object which contains the text.
+sig+ is a data object where the generated signature is stored. | [
"Create",
"a",
"signature",
"for",
"the",
"text",
".",
"+",
"plain",
"+",
"is",
"a",
"data",
"object",
"which",
"contains",
"the",
"text",
".",
"+",
"sig",
"+",
"is",
"a",
"data",
"object",
"where",
"the",
"generated",
"signature",
"is",
"stored",
"."
] | e84f42e2e8d956940c2430e5ccfbba9e989e3370 | https://github.com/ueno/ruby-gpgme/blob/e84f42e2e8d956940c2430e5ccfbba9e989e3370/lib/gpgme/ctx.rb#L472-L477 | train |
ueno/ruby-gpgme | lib/gpgme/ctx.rb | GPGME.Ctx.encrypt | def encrypt(recp, plain, cipher = Data.new, flags = 0)
err = GPGME::gpgme_op_encrypt(self, recp, flags, plain, cipher)
exc = GPGME::error_to_exception(err)
raise exc if exc
cipher
end | ruby | def encrypt(recp, plain, cipher = Data.new, flags = 0)
err = GPGME::gpgme_op_encrypt(self, recp, flags, plain, cipher)
exc = GPGME::error_to_exception(err)
raise exc if exc
cipher
end | [
"def",
"encrypt",
"(",
"recp",
",",
"plain",
",",
"cipher",
"=",
"Data",
".",
"new",
",",
"flags",
"=",
"0",
")",
"err",
"=",
"GPGME",
"::",
"gpgme_op_encrypt",
"(",
"self",
",",
"recp",
",",
"flags",
",",
"plain",
",",
"cipher",
")",
"exc",
"=",
"GPGME",
"::",
"error_to_exception",
"(",
"err",
")",
"raise",
"exc",
"if",
"exc",
"cipher",
"end"
] | Encrypt the plaintext in the data object for the recipients and
return the ciphertext. | [
"Encrypt",
"the",
"plaintext",
"in",
"the",
"data",
"object",
"for",
"the",
"recipients",
"and",
"return",
"the",
"ciphertext",
"."
] | e84f42e2e8d956940c2430e5ccfbba9e989e3370 | https://github.com/ueno/ruby-gpgme/blob/e84f42e2e8d956940c2430e5ccfbba9e989e3370/lib/gpgme/ctx.rb#L485-L490 | train |
ueno/ruby-gpgme | lib/gpgme/crypto.rb | GPGME.Crypto.encrypt | def encrypt(plain, options = {})
options = @default_options.merge options
plain_data = Data.new(plain)
cipher_data = Data.new(options[:output])
keys = Key.find(:public, options[:recipients])
keys = nil if options[:symmetric]
flags = 0
flags |= GPGME::ENCRYPT_ALWAYS_TRUST if options[:always_trust]
GPGME::Ctx.new(options) do |ctx|
begin
if options[:sign]
if options[:signers]
signers = Key.find(:public, options[:signers], :sign)
ctx.add_signer(*signers)
end
ctx.encrypt_sign(keys, plain_data, cipher_data, flags)
else
ctx.encrypt(keys, plain_data, cipher_data, flags)
end
rescue GPGME::Error::UnusablePublicKey => exc
exc.keys = ctx.encrypt_result.invalid_recipients
raise exc
rescue GPGME::Error::UnusableSecretKey => exc
exc.keys = ctx.sign_result.invalid_signers
raise exc
end
end
cipher_data.seek(0)
cipher_data
end | ruby | def encrypt(plain, options = {})
options = @default_options.merge options
plain_data = Data.new(plain)
cipher_data = Data.new(options[:output])
keys = Key.find(:public, options[:recipients])
keys = nil if options[:symmetric]
flags = 0
flags |= GPGME::ENCRYPT_ALWAYS_TRUST if options[:always_trust]
GPGME::Ctx.new(options) do |ctx|
begin
if options[:sign]
if options[:signers]
signers = Key.find(:public, options[:signers], :sign)
ctx.add_signer(*signers)
end
ctx.encrypt_sign(keys, plain_data, cipher_data, flags)
else
ctx.encrypt(keys, plain_data, cipher_data, flags)
end
rescue GPGME::Error::UnusablePublicKey => exc
exc.keys = ctx.encrypt_result.invalid_recipients
raise exc
rescue GPGME::Error::UnusableSecretKey => exc
exc.keys = ctx.sign_result.invalid_signers
raise exc
end
end
cipher_data.seek(0)
cipher_data
end | [
"def",
"encrypt",
"(",
"plain",
",",
"options",
"=",
"{",
"}",
")",
"options",
"=",
"@default_options",
".",
"merge",
"options",
"plain_data",
"=",
"Data",
".",
"new",
"(",
"plain",
")",
"cipher_data",
"=",
"Data",
".",
"new",
"(",
"options",
"[",
":output",
"]",
")",
"keys",
"=",
"Key",
".",
"find",
"(",
":public",
",",
"options",
"[",
":recipients",
"]",
")",
"keys",
"=",
"nil",
"if",
"options",
"[",
":symmetric",
"]",
"flags",
"=",
"0",
"flags",
"|=",
"GPGME",
"::",
"ENCRYPT_ALWAYS_TRUST",
"if",
"options",
"[",
":always_trust",
"]",
"GPGME",
"::",
"Ctx",
".",
"new",
"(",
"options",
")",
"do",
"|",
"ctx",
"|",
"begin",
"if",
"options",
"[",
":sign",
"]",
"if",
"options",
"[",
":signers",
"]",
"signers",
"=",
"Key",
".",
"find",
"(",
":public",
",",
"options",
"[",
":signers",
"]",
",",
":sign",
")",
"ctx",
".",
"add_signer",
"(",
"signers",
")",
"end",
"ctx",
".",
"encrypt_sign",
"(",
"keys",
",",
"plain_data",
",",
"cipher_data",
",",
"flags",
")",
"else",
"ctx",
".",
"encrypt",
"(",
"keys",
",",
"plain_data",
",",
"cipher_data",
",",
"flags",
")",
"end",
"rescue",
"GPGME",
"::",
"Error",
"::",
"UnusablePublicKey",
"=>",
"exc",
"exc",
".",
"keys",
"=",
"ctx",
".",
"encrypt_result",
".",
"invalid_recipients",
"raise",
"exc",
"rescue",
"GPGME",
"::",
"Error",
"::",
"UnusableSecretKey",
"=>",
"exc",
"exc",
".",
"keys",
"=",
"ctx",
".",
"sign_result",
".",
"invalid_signers",
"raise",
"exc",
"end",
"end",
"cipher_data",
".",
"seek",
"(",
"0",
")",
"cipher_data",
"end"
] | Encrypts an element
crypto.encrypt something, options
Will return a {GPGME::Data} element which can then be read.
Must have some key imported, look for {GPGME::Key.import} to know how
to import one, or the gpg documentation to know how to create one
@param plain
Must be something that can be converted into a {GPGME::Data} object, or
a {GPGME::Data} object itself.
@param [Hash] options
The optional parameters are as follows:
* +:recipients+ for which recipient do you want to encrypt this file. It
will pick the first one available if none specified. Can be an array of
identifiers or just one (a string).
* +:symmetric+ if set to true, will ignore +:recipients+, and will perform
a symmetric encryption. Must provide a password via the +:password+
option.
* +:always_trust+ if set to true specifies all the recipients to be
trusted, thus not requiring confirmation.
* +:sign+ if set to true, performs a combined sign and encrypt operation.
* +:signers+ if +:sign+ specified to true, a list of additional possible
signers. Must be an array of sign identifiers.
* +:output+ if specified, it will write the output into it. It will be
converted to a {GPGME::Data} object, so it could be a file for example.
* Any other option accepted by {GPGME::Ctx.new}
@return [GPGME::Data] a {GPGME::Data} object that can be read.
@example returns a {GPGME::Data} that can be later encrypted
encrypted = crypto.encrypt "Hello world!"
encrypted.read # => Encrypted stuff
@example to be decrypted by [email protected].
crypto.encrypt "Hello", :recipients => "[email protected]"
@example If I didn't trust any of my keys by default
crypto.encrypt "Hello" # => GPGME::Error::General
crypto.encrypt "Hello", :always_trust => true # => Will work fine
@example encrypted string that can be decrypted and/or *verified*
crypto.encrypt "Hello", :sign => true
@example multiple signers
crypto.encrypt "Hello", :sign => true, :signers => "[email protected]"
@example writing to a file instead
file = File.open("signed.sec","w+")
crypto.encrypt "Hello", :output => file # output written to signed.sec
@raise [GPGME::Error::General] when trying to encrypt with a key that is
not trusted, and +:always_trust+ wasn't specified | [
"Encrypts",
"an",
"element"
] | e84f42e2e8d956940c2430e5ccfbba9e989e3370 | https://github.com/ueno/ruby-gpgme/blob/e84f42e2e8d956940c2430e5ccfbba9e989e3370/lib/gpgme/crypto.rb#L79-L112 | train |
ueno/ruby-gpgme | lib/gpgme/crypto.rb | GPGME.Crypto.decrypt | def decrypt(cipher, options = {})
options = @default_options.merge options
plain_data = Data.new(options[:output])
cipher_data = Data.new(cipher)
GPGME::Ctx.new(options) do |ctx|
begin
ctx.decrypt_verify(cipher_data, plain_data)
rescue GPGME::Error::UnsupportedAlgorithm => exc
exc.algorithm = ctx.decrypt_result.unsupported_algorithm
raise exc
rescue GPGME::Error::WrongKeyUsage => exc
exc.key_usage = ctx.decrypt_result.wrong_key_usage
raise exc
end
verify_result = ctx.verify_result
if verify_result && block_given?
verify_result.signatures.each do |signature|
yield signature
end
end
end
plain_data.seek(0)
plain_data
end | ruby | def decrypt(cipher, options = {})
options = @default_options.merge options
plain_data = Data.new(options[:output])
cipher_data = Data.new(cipher)
GPGME::Ctx.new(options) do |ctx|
begin
ctx.decrypt_verify(cipher_data, plain_data)
rescue GPGME::Error::UnsupportedAlgorithm => exc
exc.algorithm = ctx.decrypt_result.unsupported_algorithm
raise exc
rescue GPGME::Error::WrongKeyUsage => exc
exc.key_usage = ctx.decrypt_result.wrong_key_usage
raise exc
end
verify_result = ctx.verify_result
if verify_result && block_given?
verify_result.signatures.each do |signature|
yield signature
end
end
end
plain_data.seek(0)
plain_data
end | [
"def",
"decrypt",
"(",
"cipher",
",",
"options",
"=",
"{",
"}",
")",
"options",
"=",
"@default_options",
".",
"merge",
"options",
"plain_data",
"=",
"Data",
".",
"new",
"(",
"options",
"[",
":output",
"]",
")",
"cipher_data",
"=",
"Data",
".",
"new",
"(",
"cipher",
")",
"GPGME",
"::",
"Ctx",
".",
"new",
"(",
"options",
")",
"do",
"|",
"ctx",
"|",
"begin",
"ctx",
".",
"decrypt_verify",
"(",
"cipher_data",
",",
"plain_data",
")",
"rescue",
"GPGME",
"::",
"Error",
"::",
"UnsupportedAlgorithm",
"=>",
"exc",
"exc",
".",
"algorithm",
"=",
"ctx",
".",
"decrypt_result",
".",
"unsupported_algorithm",
"raise",
"exc",
"rescue",
"GPGME",
"::",
"Error",
"::",
"WrongKeyUsage",
"=>",
"exc",
"exc",
".",
"key_usage",
"=",
"ctx",
".",
"decrypt_result",
".",
"wrong_key_usage",
"raise",
"exc",
"end",
"verify_result",
"=",
"ctx",
".",
"verify_result",
"if",
"verify_result",
"&&",
"block_given?",
"verify_result",
".",
"signatures",
".",
"each",
"do",
"|",
"signature",
"|",
"yield",
"signature",
"end",
"end",
"end",
"plain_data",
".",
"seek",
"(",
"0",
")",
"plain_data",
"end"
] | Decrypts a previously encrypted element
crypto.decrypt cipher, options, &block
Must have the appropiate key to be able to decrypt, of course. Returns
a {GPGME::Data} object which can then be read.
@param cipher
Must be something that can be converted into a {GPGME::Data} object,
or a {GPGME::Data} object itself. It is the element that will be
decrypted.
@param [Hash] options
The optional parameters:
* +:output+ if specified, it will write the output into it. It will
me converted to a {GPGME::Data} object, so it can also be a file,
for example.
* If the file was encrypted with symmentric encryption, must provide
a :password option.
* Any other option accepted by {GPGME::Ctx.new}
@param &block
In the block all the signatures are yielded, so one could verify them.
See examples.
@return [GPGME::Data] a {GPGME::Data} that can be read.
@example Simple decrypt
crypto.decrypt encrypted_data
@example symmetric encryption, or passwored key
crypto.decrypt encrypted_data, :password => "gpgme"
@example Output to file
file = File.open("decrypted.txt", "w+")
crypto.decrypt encrypted_data, :output => file
@example Verifying signatures
crypto.decrypt encrypted_data do |signature|
raise "Signature could not be verified" unless signature.valid?
end
@raise [GPGME::Error::UnsupportedAlgorithm] when the cipher was encrypted
using an algorithm that's not supported currently.
@raise [GPGME::Error::WrongKeyUsage] TODO Don't know when
@raise [GPGME::Error::DecryptFailed] when the cipher was encrypted
for a key that's not available currently. | [
"Decrypts",
"a",
"previously",
"encrypted",
"element"
] | e84f42e2e8d956940c2430e5ccfbba9e989e3370 | https://github.com/ueno/ruby-gpgme/blob/e84f42e2e8d956940c2430e5ccfbba9e989e3370/lib/gpgme/crypto.rb#L164-L192 | train |
ueno/ruby-gpgme | lib/gpgme/crypto.rb | GPGME.Crypto.sign | def sign(text, options = {})
options = @default_options.merge options
plain = Data.new(text)
output = Data.new(options[:output])
mode = options[:mode] || GPGME::SIG_MODE_NORMAL
GPGME::Ctx.new(options) do |ctx|
if options[:signer]
signers = Key.find(:secret, options[:signer], :sign)
ctx.add_signer(*signers)
end
begin
ctx.sign(plain, output, mode)
rescue GPGME::Error::UnusableSecretKey => exc
exc.keys = ctx.sign_result.invalid_signers
raise exc
end
end
output.seek(0)
output
end | ruby | def sign(text, options = {})
options = @default_options.merge options
plain = Data.new(text)
output = Data.new(options[:output])
mode = options[:mode] || GPGME::SIG_MODE_NORMAL
GPGME::Ctx.new(options) do |ctx|
if options[:signer]
signers = Key.find(:secret, options[:signer], :sign)
ctx.add_signer(*signers)
end
begin
ctx.sign(plain, output, mode)
rescue GPGME::Error::UnusableSecretKey => exc
exc.keys = ctx.sign_result.invalid_signers
raise exc
end
end
output.seek(0)
output
end | [
"def",
"sign",
"(",
"text",
",",
"options",
"=",
"{",
"}",
")",
"options",
"=",
"@default_options",
".",
"merge",
"options",
"plain",
"=",
"Data",
".",
"new",
"(",
"text",
")",
"output",
"=",
"Data",
".",
"new",
"(",
"options",
"[",
":output",
"]",
")",
"mode",
"=",
"options",
"[",
":mode",
"]",
"||",
"GPGME",
"::",
"SIG_MODE_NORMAL",
"GPGME",
"::",
"Ctx",
".",
"new",
"(",
"options",
")",
"do",
"|",
"ctx",
"|",
"if",
"options",
"[",
":signer",
"]",
"signers",
"=",
"Key",
".",
"find",
"(",
":secret",
",",
"options",
"[",
":signer",
"]",
",",
":sign",
")",
"ctx",
".",
"add_signer",
"(",
"signers",
")",
"end",
"begin",
"ctx",
".",
"sign",
"(",
"plain",
",",
"output",
",",
"mode",
")",
"rescue",
"GPGME",
"::",
"Error",
"::",
"UnusableSecretKey",
"=>",
"exc",
"exc",
".",
"keys",
"=",
"ctx",
".",
"sign_result",
".",
"invalid_signers",
"raise",
"exc",
"end",
"end",
"output",
".",
"seek",
"(",
"0",
")",
"output",
"end"
] | Creates a signature of a text
crypto.sign text, options
Must have the appropiate key to be able to decrypt, of course. Returns
a {GPGME::Data} object which can then be read.
@param text
The object that will be signed. Must be something that can be converted
to {GPGME::Data}.
@param [Hash] options
Optional parameters.
* +:signer+ sign identifier to sign the text with. Will use the first
key it finds if none specified.
* +:output+ if specified, it will write the output into it. It will be
converted to a {GPGME::Data} object, so it could be a file for example.
* +:mode+ Desired type of signature. Options are:
- +GPGME::SIG_MODE_NORMAL+ for a normal signature. The default one if
not specified.
- +GPGME::SIG_MODE_DETACH+ for a detached signature
- +GPGME::SIG_MODE_CLEAR+ for a cleartext signature
* Any other option accepted by {GPGME::Ctx.new}
@return [GPGME::Data] a {GPGME::Data} that can be read.
@example normal sign
crypto.sign "Hi there"
@example outputing to a file
file = File.open("text.sign", "w+")
crypto.sign "Hi there", :options => file
@example doing a detached signature
crypto.sign "Hi there", :mode => GPGME::SIG_MODE_DETACH
@example specifying the signer
crypto.sign "Hi there", :signer => "[email protected]"
@raise [GPGME::Error::UnusableSecretKey] TODO don't know when | [
"Creates",
"a",
"signature",
"of",
"a",
"text"
] | e84f42e2e8d956940c2430e5ccfbba9e989e3370 | https://github.com/ueno/ruby-gpgme/blob/e84f42e2e8d956940c2430e5ccfbba9e989e3370/lib/gpgme/crypto.rb#L235-L258 | train |
ueno/ruby-gpgme | lib/gpgme/crypto.rb | GPGME.Crypto.verify | def verify(sig, options = {})
options = @default_options.merge options
sig = Data.new(sig)
signed_text = Data.new(options[:signed_text])
output = Data.new(options[:output]) unless options[:signed_text]
GPGME::Ctx.new(options) do |ctx|
ctx.verify(sig, signed_text, output)
ctx.verify_result.signatures.each do |signature|
yield signature
end
end
if output
output.seek(0)
output
end
end | ruby | def verify(sig, options = {})
options = @default_options.merge options
sig = Data.new(sig)
signed_text = Data.new(options[:signed_text])
output = Data.new(options[:output]) unless options[:signed_text]
GPGME::Ctx.new(options) do |ctx|
ctx.verify(sig, signed_text, output)
ctx.verify_result.signatures.each do |signature|
yield signature
end
end
if output
output.seek(0)
output
end
end | [
"def",
"verify",
"(",
"sig",
",",
"options",
"=",
"{",
"}",
")",
"options",
"=",
"@default_options",
".",
"merge",
"options",
"sig",
"=",
"Data",
".",
"new",
"(",
"sig",
")",
"signed_text",
"=",
"Data",
".",
"new",
"(",
"options",
"[",
":signed_text",
"]",
")",
"output",
"=",
"Data",
".",
"new",
"(",
"options",
"[",
":output",
"]",
")",
"unless",
"options",
"[",
":signed_text",
"]",
"GPGME",
"::",
"Ctx",
".",
"new",
"(",
"options",
")",
"do",
"|",
"ctx",
"|",
"ctx",
".",
"verify",
"(",
"sig",
",",
"signed_text",
",",
"output",
")",
"ctx",
".",
"verify_result",
".",
"signatures",
".",
"each",
"do",
"|",
"signature",
"|",
"yield",
"signature",
"end",
"end",
"if",
"output",
"output",
".",
"seek",
"(",
"0",
")",
"output",
"end",
"end"
] | Verifies a previously signed element
crypto.verify sig, options, &block
Must have the proper keys available.
@param sig
The signature itself. Must be possible to convert into a {GPGME::Data}
object, so can be a file.
@param [Hash] options
* +:signed_text+ if the sign is detached, then must be the plain text
for which the signature was created.
* +:output+ where to store the result of the signature. Will be
converted to a {GPGME::Data} object.
* Any other option accepted by {GPGME::Ctx.new}
@param &block
In the block all the signatures are yielded, so one could verify them.
See examples.
@return [GPGME::Data] unless the sign is detached, the {GPGME::Data}
object with the plain text. If the sign is detached, will return nil.
@example simple verification
sign = crypto.sign("Hi there")
data = crypto.verify(sign) { |signature| signature.valid? }
data.read # => "Hi there"
@example saving output to file
sign = crypto.sign("Hi there")
out = File.open("test.asc", "w+")
crypto.verify(sign, :output => out) {|signature| signature.valid?}
out.read # => "Hi there"
@example verifying a detached signature
sign = crypto.detach_sign("Hi there")
# Will fail
crypto.verify(sign) { |signature| signature.valid? }
# Will succeed
crypto.verify(sign, :signed_text => "hi there") do |signature|
signature.valid?
end | [
"Verifies",
"a",
"previously",
"signed",
"element"
] | e84f42e2e8d956940c2430e5ccfbba9e989e3370 | https://github.com/ueno/ruby-gpgme/blob/e84f42e2e8d956940c2430e5ccfbba9e989e3370/lib/gpgme/crypto.rb#L304-L322 | train |
mojombo/grit | lib/grit/index.rb | Grit.Index.add | def add(path, data)
path = path.split('/')
filename = path.pop
current = self.tree
path.each do |dir|
current[dir] ||= {}
node = current[dir]
current = node
end
current[filename] = data
end | ruby | def add(path, data)
path = path.split('/')
filename = path.pop
current = self.tree
path.each do |dir|
current[dir] ||= {}
node = current[dir]
current = node
end
current[filename] = data
end | [
"def",
"add",
"(",
"path",
",",
"data",
")",
"path",
"=",
"path",
".",
"split",
"(",
"'/'",
")",
"filename",
"=",
"path",
".",
"pop",
"current",
"=",
"self",
".",
"tree",
"path",
".",
"each",
"do",
"|",
"dir",
"|",
"current",
"[",
"dir",
"]",
"||=",
"{",
"}",
"node",
"=",
"current",
"[",
"dir",
"]",
"current",
"=",
"node",
"end",
"current",
"[",
"filename",
"]",
"=",
"data",
"end"
] | Initialize a new Index object.
repo - The Grit::Repo to which the index belongs.
Returns the newly initialized Grit::Index.
Public: Add a file to the index.
path - The String file path including filename (no slash prefix).
data - The String binary contents of the file.
Returns nothing. | [
"Initialize",
"a",
"new",
"Index",
"object",
"."
] | 5608567286e64a1c55c5e7fcd415364e04f8986e | https://github.com/mojombo/grit/blob/5608567286e64a1c55c5e7fcd415364e04f8986e/lib/grit/index.rb#L36-L49 | train |
mojombo/grit | lib/grit/index.rb | Grit.Index.write_tree | def write_tree(tree = nil, now_tree = nil)
tree = self.tree if !tree
tree_contents = {}
# fill in original tree
now_tree = read_tree(now_tree) if(now_tree && now_tree.is_a?(String))
now_tree.contents.each do |obj|
sha = [obj.id].pack("H*")
k = obj.name
k += '/' if (obj.class == Grit::Tree)
tmode = obj.mode.to_i.to_s ## remove zero-padding
tree_contents[k] = "%s %s\0%s" % [tmode, obj.name, sha]
end if now_tree
# overwrite with new tree contents
tree.each do |k, v|
case v
when Array
sha, mode = v
if sha.size == 40 # must be a sha
sha = [sha].pack("H*")
mode = mode.to_i.to_s # leading 0s not allowed
k = k.split('/').last # slashes not allowed
str = "%s %s\0%s" % [mode, k, sha]
tree_contents[k] = str
end
when String
sha = write_blob(v)
sha = [sha].pack("H*")
str = "%s %s\0%s" % ['100644', k, sha]
tree_contents[k] = str
when Hash
ctree = now_tree/k if now_tree
sha = write_tree(v, ctree)
sha = [sha].pack("H*")
str = "%s %s\0%s" % ['40000', k, sha]
tree_contents[k + '/'] = str
when false
tree_contents.delete(k)
end
end
tr = tree_contents.sort.map { |k, v| v }.join('')
@last_tree_size = tr.size
self.repo.git.put_raw_object(tr, 'tree')
end | ruby | def write_tree(tree = nil, now_tree = nil)
tree = self.tree if !tree
tree_contents = {}
# fill in original tree
now_tree = read_tree(now_tree) if(now_tree && now_tree.is_a?(String))
now_tree.contents.each do |obj|
sha = [obj.id].pack("H*")
k = obj.name
k += '/' if (obj.class == Grit::Tree)
tmode = obj.mode.to_i.to_s ## remove zero-padding
tree_contents[k] = "%s %s\0%s" % [tmode, obj.name, sha]
end if now_tree
# overwrite with new tree contents
tree.each do |k, v|
case v
when Array
sha, mode = v
if sha.size == 40 # must be a sha
sha = [sha].pack("H*")
mode = mode.to_i.to_s # leading 0s not allowed
k = k.split('/').last # slashes not allowed
str = "%s %s\0%s" % [mode, k, sha]
tree_contents[k] = str
end
when String
sha = write_blob(v)
sha = [sha].pack("H*")
str = "%s %s\0%s" % ['100644', k, sha]
tree_contents[k] = str
when Hash
ctree = now_tree/k if now_tree
sha = write_tree(v, ctree)
sha = [sha].pack("H*")
str = "%s %s\0%s" % ['40000', k, sha]
tree_contents[k + '/'] = str
when false
tree_contents.delete(k)
end
end
tr = tree_contents.sort.map { |k, v| v }.join('')
@last_tree_size = tr.size
self.repo.git.put_raw_object(tr, 'tree')
end | [
"def",
"write_tree",
"(",
"tree",
"=",
"nil",
",",
"now_tree",
"=",
"nil",
")",
"tree",
"=",
"self",
".",
"tree",
"if",
"!",
"tree",
"tree_contents",
"=",
"{",
"}",
"# fill in original tree",
"now_tree",
"=",
"read_tree",
"(",
"now_tree",
")",
"if",
"(",
"now_tree",
"&&",
"now_tree",
".",
"is_a?",
"(",
"String",
")",
")",
"now_tree",
".",
"contents",
".",
"each",
"do",
"|",
"obj",
"|",
"sha",
"=",
"[",
"obj",
".",
"id",
"]",
".",
"pack",
"(",
"\"H*\"",
")",
"k",
"=",
"obj",
".",
"name",
"k",
"+=",
"'/'",
"if",
"(",
"obj",
".",
"class",
"==",
"Grit",
"::",
"Tree",
")",
"tmode",
"=",
"obj",
".",
"mode",
".",
"to_i",
".",
"to_s",
"## remove zero-padding",
"tree_contents",
"[",
"k",
"]",
"=",
"\"%s %s\\0%s\"",
"%",
"[",
"tmode",
",",
"obj",
".",
"name",
",",
"sha",
"]",
"end",
"if",
"now_tree",
"# overwrite with new tree contents",
"tree",
".",
"each",
"do",
"|",
"k",
",",
"v",
"|",
"case",
"v",
"when",
"Array",
"sha",
",",
"mode",
"=",
"v",
"if",
"sha",
".",
"size",
"==",
"40",
"# must be a sha",
"sha",
"=",
"[",
"sha",
"]",
".",
"pack",
"(",
"\"H*\"",
")",
"mode",
"=",
"mode",
".",
"to_i",
".",
"to_s",
"# leading 0s not allowed",
"k",
"=",
"k",
".",
"split",
"(",
"'/'",
")",
".",
"last",
"# slashes not allowed",
"str",
"=",
"\"%s %s\\0%s\"",
"%",
"[",
"mode",
",",
"k",
",",
"sha",
"]",
"tree_contents",
"[",
"k",
"]",
"=",
"str",
"end",
"when",
"String",
"sha",
"=",
"write_blob",
"(",
"v",
")",
"sha",
"=",
"[",
"sha",
"]",
".",
"pack",
"(",
"\"H*\"",
")",
"str",
"=",
"\"%s %s\\0%s\"",
"%",
"[",
"'100644'",
",",
"k",
",",
"sha",
"]",
"tree_contents",
"[",
"k",
"]",
"=",
"str",
"when",
"Hash",
"ctree",
"=",
"now_tree",
"/",
"k",
"if",
"now_tree",
"sha",
"=",
"write_tree",
"(",
"v",
",",
"ctree",
")",
"sha",
"=",
"[",
"sha",
"]",
".",
"pack",
"(",
"\"H*\"",
")",
"str",
"=",
"\"%s %s\\0%s\"",
"%",
"[",
"'40000'",
",",
"k",
",",
"sha",
"]",
"tree_contents",
"[",
"k",
"+",
"'/'",
"]",
"=",
"str",
"when",
"false",
"tree_contents",
".",
"delete",
"(",
"k",
")",
"end",
"end",
"tr",
"=",
"tree_contents",
".",
"sort",
".",
"map",
"{",
"|",
"k",
",",
"v",
"|",
"v",
"}",
".",
"join",
"(",
"''",
")",
"@last_tree_size",
"=",
"tr",
".",
"size",
"self",
".",
"repo",
".",
"git",
".",
"put_raw_object",
"(",
"tr",
",",
"'tree'",
")",
"end"
] | Recursively write a tree to the index.
tree - The Hash tree map:
key - The String directory or filename.
val - The Hash submap or the String contents of the file.
now_tree - The Grit::Tree representing the a previous tree upon which
this tree will be based (default: nil).
Returns the String SHA1 String of the tree. | [
"Recursively",
"write",
"a",
"tree",
"to",
"the",
"index",
"."
] | 5608567286e64a1c55c5e7fcd415364e04f8986e | https://github.com/mojombo/grit/blob/5608567286e64a1c55c5e7fcd415364e04f8986e/lib/grit/index.rb#L165-L210 | train |
mojombo/grit | lib/grit/tree.rb | Grit.Tree.content_from_string | def content_from_string(repo, text)
mode, type, id, name = text.split(/ |\t/, 4)
case type
when "tree"
Tree.create(repo, :id => id, :mode => mode, :name => name)
when "blob"
Blob.create(repo, :id => id, :mode => mode, :name => name)
when "link"
Blob.create(repo, :id => id, :mode => mode, :name => name)
when "commit"
Submodule.create(repo, :id => id, :mode => mode, :name => name)
else
raise Grit::InvalidObjectType, type
end
end | ruby | def content_from_string(repo, text)
mode, type, id, name = text.split(/ |\t/, 4)
case type
when "tree"
Tree.create(repo, :id => id, :mode => mode, :name => name)
when "blob"
Blob.create(repo, :id => id, :mode => mode, :name => name)
when "link"
Blob.create(repo, :id => id, :mode => mode, :name => name)
when "commit"
Submodule.create(repo, :id => id, :mode => mode, :name => name)
else
raise Grit::InvalidObjectType, type
end
end | [
"def",
"content_from_string",
"(",
"repo",
",",
"text",
")",
"mode",
",",
"type",
",",
"id",
",",
"name",
"=",
"text",
".",
"split",
"(",
"/",
"\\t",
"/",
",",
"4",
")",
"case",
"type",
"when",
"\"tree\"",
"Tree",
".",
"create",
"(",
"repo",
",",
":id",
"=>",
"id",
",",
":mode",
"=>",
"mode",
",",
":name",
"=>",
"name",
")",
"when",
"\"blob\"",
"Blob",
".",
"create",
"(",
"repo",
",",
":id",
"=>",
"id",
",",
":mode",
"=>",
"mode",
",",
":name",
"=>",
"name",
")",
"when",
"\"link\"",
"Blob",
".",
"create",
"(",
"repo",
",",
":id",
"=>",
"id",
",",
":mode",
"=>",
"mode",
",",
":name",
"=>",
"name",
")",
"when",
"\"commit\"",
"Submodule",
".",
"create",
"(",
"repo",
",",
":id",
"=>",
"id",
",",
":mode",
"=>",
"mode",
",",
":name",
"=>",
"name",
")",
"else",
"raise",
"Grit",
"::",
"InvalidObjectType",
",",
"type",
"end",
"end"
] | Parse a content item and create the appropriate object
+repo+ is the Repo
+text+ is the single line containing the items data in `git ls-tree` format
Returns Grit::Blob or Grit::Tree | [
"Parse",
"a",
"content",
"item",
"and",
"create",
"the",
"appropriate",
"object",
"+",
"repo",
"+",
"is",
"the",
"Repo",
"+",
"text",
"+",
"is",
"the",
"single",
"line",
"containing",
"the",
"items",
"data",
"in",
"git",
"ls",
"-",
"tree",
"format"
] | 5608567286e64a1c55c5e7fcd415364e04f8986e | https://github.com/mojombo/grit/blob/5608567286e64a1c55c5e7fcd415364e04f8986e/lib/grit/tree.rb#L67-L81 | train |
mojombo/grit | lib/grit/tree.rb | Grit.Tree./ | def /(file)
if file =~ /\//
file.split("/").inject(self) { |acc, x| acc/x } rescue nil
else
self.contents.find { |c| c.name == file }
end
end | ruby | def /(file)
if file =~ /\//
file.split("/").inject(self) { |acc, x| acc/x } rescue nil
else
self.contents.find { |c| c.name == file }
end
end | [
"def",
"/",
"(",
"file",
")",
"if",
"file",
"=~",
"/",
"\\/",
"/",
"file",
".",
"split",
"(",
"\"/\"",
")",
".",
"inject",
"(",
"self",
")",
"{",
"|",
"acc",
",",
"x",
"|",
"acc",
"/",
"x",
"}",
"rescue",
"nil",
"else",
"self",
".",
"contents",
".",
"find",
"{",
"|",
"c",
"|",
"c",
".",
"name",
"==",
"file",
"}",
"end",
"end"
] | Find the named object in this tree's contents
Examples
Repo.new('/path/to/grit').tree/'lib'
# => #<Grit::Tree "6cc23ee138be09ff8c28b07162720018b244e95e">
Repo.new('/path/to/grit').tree/'README.txt'
# => #<Grit::Blob "8b1e02c0fb554eed2ce2ef737a68bb369d7527df">
Returns Grit::Blob or Grit::Tree or nil if not found | [
"Find",
"the",
"named",
"object",
"in",
"this",
"tree",
"s",
"contents"
] | 5608567286e64a1c55c5e7fcd415364e04f8986e | https://github.com/mojombo/grit/blob/5608567286e64a1c55c5e7fcd415364e04f8986e/lib/grit/tree.rb#L92-L98 | train |
mojombo/grit | lib/grit/submodule.rb | Grit.Submodule.create_initialize | def create_initialize(repo, atts)
@repo = repo
atts.each do |k, v|
instance_variable_set("@#{k}".to_sym, v)
end
self
end | ruby | def create_initialize(repo, atts)
@repo = repo
atts.each do |k, v|
instance_variable_set("@#{k}".to_sym, v)
end
self
end | [
"def",
"create_initialize",
"(",
"repo",
",",
"atts",
")",
"@repo",
"=",
"repo",
"atts",
".",
"each",
"do",
"|",
"k",
",",
"v",
"|",
"instance_variable_set",
"(",
"\"@#{k}\"",
".",
"to_sym",
",",
"v",
")",
"end",
"self",
"end"
] | Initializer for Submodule.create
+repo+ is the Repo
+atts+ is a Hash of instance variable data
Returns Grit::Submodule | [
"Initializer",
"for",
"Submodule",
".",
"create",
"+",
"repo",
"+",
"is",
"the",
"Repo",
"+",
"atts",
"+",
"is",
"a",
"Hash",
"of",
"instance",
"variable",
"data"
] | 5608567286e64a1c55c5e7fcd415364e04f8986e | https://github.com/mojombo/grit/blob/5608567286e64a1c55c5e7fcd415364e04f8986e/lib/grit/submodule.rb#L22-L28 | train |
mojombo/grit | lib/grit/submodule.rb | Grit.Submodule.url | def url(ref)
config = self.class.config(@repo, ref)
lookup = config.keys.inject({}) do |acc, key|
id = config[key]['id']
acc[id] = config[key]['url']
acc
end
lookup[@id]
end | ruby | def url(ref)
config = self.class.config(@repo, ref)
lookup = config.keys.inject({}) do |acc, key|
id = config[key]['id']
acc[id] = config[key]['url']
acc
end
lookup[@id]
end | [
"def",
"url",
"(",
"ref",
")",
"config",
"=",
"self",
".",
"class",
".",
"config",
"(",
"@repo",
",",
"ref",
")",
"lookup",
"=",
"config",
".",
"keys",
".",
"inject",
"(",
"{",
"}",
")",
"do",
"|",
"acc",
",",
"key",
"|",
"id",
"=",
"config",
"[",
"key",
"]",
"[",
"'id'",
"]",
"acc",
"[",
"id",
"]",
"=",
"config",
"[",
"key",
"]",
"[",
"'url'",
"]",
"acc",
"end",
"lookup",
"[",
"@id",
"]",
"end"
] | The url of this submodule
+ref+ is the committish that should be used to look up the url
Returns String | [
"The",
"url",
"of",
"this",
"submodule",
"+",
"ref",
"+",
"is",
"the",
"committish",
"that",
"should",
"be",
"used",
"to",
"look",
"up",
"the",
"url"
] | 5608567286e64a1c55c5e7fcd415364e04f8986e | https://github.com/mojombo/grit/blob/5608567286e64a1c55c5e7fcd415364e04f8986e/lib/grit/submodule.rb#L34-L44 | train |
mojombo/grit | lib/grit/status.rb | Grit.Status.diff_files | def diff_files
hsh = {}
@base.git.diff_files.split("\n").each do |line|
(info, file) = line.split("\t")
(mode_src, mode_dest, sha_src, sha_dest, type) = info.split
hsh[file] = {:path => file, :mode_file => mode_src.to_s[1, 7], :mode_index => mode_dest,
:sha_file => sha_src, :sha_index => sha_dest, :type => type}
end
hsh
end | ruby | def diff_files
hsh = {}
@base.git.diff_files.split("\n").each do |line|
(info, file) = line.split("\t")
(mode_src, mode_dest, sha_src, sha_dest, type) = info.split
hsh[file] = {:path => file, :mode_file => mode_src.to_s[1, 7], :mode_index => mode_dest,
:sha_file => sha_src, :sha_index => sha_dest, :type => type}
end
hsh
end | [
"def",
"diff_files",
"hsh",
"=",
"{",
"}",
"@base",
".",
"git",
".",
"diff_files",
".",
"split",
"(",
"\"\\n\"",
")",
".",
"each",
"do",
"|",
"line",
"|",
"(",
"info",
",",
"file",
")",
"=",
"line",
".",
"split",
"(",
"\"\\t\"",
")",
"(",
"mode_src",
",",
"mode_dest",
",",
"sha_src",
",",
"sha_dest",
",",
"type",
")",
"=",
"info",
".",
"split",
"hsh",
"[",
"file",
"]",
"=",
"{",
":path",
"=>",
"file",
",",
":mode_file",
"=>",
"mode_src",
".",
"to_s",
"[",
"1",
",",
"7",
"]",
",",
":mode_index",
"=>",
"mode_dest",
",",
":sha_file",
"=>",
"sha_src",
",",
":sha_index",
"=>",
"sha_dest",
",",
":type",
"=>",
"type",
"}",
"end",
"hsh",
"end"
] | compares the index and the working directory | [
"compares",
"the",
"index",
"and",
"the",
"working",
"directory"
] | 5608567286e64a1c55c5e7fcd415364e04f8986e | https://github.com/mojombo/grit/blob/5608567286e64a1c55c5e7fcd415364e04f8986e/lib/grit/status.rb#L118-L127 | train |
mojombo/grit | lib/grit/actor.rb | Grit.Actor.output | def output(time)
offset = time.utc_offset / 60
"%s <%s> %d %+.2d%.2d" % [
@name,
@email || "null",
time.to_i,
offset / 60,
offset.abs % 60]
end | ruby | def output(time)
offset = time.utc_offset / 60
"%s <%s> %d %+.2d%.2d" % [
@name,
@email || "null",
time.to_i,
offset / 60,
offset.abs % 60]
end | [
"def",
"output",
"(",
"time",
")",
"offset",
"=",
"time",
".",
"utc_offset",
"/",
"60",
"\"%s <%s> %d %+.2d%.2d\"",
"%",
"[",
"@name",
",",
"@email",
"||",
"\"null\"",
",",
"time",
".",
"to_i",
",",
"offset",
"/",
"60",
",",
"offset",
".",
"abs",
"%",
"60",
"]",
"end"
] | Outputs an actor string for Git commits.
actor = Actor.new('bob', '[email protected]')
actor.output(time) # => "bob <[email protected]> UNIX_TIME +0700"
time - The Time the commit was authored or committed.
Returns a String. | [
"Outputs",
"an",
"actor",
"string",
"for",
"Git",
"commits",
"."
] | 5608567286e64a1c55c5e7fcd415364e04f8986e | https://github.com/mojombo/grit/blob/5608567286e64a1c55c5e7fcd415364e04f8986e/lib/grit/actor.rb#L36-L44 | train |
mojombo/grit | lib/grit/repo.rb | Grit.Repo.recent_tag_name | def recent_tag_name(committish = nil, options = {})
value = git.describe({:always => true}.update(options), committish.to_s).to_s.strip
value.size.zero? ? nil : value
end | ruby | def recent_tag_name(committish = nil, options = {})
value = git.describe({:always => true}.update(options), committish.to_s).to_s.strip
value.size.zero? ? nil : value
end | [
"def",
"recent_tag_name",
"(",
"committish",
"=",
"nil",
",",
"options",
"=",
"{",
"}",
")",
"value",
"=",
"git",
".",
"describe",
"(",
"{",
":always",
"=>",
"true",
"}",
".",
"update",
"(",
"options",
")",
",",
"committish",
".",
"to_s",
")",
".",
"to_s",
".",
"strip",
"value",
".",
"size",
".",
"zero?",
"?",
"nil",
":",
"value",
"end"
] | Finds the most recent annotated tag name that is reachable from a commit.
@repo.recent_tag_name('master')
# => "v1.0-0-abcdef"
committish - optional commit SHA, branch, or tag name.
options - optional hash of options to pass to git.
Default: {:always => true}
:tags => true # use lightweight tags too.
:abbrev => Integer # number of hex digits to form the unique
name. Defaults to 7.
:long => true # always output tag + commit sha
# see `git describe` docs for more options.
Returns the String tag name, or just the commit if no tag is
found. If there have been updates since the tag was made, a
suffix is added with the number of commits since the tag, and
the abbreviated object name of the most recent commit.
Returns nil if the committish value is not found. | [
"Finds",
"the",
"most",
"recent",
"annotated",
"tag",
"name",
"that",
"is",
"reachable",
"from",
"a",
"commit",
"."
] | 5608567286e64a1c55c5e7fcd415364e04f8986e | https://github.com/mojombo/grit/blob/5608567286e64a1c55c5e7fcd415364e04f8986e/lib/grit/repo.rb#L300-L303 | train |
mojombo/grit | lib/grit/repo.rb | Grit.Repo.refs_list | def refs_list
refs = self.git.for_each_ref
refarr = refs.split("\n").map do |line|
shatype, ref = line.split("\t")
sha, type = shatype.split(' ')
[ref, sha, type]
end
refarr
end | ruby | def refs_list
refs = self.git.for_each_ref
refarr = refs.split("\n").map do |line|
shatype, ref = line.split("\t")
sha, type = shatype.split(' ')
[ref, sha, type]
end
refarr
end | [
"def",
"refs_list",
"refs",
"=",
"self",
".",
"git",
".",
"for_each_ref",
"refarr",
"=",
"refs",
".",
"split",
"(",
"\"\\n\"",
")",
".",
"map",
"do",
"|",
"line",
"|",
"shatype",
",",
"ref",
"=",
"line",
".",
"split",
"(",
"\"\\t\"",
")",
"sha",
",",
"type",
"=",
"shatype",
".",
"split",
"(",
"' '",
")",
"[",
"ref",
",",
"sha",
",",
"type",
"]",
"end",
"refarr",
"end"
] | returns an array of hashes representing all references | [
"returns",
"an",
"array",
"of",
"hashes",
"representing",
"all",
"references"
] | 5608567286e64a1c55c5e7fcd415364e04f8986e | https://github.com/mojombo/grit/blob/5608567286e64a1c55c5e7fcd415364e04f8986e/lib/grit/repo.rb#L350-L358 | train |
mojombo/grit | lib/grit/repo.rb | Grit.Repo.commit_deltas_from | def commit_deltas_from(other_repo, ref = "master", other_ref = "master")
# TODO: we should be able to figure out the branch point, rather than
# rev-list'ing the whole thing
repo_refs = self.git.rev_list({}, ref).strip.split("\n")
other_repo_refs = other_repo.git.rev_list({}, other_ref).strip.split("\n")
(other_repo_refs - repo_refs).map do |refn|
Commit.find_all(other_repo, refn, {:max_count => 1}).first
end
end | ruby | def commit_deltas_from(other_repo, ref = "master", other_ref = "master")
# TODO: we should be able to figure out the branch point, rather than
# rev-list'ing the whole thing
repo_refs = self.git.rev_list({}, ref).strip.split("\n")
other_repo_refs = other_repo.git.rev_list({}, other_ref).strip.split("\n")
(other_repo_refs - repo_refs).map do |refn|
Commit.find_all(other_repo, refn, {:max_count => 1}).first
end
end | [
"def",
"commit_deltas_from",
"(",
"other_repo",
",",
"ref",
"=",
"\"master\"",
",",
"other_ref",
"=",
"\"master\"",
")",
"# TODO: we should be able to figure out the branch point, rather than",
"# rev-list'ing the whole thing",
"repo_refs",
"=",
"self",
".",
"git",
".",
"rev_list",
"(",
"{",
"}",
",",
"ref",
")",
".",
"strip",
".",
"split",
"(",
"\"\\n\"",
")",
"other_repo_refs",
"=",
"other_repo",
".",
"git",
".",
"rev_list",
"(",
"{",
"}",
",",
"other_ref",
")",
".",
"strip",
".",
"split",
"(",
"\"\\n\"",
")",
"(",
"other_repo_refs",
"-",
"repo_refs",
")",
".",
"map",
"do",
"|",
"refn",
"|",
"Commit",
".",
"find_all",
"(",
"other_repo",
",",
"refn",
",",
"{",
":max_count",
"=>",
"1",
"}",
")",
".",
"first",
"end",
"end"
] | Returns a list of commits that is in +other_repo+ but not in self
Returns Grit::Commit[] | [
"Returns",
"a",
"list",
"of",
"commits",
"that",
"is",
"in",
"+",
"other_repo",
"+",
"but",
"not",
"in",
"self"
] | 5608567286e64a1c55c5e7fcd415364e04f8986e | https://github.com/mojombo/grit/blob/5608567286e64a1c55c5e7fcd415364e04f8986e/lib/grit/repo.rb#L433-L442 | train |
mojombo/grit | lib/grit/repo.rb | Grit.Repo.log | def log(commit = 'master', path = nil, options = {})
default_options = {:pretty => "raw"}
actual_options = default_options.merge(options)
arg = path ? [commit, '--', path] : [commit]
commits = self.git.log(actual_options, *arg)
Commit.list_from_string(self, commits)
end | ruby | def log(commit = 'master', path = nil, options = {})
default_options = {:pretty => "raw"}
actual_options = default_options.merge(options)
arg = path ? [commit, '--', path] : [commit]
commits = self.git.log(actual_options, *arg)
Commit.list_from_string(self, commits)
end | [
"def",
"log",
"(",
"commit",
"=",
"'master'",
",",
"path",
"=",
"nil",
",",
"options",
"=",
"{",
"}",
")",
"default_options",
"=",
"{",
":pretty",
"=>",
"\"raw\"",
"}",
"actual_options",
"=",
"default_options",
".",
"merge",
"(",
"options",
")",
"arg",
"=",
"path",
"?",
"[",
"commit",
",",
"'--'",
",",
"path",
"]",
":",
"[",
"commit",
"]",
"commits",
"=",
"self",
".",
"git",
".",
"log",
"(",
"actual_options",
",",
"arg",
")",
"Commit",
".",
"list_from_string",
"(",
"self",
",",
"commits",
")",
"end"
] | The commit log for a treeish
Returns Grit::Commit[] | [
"The",
"commit",
"log",
"for",
"a",
"treeish"
] | 5608567286e64a1c55c5e7fcd415364e04f8986e | https://github.com/mojombo/grit/blob/5608567286e64a1c55c5e7fcd415364e04f8986e/lib/grit/repo.rb#L541-L547 | train |
mojombo/grit | lib/grit/repo.rb | Grit.Repo.alternates= | def alternates=(alts)
alts.each do |alt|
unless File.exist?(alt)
raise "Could not set alternates. Alternate path #{alt} must exist"
end
end
if alts.empty?
self.git.fs_write('objects/info/alternates', '')
else
self.git.fs_write('objects/info/alternates', alts.join("\n"))
end
end | ruby | def alternates=(alts)
alts.each do |alt|
unless File.exist?(alt)
raise "Could not set alternates. Alternate path #{alt} must exist"
end
end
if alts.empty?
self.git.fs_write('objects/info/alternates', '')
else
self.git.fs_write('objects/info/alternates', alts.join("\n"))
end
end | [
"def",
"alternates",
"=",
"(",
"alts",
")",
"alts",
".",
"each",
"do",
"|",
"alt",
"|",
"unless",
"File",
".",
"exist?",
"(",
"alt",
")",
"raise",
"\"Could not set alternates. Alternate path #{alt} must exist\"",
"end",
"end",
"if",
"alts",
".",
"empty?",
"self",
".",
"git",
".",
"fs_write",
"(",
"'objects/info/alternates'",
",",
"''",
")",
"else",
"self",
".",
"git",
".",
"fs_write",
"(",
"'objects/info/alternates'",
",",
"alts",
".",
"join",
"(",
"\"\\n\"",
")",
")",
"end",
"end"
] | Sets the alternates
+alts+ is the Array of String paths representing the alternates
Returns nothing | [
"Sets",
"the",
"alternates",
"+",
"alts",
"+",
"is",
"the",
"Array",
"of",
"String",
"paths",
"representing",
"the",
"alternates"
] | 5608567286e64a1c55c5e7fcd415364e04f8986e | https://github.com/mojombo/grit/blob/5608567286e64a1c55c5e7fcd415364e04f8986e/lib/grit/repo.rb#L663-L675 | train |
mojombo/grit | lib/grit/commit.rb | Grit.Commit.diffs | def diffs(options = {})
if parents.empty?
show
else
self.class.diff(@repo, parents.first.id, @id, [], options)
end
end | ruby | def diffs(options = {})
if parents.empty?
show
else
self.class.diff(@repo, parents.first.id, @id, [], options)
end
end | [
"def",
"diffs",
"(",
"options",
"=",
"{",
"}",
")",
"if",
"parents",
".",
"empty?",
"show",
"else",
"self",
".",
"class",
".",
"diff",
"(",
"@repo",
",",
"parents",
".",
"first",
".",
"id",
",",
"@id",
",",
"[",
"]",
",",
"options",
")",
"end",
"end"
] | Shows diffs between the commit's parent and the commit.
options - An optional Hash of options, passed to Grit::Commit.diff.
Returns Grit::Diff[] (baked) | [
"Shows",
"diffs",
"between",
"the",
"commit",
"s",
"parent",
"and",
"the",
"commit",
"."
] | 5608567286e64a1c55c5e7fcd415364e04f8986e | https://github.com/mojombo/grit/blob/5608567286e64a1c55c5e7fcd415364e04f8986e/lib/grit/commit.rb#L219-L225 | train |
mojombo/grit | lib/grit/git.rb | Grit.Git.fs_write | def fs_write(file, contents)
path = File.join(self.git_dir, file)
FileUtils.mkdir_p(File.dirname(path))
File.open(path, 'w') do |f|
f.write(contents)
end
end | ruby | def fs_write(file, contents)
path = File.join(self.git_dir, file)
FileUtils.mkdir_p(File.dirname(path))
File.open(path, 'w') do |f|
f.write(contents)
end
end | [
"def",
"fs_write",
"(",
"file",
",",
"contents",
")",
"path",
"=",
"File",
".",
"join",
"(",
"self",
".",
"git_dir",
",",
"file",
")",
"FileUtils",
".",
"mkdir_p",
"(",
"File",
".",
"dirname",
"(",
"path",
")",
")",
"File",
".",
"open",
"(",
"path",
",",
"'w'",
")",
"do",
"|",
"f",
"|",
"f",
".",
"write",
"(",
"contents",
")",
"end",
"end"
] | Write a normal file to the filesystem.
+file+ is the relative path from the Git dir
+contents+ is the String content to be written
Returns nothing | [
"Write",
"a",
"normal",
"file",
"to",
"the",
"filesystem",
".",
"+",
"file",
"+",
"is",
"the",
"relative",
"path",
"from",
"the",
"Git",
"dir",
"+",
"contents",
"+",
"is",
"the",
"String",
"content",
"to",
"be",
"written"
] | 5608567286e64a1c55c5e7fcd415364e04f8986e | https://github.com/mojombo/grit/blob/5608567286e64a1c55c5e7fcd415364e04f8986e/lib/grit/git.rb#L128-L134 | train |
mojombo/grit | lib/grit/git.rb | Grit.Git.fs_move | def fs_move(from, to)
FileUtils.mv(File.join(self.git_dir, from), File.join(self.git_dir, to))
end | ruby | def fs_move(from, to)
FileUtils.mv(File.join(self.git_dir, from), File.join(self.git_dir, to))
end | [
"def",
"fs_move",
"(",
"from",
",",
"to",
")",
"FileUtils",
".",
"mv",
"(",
"File",
".",
"join",
"(",
"self",
".",
"git_dir",
",",
"from",
")",
",",
"File",
".",
"join",
"(",
"self",
".",
"git_dir",
",",
"to",
")",
")",
"end"
] | Move a normal file
+from+ is the relative path to the current file
+to+ is the relative path to the destination file
Returns nothing | [
"Move",
"a",
"normal",
"file",
"+",
"from",
"+",
"is",
"the",
"relative",
"path",
"to",
"the",
"current",
"file",
"+",
"to",
"+",
"is",
"the",
"relative",
"path",
"to",
"the",
"destination",
"file"
] | 5608567286e64a1c55c5e7fcd415364e04f8986e | https://github.com/mojombo/grit/blob/5608567286e64a1c55c5e7fcd415364e04f8986e/lib/grit/git.rb#L149-L151 | train |
mojombo/grit | lib/grit/git.rb | Grit.Git.fs_chmod | def fs_chmod(mode, file = '/')
FileUtils.chmod_R(mode, File.join(self.git_dir, file))
end | ruby | def fs_chmod(mode, file = '/')
FileUtils.chmod_R(mode, File.join(self.git_dir, file))
end | [
"def",
"fs_chmod",
"(",
"mode",
",",
"file",
"=",
"'/'",
")",
"FileUtils",
".",
"chmod_R",
"(",
"mode",
",",
"File",
".",
"join",
"(",
"self",
".",
"git_dir",
",",
"file",
")",
")",
"end"
] | Chmod the the file or dir and everything beneath
+file+ is the relative path from the Git dir
Returns nothing | [
"Chmod",
"the",
"the",
"file",
"or",
"dir",
"and",
"everything",
"beneath",
"+",
"file",
"+",
"is",
"the",
"relative",
"path",
"from",
"the",
"Git",
"dir"
] | 5608567286e64a1c55c5e7fcd415364e04f8986e | https://github.com/mojombo/grit/blob/5608567286e64a1c55c5e7fcd415364e04f8986e/lib/grit/git.rb#L165-L167 | train |
mojombo/grit | lib/grit/git.rb | Grit.Git.check_applies | def check_applies(options={}, head_sha=nil, applies_sha=nil)
options, head_sha, applies_sha = {}, options, head_sha if !options.is_a?(Hash)
options = options.dup
options[:env] &&= options[:env].dup
git_index = create_tempfile('index', true)
(options[:env] ||= {}).merge!('GIT_INDEX_FILE' => git_index)
options[:raise] = true
status = 0
begin
native(:read_tree, options.dup, head_sha)
stdin = native(:diff, options.dup, "#{applies_sha}^", applies_sha)
native(:apply, options.merge(:check => true, :cached => true, :input => stdin))
rescue CommandFailed => fail
status += fail.exitstatus
end
status
end | ruby | def check_applies(options={}, head_sha=nil, applies_sha=nil)
options, head_sha, applies_sha = {}, options, head_sha if !options.is_a?(Hash)
options = options.dup
options[:env] &&= options[:env].dup
git_index = create_tempfile('index', true)
(options[:env] ||= {}).merge!('GIT_INDEX_FILE' => git_index)
options[:raise] = true
status = 0
begin
native(:read_tree, options.dup, head_sha)
stdin = native(:diff, options.dup, "#{applies_sha}^", applies_sha)
native(:apply, options.merge(:check => true, :cached => true, :input => stdin))
rescue CommandFailed => fail
status += fail.exitstatus
end
status
end | [
"def",
"check_applies",
"(",
"options",
"=",
"{",
"}",
",",
"head_sha",
"=",
"nil",
",",
"applies_sha",
"=",
"nil",
")",
"options",
",",
"head_sha",
",",
"applies_sha",
"=",
"{",
"}",
",",
"options",
",",
"head_sha",
"if",
"!",
"options",
".",
"is_a?",
"(",
"Hash",
")",
"options",
"=",
"options",
".",
"dup",
"options",
"[",
":env",
"]",
"&&=",
"options",
"[",
":env",
"]",
".",
"dup",
"git_index",
"=",
"create_tempfile",
"(",
"'index'",
",",
"true",
")",
"(",
"options",
"[",
":env",
"]",
"||=",
"{",
"}",
")",
".",
"merge!",
"(",
"'GIT_INDEX_FILE'",
"=>",
"git_index",
")",
"options",
"[",
":raise",
"]",
"=",
"true",
"status",
"=",
"0",
"begin",
"native",
"(",
":read_tree",
",",
"options",
".",
"dup",
",",
"head_sha",
")",
"stdin",
"=",
"native",
"(",
":diff",
",",
"options",
".",
"dup",
",",
"\"#{applies_sha}^\"",
",",
"applies_sha",
")",
"native",
"(",
":apply",
",",
"options",
".",
"merge",
"(",
":check",
"=>",
"true",
",",
":cached",
"=>",
"true",
",",
":input",
"=>",
"stdin",
")",
")",
"rescue",
"CommandFailed",
"=>",
"fail",
"status",
"+=",
"fail",
".",
"exitstatus",
"end",
"status",
"end"
] | Checks if the patch of a commit can be applied to the given head.
options - grit command options hash
head_sha - String SHA or ref to check the patch against.
applies_sha - String SHA of the patch. The patch itself is retrieved
with #get_patch.
Returns 0 if the patch applies cleanly (according to `git apply`), or
an Integer that is the sum of the failed exit statuses. | [
"Checks",
"if",
"the",
"patch",
"of",
"a",
"commit",
"can",
"be",
"applied",
"to",
"the",
"given",
"head",
"."
] | 5608567286e64a1c55c5e7fcd415364e04f8986e | https://github.com/mojombo/grit/blob/5608567286e64a1c55c5e7fcd415364e04f8986e/lib/grit/git.rb#L207-L225 | train |
mojombo/grit | lib/grit/git.rb | Grit.Git.get_patch | def get_patch(options={}, applies_sha=nil)
options, applies_sha = {}, options if !options.is_a?(Hash)
options = options.dup
options[:env] &&= options[:env].dup
git_index = create_tempfile('index', true)
(options[:env] ||= {}).merge!('GIT_INDEX_FILE' => git_index)
native(:diff, options, "#{applies_sha}^", applies_sha)
end | ruby | def get_patch(options={}, applies_sha=nil)
options, applies_sha = {}, options if !options.is_a?(Hash)
options = options.dup
options[:env] &&= options[:env].dup
git_index = create_tempfile('index', true)
(options[:env] ||= {}).merge!('GIT_INDEX_FILE' => git_index)
native(:diff, options, "#{applies_sha}^", applies_sha)
end | [
"def",
"get_patch",
"(",
"options",
"=",
"{",
"}",
",",
"applies_sha",
"=",
"nil",
")",
"options",
",",
"applies_sha",
"=",
"{",
"}",
",",
"options",
"if",
"!",
"options",
".",
"is_a?",
"(",
"Hash",
")",
"options",
"=",
"options",
".",
"dup",
"options",
"[",
":env",
"]",
"&&=",
"options",
"[",
":env",
"]",
".",
"dup",
"git_index",
"=",
"create_tempfile",
"(",
"'index'",
",",
"true",
")",
"(",
"options",
"[",
":env",
"]",
"||=",
"{",
"}",
")",
".",
"merge!",
"(",
"'GIT_INDEX_FILE'",
"=>",
"git_index",
")",
"native",
"(",
":diff",
",",
"options",
",",
"\"#{applies_sha}^\"",
",",
"applies_sha",
")",
"end"
] | Gets a patch for a given SHA using `git diff`.
options - grit command options hash
applies_sha - String SHA to get the patch from, using this command:
`git diff #{applies_sha}^ #{applies_sha}`
Returns the String patch from `git diff`. | [
"Gets",
"a",
"patch",
"for",
"a",
"given",
"SHA",
"using",
"git",
"diff",
"."
] | 5608567286e64a1c55c5e7fcd415364e04f8986e | https://github.com/mojombo/grit/blob/5608567286e64a1c55c5e7fcd415364e04f8986e/lib/grit/git.rb#L234-L243 | train |
mojombo/grit | lib/grit/git.rb | Grit.Git.apply_patch | def apply_patch(options={}, head_sha=nil, patch=nil)
options, head_sha, patch = {}, options, head_sha if !options.is_a?(Hash)
options = options.dup
options[:env] &&= options[:env].dup
options[:raise] = true
git_index = create_tempfile('index', true)
(options[:env] ||= {}).merge!('GIT_INDEX_FILE' => git_index)
begin
native(:read_tree, options.dup, head_sha)
native(:apply, options.merge(:cached => true, :input => patch))
rescue CommandFailed
return false
end
native(:write_tree, :env => options[:env]).to_s.chomp!
end | ruby | def apply_patch(options={}, head_sha=nil, patch=nil)
options, head_sha, patch = {}, options, head_sha if !options.is_a?(Hash)
options = options.dup
options[:env] &&= options[:env].dup
options[:raise] = true
git_index = create_tempfile('index', true)
(options[:env] ||= {}).merge!('GIT_INDEX_FILE' => git_index)
begin
native(:read_tree, options.dup, head_sha)
native(:apply, options.merge(:cached => true, :input => patch))
rescue CommandFailed
return false
end
native(:write_tree, :env => options[:env]).to_s.chomp!
end | [
"def",
"apply_patch",
"(",
"options",
"=",
"{",
"}",
",",
"head_sha",
"=",
"nil",
",",
"patch",
"=",
"nil",
")",
"options",
",",
"head_sha",
",",
"patch",
"=",
"{",
"}",
",",
"options",
",",
"head_sha",
"if",
"!",
"options",
".",
"is_a?",
"(",
"Hash",
")",
"options",
"=",
"options",
".",
"dup",
"options",
"[",
":env",
"]",
"&&=",
"options",
"[",
":env",
"]",
".",
"dup",
"options",
"[",
":raise",
"]",
"=",
"true",
"git_index",
"=",
"create_tempfile",
"(",
"'index'",
",",
"true",
")",
"(",
"options",
"[",
":env",
"]",
"||=",
"{",
"}",
")",
".",
"merge!",
"(",
"'GIT_INDEX_FILE'",
"=>",
"git_index",
")",
"begin",
"native",
"(",
":read_tree",
",",
"options",
".",
"dup",
",",
"head_sha",
")",
"native",
"(",
":apply",
",",
"options",
".",
"merge",
"(",
":cached",
"=>",
"true",
",",
":input",
"=>",
"patch",
")",
")",
"rescue",
"CommandFailed",
"return",
"false",
"end",
"native",
"(",
":write_tree",
",",
":env",
"=>",
"options",
"[",
":env",
"]",
")",
".",
"to_s",
".",
"chomp!",
"end"
] | Applies the given patch against the given SHA of the current repo.
options - grit command hash
head_sha - String SHA or ref to apply the patch to.
patch - The String patch to apply. Get this from #get_patch.
Returns the String Tree SHA on a successful patch application, or false. | [
"Applies",
"the",
"given",
"patch",
"against",
"the",
"given",
"SHA",
"of",
"the",
"current",
"repo",
"."
] | 5608567286e64a1c55c5e7fcd415364e04f8986e | https://github.com/mojombo/grit/blob/5608567286e64a1c55c5e7fcd415364e04f8986e/lib/grit/git.rb#L252-L268 | train |
mojombo/grit | lib/grit/git.rb | Grit.Git.native | def native(cmd, options = {}, *args, &block)
args = args.first if args.size == 1 && args[0].is_a?(Array)
args.map! { |a| a.to_s }
args.reject! { |a| a.empty? }
# special option arguments
env = options.delete(:env) || {}
raise_errors = options.delete(:raise)
process_info = options.delete(:process_info)
# fall back to using a shell when the last argument looks like it wants to
# start a pipeline for compatibility with previous versions of grit.
return run(prefix, cmd, '', options, args) if args[-1].to_s[0] == ?|
# more options
input = options.delete(:input)
timeout = options.delete(:timeout); timeout = true if timeout.nil?
base = options.delete(:base); base = true if base.nil?
chdir = options.delete(:chdir)
# build up the git process argv
argv = []
argv << Git.git_binary
argv << "--git-dir=#{git_dir}" if base
argv << cmd.to_s.tr('_', '-')
argv.concat(options_to_argv(options))
argv.concat(args)
# run it and deal with fallout
Grit.log(argv.join(' ')) if Grit.debug
process =
Child.new(env, *(argv + [{
:input => input,
:chdir => chdir,
:timeout => (Grit::Git.git_timeout if timeout == true),
:max => (Grit::Git.git_max_size if timeout == true)
}]))
Grit.log(process.out) if Grit.debug
Grit.log(process.err) if Grit.debug
status = process.status
if raise_errors && !status.success?
raise CommandFailed.new(argv.join(' '), status.exitstatus, process.err)
elsif process_info
[status.exitstatus, process.out, process.err]
else
process.out
end
rescue TimeoutExceeded, MaximumOutputExceeded
raise GitTimeout, argv.join(' ')
end | ruby | def native(cmd, options = {}, *args, &block)
args = args.first if args.size == 1 && args[0].is_a?(Array)
args.map! { |a| a.to_s }
args.reject! { |a| a.empty? }
# special option arguments
env = options.delete(:env) || {}
raise_errors = options.delete(:raise)
process_info = options.delete(:process_info)
# fall back to using a shell when the last argument looks like it wants to
# start a pipeline for compatibility with previous versions of grit.
return run(prefix, cmd, '', options, args) if args[-1].to_s[0] == ?|
# more options
input = options.delete(:input)
timeout = options.delete(:timeout); timeout = true if timeout.nil?
base = options.delete(:base); base = true if base.nil?
chdir = options.delete(:chdir)
# build up the git process argv
argv = []
argv << Git.git_binary
argv << "--git-dir=#{git_dir}" if base
argv << cmd.to_s.tr('_', '-')
argv.concat(options_to_argv(options))
argv.concat(args)
# run it and deal with fallout
Grit.log(argv.join(' ')) if Grit.debug
process =
Child.new(env, *(argv + [{
:input => input,
:chdir => chdir,
:timeout => (Grit::Git.git_timeout if timeout == true),
:max => (Grit::Git.git_max_size if timeout == true)
}]))
Grit.log(process.out) if Grit.debug
Grit.log(process.err) if Grit.debug
status = process.status
if raise_errors && !status.success?
raise CommandFailed.new(argv.join(' '), status.exitstatus, process.err)
elsif process_info
[status.exitstatus, process.out, process.err]
else
process.out
end
rescue TimeoutExceeded, MaximumOutputExceeded
raise GitTimeout, argv.join(' ')
end | [
"def",
"native",
"(",
"cmd",
",",
"options",
"=",
"{",
"}",
",",
"*",
"args",
",",
"&",
"block",
")",
"args",
"=",
"args",
".",
"first",
"if",
"args",
".",
"size",
"==",
"1",
"&&",
"args",
"[",
"0",
"]",
".",
"is_a?",
"(",
"Array",
")",
"args",
".",
"map!",
"{",
"|",
"a",
"|",
"a",
".",
"to_s",
"}",
"args",
".",
"reject!",
"{",
"|",
"a",
"|",
"a",
".",
"empty?",
"}",
"# special option arguments",
"env",
"=",
"options",
".",
"delete",
"(",
":env",
")",
"||",
"{",
"}",
"raise_errors",
"=",
"options",
".",
"delete",
"(",
":raise",
")",
"process_info",
"=",
"options",
".",
"delete",
"(",
":process_info",
")",
"# fall back to using a shell when the last argument looks like it wants to",
"# start a pipeline for compatibility with previous versions of grit.",
"return",
"run",
"(",
"prefix",
",",
"cmd",
",",
"''",
",",
"options",
",",
"args",
")",
"if",
"args",
"[",
"-",
"1",
"]",
".",
"to_s",
"[",
"0",
"]",
"==",
"?|",
"# more options",
"input",
"=",
"options",
".",
"delete",
"(",
":input",
")",
"timeout",
"=",
"options",
".",
"delete",
"(",
":timeout",
")",
";",
"timeout",
"=",
"true",
"if",
"timeout",
".",
"nil?",
"base",
"=",
"options",
".",
"delete",
"(",
":base",
")",
";",
"base",
"=",
"true",
"if",
"base",
".",
"nil?",
"chdir",
"=",
"options",
".",
"delete",
"(",
":chdir",
")",
"# build up the git process argv",
"argv",
"=",
"[",
"]",
"argv",
"<<",
"Git",
".",
"git_binary",
"argv",
"<<",
"\"--git-dir=#{git_dir}\"",
"if",
"base",
"argv",
"<<",
"cmd",
".",
"to_s",
".",
"tr",
"(",
"'_'",
",",
"'-'",
")",
"argv",
".",
"concat",
"(",
"options_to_argv",
"(",
"options",
")",
")",
"argv",
".",
"concat",
"(",
"args",
")",
"# run it and deal with fallout",
"Grit",
".",
"log",
"(",
"argv",
".",
"join",
"(",
"' '",
")",
")",
"if",
"Grit",
".",
"debug",
"process",
"=",
"Child",
".",
"new",
"(",
"env",
",",
"(",
"argv",
"+",
"[",
"{",
":input",
"=>",
"input",
",",
":chdir",
"=>",
"chdir",
",",
":timeout",
"=>",
"(",
"Grit",
"::",
"Git",
".",
"git_timeout",
"if",
"timeout",
"==",
"true",
")",
",",
":max",
"=>",
"(",
"Grit",
"::",
"Git",
".",
"git_max_size",
"if",
"timeout",
"==",
"true",
")",
"}",
"]",
")",
")",
"Grit",
".",
"log",
"(",
"process",
".",
"out",
")",
"if",
"Grit",
".",
"debug",
"Grit",
".",
"log",
"(",
"process",
".",
"err",
")",
"if",
"Grit",
".",
"debug",
"status",
"=",
"process",
".",
"status",
"if",
"raise_errors",
"&&",
"!",
"status",
".",
"success?",
"raise",
"CommandFailed",
".",
"new",
"(",
"argv",
".",
"join",
"(",
"' '",
")",
",",
"status",
".",
"exitstatus",
",",
"process",
".",
"err",
")",
"elsif",
"process_info",
"[",
"status",
".",
"exitstatus",
",",
"process",
".",
"out",
",",
"process",
".",
"err",
"]",
"else",
"process",
".",
"out",
"end",
"rescue",
"TimeoutExceeded",
",",
"MaximumOutputExceeded",
"raise",
"GitTimeout",
",",
"argv",
".",
"join",
"(",
"' '",
")",
"end"
] | Execute a git command, bypassing any library implementation.
cmd - The name of the git command as a Symbol. Underscores are
converted to dashes as in :rev_parse => 'rev-parse'.
options - Command line option arguments passed to the git command.
Single char keys are converted to short options (:a => -a).
Multi-char keys are converted to long options (:arg => '--arg').
Underscores in keys are converted to dashes. These special options
are used to control command execution and are not passed in command
invocation:
:timeout - Maximum amount of time the command can run for before
being aborted. When true, use Grit::Git.git_timeout; when numeric,
use that number of seconds; when false or 0, disable timeout.
:base - Set false to avoid passing the --git-dir argument when
invoking the git command.
:env - Hash of environment variable key/values that are set on the
child process.
:raise - When set true, commands that exit with a non-zero status
raise a CommandFailed exception. This option is available only on
platforms that support fork(2).
:process_info - By default, a single string with output written to
the process's stdout is returned. Setting this option to true
results in a [exitstatus, out, err] tuple being returned instead.
args - Non-option arguments passed on the command line.
Optionally yields to the block an IO object attached to the child
process's STDIN.
Examples
git.native(:rev_list, {:max_count => 10, :header => true}, "master")
Returns a String with all output written to the child process's stdout
when the :process_info option is not set.
Returns a [exitstatus, out, err] tuple when the :process_info option is
set. The exitstatus is an small integer that was the process's exit
status. The out and err elements are the data written to stdout and
stderr as Strings.
Raises Grit::Git::GitTimeout when the timeout is exceeded or when more
than Grit::Git.git_max_size bytes are output.
Raises Grit::Git::CommandFailed when the :raise option is set true and the
git command exits with a non-zero exit status. The CommandFailed's #command,
#exitstatus, and #err attributes can be used to retrieve additional
detail about the error. | [
"Execute",
"a",
"git",
"command",
"bypassing",
"any",
"library",
"implementation",
"."
] | 5608567286e64a1c55c5e7fcd415364e04f8986e | https://github.com/mojombo/grit/blob/5608567286e64a1c55c5e7fcd415364e04f8986e/lib/grit/git.rb#L313-L364 | train |
mojombo/grit | lib/grit/git.rb | Grit.Git.run | def run(prefix, cmd, postfix, options, args, &block)
timeout = options.delete(:timeout) rescue nil
timeout = true if timeout.nil?
base = options.delete(:base) rescue nil
base = true if base.nil?
if input = options.delete(:input)
block = lambda { |stdin| stdin.write(input) }
end
opt_args = transform_options(options)
if RUBY_PLATFORM.downcase =~ /mswin(?!ce)|mingw|bccwin/
ext_args = args.reject { |a| a.empty? }.map { |a| (a == '--' || a[0].chr == '|' || Grit.no_quote) ? a : "\"#{e(a)}\"" }
gitdir = base ? "--git-dir=\"#{self.git_dir}\"" : ""
call = "#{prefix}#{Git.git_binary} #{gitdir} #{cmd.to_s.gsub(/_/, '-')} #{(opt_args + ext_args).join(' ')}#{e(postfix)}"
else
ext_args = args.reject { |a| a.empty? }.map { |a| (a == '--' || a[0].chr == '|' || Grit.no_quote) ? a : "'#{e(a)}'" }
gitdir = base ? "--git-dir='#{self.git_dir}'" : ""
call = "#{prefix}#{Git.git_binary} #{gitdir} #{cmd.to_s.gsub(/_/, '-')} #{(opt_args + ext_args).join(' ')}#{e(postfix)}"
end
Grit.log(call) if Grit.debug
response, err = timeout ? sh(call, &block) : wild_sh(call, &block)
Grit.log(response) if Grit.debug
Grit.log(err) if Grit.debug
response
end | ruby | def run(prefix, cmd, postfix, options, args, &block)
timeout = options.delete(:timeout) rescue nil
timeout = true if timeout.nil?
base = options.delete(:base) rescue nil
base = true if base.nil?
if input = options.delete(:input)
block = lambda { |stdin| stdin.write(input) }
end
opt_args = transform_options(options)
if RUBY_PLATFORM.downcase =~ /mswin(?!ce)|mingw|bccwin/
ext_args = args.reject { |a| a.empty? }.map { |a| (a == '--' || a[0].chr == '|' || Grit.no_quote) ? a : "\"#{e(a)}\"" }
gitdir = base ? "--git-dir=\"#{self.git_dir}\"" : ""
call = "#{prefix}#{Git.git_binary} #{gitdir} #{cmd.to_s.gsub(/_/, '-')} #{(opt_args + ext_args).join(' ')}#{e(postfix)}"
else
ext_args = args.reject { |a| a.empty? }.map { |a| (a == '--' || a[0].chr == '|' || Grit.no_quote) ? a : "'#{e(a)}'" }
gitdir = base ? "--git-dir='#{self.git_dir}'" : ""
call = "#{prefix}#{Git.git_binary} #{gitdir} #{cmd.to_s.gsub(/_/, '-')} #{(opt_args + ext_args).join(' ')}#{e(postfix)}"
end
Grit.log(call) if Grit.debug
response, err = timeout ? sh(call, &block) : wild_sh(call, &block)
Grit.log(response) if Grit.debug
Grit.log(err) if Grit.debug
response
end | [
"def",
"run",
"(",
"prefix",
",",
"cmd",
",",
"postfix",
",",
"options",
",",
"args",
",",
"&",
"block",
")",
"timeout",
"=",
"options",
".",
"delete",
"(",
":timeout",
")",
"rescue",
"nil",
"timeout",
"=",
"true",
"if",
"timeout",
".",
"nil?",
"base",
"=",
"options",
".",
"delete",
"(",
":base",
")",
"rescue",
"nil",
"base",
"=",
"true",
"if",
"base",
".",
"nil?",
"if",
"input",
"=",
"options",
".",
"delete",
"(",
":input",
")",
"block",
"=",
"lambda",
"{",
"|",
"stdin",
"|",
"stdin",
".",
"write",
"(",
"input",
")",
"}",
"end",
"opt_args",
"=",
"transform_options",
"(",
"options",
")",
"if",
"RUBY_PLATFORM",
".",
"downcase",
"=~",
"/",
"/",
"ext_args",
"=",
"args",
".",
"reject",
"{",
"|",
"a",
"|",
"a",
".",
"empty?",
"}",
".",
"map",
"{",
"|",
"a",
"|",
"(",
"a",
"==",
"'--'",
"||",
"a",
"[",
"0",
"]",
".",
"chr",
"==",
"'|'",
"||",
"Grit",
".",
"no_quote",
")",
"?",
"a",
":",
"\"\\\"#{e(a)}\\\"\"",
"}",
"gitdir",
"=",
"base",
"?",
"\"--git-dir=\\\"#{self.git_dir}\\\"\"",
":",
"\"\"",
"call",
"=",
"\"#{prefix}#{Git.git_binary} #{gitdir} #{cmd.to_s.gsub(/_/, '-')} #{(opt_args + ext_args).join(' ')}#{e(postfix)}\"",
"else",
"ext_args",
"=",
"args",
".",
"reject",
"{",
"|",
"a",
"|",
"a",
".",
"empty?",
"}",
".",
"map",
"{",
"|",
"a",
"|",
"(",
"a",
"==",
"'--'",
"||",
"a",
"[",
"0",
"]",
".",
"chr",
"==",
"'|'",
"||",
"Grit",
".",
"no_quote",
")",
"?",
"a",
":",
"\"'#{e(a)}'\"",
"}",
"gitdir",
"=",
"base",
"?",
"\"--git-dir='#{self.git_dir}'\"",
":",
"\"\"",
"call",
"=",
"\"#{prefix}#{Git.git_binary} #{gitdir} #{cmd.to_s.gsub(/_/, '-')} #{(opt_args + ext_args).join(' ')}#{e(postfix)}\"",
"end",
"Grit",
".",
"log",
"(",
"call",
")",
"if",
"Grit",
".",
"debug",
"response",
",",
"err",
"=",
"timeout",
"?",
"sh",
"(",
"call",
",",
"block",
")",
":",
"wild_sh",
"(",
"call",
",",
"block",
")",
"Grit",
".",
"log",
"(",
"response",
")",
"if",
"Grit",
".",
"debug",
"Grit",
".",
"log",
"(",
"err",
")",
"if",
"Grit",
".",
"debug",
"response",
"end"
] | DEPRECATED OPEN3-BASED COMMAND EXECUTION | [
"DEPRECATED",
"OPEN3",
"-",
"BASED",
"COMMAND",
"EXECUTION"
] | 5608567286e64a1c55c5e7fcd415364e04f8986e | https://github.com/mojombo/grit/blob/5608567286e64a1c55c5e7fcd415364e04f8986e/lib/grit/git.rb#L422-L450 | train |
mojombo/grit | lib/grit/git.rb | Grit.Git.transform_options | def transform_options(options)
args = []
options.keys.each do |opt|
if opt.to_s.size == 1
if options[opt] == true
args << "-#{opt}"
elsif options[opt] == false
# ignore
else
val = options.delete(opt)
args << "-#{opt.to_s} '#{e(val)}'"
end
else
if options[opt] == true
args << "--#{opt.to_s.gsub(/_/, '-')}"
elsif options[opt] == false
# ignore
else
val = options.delete(opt)
args << "--#{opt.to_s.gsub(/_/, '-')}='#{e(val)}'"
end
end
end
args
end | ruby | def transform_options(options)
args = []
options.keys.each do |opt|
if opt.to_s.size == 1
if options[opt] == true
args << "-#{opt}"
elsif options[opt] == false
# ignore
else
val = options.delete(opt)
args << "-#{opt.to_s} '#{e(val)}'"
end
else
if options[opt] == true
args << "--#{opt.to_s.gsub(/_/, '-')}"
elsif options[opt] == false
# ignore
else
val = options.delete(opt)
args << "--#{opt.to_s.gsub(/_/, '-')}='#{e(val)}'"
end
end
end
args
end | [
"def",
"transform_options",
"(",
"options",
")",
"args",
"=",
"[",
"]",
"options",
".",
"keys",
".",
"each",
"do",
"|",
"opt",
"|",
"if",
"opt",
".",
"to_s",
".",
"size",
"==",
"1",
"if",
"options",
"[",
"opt",
"]",
"==",
"true",
"args",
"<<",
"\"-#{opt}\"",
"elsif",
"options",
"[",
"opt",
"]",
"==",
"false",
"# ignore",
"else",
"val",
"=",
"options",
".",
"delete",
"(",
"opt",
")",
"args",
"<<",
"\"-#{opt.to_s} '#{e(val)}'\"",
"end",
"else",
"if",
"options",
"[",
"opt",
"]",
"==",
"true",
"args",
"<<",
"\"--#{opt.to_s.gsub(/_/, '-')}\"",
"elsif",
"options",
"[",
"opt",
"]",
"==",
"false",
"# ignore",
"else",
"val",
"=",
"options",
".",
"delete",
"(",
"opt",
")",
"args",
"<<",
"\"--#{opt.to_s.gsub(/_/, '-')}='#{e(val)}'\"",
"end",
"end",
"end",
"args",
"end"
] | Transform Ruby style options into git command line options
+options+ is a hash of Ruby style options
Returns String[]
e.g. ["--max-count=10", "--header"] | [
"Transform",
"Ruby",
"style",
"options",
"into",
"git",
"command",
"line",
"options",
"+",
"options",
"+",
"is",
"a",
"hash",
"of",
"Ruby",
"style",
"options"
] | 5608567286e64a1c55c5e7fcd415364e04f8986e | https://github.com/mojombo/grit/blob/5608567286e64a1c55c5e7fcd415364e04f8986e/lib/grit/git.rb#L474-L498 | train |
pact-foundation/pact-mock_service | lib/pact/consumer_contract/request_decorator.rb | Pact.RequestDecorator.body | def body
if content_type_is_form && request.body.is_a?(Hash)
URI.encode_www_form convert_hash_body_to_array_of_arrays
else
Pact::Reification.from_term(request.body)
end
end | ruby | def body
if content_type_is_form && request.body.is_a?(Hash)
URI.encode_www_form convert_hash_body_to_array_of_arrays
else
Pact::Reification.from_term(request.body)
end
end | [
"def",
"body",
"if",
"content_type_is_form",
"&&",
"request",
".",
"body",
".",
"is_a?",
"(",
"Hash",
")",
"URI",
".",
"encode_www_form",
"convert_hash_body_to_array_of_arrays",
"else",
"Pact",
"::",
"Reification",
".",
"from_term",
"(",
"request",
".",
"body",
")",
"end",
"end"
] | This feels wrong to be checking the class type of the body
Do this better somehow. | [
"This",
"feels",
"wrong",
"to",
"be",
"checking",
"the",
"class",
"type",
"of",
"the",
"body",
"Do",
"this",
"better",
"somehow",
"."
] | 3c26b469cbb796fa0045bb617b64c41c6b13b547 | https://github.com/pact-foundation/pact-mock_service/blob/3c26b469cbb796fa0045bb617b64c41c6b13b547/lib/pact/consumer_contract/request_decorator.rb#L49-L55 | train |
pact-foundation/pact-mock_service | lib/pact/consumer_contract/request_decorator.rb | Pact.RequestDecorator.convert_hash_body_to_array_of_arrays | def convert_hash_body_to_array_of_arrays
arrays = []
request.body.keys.each do | key |
[*request.body[key]].each do | value |
arrays << [key, value]
end
end
Pact::Reification.from_term(arrays)
end | ruby | def convert_hash_body_to_array_of_arrays
arrays = []
request.body.keys.each do | key |
[*request.body[key]].each do | value |
arrays << [key, value]
end
end
Pact::Reification.from_term(arrays)
end | [
"def",
"convert_hash_body_to_array_of_arrays",
"arrays",
"=",
"[",
"]",
"request",
".",
"body",
".",
"keys",
".",
"each",
"do",
"|",
"key",
"|",
"[",
"request",
".",
"body",
"[",
"key",
"]",
"]",
".",
"each",
"do",
"|",
"value",
"|",
"arrays",
"<<",
"[",
"key",
",",
"value",
"]",
"end",
"end",
"Pact",
"::",
"Reification",
".",
"from_term",
"(",
"arrays",
")",
"end"
] | This probably belongs somewhere else. | [
"This",
"probably",
"belongs",
"somewhere",
"else",
"."
] | 3c26b469cbb796fa0045bb617b64c41c6b13b547 | https://github.com/pact-foundation/pact-mock_service/blob/3c26b469cbb796fa0045bb617b64c41c6b13b547/lib/pact/consumer_contract/request_decorator.rb#L62-L71 | train |
theforeman/foreman-tasks | app/services/foreman_tasks/proxy_selector.rb | ForemanTasks.ProxySelector.select_by_jobs_count | def select_by_jobs_count(proxies)
exclude = @tasks.keys + @offline
@tasks.merge!(get_counts(proxies - exclude))
next_proxy = @tasks.select { |proxy, _| proxies.include?(proxy) }
.min_by { |_, job_count| job_count }.try(:first)
@tasks[next_proxy] += 1 if next_proxy.present?
next_proxy
end | ruby | def select_by_jobs_count(proxies)
exclude = @tasks.keys + @offline
@tasks.merge!(get_counts(proxies - exclude))
next_proxy = @tasks.select { |proxy, _| proxies.include?(proxy) }
.min_by { |_, job_count| job_count }.try(:first)
@tasks[next_proxy] += 1 if next_proxy.present?
next_proxy
end | [
"def",
"select_by_jobs_count",
"(",
"proxies",
")",
"exclude",
"=",
"@tasks",
".",
"keys",
"+",
"@offline",
"@tasks",
".",
"merge!",
"(",
"get_counts",
"(",
"proxies",
"-",
"exclude",
")",
")",
"next_proxy",
"=",
"@tasks",
".",
"select",
"{",
"|",
"proxy",
",",
"_",
"|",
"proxies",
".",
"include?",
"(",
"proxy",
")",
"}",
".",
"min_by",
"{",
"|",
"_",
",",
"job_count",
"|",
"job_count",
"}",
".",
"try",
"(",
":first",
")",
"@tasks",
"[",
"next_proxy",
"]",
"+=",
"1",
"if",
"next_proxy",
".",
"present?",
"next_proxy",
"end"
] | Get the least loaded proxy from the given list of proxies | [
"Get",
"the",
"least",
"loaded",
"proxy",
"from",
"the",
"given",
"list",
"of",
"proxies"
] | d99094fa99d6b34324e6c8d10da4d012675c6e36 | https://github.com/theforeman/foreman-tasks/blob/d99094fa99d6b34324e6c8d10da4d012675c6e36/app/services/foreman_tasks/proxy_selector.rb#L33-L40 | train |
theforeman/foreman-tasks | app/models/foreman_tasks/lock.rb | ForemanTasks.Lock.colliding_locks | def colliding_locks
task_ids = task.self_and_parents.map(&:id)
colliding_locks_scope = Lock.active.where(Lock.arel_table[:task_id].not_in(task_ids))
colliding_locks_scope = colliding_locks_scope.where(name: name,
resource_id: resource_id,
resource_type: resource_type)
unless exclusive?
colliding_locks_scope = colliding_locks_scope.where(:exclusive => true)
end
colliding_locks_scope
end | ruby | def colliding_locks
task_ids = task.self_and_parents.map(&:id)
colliding_locks_scope = Lock.active.where(Lock.arel_table[:task_id].not_in(task_ids))
colliding_locks_scope = colliding_locks_scope.where(name: name,
resource_id: resource_id,
resource_type: resource_type)
unless exclusive?
colliding_locks_scope = colliding_locks_scope.where(:exclusive => true)
end
colliding_locks_scope
end | [
"def",
"colliding_locks",
"task_ids",
"=",
"task",
".",
"self_and_parents",
".",
"map",
"(",
":id",
")",
"colliding_locks_scope",
"=",
"Lock",
".",
"active",
".",
"where",
"(",
"Lock",
".",
"arel_table",
"[",
":task_id",
"]",
".",
"not_in",
"(",
"task_ids",
")",
")",
"colliding_locks_scope",
"=",
"colliding_locks_scope",
".",
"where",
"(",
"name",
":",
"name",
",",
"resource_id",
":",
"resource_id",
",",
"resource_type",
":",
"resource_type",
")",
"unless",
"exclusive?",
"colliding_locks_scope",
"=",
"colliding_locks_scope",
".",
"where",
"(",
":exclusive",
"=>",
"true",
")",
"end",
"colliding_locks_scope",
"end"
] | returns a scope of the locks colliding with this one | [
"returns",
"a",
"scope",
"of",
"the",
"locks",
"colliding",
"with",
"this",
"one"
] | d99094fa99d6b34324e6c8d10da4d012675c6e36 | https://github.com/theforeman/foreman-tasks/blob/d99094fa99d6b34324e6c8d10da4d012675c6e36/app/models/foreman_tasks/lock.rb#L53-L63 | train |
theforeman/foreman-tasks | app/models/foreman_tasks/remote_task.rb | ForemanTasks.RemoteTask.trigger | def trigger(proxy_action_name, input)
response = begin
proxy.trigger_task(proxy_action_name, input).merge('result' => 'success')
rescue RestClient::Exception => e
logger.warn "Could not trigger task on the smart proxy: #{e.message}"
{}
end
update_from_batch_trigger(response)
save!
end | ruby | def trigger(proxy_action_name, input)
response = begin
proxy.trigger_task(proxy_action_name, input).merge('result' => 'success')
rescue RestClient::Exception => e
logger.warn "Could not trigger task on the smart proxy: #{e.message}"
{}
end
update_from_batch_trigger(response)
save!
end | [
"def",
"trigger",
"(",
"proxy_action_name",
",",
"input",
")",
"response",
"=",
"begin",
"proxy",
".",
"trigger_task",
"(",
"proxy_action_name",
",",
"input",
")",
".",
"merge",
"(",
"'result'",
"=>",
"'success'",
")",
"rescue",
"RestClient",
"::",
"Exception",
"=>",
"e",
"logger",
".",
"warn",
"\"Could not trigger task on the smart proxy: #{e.message}\"",
"{",
"}",
"end",
"update_from_batch_trigger",
"(",
"response",
")",
"save!",
"end"
] | Triggers a task on the proxy "the old way" | [
"Triggers",
"a",
"task",
"on",
"the",
"proxy",
"the",
"old",
"way"
] | d99094fa99d6b34324e6c8d10da4d012675c6e36 | https://github.com/theforeman/foreman-tasks/blob/d99094fa99d6b34324e6c8d10da4d012675c6e36/app/models/foreman_tasks/remote_task.rb#L16-L25 | train |
theforeman/foreman-tasks | app/lib/actions/proxy_action.rb | Actions.ProxyAction.fill_continuous_output | def fill_continuous_output(continuous_output)
failed_proxy_tasks.each do |failure_data|
message = _('Initialization error: %s') %
"#{failure_data[:exception_class]} - #{failure_data[:exception_message]}"
continuous_output.add_output(message, 'debug', failure_data[:timestamp])
end
end | ruby | def fill_continuous_output(continuous_output)
failed_proxy_tasks.each do |failure_data|
message = _('Initialization error: %s') %
"#{failure_data[:exception_class]} - #{failure_data[:exception_message]}"
continuous_output.add_output(message, 'debug', failure_data[:timestamp])
end
end | [
"def",
"fill_continuous_output",
"(",
"continuous_output",
")",
"failed_proxy_tasks",
".",
"each",
"do",
"|",
"failure_data",
"|",
"message",
"=",
"_",
"(",
"'Initialization error: %s'",
")",
"%",
"\"#{failure_data[:exception_class]} - #{failure_data[:exception_message]}\"",
"continuous_output",
".",
"add_output",
"(",
"message",
",",
"'debug'",
",",
"failure_data",
"[",
":timestamp",
"]",
")",
"end",
"end"
] | The proxy action is able to contribute to continuous output | [
"The",
"proxy",
"action",
"is",
"able",
"to",
"contribute",
"to",
"continuous",
"output"
] | d99094fa99d6b34324e6c8d10da4d012675c6e36 | https://github.com/theforeman/foreman-tasks/blob/d99094fa99d6b34324e6c8d10da4d012675c6e36/app/lib/actions/proxy_action.rb#L167-L173 | train |
theforeman/foreman-tasks | app/lib/actions/recurring_action.rb | Actions.RecurringAction.trigger_repeat | def trigger_repeat(execution_plan)
request_id = ::Logging.mdc['request']
::Logging.mdc['request'] = SecureRandom.uuid
if execution_plan.delay_record && recurring_logic_task_group
args = execution_plan.delay_record.args
logic = recurring_logic_task_group.recurring_logic
logic.trigger_repeat_after(task.start_at, self.class, *args)
end
ensure
::Logging.mdc['request'] = request_id
end | ruby | def trigger_repeat(execution_plan)
request_id = ::Logging.mdc['request']
::Logging.mdc['request'] = SecureRandom.uuid
if execution_plan.delay_record && recurring_logic_task_group
args = execution_plan.delay_record.args
logic = recurring_logic_task_group.recurring_logic
logic.trigger_repeat_after(task.start_at, self.class, *args)
end
ensure
::Logging.mdc['request'] = request_id
end | [
"def",
"trigger_repeat",
"(",
"execution_plan",
")",
"request_id",
"=",
"::",
"Logging",
".",
"mdc",
"[",
"'request'",
"]",
"::",
"Logging",
".",
"mdc",
"[",
"'request'",
"]",
"=",
"SecureRandom",
".",
"uuid",
"if",
"execution_plan",
".",
"delay_record",
"&&",
"recurring_logic_task_group",
"args",
"=",
"execution_plan",
".",
"delay_record",
".",
"args",
"logic",
"=",
"recurring_logic_task_group",
".",
"recurring_logic",
"logic",
".",
"trigger_repeat_after",
"(",
"task",
".",
"start_at",
",",
"self",
".",
"class",
",",
"args",
")",
"end",
"ensure",
"::",
"Logging",
".",
"mdc",
"[",
"'request'",
"]",
"=",
"request_id",
"end"
] | Hook to be called when a repetition needs to be triggered. This either happens when the plan goes into planned state
or when it fails. | [
"Hook",
"to",
"be",
"called",
"when",
"a",
"repetition",
"needs",
"to",
"be",
"triggered",
".",
"This",
"either",
"happens",
"when",
"the",
"plan",
"goes",
"into",
"planned",
"state",
"or",
"when",
"it",
"fails",
"."
] | d99094fa99d6b34324e6c8d10da4d012675c6e36 | https://github.com/theforeman/foreman-tasks/blob/d99094fa99d6b34324e6c8d10da4d012675c6e36/app/lib/actions/recurring_action.rb#L14-L24 | train |
bitbucket-rest-api/bitbucket | lib/bitbucket_rest_api/repos/following.rb | BitBucket.Repos::Following.followers | def followers(user_name, repo_name, params={})
_update_user_repo_params(user_name, repo_name)
_validate_user_repo_params(user, repo) unless user? && repo?
normalize! params
response = get_request("/1.0/repositories/#{user}/#{repo.downcase}/followers/", params)
return response unless block_given?
response.each { |el| yield el }
end | ruby | def followers(user_name, repo_name, params={})
_update_user_repo_params(user_name, repo_name)
_validate_user_repo_params(user, repo) unless user? && repo?
normalize! params
response = get_request("/1.0/repositories/#{user}/#{repo.downcase}/followers/", params)
return response unless block_given?
response.each { |el| yield el }
end | [
"def",
"followers",
"(",
"user_name",
",",
"repo_name",
",",
"params",
"=",
"{",
"}",
")",
"_update_user_repo_params",
"(",
"user_name",
",",
"repo_name",
")",
"_validate_user_repo_params",
"(",
"user",
",",
"repo",
")",
"unless",
"user?",
"&&",
"repo?",
"normalize!",
"params",
"response",
"=",
"get_request",
"(",
"\"/1.0/repositories/#{user}/#{repo.downcase}/followers/\"",
",",
"params",
")",
"return",
"response",
"unless",
"block_given?",
"response",
".",
"each",
"{",
"|",
"el",
"|",
"yield",
"el",
"}",
"end"
] | List repo followers
= Examples
bitbucket = BitBucket.new :user => 'user-name', :repo => 'repo-name'
bitbucket.repos.following.followers
bitbucket.repos.following.followers { |watcher| ... } | [
"List",
"repo",
"followers"
] | e03b6935104d59b3d9a922474c3dc210a5ef76d2 | https://github.com/bitbucket-rest-api/bitbucket/blob/e03b6935104d59b3d9a922474c3dc210a5ef76d2/lib/bitbucket_rest_api/repos/following.rb#L13-L21 | train |
bitbucket-rest-api/bitbucket | lib/bitbucket_rest_api/repos/following.rb | BitBucket.Repos::Following.followed | def followed(*args)
params = args.extract_options!
normalize! params
response = get_request("/1.0/user/follows", params)
return response unless block_given?
response.each { |el| yield el }
end | ruby | def followed(*args)
params = args.extract_options!
normalize! params
response = get_request("/1.0/user/follows", params)
return response unless block_given?
response.each { |el| yield el }
end | [
"def",
"followed",
"(",
"*",
"args",
")",
"params",
"=",
"args",
".",
"extract_options!",
"normalize!",
"params",
"response",
"=",
"get_request",
"(",
"\"/1.0/user/follows\"",
",",
"params",
")",
"return",
"response",
"unless",
"block_given?",
"response",
".",
"each",
"{",
"|",
"el",
"|",
"yield",
"el",
"}",
"end"
] | List repos being followed by the authenticated user
= Examples
bitbucket = BitBucket.new :oauth_token => '...', :oauth_secret => '...'
bitbucket.repos.following.followed | [
"List",
"repos",
"being",
"followed",
"by",
"the",
"authenticated",
"user"
] | e03b6935104d59b3d9a922474c3dc210a5ef76d2 | https://github.com/bitbucket-rest-api/bitbucket/blob/e03b6935104d59b3d9a922474c3dc210a5ef76d2/lib/bitbucket_rest_api/repos/following.rb#L29-L36 | train |
bitbucket-rest-api/bitbucket | lib/bitbucket_rest_api/repos/components.rb | BitBucket.Repos::Components.get | def get(user_name, repo_name, component_id, params={})
update_and_validate_user_repo_params(user_name, repo_name)
normalize! params
get_request("/2.0/repositories/#{user}/#{repo.downcase}/components/#{component_id}", params)
end | ruby | def get(user_name, repo_name, component_id, params={})
update_and_validate_user_repo_params(user_name, repo_name)
normalize! params
get_request("/2.0/repositories/#{user}/#{repo.downcase}/components/#{component_id}", params)
end | [
"def",
"get",
"(",
"user_name",
",",
"repo_name",
",",
"component_id",
",",
"params",
"=",
"{",
"}",
")",
"update_and_validate_user_repo_params",
"(",
"user_name",
",",
"repo_name",
")",
"normalize!",
"params",
"get_request",
"(",
"\"/2.0/repositories/#{user}/#{repo.downcase}/components/#{component_id}\"",
",",
"params",
")",
"end"
] | Get a component by it's ID
= Examples
bitbucket = BitBucket.new
bitbucket.repos.components.get 'user-name', 'repo-name', 1 | [
"Get",
"a",
"component",
"by",
"it",
"s",
"ID"
] | e03b6935104d59b3d9a922474c3dc210a5ef76d2 | https://github.com/bitbucket-rest-api/bitbucket/blob/e03b6935104d59b3d9a922474c3dc210a5ef76d2/lib/bitbucket_rest_api/repos/components.rb#L29-L34 | train |
bitbucket-rest-api/bitbucket | lib/bitbucket_rest_api/repos/services.rb | BitBucket.Repos::Services.create | def create(user_name, repo_name, params={})
_update_user_repo_params(user_name, repo_name)
_validate_user_repo_params(user, repo) unless user? && repo?
normalize! params
assert_required_keys(REQUIRED_KEY_PARAM_NAMES, params)
post_request("/1.0/repositories/#{user}/#{repo.downcase}/services", params)
end | ruby | def create(user_name, repo_name, params={})
_update_user_repo_params(user_name, repo_name)
_validate_user_repo_params(user, repo) unless user? && repo?
normalize! params
assert_required_keys(REQUIRED_KEY_PARAM_NAMES, params)
post_request("/1.0/repositories/#{user}/#{repo.downcase}/services", params)
end | [
"def",
"create",
"(",
"user_name",
",",
"repo_name",
",",
"params",
"=",
"{",
"}",
")",
"_update_user_repo_params",
"(",
"user_name",
",",
"repo_name",
")",
"_validate_user_repo_params",
"(",
"user",
",",
"repo",
")",
"unless",
"user?",
"&&",
"repo?",
"normalize!",
"params",
"assert_required_keys",
"(",
"REQUIRED_KEY_PARAM_NAMES",
",",
"params",
")",
"post_request",
"(",
"\"/1.0/repositories/#{user}/#{repo.downcase}/services\"",
",",
"params",
")",
"end"
] | Create a service
= Inputs
* <tt>:type</tt> - One of the supported services. The type is a case-insensitive value.
= Examples
bitbucket = BitBucket.new
bitbucket.repos.services.create 'user-name', 'repo-name',
"type" => "Basecamp",
"Password" => "...",
"Username" => "...",
"Discussion URL" => "..." | [
"Create",
"a",
"service"
] | e03b6935104d59b3d9a922474c3dc210a5ef76d2 | https://github.com/bitbucket-rest-api/bitbucket/blob/e03b6935104d59b3d9a922474c3dc210a5ef76d2/lib/bitbucket_rest_api/repos/services.rb#L55-L62 | train |
bitbucket-rest-api/bitbucket | lib/bitbucket_rest_api/repos/services.rb | BitBucket.Repos::Services.edit | def edit(user_name, repo_name, service_id, params={})
_update_user_repo_params(user_name, repo_name)
_validate_user_repo_params(user, repo) unless user? && repo?
_validate_presence_of(service_id)
normalize! params
put_request("/1.0/repositories/#{user}/#{repo.downcase}/services/#{service_id}", params)
end | ruby | def edit(user_name, repo_name, service_id, params={})
_update_user_repo_params(user_name, repo_name)
_validate_user_repo_params(user, repo) unless user? && repo?
_validate_presence_of(service_id)
normalize! params
put_request("/1.0/repositories/#{user}/#{repo.downcase}/services/#{service_id}", params)
end | [
"def",
"edit",
"(",
"user_name",
",",
"repo_name",
",",
"service_id",
",",
"params",
"=",
"{",
"}",
")",
"_update_user_repo_params",
"(",
"user_name",
",",
"repo_name",
")",
"_validate_user_repo_params",
"(",
"user",
",",
"repo",
")",
"unless",
"user?",
"&&",
"repo?",
"_validate_presence_of",
"(",
"service_id",
")",
"normalize!",
"params",
"put_request",
"(",
"\"/1.0/repositories/#{user}/#{repo.downcase}/services/#{service_id}\"",
",",
"params",
")",
"end"
] | Edit a service
= Inputs
* <tt>:type</tt> - One of the supported services. The type is a case-insensitive value.
= Examples
bitbucket = BitBucket.new
bitbucket.repos.services.edit 'user-name', 'repo-name', 109172378,
"type" => "Basecamp",
"Password" => "...",
"Username" => "...",
"Discussion URL" => "..." | [
"Edit",
"a",
"service"
] | e03b6935104d59b3d9a922474c3dc210a5ef76d2 | https://github.com/bitbucket-rest-api/bitbucket/blob/e03b6935104d59b3d9a922474c3dc210a5ef76d2/lib/bitbucket_rest_api/repos/services.rb#L77-L85 | train |
bitbucket-rest-api/bitbucket | lib/bitbucket_rest_api/repos/default_reviewers.rb | BitBucket.Repos::DefaultReviewers.get | def get(user_name, repo_name, reviewer_username, params={})
update_and_validate_user_repo_params(user_name, repo_name)
normalize! params
get_request("/2.0/repositories/#{user_name}/#{repo_name}/default-reviewers/#{reviewer_username}", params)
end | ruby | def get(user_name, repo_name, reviewer_username, params={})
update_and_validate_user_repo_params(user_name, repo_name)
normalize! params
get_request("/2.0/repositories/#{user_name}/#{repo_name}/default-reviewers/#{reviewer_username}", params)
end | [
"def",
"get",
"(",
"user_name",
",",
"repo_name",
",",
"reviewer_username",
",",
"params",
"=",
"{",
"}",
")",
"update_and_validate_user_repo_params",
"(",
"user_name",
",",
"repo_name",
")",
"normalize!",
"params",
"get_request",
"(",
"\"/2.0/repositories/#{user_name}/#{repo_name}/default-reviewers/#{reviewer_username}\"",
",",
"params",
")",
"end"
] | Get a default reviewer's info
= Examples
bitbucket = BitBucket.new
bitbucket.repos.default_reviewers.get 'user-name', 'repo-name', 'reviewer-username' | [
"Get",
"a",
"default",
"reviewer",
"s",
"info"
] | e03b6935104d59b3d9a922474c3dc210a5ef76d2 | https://github.com/bitbucket-rest-api/bitbucket/blob/e03b6935104d59b3d9a922474c3dc210a5ef76d2/lib/bitbucket_rest_api/repos/default_reviewers.rb#L27-L32 | train |
bitbucket-rest-api/bitbucket | lib/bitbucket_rest_api/repos/default_reviewers.rb | BitBucket.Repos::DefaultReviewers.add | def add(user_name, repo_name, reviewer_username, params={})
update_and_validate_user_repo_params(user_name, repo_name)
normalize! params
put_request("/2.0/repositories/#{user_name}/#{repo_name}/default-reviewers/#{reviewer_username}", params)
end | ruby | def add(user_name, repo_name, reviewer_username, params={})
update_and_validate_user_repo_params(user_name, repo_name)
normalize! params
put_request("/2.0/repositories/#{user_name}/#{repo_name}/default-reviewers/#{reviewer_username}", params)
end | [
"def",
"add",
"(",
"user_name",
",",
"repo_name",
",",
"reviewer_username",
",",
"params",
"=",
"{",
"}",
")",
"update_and_validate_user_repo_params",
"(",
"user_name",
",",
"repo_name",
")",
"normalize!",
"params",
"put_request",
"(",
"\"/2.0/repositories/#{user_name}/#{repo_name}/default-reviewers/#{reviewer_username}\"",
",",
"params",
")",
"end"
] | Add a user to the default-reviewers list for the repo
= Examples
bitbucket = BitBucket.new
bitbucket.repos.default_reviewers.add 'user-name', 'repo-name', 'reviewer-username' | [
"Add",
"a",
"user",
"to",
"the",
"default",
"-",
"reviewers",
"list",
"for",
"the",
"repo"
] | e03b6935104d59b3d9a922474c3dc210a5ef76d2 | https://github.com/bitbucket-rest-api/bitbucket/blob/e03b6935104d59b3d9a922474c3dc210a5ef76d2/lib/bitbucket_rest_api/repos/default_reviewers.rb#L40-L45 | train |
bitbucket-rest-api/bitbucket | lib/bitbucket_rest_api/repos/default_reviewers.rb | BitBucket.Repos::DefaultReviewers.remove | def remove(user_name, repo_name, reviewer_username, params={})
update_and_validate_user_repo_params(user_name, repo_name)
normalize! params
delete_request("/2.0/repositories/#{user_name}/#{repo_name}/default-reviewers/#{reviewer_username}", params)
end | ruby | def remove(user_name, repo_name, reviewer_username, params={})
update_and_validate_user_repo_params(user_name, repo_name)
normalize! params
delete_request("/2.0/repositories/#{user_name}/#{repo_name}/default-reviewers/#{reviewer_username}", params)
end | [
"def",
"remove",
"(",
"user_name",
",",
"repo_name",
",",
"reviewer_username",
",",
"params",
"=",
"{",
"}",
")",
"update_and_validate_user_repo_params",
"(",
"user_name",
",",
"repo_name",
")",
"normalize!",
"params",
"delete_request",
"(",
"\"/2.0/repositories/#{user_name}/#{repo_name}/default-reviewers/#{reviewer_username}\"",
",",
"params",
")",
"end"
] | Remove a user from the default-reviewers list for the repo
= Examples
bitbucket = BitBucket.new
bitbucket.repos.default_reviewers.remove 'user-name', 'repo-name', 'reviewer-username' | [
"Remove",
"a",
"user",
"from",
"the",
"default",
"-",
"reviewers",
"list",
"for",
"the",
"repo"
] | e03b6935104d59b3d9a922474c3dc210a5ef76d2 | https://github.com/bitbucket-rest-api/bitbucket/blob/e03b6935104d59b3d9a922474c3dc210a5ef76d2/lib/bitbucket_rest_api/repos/default_reviewers.rb#L53-L57 | train |
bitbucket-rest-api/bitbucket | lib/bitbucket_rest_api/issues/components.rb | BitBucket.Issues::Components.get | def get(user_name, repo_name, component_id, params={})
_update_user_repo_params(user_name, repo_name)
_validate_user_repo_params(user, repo) unless user? && repo?
_validate_presence_of component_id
normalize! params
get_request("/1.0/repositories/#{user}/#{repo.downcase}/issues/components/#{component_id}", params)
end | ruby | def get(user_name, repo_name, component_id, params={})
_update_user_repo_params(user_name, repo_name)
_validate_user_repo_params(user, repo) unless user? && repo?
_validate_presence_of component_id
normalize! params
get_request("/1.0/repositories/#{user}/#{repo.downcase}/issues/components/#{component_id}", params)
end | [
"def",
"get",
"(",
"user_name",
",",
"repo_name",
",",
"component_id",
",",
"params",
"=",
"{",
"}",
")",
"_update_user_repo_params",
"(",
"user_name",
",",
"repo_name",
")",
"_validate_user_repo_params",
"(",
"user",
",",
"repo",
")",
"unless",
"user?",
"&&",
"repo?",
"_validate_presence_of",
"component_id",
"normalize!",
"params",
"get_request",
"(",
"\"/1.0/repositories/#{user}/#{repo.downcase}/issues/components/#{component_id}\"",
",",
"params",
")",
"end"
] | Get a single component
= Examples
bitbucket = BitBucket.new
bitbucket.issues.components.find 'user-name', 'repo-name', 'component-id' | [
"Get",
"a",
"single",
"component"
] | e03b6935104d59b3d9a922474c3dc210a5ef76d2 | https://github.com/bitbucket-rest-api/bitbucket/blob/e03b6935104d59b3d9a922474c3dc210a5ef76d2/lib/bitbucket_rest_api/issues/components.rb#L36-L43 | train |
bitbucket-rest-api/bitbucket | lib/bitbucket_rest_api/issues/components.rb | BitBucket.Issues::Components.update | def update(user_name, repo_name, component_id, params={})
_update_user_repo_params(user_name, repo_name)
_validate_user_repo_params(user, repo) unless user? && repo?
_validate_presence_of component_id
normalize! params
filter! VALID_COMPONENT_INPUTS, params
assert_required_keys(VALID_COMPONENT_INPUTS, params)
put_request("/1.0/repositories/#{user}/#{repo.downcase}/issues/components/#{component_id}", params)
end | ruby | def update(user_name, repo_name, component_id, params={})
_update_user_repo_params(user_name, repo_name)
_validate_user_repo_params(user, repo) unless user? && repo?
_validate_presence_of component_id
normalize! params
filter! VALID_COMPONENT_INPUTS, params
assert_required_keys(VALID_COMPONENT_INPUTS, params)
put_request("/1.0/repositories/#{user}/#{repo.downcase}/issues/components/#{component_id}", params)
end | [
"def",
"update",
"(",
"user_name",
",",
"repo_name",
",",
"component_id",
",",
"params",
"=",
"{",
"}",
")",
"_update_user_repo_params",
"(",
"user_name",
",",
"repo_name",
")",
"_validate_user_repo_params",
"(",
"user",
",",
"repo",
")",
"unless",
"user?",
"&&",
"repo?",
"_validate_presence_of",
"component_id",
"normalize!",
"params",
"filter!",
"VALID_COMPONENT_INPUTS",
",",
"params",
"assert_required_keys",
"(",
"VALID_COMPONENT_INPUTS",
",",
"params",
")",
"put_request",
"(",
"\"/1.0/repositories/#{user}/#{repo.downcase}/issues/components/#{component_id}\"",
",",
"params",
")",
"end"
] | Update a component
= Inputs
<tt>:name</tt> - Required string
= Examples
@bitbucket = BitBucket.new
@bitbucket.issues.components.update 'user-name', 'repo-name', 'component-id',
:name => 'API' | [
"Update",
"a",
"component"
] | e03b6935104d59b3d9a922474c3dc210a5ef76d2 | https://github.com/bitbucket-rest-api/bitbucket/blob/e03b6935104d59b3d9a922474c3dc210a5ef76d2/lib/bitbucket_rest_api/issues/components.rb#L76-L86 | train |
bitbucket-rest-api/bitbucket | lib/bitbucket_rest_api/issues/components.rb | BitBucket.Issues::Components.delete | def delete(user_name, repo_name, component_id, params={})
_update_user_repo_params(user_name, repo_name)
_validate_user_repo_params(user, repo) unless user? && repo?
_validate_presence_of component_id
normalize! params
delete_request("/1.0/repositories/#{user}/#{repo.downcase}/issues/components/#{component_id}", params)
end | ruby | def delete(user_name, repo_name, component_id, params={})
_update_user_repo_params(user_name, repo_name)
_validate_user_repo_params(user, repo) unless user? && repo?
_validate_presence_of component_id
normalize! params
delete_request("/1.0/repositories/#{user}/#{repo.downcase}/issues/components/#{component_id}", params)
end | [
"def",
"delete",
"(",
"user_name",
",",
"repo_name",
",",
"component_id",
",",
"params",
"=",
"{",
"}",
")",
"_update_user_repo_params",
"(",
"user_name",
",",
"repo_name",
")",
"_validate_user_repo_params",
"(",
"user",
",",
"repo",
")",
"unless",
"user?",
"&&",
"repo?",
"_validate_presence_of",
"component_id",
"normalize!",
"params",
"delete_request",
"(",
"\"/1.0/repositories/#{user}/#{repo.downcase}/issues/components/#{component_id}\"",
",",
"params",
")",
"end"
] | Delete a component
= Examples
bitbucket = BitBucket.new
bitbucket.issues.components.delete 'user-name', 'repo-name', 'component-id' | [
"Delete",
"a",
"component"
] | e03b6935104d59b3d9a922474c3dc210a5ef76d2 | https://github.com/bitbucket-rest-api/bitbucket/blob/e03b6935104d59b3d9a922474c3dc210a5ef76d2/lib/bitbucket_rest_api/issues/components.rb#L95-L103 | train |
bitbucket-rest-api/bitbucket | lib/bitbucket_rest_api/repos/keys.rb | BitBucket.Repos::Keys.create | def create(user_name, repo_name, params={})
_update_user_repo_params(user_name, repo_name)
_validate_user_repo_params(user, repo) unless user? && repo?
normalize! params
filter! VALID_KEY_PARAM_NAMES, params
assert_required_keys(VALID_KEY_PARAM_NAMES, params)
options = { headers: { "Content-Type" => "application/json" } }
post_request("/1.0/repositories/#{user}/#{repo.downcase}/deploy-keys/", params, options)
end | ruby | def create(user_name, repo_name, params={})
_update_user_repo_params(user_name, repo_name)
_validate_user_repo_params(user, repo) unless user? && repo?
normalize! params
filter! VALID_KEY_PARAM_NAMES, params
assert_required_keys(VALID_KEY_PARAM_NAMES, params)
options = { headers: { "Content-Type" => "application/json" } }
post_request("/1.0/repositories/#{user}/#{repo.downcase}/deploy-keys/", params, options)
end | [
"def",
"create",
"(",
"user_name",
",",
"repo_name",
",",
"params",
"=",
"{",
"}",
")",
"_update_user_repo_params",
"(",
"user_name",
",",
"repo_name",
")",
"_validate_user_repo_params",
"(",
"user",
",",
"repo",
")",
"unless",
"user?",
"&&",
"repo?",
"normalize!",
"params",
"filter!",
"VALID_KEY_PARAM_NAMES",
",",
"params",
"assert_required_keys",
"(",
"VALID_KEY_PARAM_NAMES",
",",
"params",
")",
"options",
"=",
"{",
"headers",
":",
"{",
"\"Content-Type\"",
"=>",
"\"application/json\"",
"}",
"}",
"post_request",
"(",
"\"/1.0/repositories/#{user}/#{repo.downcase}/deploy-keys/\"",
",",
"params",
",",
"options",
")",
"end"
] | Create a key
= Inputs
* <tt>:title</tt> - Required string.
* <tt>:key</tt> - Required string.
= Examples
bitbucket = BitBucket.new
bitbucket.repos.keys.create 'user-name', 'repo-name',
"label" => "octocat@octomac",
"key" => "ssh-rsa AAA..." | [
"Create",
"a",
"key"
] | e03b6935104d59b3d9a922474c3dc210a5ef76d2 | https://github.com/bitbucket-rest-api/bitbucket/blob/e03b6935104d59b3d9a922474c3dc210a5ef76d2/lib/bitbucket_rest_api/repos/keys.rb#L38-L47 | train |
bitbucket-rest-api/bitbucket | lib/bitbucket_rest_api/repos/keys.rb | BitBucket.Repos::Keys.edit | def edit(user_name, repo_name, key_id, params={})
_update_user_repo_params(user_name, repo_name)
_validate_user_repo_params(user, repo) unless user? && repo?
_validate_presence_of key_id
normalize! params
filter! VALID_KEY_PARAM_NAMES, params
put_request("/1.0/repositories/#{user}/#{repo.downcase}/deploy-keys/#{key_id}", params)
end | ruby | def edit(user_name, repo_name, key_id, params={})
_update_user_repo_params(user_name, repo_name)
_validate_user_repo_params(user, repo) unless user? && repo?
_validate_presence_of key_id
normalize! params
filter! VALID_KEY_PARAM_NAMES, params
put_request("/1.0/repositories/#{user}/#{repo.downcase}/deploy-keys/#{key_id}", params)
end | [
"def",
"edit",
"(",
"user_name",
",",
"repo_name",
",",
"key_id",
",",
"params",
"=",
"{",
"}",
")",
"_update_user_repo_params",
"(",
"user_name",
",",
"repo_name",
")",
"_validate_user_repo_params",
"(",
"user",
",",
"repo",
")",
"unless",
"user?",
"&&",
"repo?",
"_validate_presence_of",
"key_id",
"normalize!",
"params",
"filter!",
"VALID_KEY_PARAM_NAMES",
",",
"params",
"put_request",
"(",
"\"/1.0/repositories/#{user}/#{repo.downcase}/deploy-keys/#{key_id}\"",
",",
"params",
")",
"end"
] | Edit a key
= Inputs
* <tt>:title</tt> - Required string.
* <tt>:key</tt> - Required string.
= Examples
bitbucket = BitBucket.new
bitbucket.repos.keys.edit 'user-name', 'repo-name',
"label" => "octocat@octomac",
"key" => "ssh-rsa AAA..." | [
"Edit",
"a",
"key"
] | e03b6935104d59b3d9a922474c3dc210a5ef76d2 | https://github.com/bitbucket-rest-api/bitbucket/blob/e03b6935104d59b3d9a922474c3dc210a5ef76d2/lib/bitbucket_rest_api/repos/keys.rb#L61-L70 | train |
bitbucket-rest-api/bitbucket | lib/bitbucket_rest_api/teams.rb | BitBucket.Teams.members | def members(team_name)
response = get_request("/2.0/teams/#{team_name.to_s}/members")
return response["values"] unless block_given?
response["values"].each { |el| yield el }
end | ruby | def members(team_name)
response = get_request("/2.0/teams/#{team_name.to_s}/members")
return response["values"] unless block_given?
response["values"].each { |el| yield el }
end | [
"def",
"members",
"(",
"team_name",
")",
"response",
"=",
"get_request",
"(",
"\"/2.0/teams/#{team_name.to_s}/members\"",
")",
"return",
"response",
"[",
"\"values\"",
"]",
"unless",
"block_given?",
"response",
"[",
"\"values\"",
"]",
".",
"each",
"{",
"|",
"el",
"|",
"yield",
"el",
"}",
"end"
] | List members of the provided team
= Examples
bitbucket = BitBucket.new :oauth_token => '...', :oauth_secret => '...'
bitbucket.teams.members(:team_name_here)
bitbucket.teams.members(:team_name_here) { |member| ... } | [
"List",
"members",
"of",
"the",
"provided",
"team"
] | e03b6935104d59b3d9a922474c3dc210a5ef76d2 | https://github.com/bitbucket-rest-api/bitbucket/blob/e03b6935104d59b3d9a922474c3dc210a5ef76d2/lib/bitbucket_rest_api/teams.rb#L42-L46 | train |
bitbucket-rest-api/bitbucket | lib/bitbucket_rest_api/teams.rb | BitBucket.Teams.followers | def followers(team_name)
response = get_request("/2.0/teams/#{team_name.to_s}/followers")
return response["values"] unless block_given?
response["values"].each { |el| yield el }
end | ruby | def followers(team_name)
response = get_request("/2.0/teams/#{team_name.to_s}/followers")
return response["values"] unless block_given?
response["values"].each { |el| yield el }
end | [
"def",
"followers",
"(",
"team_name",
")",
"response",
"=",
"get_request",
"(",
"\"/2.0/teams/#{team_name.to_s}/followers\"",
")",
"return",
"response",
"[",
"\"values\"",
"]",
"unless",
"block_given?",
"response",
"[",
"\"values\"",
"]",
".",
"each",
"{",
"|",
"el",
"|",
"yield",
"el",
"}",
"end"
] | List followers of the provided team
= Examples
bitbucket = BitBucket.new :oauth_token => '...', :oauth_secret => '...'
bitbucket.teams.followers(:team_name_here)
bitbucket.teams.followers(:team_name_here) { |follower| ... } | [
"List",
"followers",
"of",
"the",
"provided",
"team"
] | e03b6935104d59b3d9a922474c3dc210a5ef76d2 | https://github.com/bitbucket-rest-api/bitbucket/blob/e03b6935104d59b3d9a922474c3dc210a5ef76d2/lib/bitbucket_rest_api/teams.rb#L54-L58 | train |
bitbucket-rest-api/bitbucket | lib/bitbucket_rest_api/teams.rb | BitBucket.Teams.following | def following(team_name)
response = get_request("/2.0/teams/#{team_name.to_s}/following")
return response["values"] unless block_given?
response["values"].each { |el| yield el }
end | ruby | def following(team_name)
response = get_request("/2.0/teams/#{team_name.to_s}/following")
return response["values"] unless block_given?
response["values"].each { |el| yield el }
end | [
"def",
"following",
"(",
"team_name",
")",
"response",
"=",
"get_request",
"(",
"\"/2.0/teams/#{team_name.to_s}/following\"",
")",
"return",
"response",
"[",
"\"values\"",
"]",
"unless",
"block_given?",
"response",
"[",
"\"values\"",
"]",
".",
"each",
"{",
"|",
"el",
"|",
"yield",
"el",
"}",
"end"
] | List accounts following the provided team
= Examples
bitbucket = BitBucket.new :oauth_token => '...', :oauth_secret => '...'
bitbucket.teams.following(:team_name_here)
bitbucket.teams.following(:team_name_here) { |followee| ... } | [
"List",
"accounts",
"following",
"the",
"provided",
"team"
] | e03b6935104d59b3d9a922474c3dc210a5ef76d2 | https://github.com/bitbucket-rest-api/bitbucket/blob/e03b6935104d59b3d9a922474c3dc210a5ef76d2/lib/bitbucket_rest_api/teams.rb#L66-L70 | train |
bitbucket-rest-api/bitbucket | lib/bitbucket_rest_api/teams.rb | BitBucket.Teams.repos | def repos(team_name)
response = get_request("/2.0/repositories/#{team_name.to_s}")
return response["values"] unless block_given?
response["values"].each { |el| yield el }
end | ruby | def repos(team_name)
response = get_request("/2.0/repositories/#{team_name.to_s}")
return response["values"] unless block_given?
response["values"].each { |el| yield el }
end | [
"def",
"repos",
"(",
"team_name",
")",
"response",
"=",
"get_request",
"(",
"\"/2.0/repositories/#{team_name.to_s}\"",
")",
"return",
"response",
"[",
"\"values\"",
"]",
"unless",
"block_given?",
"response",
"[",
"\"values\"",
"]",
".",
"each",
"{",
"|",
"el",
"|",
"yield",
"el",
"}",
"end"
] | List repos for provided team
Private repos will only be returned if the user is authorized to view them
= Examples
bitbucket = BitBucket.new :oauth_token => '...', :oauth_secret => '...'
bitbucket.teams.repos(:team_name_here)
bitbucket.teams.repos(:team_name_here) { |repo| ... } | [
"List",
"repos",
"for",
"provided",
"team",
"Private",
"repos",
"will",
"only",
"be",
"returned",
"if",
"the",
"user",
"is",
"authorized",
"to",
"view",
"them"
] | e03b6935104d59b3d9a922474c3dc210a5ef76d2 | https://github.com/bitbucket-rest-api/bitbucket/blob/e03b6935104d59b3d9a922474c3dc210a5ef76d2/lib/bitbucket_rest_api/teams.rb#L79-L83 | train |
bitbucket-rest-api/bitbucket | lib/bitbucket_rest_api/issues.rb | BitBucket.Issues.list_repo | def list_repo(user_name, repo_name, params={ })
_update_user_repo_params(user_name, repo_name)
_validate_user_repo_params(user, repo) unless user? && repo?
normalize! params
filter! VALID_ISSUE_PARAM_NAMES, params
# _merge_mime_type(:issue, params)
assert_valid_values(VALID_ISSUE_PARAM_VALUES, params)
response = get_request("/1.0/repositories/#{user}/#{repo.downcase}/issues", params)
return response.issues unless block_given?
response.issues.each { |el| yield el }
end | ruby | def list_repo(user_name, repo_name, params={ })
_update_user_repo_params(user_name, repo_name)
_validate_user_repo_params(user, repo) unless user? && repo?
normalize! params
filter! VALID_ISSUE_PARAM_NAMES, params
# _merge_mime_type(:issue, params)
assert_valid_values(VALID_ISSUE_PARAM_VALUES, params)
response = get_request("/1.0/repositories/#{user}/#{repo.downcase}/issues", params)
return response.issues unless block_given?
response.issues.each { |el| yield el }
end | [
"def",
"list_repo",
"(",
"user_name",
",",
"repo_name",
",",
"params",
"=",
"{",
"}",
")",
"_update_user_repo_params",
"(",
"user_name",
",",
"repo_name",
")",
"_validate_user_repo_params",
"(",
"user",
",",
"repo",
")",
"unless",
"user?",
"&&",
"repo?",
"normalize!",
"params",
"filter!",
"VALID_ISSUE_PARAM_NAMES",
",",
"params",
"# _merge_mime_type(:issue, params)",
"assert_valid_values",
"(",
"VALID_ISSUE_PARAM_VALUES",
",",
"params",
")",
"response",
"=",
"get_request",
"(",
"\"/1.0/repositories/#{user}/#{repo.downcase}/issues\"",
",",
"params",
")",
"return",
"response",
".",
"issues",
"unless",
"block_given?",
"response",
".",
"issues",
".",
"each",
"{",
"|",
"el",
"|",
"yield",
"el",
"}",
"end"
] | List issues for a repository
= Inputs
<tt>:limit</tt> - Optional - Number of issues to retrieve, default 15
<tt>:start</tt> - Optional - Issue offset, default 0
<tt>:search</tt> - Optional - A string to search for
<tt>:sort</tt> - Optional - Sorts the output by any of the metadata fields
<tt>:title</tt> - Optional - Contains a filter operation to restrict the list of issues by the issue title
<tt>:content</tt> - Optional - Contains a filter operation to restrict the list of issues by the issue content
<tt>:version</tt> - Optional - Contains an is or ! ( is not) filter to restrict the list of issues by the version
<tt>:milestone</tt> - Optional - Contains an is or ! ( is not) filter to restrict the list of issues by the milestone
<tt>:component</tt> - Optional - Contains an is or ! ( is not) filter to restrict the list of issues by the component
<tt>:kind</tt> - Optional - Contains an is or ! ( is not) filter to restrict the list of issues by the issue kind
<tt>:status</tt> - Optional - Contains an is or ! ( is not) filter to restrict the list of issues by the issue status
<tt>:responsible</tt> - Optional - Contains an is or ! ( is not) filter to restrict the list of issues by the user responsible
<tt>:reported_by</tt> - Optional - Contains a filter operation to restrict the list of issues by the user that reported the issue
= Examples
bitbucket = BitBucket.new :user => 'user-name', :repo => 'repo-name'
bitbucket.issues.list_repo :filter => 'kind=bug&kind=enhancement' | [
"List",
"issues",
"for",
"a",
"repository"
] | e03b6935104d59b3d9a922474c3dc210a5ef76d2 | https://github.com/bitbucket-rest-api/bitbucket/blob/e03b6935104d59b3d9a922474c3dc210a5ef76d2/lib/bitbucket_rest_api/issues.rb#L76-L88 | train |
bitbucket-rest-api/bitbucket | lib/bitbucket_rest_api/issues.rb | BitBucket.Issues.create | def create(user_name, repo_name, params={ })
_update_user_repo_params(user_name, repo_name)
_validate_user_repo_params(user, repo) unless user? && repo?
normalize! params
_merge_user_into_params!(params) unless params.has_key?('user')
# _merge_mime_type(:issue, params)
filter! VALID_ISSUE_PARAM_NAMES, params
assert_required_keys(%w[ title ], params)
post_request("/1.0/repositories/#{user}/#{repo.downcase}/issues/", params)
end | ruby | def create(user_name, repo_name, params={ })
_update_user_repo_params(user_name, repo_name)
_validate_user_repo_params(user, repo) unless user? && repo?
normalize! params
_merge_user_into_params!(params) unless params.has_key?('user')
# _merge_mime_type(:issue, params)
filter! VALID_ISSUE_PARAM_NAMES, params
assert_required_keys(%w[ title ], params)
post_request("/1.0/repositories/#{user}/#{repo.downcase}/issues/", params)
end | [
"def",
"create",
"(",
"user_name",
",",
"repo_name",
",",
"params",
"=",
"{",
"}",
")",
"_update_user_repo_params",
"(",
"user_name",
",",
"repo_name",
")",
"_validate_user_repo_params",
"(",
"user",
",",
"repo",
")",
"unless",
"user?",
"&&",
"repo?",
"normalize!",
"params",
"_merge_user_into_params!",
"(",
"params",
")",
"unless",
"params",
".",
"has_key?",
"(",
"'user'",
")",
"# _merge_mime_type(:issue, params)",
"filter!",
"VALID_ISSUE_PARAM_NAMES",
",",
"params",
"assert_required_keys",
"(",
"%w[",
"title",
"]",
",",
"params",
")",
"post_request",
"(",
"\"/1.0/repositories/#{user}/#{repo.downcase}/issues/\"",
",",
"params",
")",
"end"
] | Create an issue
= Inputs
<tt>:title</tt> - Required string
<tt>:content</tt> - Optional string
<tt>:responsible</tt> - Optional string - Login for the user that this issue should be assigned to.
<tt>:milestone</tt> - Optional number - Milestone to associate this issue with
<tt>:version</tt> - Optional number - Version to associate this issue with
<tt>:component</tt> - Optional number - Component to associate this issue with
<tt>:priority</tt> - Optional string - The priority of this issue
* <tt>trivial</tt>
* <tt>minor</tt>
* <tt>major</tt>
* <tt>critical</tt>
* <tt>blocker</tt>
<tt>:status</tt> - Optional string - The status of this issue
* <tt>new</tt>
* <tt>open</tt>
* <tt>resolved</tt>
* <tt>on hold</tt>
* <tt>invalid</tt>
* <tt>duplicate</tt>
* <tt>wontfix</tt>
<tt>:kind</tt> - Optional string - The kind of issue
* <tt>bug</tt>
* <tt>enhancement</tt>
* <tt>proposal</tt>
* <tt>task</tt>
= Examples
bitbucket = BitBucket.new :user => 'user-name', :repo => 'repo-name'
bitbucket.issues.create
"title" => "Found a bug",
"content" => "I'm having a problem with this.",
"responsible" => "octocat",
"milestone" => 1,
"priority" => "blocker" | [
"Create",
"an",
"issue"
] | e03b6935104d59b3d9a922474c3dc210a5ef76d2 | https://github.com/bitbucket-rest-api/bitbucket/blob/e03b6935104d59b3d9a922474c3dc210a5ef76d2/lib/bitbucket_rest_api/issues.rb#L166-L177 | train |
bitbucket-rest-api/bitbucket | lib/bitbucket_rest_api/api.rb | BitBucket.API.method_missing | def method_missing(method, *args, &block) # :nodoc:
case method.to_s
when /^(.*)\?$/
return !self.send($1.to_s).nil?
when /^clear_(.*)$/
self.send("#{$1.to_s}=", nil)
else
super
end
end | ruby | def method_missing(method, *args, &block) # :nodoc:
case method.to_s
when /^(.*)\?$/
return !self.send($1.to_s).nil?
when /^clear_(.*)$/
self.send("#{$1.to_s}=", nil)
else
super
end
end | [
"def",
"method_missing",
"(",
"method",
",",
"*",
"args",
",",
"&",
"block",
")",
"# :nodoc:",
"case",
"method",
".",
"to_s",
"when",
"/",
"\\?",
"/",
"return",
"!",
"self",
".",
"send",
"(",
"$1",
".",
"to_s",
")",
".",
"nil?",
"when",
"/",
"/",
"self",
".",
"send",
"(",
"\"#{$1.to_s}=\"",
",",
"nil",
")",
"else",
"super",
"end",
"end"
] | Responds to attribute query or attribute clear | [
"Responds",
"to",
"attribute",
"query",
"or",
"attribute",
"clear"
] | e03b6935104d59b3d9a922474c3dc210a5ef76d2 | https://github.com/bitbucket-rest-api/bitbucket/blob/e03b6935104d59b3d9a922474c3dc210a5ef76d2/lib/bitbucket_rest_api/api.rb#L71-L80 | train |
Subsets and Splits
No community queries yet
The top public SQL queries from the community will appear here once available.