id int32 0 24.9k | repo stringlengths 5 58 | path stringlengths 9 168 | func_name stringlengths 9 130 | original_string stringlengths 66 10.5k | language stringclasses 1
value | code stringlengths 66 10.5k | code_tokens list | docstring stringlengths 8 16k | docstring_tokens list | sha stringlengths 40 40 | url stringlengths 94 266 |
|---|---|---|---|---|---|---|---|---|---|---|---|
19,500 | comfy/comfy-bootstrap-form | lib/comfy_bootstrap_form/form_builder.rb | ComfyBootstrapForm.FormBuilder.draw_control_column | def draw_control_column(bootstrap, offset:)
return yield unless bootstrap.horizontal?
css_class = bootstrap.control_col_class.to_s
css_class += " #{bootstrap.offset_col_class}" if offset
content_tag(:div, class: css_class) do
yield
end
end | ruby | def draw_control_column(bootstrap, offset:)
return yield unless bootstrap.horizontal?
css_class = bootstrap.control_col_class.to_s
css_class += " #{bootstrap.offset_col_class}" if offset
content_tag(:div, class: css_class) do
yield
end
end | [
"def",
"draw_control_column",
"(",
"bootstrap",
",",
"offset",
":",
")",
"return",
"yield",
"unless",
"bootstrap",
".",
"horizontal?",
"css_class",
"=",
"bootstrap",
".",
"control_col_class",
".",
"to_s",
"css_class",
"+=",
"\" #{bootstrap.offset_col_class}\"",
"if",
... | Wrapping in control in column wrapper | [
"Wrapping",
"in",
"control",
"in",
"column",
"wrapper"
] | 461d5cbd552469eb95e35fbcbed03d13ec702ef7 | https://github.com/comfy/comfy-bootstrap-form/blob/461d5cbd552469eb95e35fbcbed03d13ec702ef7/lib/comfy_bootstrap_form/form_builder.rb#L370-L377 |
19,501 | comfy/comfy-bootstrap-form | lib/comfy_bootstrap_form/form_builder.rb | ComfyBootstrapForm.FormBuilder.draw_form_group_fieldset | def draw_form_group_fieldset(bootstrap, method)
options = {}
unless bootstrap.label[:hide]
label_text = bootstrap.label[:text]
label_text ||= ActionView::Helpers::Tags::Label::LabelBuilder
.new(@template, @object_name.to_s, method, @object, nil).translation
add_css_class!... | ruby | def draw_form_group_fieldset(bootstrap, method)
options = {}
unless bootstrap.label[:hide]
label_text = bootstrap.label[:text]
label_text ||= ActionView::Helpers::Tags::Label::LabelBuilder
.new(@template, @object_name.to_s, method, @object, nil).translation
add_css_class!... | [
"def",
"draw_form_group_fieldset",
"(",
"bootstrap",
",",
"method",
")",
"options",
"=",
"{",
"}",
"unless",
"bootstrap",
".",
"label",
"[",
":hide",
"]",
"label_text",
"=",
"bootstrap",
".",
"label",
"[",
":text",
"]",
"label_text",
"||=",
"ActionView",
"::... | Wrapper for collections of radio buttons and checkboxes | [
"Wrapper",
"for",
"collections",
"of",
"radio",
"buttons",
"and",
"checkboxes"
] | 461d5cbd552469eb95e35fbcbed03d13ec702ef7 | https://github.com/comfy/comfy-bootstrap-form/blob/461d5cbd552469eb95e35fbcbed03d13ec702ef7/lib/comfy_bootstrap_form/form_builder.rb#L488-L522 |
19,502 | comfy/comfy-bootstrap-form | lib/comfy_bootstrap_form/view_helper.rb | ComfyBootstrapForm.ViewHelper.bootstrap_form_with | def bootstrap_form_with(**options, &block)
bootstrap_options = options[:bootstrap] || {}
css_classes = options.delete(:class)
if bootstrap_options[:layout].to_s == "inline"
css_classes = [css_classes, "form-inline"].compact.join(" ")
end
form_options = options.reverse_merge(buil... | ruby | def bootstrap_form_with(**options, &block)
bootstrap_options = options[:bootstrap] || {}
css_classes = options.delete(:class)
if bootstrap_options[:layout].to_s == "inline"
css_classes = [css_classes, "form-inline"].compact.join(" ")
end
form_options = options.reverse_merge(buil... | [
"def",
"bootstrap_form_with",
"(",
"**",
"options",
",",
"&",
"block",
")",
"bootstrap_options",
"=",
"options",
"[",
":bootstrap",
"]",
"||",
"{",
"}",
"css_classes",
"=",
"options",
".",
"delete",
"(",
":class",
")",
"if",
"bootstrap_options",
"[",
":layou... | Wrapper for `form_with`. Passing in Bootstrap form builder. | [
"Wrapper",
"for",
"form_with",
".",
"Passing",
"in",
"Bootstrap",
"form",
"builder",
"."
] | 461d5cbd552469eb95e35fbcbed03d13ec702ef7 | https://github.com/comfy/comfy-bootstrap-form/blob/461d5cbd552469eb95e35fbcbed03d13ec702ef7/lib/comfy_bootstrap_form/view_helper.rb#L7-L22 |
19,503 | comfy/comfy-bootstrap-form | lib/comfy_bootstrap_form/view_helper.rb | ComfyBootstrapForm.ViewHelper.supress_form_field_errors | def supress_form_field_errors
original_proc = ActionView::Base.field_error_proc
ActionView::Base.field_error_proc = proc { |input, _instance| input }
yield
ensure
ActionView::Base.field_error_proc = original_proc
end | ruby | def supress_form_field_errors
original_proc = ActionView::Base.field_error_proc
ActionView::Base.field_error_proc = proc { |input, _instance| input }
yield
ensure
ActionView::Base.field_error_proc = original_proc
end | [
"def",
"supress_form_field_errors",
"original_proc",
"=",
"ActionView",
"::",
"Base",
".",
"field_error_proc",
"ActionView",
"::",
"Base",
".",
"field_error_proc",
"=",
"proc",
"{",
"|",
"input",
",",
"_instance",
"|",
"input",
"}",
"yield",
"ensure",
"ActionView"... | By default, Rails will wrap form fields with extra html to indicate
inputs with errors. We need to handle this in the builder to render
Bootstrap specific markup. So we need to bypass this. | [
"By",
"default",
"Rails",
"will",
"wrap",
"form",
"fields",
"with",
"extra",
"html",
"to",
"indicate",
"inputs",
"with",
"errors",
".",
"We",
"need",
"to",
"handle",
"this",
"in",
"the",
"builder",
"to",
"render",
"Bootstrap",
"specific",
"markup",
".",
"S... | 461d5cbd552469eb95e35fbcbed03d13ec702ef7 | https://github.com/comfy/comfy-bootstrap-form/blob/461d5cbd552469eb95e35fbcbed03d13ec702ef7/lib/comfy_bootstrap_form/view_helper.rb#L48-L54 |
19,504 | adelevie/parse-ruby-client | lib/parse/client.rb | Parse.Client.request | def request(uri, method = :get, body = nil, query = nil, content_type = nil)
headers = {}
{
'Content-Type' => content_type || 'application/json',
'User-Agent' => "Parse for Ruby, #{VERSION}",
Protocol::HEADER_MASTER_KEY => @master_key,
... | ruby | def request(uri, method = :get, body = nil, query = nil, content_type = nil)
headers = {}
{
'Content-Type' => content_type || 'application/json',
'User-Agent' => "Parse for Ruby, #{VERSION}",
Protocol::HEADER_MASTER_KEY => @master_key,
... | [
"def",
"request",
"(",
"uri",
",",
"method",
"=",
":get",
",",
"body",
"=",
"nil",
",",
"query",
"=",
"nil",
",",
"content_type",
"=",
"nil",
")",
"headers",
"=",
"{",
"}",
"{",
"'Content-Type'",
"=>",
"content_type",
"||",
"'application/json'",
",",
"... | Perform an HTTP request for the given uri and method
with common basic response handling. Will raise a
ParseProtocolError if the response has an error status code,
and will return the parsed JSON body on success, if there is one. | [
"Perform",
"an",
"HTTP",
"request",
"for",
"the",
"given",
"uri",
"and",
"method",
"with",
"common",
"basic",
"response",
"handling",
".",
"Will",
"raise",
"a",
"ParseProtocolError",
"if",
"the",
"response",
"has",
"an",
"error",
"status",
"code",
"and",
"wi... | 323e931594681e89bc3547dd998312b15040f982 | https://github.com/adelevie/parse-ruby-client/blob/323e931594681e89bc3547dd998312b15040f982/lib/parse/client.rb#L87-L109 |
19,505 | adelevie/parse-ruby-client | lib/parse/object.rb | Parse.Object.save | def save
if @parse_object_id
method = :put
merge!(@op_fields) # use ops instead of our own view of the columns
else
method = :post
end
body = safe_hash.to_json
data = @client.request(uri, method, body)
if data
# array ops can return mutated view of a... | ruby | def save
if @parse_object_id
method = :put
merge!(@op_fields) # use ops instead of our own view of the columns
else
method = :post
end
body = safe_hash.to_json
data = @client.request(uri, method, body)
if data
# array ops can return mutated view of a... | [
"def",
"save",
"if",
"@parse_object_id",
"method",
"=",
":put",
"merge!",
"(",
"@op_fields",
")",
"# use ops instead of our own view of the columns",
"else",
"method",
"=",
":post",
"end",
"body",
"=",
"safe_hash",
".",
"to_json",
"data",
"=",
"@client",
".",
"req... | Write the current state of the local object to the API.
If the object has never been saved before, this will create
a new object, otherwise it will update the existing stored object. | [
"Write",
"the",
"current",
"state",
"of",
"the",
"local",
"object",
"to",
"the",
"API",
".",
"If",
"the",
"object",
"has",
"never",
"been",
"saved",
"before",
"this",
"will",
"create",
"a",
"new",
"object",
"otherwise",
"it",
"will",
"update",
"the",
"ex... | 323e931594681e89bc3547dd998312b15040f982 | https://github.com/adelevie/parse-ruby-client/blob/323e931594681e89bc3547dd998312b15040f982/lib/parse/object.rb#L59-L84 |
19,506 | adelevie/parse-ruby-client | lib/parse/object.rb | Parse.Object.safe_hash | def safe_hash
Hash[map do |key, value|
if Protocol::RESERVED_KEYS.include?(key)
nil
elsif value.is_a?(Hash) &&
value[Protocol::KEY_TYPE] == Protocol::TYPE_RELATION
nil
elsif value.nil?
[key, Protocol::DELETE_OP]
else
[key, Parse... | ruby | def safe_hash
Hash[map do |key, value|
if Protocol::RESERVED_KEYS.include?(key)
nil
elsif value.is_a?(Hash) &&
value[Protocol::KEY_TYPE] == Protocol::TYPE_RELATION
nil
elsif value.nil?
[key, Protocol::DELETE_OP]
else
[key, Parse... | [
"def",
"safe_hash",
"Hash",
"[",
"map",
"do",
"|",
"key",
",",
"value",
"|",
"if",
"Protocol",
"::",
"RESERVED_KEYS",
".",
"include?",
"(",
"key",
")",
"nil",
"elsif",
"value",
".",
"is_a?",
"(",
"Hash",
")",
"&&",
"value",
"[",
"Protocol",
"::",
"KE... | representation of object to send on saves | [
"representation",
"of",
"object",
"to",
"send",
"on",
"saves"
] | 323e931594681e89bc3547dd998312b15040f982 | https://github.com/adelevie/parse-ruby-client/blob/323e931594681e89bc3547dd998312b15040f982/lib/parse/object.rb#L87-L100 |
19,507 | adelevie/parse-ruby-client | lib/parse/object.rb | Parse.Object.increment | def increment(field, amount = 1)
# value = (self[field] || 0) + amount
# self[field] = value
# if !@parse_object_id
# # TODO - warn that the object must be stored first
# return nil
# end
body = { field => Parse::Increment.new(amount) }.to_json
data = @client.request(u... | ruby | def increment(field, amount = 1)
# value = (self[field] || 0) + amount
# self[field] = value
# if !@parse_object_id
# # TODO - warn that the object must be stored first
# return nil
# end
body = { field => Parse::Increment.new(amount) }.to_json
data = @client.request(u... | [
"def",
"increment",
"(",
"field",
",",
"amount",
"=",
"1",
")",
"# value = (self[field] || 0) + amount",
"# self[field] = value",
"# if !@parse_object_id",
"# # TODO - warn that the object must be stored first",
"# return nil",
"# end",
"body",
"=",
"{",
"field",
"=>",
"Par... | Increment the given field by an amount, which defaults to 1.
Saves immediately to reflect incremented | [
"Increment",
"the",
"given",
"field",
"by",
"an",
"amount",
"which",
"defaults",
"to",
"1",
".",
"Saves",
"immediately",
"to",
"reflect",
"incremented"
] | 323e931594681e89bc3547dd998312b15040f982 | https://github.com/adelevie/parse-ruby-client/blob/323e931594681e89bc3547dd998312b15040f982/lib/parse/object.rb#L175-L187 |
19,508 | adelevie/parse-ruby-client | lib/parse/object.rb | Parse.Object.parse | def parse(data)
return unless data
@parse_object_id ||= data[Protocol::KEY_OBJECT_ID]
if data.key? Protocol::KEY_CREATED_AT
@created_at = DateTime.parse data[Protocol::KEY_CREATED_AT]
end
if data.key? Protocol::KEY_UPDATED_AT
@updated_at = DateTime.parse data[Protocol::K... | ruby | def parse(data)
return unless data
@parse_object_id ||= data[Protocol::KEY_OBJECT_ID]
if data.key? Protocol::KEY_CREATED_AT
@created_at = DateTime.parse data[Protocol::KEY_CREATED_AT]
end
if data.key? Protocol::KEY_UPDATED_AT
@updated_at = DateTime.parse data[Protocol::K... | [
"def",
"parse",
"(",
"data",
")",
"return",
"unless",
"data",
"@parse_object_id",
"||=",
"data",
"[",
"Protocol",
"::",
"KEY_OBJECT_ID",
"]",
"if",
"data",
".",
"key?",
"Protocol",
"::",
"KEY_CREATED_AT",
"@created_at",
"=",
"DateTime",
".",
"parse",
"data",
... | Merge a hash parsed from the JSON representation into
this instance. This will extract the reserved fields,
merge the hash keys, and then ensure that the reserved
fields do not occur in the underlying hash storage. | [
"Merge",
"a",
"hash",
"parsed",
"from",
"the",
"JSON",
"representation",
"into",
"this",
"instance",
".",
"This",
"will",
"extract",
"the",
"reserved",
"fields",
"merge",
"the",
"hash",
"keys",
"and",
"then",
"ensure",
"that",
"the",
"reserved",
"fields",
"d... | 323e931594681e89bc3547dd998312b15040f982 | https://github.com/adelevie/parse-ruby-client/blob/323e931594681e89bc3547dd998312b15040f982/lib/parse/object.rb#L202-L222 |
19,509 | acquia/moonshot | lib/moonshot/unicode_table.rb | Moonshot.UnicodeTable.draw_children | def draw_children
first = true
@children.each do |child|
child.draw(1, first)
first = false
end
puts '└──'
end | ruby | def draw_children
first = true
@children.each do |child|
child.draw(1, first)
first = false
end
puts '└──'
end | [
"def",
"draw_children",
"first",
"=",
"true",
"@children",
".",
"each",
"do",
"|",
"child",
"|",
"child",
".",
"draw",
"(",
"1",
",",
"first",
")",
"first",
"=",
"false",
"end",
"puts",
"'└──'",
"end"
] | Draw all children at the same level, for having multiple top-level
peer leaves. | [
"Draw",
"all",
"children",
"at",
"the",
"same",
"level",
"for",
"having",
"multiple",
"top",
"-",
"level",
"peer",
"leaves",
"."
] | d2f3a81f0674c8fabf07742038f806777d15c819 | https://github.com/acquia/moonshot/blob/d2f3a81f0674c8fabf07742038f806777d15c819/lib/moonshot/unicode_table.rb#L54-L61 |
19,510 | acquia/moonshot | lib/moonshot/artifact_repository/s3_bucket_via_github_releases.rb | Moonshot::ArtifactRepository.S3BucketViaGithubReleases.upload_to_s3 | def upload_to_s3(file, key)
attempts = 0
begin
super
unless (checksum = checksum_file(file)).nil?
verify_s3_checksum(key, checksum, attempt: attempts)
end
rescue RuntimeError => e
unless (attempts += 1) > 3
# Wait 10 seconds before trying again.
... | ruby | def upload_to_s3(file, key)
attempts = 0
begin
super
unless (checksum = checksum_file(file)).nil?
verify_s3_checksum(key, checksum, attempt: attempts)
end
rescue RuntimeError => e
unless (attempts += 1) > 3
# Wait 10 seconds before trying again.
... | [
"def",
"upload_to_s3",
"(",
"file",
",",
"key",
")",
"attempts",
"=",
"0",
"begin",
"super",
"unless",
"(",
"checksum",
"=",
"checksum_file",
"(",
"file",
")",
")",
".",
"nil?",
"verify_s3_checksum",
"(",
"key",
",",
"checksum",
",",
"attempt",
":",
"att... | Uploads the file to s3 and verifies the checksum.
@param file [String] File to be uploaded to s3.
@param key [String] Name of the object to be created on s3.
@raise [RuntimeError] If the file fails to upload correctly after 3
attempts. | [
"Uploads",
"the",
"file",
"to",
"s3",
"and",
"verifies",
"the",
"checksum",
"."
] | d2f3a81f0674c8fabf07742038f806777d15c819 | https://github.com/acquia/moonshot/blob/d2f3a81f0674c8fabf07742038f806777d15c819/lib/moonshot/artifact_repository/s3_bucket_via_github_releases.rb#L93-L110 |
19,511 | acquia/moonshot | lib/moonshot/artifact_repository/s3_bucket_via_github_releases.rb | Moonshot::ArtifactRepository.S3BucketViaGithubReleases.download_from_github | def download_from_github(version)
file_pattern = "*#{version}*.tar.gz"
attempts = 0
Retriable.retriable on: RuntimeError do
# Make sure the directory is empty before downloading the release.
FileUtils.rm(Dir.glob('*'))
# Download the release and find the actual build file.
... | ruby | def download_from_github(version)
file_pattern = "*#{version}*.tar.gz"
attempts = 0
Retriable.retriable on: RuntimeError do
# Make sure the directory is empty before downloading the release.
FileUtils.rm(Dir.glob('*'))
# Download the release and find the actual build file.
... | [
"def",
"download_from_github",
"(",
"version",
")",
"file_pattern",
"=",
"\"*#{version}*.tar.gz\"",
"attempts",
"=",
"0",
"Retriable",
".",
"retriable",
"on",
":",
"RuntimeError",
"do",
"# Make sure the directory is empty before downloading the release.",
"FileUtils",
".",
... | Downloads the release build from github and verifies the checksum.
@param version [String] Version to be downloaded
@param [String] Build file downloaded.
@raise [RuntimeError] If the file fails to download correctly after 3
attempts. | [
"Downloads",
"the",
"release",
"build",
"from",
"github",
"and",
"verifies",
"the",
"checksum",
"."
] | d2f3a81f0674c8fabf07742038f806777d15c819 | https://github.com/acquia/moonshot/blob/d2f3a81f0674c8fabf07742038f806777d15c819/lib/moonshot/artifact_repository/s3_bucket_via_github_releases.rb#L118-L139 |
19,512 | acquia/moonshot | lib/moonshot/artifact_repository/s3_bucket_via_github_releases.rb | Moonshot::ArtifactRepository.S3BucketViaGithubReleases.verify_download_checksum | def verify_download_checksum(build_file, checksum_file, attempt: 0)
expected = File.read(checksum_file)
actual = Digest::MD5.file(build_file).hexdigest
if actual != expected
log.error("GitHub fie #{build_file} checksum should be #{expected} " \
"but was #{actual}.")
b... | ruby | def verify_download_checksum(build_file, checksum_file, attempt: 0)
expected = File.read(checksum_file)
actual = Digest::MD5.file(build_file).hexdigest
if actual != expected
log.error("GitHub fie #{build_file} checksum should be #{expected} " \
"but was #{actual}.")
b... | [
"def",
"verify_download_checksum",
"(",
"build_file",
",",
"checksum_file",
",",
"attempt",
":",
"0",
")",
"expected",
"=",
"File",
".",
"read",
"(",
"checksum_file",
")",
"actual",
"=",
"Digest",
"::",
"MD5",
".",
"file",
"(",
"build_file",
")",
".",
"hex... | Verifies the checksum for a file downloaded from github.
@param build_file [String] Build file to verify.
@param checksum_file [String] Checksum file to verify the build.
@param attempt [Integer] The attempt for this verification. | [
"Verifies",
"the",
"checksum",
"for",
"a",
"file",
"downloaded",
"from",
"github",
"."
] | d2f3a81f0674c8fabf07742038f806777d15c819 | https://github.com/acquia/moonshot/blob/d2f3a81f0674c8fabf07742038f806777d15c819/lib/moonshot/artifact_repository/s3_bucket_via_github_releases.rb#L155-L166 |
19,513 | acquia/moonshot | lib/moonshot/artifact_repository/s3_bucket_via_github_releases.rb | Moonshot::ArtifactRepository.S3BucketViaGithubReleases.backup_failed_github_file | def backup_failed_github_file(build_file, attempt)
basename = File.basename(build_file, '.tar.gz')
destination = File.join(Dir.tmpdir, basename,
".gh.failure.#{attempt}.tar.gz")
FileUtils.cp(build_file, destination)
log.info("Copied #{build_file} to #{destination}")... | ruby | def backup_failed_github_file(build_file, attempt)
basename = File.basename(build_file, '.tar.gz')
destination = File.join(Dir.tmpdir, basename,
".gh.failure.#{attempt}.tar.gz")
FileUtils.cp(build_file, destination)
log.info("Copied #{build_file} to #{destination}")... | [
"def",
"backup_failed_github_file",
"(",
"build_file",
",",
"attempt",
")",
"basename",
"=",
"File",
".",
"basename",
"(",
"build_file",
",",
"'.tar.gz'",
")",
"destination",
"=",
"File",
".",
"join",
"(",
"Dir",
".",
"tmpdir",
",",
"basename",
",",
"\".gh.f... | Backs up the failed file from a github verification.
@param build_file [String] The build file to backup.
@param attempt [Integer] Which attempt to verify the file failed. | [
"Backs",
"up",
"the",
"failed",
"file",
"from",
"a",
"github",
"verification",
"."
] | d2f3a81f0674c8fabf07742038f806777d15c819 | https://github.com/acquia/moonshot/blob/d2f3a81f0674c8fabf07742038f806777d15c819/lib/moonshot/artifact_repository/s3_bucket_via_github_releases.rb#L172-L178 |
19,514 | acquia/moonshot | lib/moonshot/artifact_repository/s3_bucket_via_github_releases.rb | Moonshot::ArtifactRepository.S3BucketViaGithubReleases.verify_s3_checksum | def verify_s3_checksum(s3_name, checksum_file, attempt: 0)
headers = s3_client.head_object(
key: s3_name,
bucket: @bucket_name
)
expected = File.read(checksum_file)
actual = headers.etag.tr('"', '')
if actual != expected
log.error("S3 file #{s3_name} checksum should... | ruby | def verify_s3_checksum(s3_name, checksum_file, attempt: 0)
headers = s3_client.head_object(
key: s3_name,
bucket: @bucket_name
)
expected = File.read(checksum_file)
actual = headers.etag.tr('"', '')
if actual != expected
log.error("S3 file #{s3_name} checksum should... | [
"def",
"verify_s3_checksum",
"(",
"s3_name",
",",
"checksum_file",
",",
"attempt",
":",
"0",
")",
"headers",
"=",
"s3_client",
".",
"head_object",
"(",
"key",
":",
"s3_name",
",",
"bucket",
":",
"@bucket_name",
")",
"expected",
"=",
"File",
".",
"read",
"(... | Verifies the checksum for a file uploaded to s3.
Uses a HEAD request and uses the etag, which is an MD5 hash.
@param s3_name [String] The object's name on s3.
@param checksum_file [String] Checksum file to verify the build.
@param attempt [Integer] The attempt for this verification. | [
"Verifies",
"the",
"checksum",
"for",
"a",
"file",
"uploaded",
"to",
"s3",
"."
] | d2f3a81f0674c8fabf07742038f806777d15c819 | https://github.com/acquia/moonshot/blob/d2f3a81f0674c8fabf07742038f806777d15c819/lib/moonshot/artifact_repository/s3_bucket_via_github_releases.rb#L187-L202 |
19,515 | acquia/moonshot | lib/moonshot/artifact_repository/s3_bucket_via_github_releases.rb | Moonshot::ArtifactRepository.S3BucketViaGithubReleases.backup_failed_s3_file | def backup_failed_s3_file(s3_name, attempt)
basename = File.basename(s3_name, '.tar.gz')
destination = "#{Dir.tmpdir}/#{basename}.s3.failure.#{attempt}.tar.gz"
s3_client.get_object(
response_target: destination,
key: s3_name,
bucket: @bucket_name
)
log.info("Copied ... | ruby | def backup_failed_s3_file(s3_name, attempt)
basename = File.basename(s3_name, '.tar.gz')
destination = "#{Dir.tmpdir}/#{basename}.s3.failure.#{attempt}.tar.gz"
s3_client.get_object(
response_target: destination,
key: s3_name,
bucket: @bucket_name
)
log.info("Copied ... | [
"def",
"backup_failed_s3_file",
"(",
"s3_name",
",",
"attempt",
")",
"basename",
"=",
"File",
".",
"basename",
"(",
"s3_name",
",",
"'.tar.gz'",
")",
"destination",
"=",
"\"#{Dir.tmpdir}/#{basename}.s3.failure.#{attempt}.tar.gz\"",
"s3_client",
".",
"get_object",
"(",
... | Backs up the failed file from an s3 verification.
@param s3_name [String] The object's name on s3.
@param attempt [Integer] Which attempt to verify the file failed. | [
"Backs",
"up",
"the",
"failed",
"file",
"from",
"an",
"s3",
"verification",
"."
] | d2f3a81f0674c8fabf07742038f806777d15c819 | https://github.com/acquia/moonshot/blob/d2f3a81f0674c8fabf07742038f806777d15c819/lib/moonshot/artifact_repository/s3_bucket_via_github_releases.rb#L208-L217 |
19,516 | acquia/moonshot | lib/moonshot/stack_asg_printer.rb | Moonshot.StackASGPrinter.get_addl_info | def get_addl_info(instance_ids)
resp = ec2_client.describe_instances(instance_ids: instance_ids)
data = {}
resp.reservations.map(&:instances).flatten.each do |instance|
data[instance.instance_id] = instance
end
data
end | ruby | def get_addl_info(instance_ids)
resp = ec2_client.describe_instances(instance_ids: instance_ids)
data = {}
resp.reservations.map(&:instances).flatten.each do |instance|
data[instance.instance_id] = instance
end
data
end | [
"def",
"get_addl_info",
"(",
"instance_ids",
")",
"resp",
"=",
"ec2_client",
".",
"describe_instances",
"(",
"instance_ids",
":",
"instance_ids",
")",
"data",
"=",
"{",
"}",
"resp",
".",
"reservations",
".",
"map",
"(",
":instances",
")",
".",
"flatten",
"."... | Get additional information about instances not returned by the ASG API. | [
"Get",
"additional",
"information",
"about",
"instances",
"not",
"returned",
"by",
"the",
"ASG",
"API",
"."
] | d2f3a81f0674c8fabf07742038f806777d15c819 | https://github.com/acquia/moonshot/blob/d2f3a81f0674c8fabf07742038f806777d15c819/lib/moonshot/stack_asg_printer.rb#L73-L81 |
19,517 | acquia/moonshot | lib/moonshot/build_mechanism/travis_deploy.rb | Moonshot::BuildMechanism.TravisDeploy.wait_for_build | def wait_for_build(version)
# Attempt to find the build. Re-attempt if the build can not
# be found on travis yet.
retry_opts = {
tries: MAX_BUILD_FIND_ATTEMPTS,
base_interval: 10
}
job_number = nil
sh_retry("bundle exec travis show #{@cli_args} #{version}",
... | ruby | def wait_for_build(version)
# Attempt to find the build. Re-attempt if the build can not
# be found on travis yet.
retry_opts = {
tries: MAX_BUILD_FIND_ATTEMPTS,
base_interval: 10
}
job_number = nil
sh_retry("bundle exec travis show #{@cli_args} #{version}",
... | [
"def",
"wait_for_build",
"(",
"version",
")",
"# Attempt to find the build. Re-attempt if the build can not",
"# be found on travis yet.",
"retry_opts",
"=",
"{",
"tries",
":",
"MAX_BUILD_FIND_ATTEMPTS",
",",
"base_interval",
":",
"10",
"}",
"job_number",
"=",
"nil",
"sh_re... | Looks for the travis build and attempts to retry if the build does not
exist yet.
@param verison [String] Build version to look for.
@return [String] Job number for the travis build. | [
"Looks",
"for",
"the",
"travis",
"build",
"and",
"attempts",
"to",
"retry",
"if",
"the",
"build",
"does",
"not",
"exist",
"yet",
"."
] | d2f3a81f0674c8fabf07742038f806777d15c819 | https://github.com/acquia/moonshot/blob/d2f3a81f0674c8fabf07742038f806777d15c819/lib/moonshot/build_mechanism/travis_deploy.rb#L68-L82 |
19,518 | acquia/moonshot | lib/moonshot/build_mechanism/travis_deploy.rb | Moonshot::BuildMechanism.TravisDeploy.wait_for_job | def wait_for_job(job_number)
authenticate
# Wait for the job to complete or hit the timeout.
start = Time.new
job = repo.job(job_number)
ilog.start_threaded("Waiting for job #{job_number} to complete.") do |s|
while !job.finished? && Time.new - start < @timeout
s.continu... | ruby | def wait_for_job(job_number)
authenticate
# Wait for the job to complete or hit the timeout.
start = Time.new
job = repo.job(job_number)
ilog.start_threaded("Waiting for job #{job_number} to complete.") do |s|
while !job.finished? && Time.new - start < @timeout
s.continu... | [
"def",
"wait_for_job",
"(",
"job_number",
")",
"authenticate",
"# Wait for the job to complete or hit the timeout.",
"start",
"=",
"Time",
".",
"new",
"job",
"=",
"repo",
".",
"job",
"(",
"job_number",
")",
"ilog",
".",
"start_threaded",
"(",
"\"Waiting for job #{job_... | Waits for a job to complete, within the defined timeout.
@param job_number [String] The job number to wait for. | [
"Waits",
"for",
"a",
"job",
"to",
"complete",
"within",
"the",
"defined",
"timeout",
"."
] | d2f3a81f0674c8fabf07742038f806777d15c819 | https://github.com/acquia/moonshot/blob/d2f3a81f0674c8fabf07742038f806777d15c819/lib/moonshot/build_mechanism/travis_deploy.rb#L87-L107 |
19,519 | acquia/moonshot | lib/moonshot/stack.rb | Moonshot.Stack.default_values | def default_values
h = {}
template.parameters.each do |p|
h[p.name] = h.default
end
h
end | ruby | def default_values
h = {}
template.parameters.each do |p|
h[p.name] = h.default
end
h
end | [
"def",
"default_values",
"h",
"=",
"{",
"}",
"template",
".",
"parameters",
".",
"each",
"do",
"|",
"p",
"|",
"h",
"[",
"p",
".",
"name",
"]",
"=",
"h",
".",
"default",
"end",
"h",
"end"
] | Return a Hash of the default values defined in the stack template. | [
"Return",
"a",
"Hash",
"of",
"the",
"default",
"values",
"defined",
"in",
"the",
"stack",
"template",
"."
] | d2f3a81f0674c8fabf07742038f806777d15c819 | https://github.com/acquia/moonshot/blob/d2f3a81f0674c8fabf07742038f806777d15c819/lib/moonshot/stack.rb#L125-L131 |
19,520 | acquia/moonshot | lib/moonshot/build_mechanism/github_release.rb | Moonshot::BuildMechanism.GithubRelease.git_tag_exists | def git_tag_exists(tag, sha)
exists = false
sh_step("git tag -l #{tag}") do |_, output|
exists = (output.strip == tag)
end
# If the tag does exist, make sure the existing SHA matches the SHA we're
# trying to build from.
if exists
sh_step("git rev-list -n 1 #{tag}") ... | ruby | def git_tag_exists(tag, sha)
exists = false
sh_step("git tag -l #{tag}") do |_, output|
exists = (output.strip == tag)
end
# If the tag does exist, make sure the existing SHA matches the SHA we're
# trying to build from.
if exists
sh_step("git rev-list -n 1 #{tag}") ... | [
"def",
"git_tag_exists",
"(",
"tag",
",",
"sha",
")",
"exists",
"=",
"false",
"sh_step",
"(",
"\"git tag -l #{tag}\"",
")",
"do",
"|",
"_",
",",
"output",
"|",
"exists",
"=",
"(",
"output",
".",
"strip",
"==",
"tag",
")",
"end",
"# If the tag does exist, m... | Determines if a valid git tag already exists.
@param tag [String] Tag to check existence for.
@param sha [String] SHA to verify the tag against.
@return [Boolean] Whether or not the tag exists.
@raise [RuntimeError] if the SHAs do not match. | [
"Determines",
"if",
"a",
"valid",
"git",
"tag",
"already",
"exists",
"."
] | d2f3a81f0674c8fabf07742038f806777d15c819 | https://github.com/acquia/moonshot/blob/d2f3a81f0674c8fabf07742038f806777d15c819/lib/moonshot/build_mechanism/github_release.rb#L107-L125 |
19,521 | acquia/moonshot | lib/moonshot/build_mechanism/github_release.rb | Moonshot::BuildMechanism.GithubRelease.hub_release_exists | def hub_release_exists(semver)
exists = false
sh_step("hub release show #{semver}", fail: false) do |_, output|
first_line = output.split("\n").first
exists = !first_line.nil? && first_line.strip == semver.to_s
end
log.info("release #{semver} already exists") if exists
exis... | ruby | def hub_release_exists(semver)
exists = false
sh_step("hub release show #{semver}", fail: false) do |_, output|
first_line = output.split("\n").first
exists = !first_line.nil? && first_line.strip == semver.to_s
end
log.info("release #{semver} already exists") if exists
exis... | [
"def",
"hub_release_exists",
"(",
"semver",
")",
"exists",
"=",
"false",
"sh_step",
"(",
"\"hub release show #{semver}\"",
",",
"fail",
":",
"false",
")",
"do",
"|",
"_",
",",
"output",
"|",
"first_line",
"=",
"output",
".",
"split",
"(",
"\"\\n\"",
")",
"... | Determines if a github release already exists.
@param semver [String] Semantic version string for the release.
@return [Boolean] | [
"Determines",
"if",
"a",
"github",
"release",
"already",
"exists",
"."
] | d2f3a81f0674c8fabf07742038f806777d15c819 | https://github.com/acquia/moonshot/blob/d2f3a81f0674c8fabf07742038f806777d15c819/lib/moonshot/build_mechanism/github_release.rb#L148-L156 |
19,522 | acquia/moonshot | lib/moonshot/build_mechanism/github_release.rb | Moonshot::BuildMechanism.GithubRelease.check_ci_status | def check_ci_status(sha)
out = nil
retry_opts = {
max_elapsed_time: @ci_status_timeout,
base_interval: 10
}
ilog.start_threaded("Check CI status for #{sha}.") do |step|
out = sh_retry("hub ci-status --verbose #{sha}", opts: retry_opts)
step.success
end
... | ruby | def check_ci_status(sha)
out = nil
retry_opts = {
max_elapsed_time: @ci_status_timeout,
base_interval: 10
}
ilog.start_threaded("Check CI status for #{sha}.") do |step|
out = sh_retry("hub ci-status --verbose #{sha}", opts: retry_opts)
step.success
end
... | [
"def",
"check_ci_status",
"(",
"sha",
")",
"out",
"=",
"nil",
"retry_opts",
"=",
"{",
"max_elapsed_time",
":",
"@ci_status_timeout",
",",
"base_interval",
":",
"10",
"}",
"ilog",
".",
"start_threaded",
"(",
"\"Check CI status for #{sha}.\"",
")",
"do",
"|",
"ste... | Checks for the commit's CI job status. If its not finished yet,
wait till timeout.
@param sha [String] Commit sha.
@return [String] Status and links to the CI jobs | [
"Checks",
"for",
"the",
"commit",
"s",
"CI",
"job",
"status",
".",
"If",
"its",
"not",
"finished",
"yet",
"wait",
"till",
"timeout",
"."
] | d2f3a81f0674c8fabf07742038f806777d15c819 | https://github.com/acquia/moonshot/blob/d2f3a81f0674c8fabf07742038f806777d15c819/lib/moonshot/build_mechanism/github_release.rb#L202-L213 |
19,523 | neilslater/games_dice | lib/games_dice/prob_helpers.rb | GamesDice::ProbabilityValidations.ClassMethods.prob_h_to_ao | def prob_h_to_ao h
rmin,rmax = h.keys.minmax
o = rmin
s = 1 + rmax - rmin
raise ArgumentError, "Range of possible results too large" if s > 1000000
a = Array.new( s, 0.0 )
h.each { |k,v| a[k-rmin] = Float(v) }
[a,o]
end | ruby | def prob_h_to_ao h
rmin,rmax = h.keys.minmax
o = rmin
s = 1 + rmax - rmin
raise ArgumentError, "Range of possible results too large" if s > 1000000
a = Array.new( s, 0.0 )
h.each { |k,v| a[k-rmin] = Float(v) }
[a,o]
end | [
"def",
"prob_h_to_ao",
"h",
"rmin",
",",
"rmax",
"=",
"h",
".",
"keys",
".",
"minmax",
"o",
"=",
"rmin",
"s",
"=",
"1",
"+",
"rmax",
"-",
"rmin",
"raise",
"ArgumentError",
",",
"\"Range of possible results too large\"",
"if",
"s",
">",
"1000000",
"a",
"=... | Convert hash to array,offset notation | [
"Convert",
"hash",
"to",
"array",
"offset",
"notation"
] | 3e1c918974103da803c6cefb009c92de85b5ea7a | https://github.com/neilslater/games_dice/blob/3e1c918974103da803c6cefb009c92de85b5ea7a/lib/games_dice/prob_helpers.rb#L37-L45 |
19,524 | neilslater/games_dice | lib/games_dice/prob_helpers.rb | GamesDice::ProbabilityValidations.ClassMethods.prob_ao_to_h | def prob_ao_to_h a, o
h = Hash.new
a.each_with_index { |v,i| h[i+o] = v if v > 0.0 }
h
end | ruby | def prob_ao_to_h a, o
h = Hash.new
a.each_with_index { |v,i| h[i+o] = v if v > 0.0 }
h
end | [
"def",
"prob_ao_to_h",
"a",
",",
"o",
"h",
"=",
"Hash",
".",
"new",
"a",
".",
"each_with_index",
"{",
"|",
"v",
",",
"i",
"|",
"h",
"[",
"i",
"+",
"o",
"]",
"=",
"v",
"if",
"v",
">",
"0.0",
"}",
"h",
"end"
] | Convert array,offset notation to hash | [
"Convert",
"array",
"offset",
"notation",
"to",
"hash"
] | 3e1c918974103da803c6cefb009c92de85b5ea7a | https://github.com/neilslater/games_dice/blob/3e1c918974103da803c6cefb009c92de85b5ea7a/lib/games_dice/prob_helpers.rb#L48-L52 |
19,525 | tpitale/legato | lib/legato/query.rb | Legato.Query.basic_options | def basic_options
Hash[BASIC_OPTION_KEYS.map { |k| [k, send(k)] }].reject {|_,v| v.nil?}
end | ruby | def basic_options
Hash[BASIC_OPTION_KEYS.map { |k| [k, send(k)] }].reject {|_,v| v.nil?}
end | [
"def",
"basic_options",
"Hash",
"[",
"BASIC_OPTION_KEYS",
".",
"map",
"{",
"|",
"k",
"|",
"[",
"k",
",",
"send",
"(",
"k",
")",
"]",
"}",
"]",
".",
"reject",
"{",
"|",
"_",
",",
"v",
"|",
"v",
".",
"nil?",
"}",
"end"
] | return a hash of basic options to merge | [
"return",
"a",
"hash",
"of",
"basic",
"options",
"to",
"merge"
] | e92a3e585a9c6a50a6cac1e053f1a6bf30f8e249 | https://github.com/tpitale/legato/blob/e92a3e585a9c6a50a6cac1e053f1a6bf30f8e249/lib/legato/query.rb#L122-L124 |
19,526 | tpitale/legato | lib/legato/query.rb | Legato.Query.results | def results(profile=nil, options={})
query = loaded? ? Query.from_query(self) : self
options, profile = profile, self.profile if profile.is_a?(Hash)
query.profile = profile
query.apply_options(self.basic_options.merge(options))
query
end | ruby | def results(profile=nil, options={})
query = loaded? ? Query.from_query(self) : self
options, profile = profile, self.profile if profile.is_a?(Hash)
query.profile = profile
query.apply_options(self.basic_options.merge(options))
query
end | [
"def",
"results",
"(",
"profile",
"=",
"nil",
",",
"options",
"=",
"{",
"}",
")",
"query",
"=",
"loaded?",
"?",
"Query",
".",
"from_query",
"(",
"self",
")",
":",
"self",
"options",
",",
"profile",
"=",
"profile",
",",
"self",
".",
"profile",
"if",
... | if no filters, we use results to add profile | [
"if",
"no",
"filters",
"we",
"use",
"results",
"to",
"add",
"profile"
] | e92a3e585a9c6a50a6cac1e053f1a6bf30f8e249 | https://github.com/tpitale/legato/blob/e92a3e585a9c6a50a6cac1e053f1a6bf30f8e249/lib/legato/query.rb#L193-L201 |
19,527 | seomoz/qless | lib/qless/job.rb | Qless.Job.requeue | def requeue(queue, opts = {})
queue_name = case queue
when String, Symbol then queue
else queue.name
end
note_state_change :requeue do
@client.call('requeue', @client.worker_name, queue_name, @jid, @klass_name,
JSON.d... | ruby | def requeue(queue, opts = {})
queue_name = case queue
when String, Symbol then queue
else queue.name
end
note_state_change :requeue do
@client.call('requeue', @client.worker_name, queue_name, @jid, @klass_name,
JSON.d... | [
"def",
"requeue",
"(",
"queue",
",",
"opts",
"=",
"{",
"}",
")",
"queue_name",
"=",
"case",
"queue",
"when",
"String",
",",
"Symbol",
"then",
"queue",
"else",
"queue",
".",
"name",
"end",
"note_state_change",
":requeue",
"do",
"@client",
".",
"call",
"("... | Move this from it's current queue into another | [
"Move",
"this",
"from",
"it",
"s",
"current",
"queue",
"into",
"another"
] | 08e16c2292c5cf0fe9322cce72d1ac6c80d372ce | https://github.com/seomoz/qless/blob/08e16c2292c5cf0fe9322cce72d1ac6c80d372ce/lib/qless/job.rb#L229-L245 |
19,528 | seomoz/qless | lib/qless/job.rb | Qless.Job.fail | def fail(group, message)
note_state_change :fail do
@client.call(
'fail',
@jid,
@worker_name,
group, message,
JSON.dump(@data)) || false
end
rescue Qless::LuaScriptError => err
raise CantFailError.new(err.message)
end | ruby | def fail(group, message)
note_state_change :fail do
@client.call(
'fail',
@jid,
@worker_name,
group, message,
JSON.dump(@data)) || false
end
rescue Qless::LuaScriptError => err
raise CantFailError.new(err.message)
end | [
"def",
"fail",
"(",
"group",
",",
"message",
")",
"note_state_change",
":fail",
"do",
"@client",
".",
"call",
"(",
"'fail'",
",",
"@jid",
",",
"@worker_name",
",",
"group",
",",
"message",
",",
"JSON",
".",
"dump",
"(",
"@data",
")",
")",
"||",
"false"... | Fail a job | [
"Fail",
"a",
"job"
] | 08e16c2292c5cf0fe9322cce72d1ac6c80d372ce | https://github.com/seomoz/qless/blob/08e16c2292c5cf0fe9322cce72d1ac6c80d372ce/lib/qless/job.rb#L251-L262 |
19,529 | seomoz/qless | lib/qless/subscriber.rb | Qless.Subscriber.start | def start
queue = ::Queue.new
@thread = Thread.start do
@listener_redis.subscribe(@channel, @my_channel) do |on|
on.subscribe do |channel|
queue.push(:subscribed) if channel == @channel
end
on.message do |channel, message|
handle_message(channe... | ruby | def start
queue = ::Queue.new
@thread = Thread.start do
@listener_redis.subscribe(@channel, @my_channel) do |on|
on.subscribe do |channel|
queue.push(:subscribed) if channel == @channel
end
on.message do |channel, message|
handle_message(channe... | [
"def",
"start",
"queue",
"=",
"::",
"Queue",
".",
"new",
"@thread",
"=",
"Thread",
".",
"start",
"do",
"@listener_redis",
".",
"subscribe",
"(",
"@channel",
",",
"@my_channel",
")",
"do",
"|",
"on",
"|",
"on",
".",
"subscribe",
"do",
"|",
"channel",
"|... | Start a thread listening | [
"Start",
"a",
"thread",
"listening"
] | 08e16c2292c5cf0fe9322cce72d1ac6c80d372ce | https://github.com/seomoz/qless/blob/08e16c2292c5cf0fe9322cce72d1ac6c80d372ce/lib/qless/subscriber.rb#L28-L44 |
19,530 | seomoz/qless | lib/qless/queue.rb | Qless.Queue.pop | def pop(count = nil)
jids = JSON.parse(@client.call('pop', @name, worker_name, (count || 1)))
jobs = jids.map { |j| Job.new(@client, j) }
count.nil? ? jobs[0] : jobs
end | ruby | def pop(count = nil)
jids = JSON.parse(@client.call('pop', @name, worker_name, (count || 1)))
jobs = jids.map { |j| Job.new(@client, j) }
count.nil? ? jobs[0] : jobs
end | [
"def",
"pop",
"(",
"count",
"=",
"nil",
")",
"jids",
"=",
"JSON",
".",
"parse",
"(",
"@client",
".",
"call",
"(",
"'pop'",
",",
"@name",
",",
"worker_name",
",",
"(",
"count",
"||",
"1",
")",
")",
")",
"jobs",
"=",
"jids",
".",
"map",
"{",
"|",... | Pop a work item off the queue | [
"Pop",
"a",
"work",
"item",
"off",
"the",
"queue"
] | 08e16c2292c5cf0fe9322cce72d1ac6c80d372ce | https://github.com/seomoz/qless/blob/08e16c2292c5cf0fe9322cce72d1ac6c80d372ce/lib/qless/queue.rb#L143-L147 |
19,531 | seomoz/qless | lib/qless/queue.rb | Qless.Queue.peek | def peek(count = nil)
jids = JSON.parse(@client.call('peek', @name, (count || 1)))
jobs = jids.map { |j| Job.new(@client, j) }
count.nil? ? jobs[0] : jobs
end | ruby | def peek(count = nil)
jids = JSON.parse(@client.call('peek', @name, (count || 1)))
jobs = jids.map { |j| Job.new(@client, j) }
count.nil? ? jobs[0] : jobs
end | [
"def",
"peek",
"(",
"count",
"=",
"nil",
")",
"jids",
"=",
"JSON",
".",
"parse",
"(",
"@client",
".",
"call",
"(",
"'peek'",
",",
"@name",
",",
"(",
"count",
"||",
"1",
")",
")",
")",
"jobs",
"=",
"jids",
".",
"map",
"{",
"|",
"j",
"|",
"Job"... | Peek at a work item | [
"Peek",
"at",
"a",
"work",
"item"
] | 08e16c2292c5cf0fe9322cce72d1ac6c80d372ce | https://github.com/seomoz/qless/blob/08e16c2292c5cf0fe9322cce72d1ac6c80d372ce/lib/qless/queue.rb#L150-L154 |
19,532 | seomoz/qless | lib/qless/queue.rb | Qless.Queue.length | def length
(@client.redis.multi do
%w[ locks work scheduled depends ].each do |suffix|
@client.redis.zcard("ql:q:#{@name}-#{suffix}")
end
end).inject(0, :+)
end | ruby | def length
(@client.redis.multi do
%w[ locks work scheduled depends ].each do |suffix|
@client.redis.zcard("ql:q:#{@name}-#{suffix}")
end
end).inject(0, :+)
end | [
"def",
"length",
"(",
"@client",
".",
"redis",
".",
"multi",
"do",
"%w[",
"locks",
"work",
"scheduled",
"depends",
"]",
".",
"each",
"do",
"|",
"suffix",
"|",
"@client",
".",
"redis",
".",
"zcard",
"(",
"\"ql:q:#{@name}-#{suffix}\"",
")",
"end",
"end",
"... | How many items in the queue? | [
"How",
"many",
"items",
"in",
"the",
"queue?"
] | 08e16c2292c5cf0fe9322cce72d1ac6c80d372ce | https://github.com/seomoz/qless/blob/08e16c2292c5cf0fe9322cce72d1ac6c80d372ce/lib/qless/queue.rb#L161-L167 |
19,533 | norman/friendly_id-globalize | lib/friendly_id/history.rb | FriendlyId.History.scope_for_slug_generator | def scope_for_slug_generator
relation = super
return relation if new_record?
relation = relation.merge(Slug.where('sluggable_id <> ?', id))
if friendly_id_config.uses?(:scoped)
relation = relation.where(Slug.arel_table[:scope].eq(serialized_scope))
end
relation
end | ruby | def scope_for_slug_generator
relation = super
return relation if new_record?
relation = relation.merge(Slug.where('sluggable_id <> ?', id))
if friendly_id_config.uses?(:scoped)
relation = relation.where(Slug.arel_table[:scope].eq(serialized_scope))
end
relation
end | [
"def",
"scope_for_slug_generator",
"relation",
"=",
"super",
"return",
"relation",
"if",
"new_record?",
"relation",
"=",
"relation",
".",
"merge",
"(",
"Slug",
".",
"where",
"(",
"'sluggable_id <> ?'",
",",
"id",
")",
")",
"if",
"friendly_id_config",
".",
"uses?... | If we're updating, don't consider historic slugs for the same record
to be conflicts. This will allow a record to revert to a previously
used slug. | [
"If",
"we",
"re",
"updating",
"don",
"t",
"consider",
"historic",
"slugs",
"for",
"the",
"same",
"record",
"to",
"be",
"conflicts",
".",
"This",
"will",
"allow",
"a",
"record",
"to",
"revert",
"to",
"a",
"previously",
"used",
"slug",
"."
] | b5c1b8b442f62d174759000facf5fb8b0eed280e | https://github.com/norman/friendly_id-globalize/blob/b5c1b8b442f62d174759000facf5fb8b0eed280e/lib/friendly_id/history.rb#L110-L118 |
19,534 | chef/chef-apply | lib/chef_apply/target_host.rb | ChefApply.TargetHost.connect! | def connect!
# Keep existing connections
return unless @backend.nil?
@backend = train_connection.connection
@backend.wait_until_ready
# When the testing function `mock_instance` is used, it will set
# this instance variable to false and handle this function call
# after the pl... | ruby | def connect!
# Keep existing connections
return unless @backend.nil?
@backend = train_connection.connection
@backend.wait_until_ready
# When the testing function `mock_instance` is used, it will set
# this instance variable to false and handle this function call
# after the pl... | [
"def",
"connect!",
"# Keep existing connections",
"return",
"unless",
"@backend",
".",
"nil?",
"@backend",
"=",
"train_connection",
".",
"connection",
"@backend",
".",
"wait_until_ready",
"# When the testing function `mock_instance` is used, it will set",
"# this instance variable ... | Establish connection to configured target. | [
"Establish",
"connection",
"to",
"configured",
"target",
"."
] | f3619c5af73714cfec942cbd1dae05c510c467e3 | https://github.com/chef/chef-apply/blob/f3619c5af73714cfec942cbd1dae05c510c467e3/lib/chef_apply/target_host.rb#L114-L131 |
19,535 | chef/chef-apply | lib/chef_apply/target_host.rb | ChefApply.TargetHost.fetch_file_contents | def fetch_file_contents(remote_path)
result = backend.file(remote_path)
if result.exist? && result.file?
result.content
else
nil
end
end | ruby | def fetch_file_contents(remote_path)
result = backend.file(remote_path)
if result.exist? && result.file?
result.content
else
nil
end
end | [
"def",
"fetch_file_contents",
"(",
"remote_path",
")",
"result",
"=",
"backend",
".",
"file",
"(",
"remote_path",
")",
"if",
"result",
".",
"exist?",
"&&",
"result",
".",
"file?",
"result",
".",
"content",
"else",
"nil",
"end",
"end"
] | Retrieve the contents of a remote file. Returns nil
if the file didn't exist or couldn't be read. | [
"Retrieve",
"the",
"contents",
"of",
"a",
"remote",
"file",
".",
"Returns",
"nil",
"if",
"the",
"file",
"didn",
"t",
"exist",
"or",
"couldn",
"t",
"be",
"read",
"."
] | f3619c5af73714cfec942cbd1dae05c510c467e3 | https://github.com/chef/chef-apply/blob/f3619c5af73714cfec942cbd1dae05c510c467e3/lib/chef_apply/target_host.rb#L198-L205 |
19,536 | chef/chef-apply | lib/chef_apply/target_resolver.rb | ChefApply.TargetResolver.targets | def targets
return @targets unless @targets.nil?
expanded_urls = []
@split_targets.each do |target|
expanded_urls = (expanded_urls | expand_targets(target))
end
@targets = expanded_urls.map do |url|
config = @conn_options.merge(config_for_target(url))
TargetHost.new... | ruby | def targets
return @targets unless @targets.nil?
expanded_urls = []
@split_targets.each do |target|
expanded_urls = (expanded_urls | expand_targets(target))
end
@targets = expanded_urls.map do |url|
config = @conn_options.merge(config_for_target(url))
TargetHost.new... | [
"def",
"targets",
"return",
"@targets",
"unless",
"@targets",
".",
"nil?",
"expanded_urls",
"=",
"[",
"]",
"@split_targets",
".",
"each",
"do",
"|",
"target",
"|",
"expanded_urls",
"=",
"(",
"expanded_urls",
"|",
"expand_targets",
"(",
"target",
")",
")",
"e... | Returns the list of targets as an array of TargetHost instances,
them to account for ranges embedded in the target name. | [
"Returns",
"the",
"list",
"of",
"targets",
"as",
"an",
"array",
"of",
"TargetHost",
"instances",
"them",
"to",
"account",
"for",
"ranges",
"embedded",
"in",
"the",
"target",
"name",
"."
] | f3619c5af73714cfec942cbd1dae05c510c467e3 | https://github.com/chef/chef-apply/blob/f3619c5af73714cfec942cbd1dae05c510c467e3/lib/chef_apply/target_resolver.rb#L36-L46 |
19,537 | chef/chef-apply | lib/chef_apply/recipe_lookup.rb | ChefApply.RecipeLookup.load_cookbook | def load_cookbook(path_or_name)
require "chef/exceptions"
if File.directory?(path_or_name)
cookbook_path = path_or_name
# First, is there a cookbook in the specified dir that matches?
require "chef/cookbook/cookbook_version_loader"
begin
v = Chef::Cookbook::Cookbook... | ruby | def load_cookbook(path_or_name)
require "chef/exceptions"
if File.directory?(path_or_name)
cookbook_path = path_or_name
# First, is there a cookbook in the specified dir that matches?
require "chef/cookbook/cookbook_version_loader"
begin
v = Chef::Cookbook::Cookbook... | [
"def",
"load_cookbook",
"(",
"path_or_name",
")",
"require",
"\"chef/exceptions\"",
"if",
"File",
".",
"directory?",
"(",
"path_or_name",
")",
"cookbook_path",
"=",
"path_or_name",
"# First, is there a cookbook in the specified dir that matches?",
"require",
"\"chef/cookbook/co... | Given a cookbook path or name, try to load that cookbook. Either return
a cookbook object or raise an error. | [
"Given",
"a",
"cookbook",
"path",
"or",
"name",
"try",
"to",
"load",
"that",
"cookbook",
".",
"Either",
"return",
"a",
"cookbook",
"object",
"or",
"raise",
"an",
"error",
"."
] | f3619c5af73714cfec942cbd1dae05c510c467e3 | https://github.com/chef/chef-apply/blob/f3619c5af73714cfec942cbd1dae05c510c467e3/lib/chef_apply/recipe_lookup.rb#L43-L76 |
19,538 | chef/chef-apply | lib/chef_apply/recipe_lookup.rb | ChefApply.RecipeLookup.find_recipe | def find_recipe(cookbook, recipe_name = nil)
recipes = cookbook.recipe_filenames_by_name
if recipe_name.nil?
default_recipe = recipes["default"]
raise NoDefaultRecipe.new(cookbook.root_dir, cookbook.name) if default_recipe.nil?
default_recipe
else
recipe = recipes[recip... | ruby | def find_recipe(cookbook, recipe_name = nil)
recipes = cookbook.recipe_filenames_by_name
if recipe_name.nil?
default_recipe = recipes["default"]
raise NoDefaultRecipe.new(cookbook.root_dir, cookbook.name) if default_recipe.nil?
default_recipe
else
recipe = recipes[recip... | [
"def",
"find_recipe",
"(",
"cookbook",
",",
"recipe_name",
"=",
"nil",
")",
"recipes",
"=",
"cookbook",
".",
"recipe_filenames_by_name",
"if",
"recipe_name",
".",
"nil?",
"default_recipe",
"=",
"recipes",
"[",
"\"default\"",
"]",
"raise",
"NoDefaultRecipe",
".",
... | Find the specified recipe or default recipe if none is specified.
Raise an error if recipe cannot be found. | [
"Find",
"the",
"specified",
"recipe",
"or",
"default",
"recipe",
"if",
"none",
"is",
"specified",
".",
"Raise",
"an",
"error",
"if",
"recipe",
"cannot",
"be",
"found",
"."
] | f3619c5af73714cfec942cbd1dae05c510c467e3 | https://github.com/chef/chef-apply/blob/f3619c5af73714cfec942cbd1dae05c510c467e3/lib/chef_apply/recipe_lookup.rb#L80-L91 |
19,539 | chef/chef-apply | lib/chef_apply/cli.rb | ChefApply.CLI.connect_target | def connect_target(target_host, reporter)
connect_message = T.status.connecting(target_host.user)
reporter.update(connect_message)
do_connect(target_host, reporter)
end | ruby | def connect_target(target_host, reporter)
connect_message = T.status.connecting(target_host.user)
reporter.update(connect_message)
do_connect(target_host, reporter)
end | [
"def",
"connect_target",
"(",
"target_host",
",",
"reporter",
")",
"connect_message",
"=",
"T",
".",
"status",
".",
"connecting",
"(",
"target_host",
".",
"user",
")",
"reporter",
".",
"update",
"(",
"connect_message",
")",
"do_connect",
"(",
"target_host",
",... | Accepts a target_host and establishes the connection to that host
while providing visual feedback via the Terminal API. | [
"Accepts",
"a",
"target_host",
"and",
"establishes",
"the",
"connection",
"to",
"that",
"host",
"while",
"providing",
"visual",
"feedback",
"via",
"the",
"Terminal",
"API",
"."
] | f3619c5af73714cfec942cbd1dae05c510c467e3 | https://github.com/chef/chef-apply/blob/f3619c5af73714cfec942cbd1dae05c510c467e3/lib/chef_apply/cli.rb#L164-L168 |
19,540 | chef/chef-apply | lib/chef_apply/cli.rb | ChefApply.CLI.generate_local_policy | def generate_local_policy(reporter)
action = Action::GenerateLocalPolicy.new(cookbook: temp_cookbook)
action.run do |event, data|
case event
when :generating
reporter.update(TS.generate_local_policy.generating)
when :exporting
reporter.update(TS.generate_local_pol... | ruby | def generate_local_policy(reporter)
action = Action::GenerateLocalPolicy.new(cookbook: temp_cookbook)
action.run do |event, data|
case event
when :generating
reporter.update(TS.generate_local_policy.generating)
when :exporting
reporter.update(TS.generate_local_pol... | [
"def",
"generate_local_policy",
"(",
"reporter",
")",
"action",
"=",
"Action",
"::",
"GenerateLocalPolicy",
".",
"new",
"(",
"cookbook",
":",
"temp_cookbook",
")",
"action",
".",
"run",
"do",
"|",
"event",
",",
"data",
"|",
"case",
"event",
"when",
":generat... | Runs the GenerateLocalPolicy action and renders UI updates
as the action reports back | [
"Runs",
"the",
"GenerateLocalPolicy",
"action",
"and",
"renders",
"UI",
"updates",
"as",
"the",
"action",
"reports",
"back"
] | f3619c5af73714cfec942cbd1dae05c510c467e3 | https://github.com/chef/chef-apply/blob/f3619c5af73714cfec942cbd1dae05c510c467e3/lib/chef_apply/cli.rb#L229-L244 |
19,541 | chef/chef-apply | lib/chef_apply/cli.rb | ChefApply.CLI.converge | def converge(reporter, local_policy_path, target_host)
reporter.update(TS.converge.converging(temp_cookbook.descriptor))
converge_args = { local_policy_path: local_policy_path, target_host: target_host }
converger = Action::ConvergeTarget.new(converge_args)
converger.run do |event, data|
... | ruby | def converge(reporter, local_policy_path, target_host)
reporter.update(TS.converge.converging(temp_cookbook.descriptor))
converge_args = { local_policy_path: local_policy_path, target_host: target_host }
converger = Action::ConvergeTarget.new(converge_args)
converger.run do |event, data|
... | [
"def",
"converge",
"(",
"reporter",
",",
"local_policy_path",
",",
"target_host",
")",
"reporter",
".",
"update",
"(",
"TS",
".",
"converge",
".",
"converging",
"(",
"temp_cookbook",
".",
"descriptor",
")",
")",
"converge_args",
"=",
"{",
"local_policy_path",
... | Runs the Converge action and renders UI updates as
the action reports back | [
"Runs",
"the",
"Converge",
"action",
"and",
"renders",
"UI",
"updates",
"as",
"the",
"action",
"reports",
"back"
] | f3619c5af73714cfec942cbd1dae05c510c467e3 | https://github.com/chef/chef-apply/blob/f3619c5af73714cfec942cbd1dae05c510c467e3/lib/chef_apply/cli.rb#L248-L270 |
19,542 | chef/chef-apply | lib/chef_apply/cli.rb | ChefApply.CLI.handle_message | def handle_message(message, data, reporter)
if message == :error # data[0] = exception
# Mark the current task as failed with whatever data is available to us
reporter.error(ChefApply::UI::ErrorPrinter.error_summary(data[0]))
end
end | ruby | def handle_message(message, data, reporter)
if message == :error # data[0] = exception
# Mark the current task as failed with whatever data is available to us
reporter.error(ChefApply::UI::ErrorPrinter.error_summary(data[0]))
end
end | [
"def",
"handle_message",
"(",
"message",
",",
"data",
",",
"reporter",
")",
"if",
"message",
"==",
":error",
"# data[0] = exception",
"# Mark the current task as failed with whatever data is available to us",
"reporter",
".",
"error",
"(",
"ChefApply",
"::",
"UI",
"::",
... | A handler for common action messages | [
"A",
"handler",
"for",
"common",
"action",
"messages"
] | f3619c5af73714cfec942cbd1dae05c510c467e3 | https://github.com/chef/chef-apply/blob/f3619c5af73714cfec942cbd1dae05c510c467e3/lib/chef_apply/cli.rb#L307-L312 |
19,543 | jamesotron/faye-rails | lib/faye-rails/rack_adapter.rb | FayeRails.RackAdapter.map | def map(opts)
if opts.is_a? Hash
opts.each do |channel, controller|
if channel.is_a? String
if FayeRails::Matcher.match? '/**', channel
routing_extension.map(channel, controller)
else
raise ArgumentError, "Invalid channel: #{channel}"
... | ruby | def map(opts)
if opts.is_a? Hash
opts.each do |channel, controller|
if channel.is_a? String
if FayeRails::Matcher.match? '/**', channel
routing_extension.map(channel, controller)
else
raise ArgumentError, "Invalid channel: #{channel}"
... | [
"def",
"map",
"(",
"opts",
")",
"if",
"opts",
".",
"is_a?",
"Hash",
"opts",
".",
"each",
"do",
"|",
"channel",
",",
"controller",
"|",
"if",
"channel",
".",
"is_a?",
"String",
"if",
"FayeRails",
"::",
"Matcher",
".",
"match?",
"'/**'",
",",
"channel",
... | Rudimentary routing support for channels to controllers.
@param opts
a Hash of mappings either string keys (channel globs)
mapping to controller constants eg:
'/widgets/**' => WidgetsController
or you can set the behaviour for unknown channels:
:default => :block
:default can be set to :allo... | [
"Rudimentary",
"routing",
"support",
"for",
"channels",
"to",
"controllers",
"."
] | 82943a0337546117f8ec9d1a40f8f6b251aac4b5 | https://github.com/jamesotron/faye-rails/blob/82943a0337546117f8ec9d1a40f8f6b251aac4b5/lib/faye-rails/rack_adapter.rb#L30-L50 |
19,544 | contentful/contentful_rails | lib/contentful_rails/markdown_renderer.rb | ContentfulRails.MarkdownRenderer.image | def image(link, title, alt_text)
# add the querystring to the image
if @image_parameters.present?
prefix = link.include?('?') ? '&' : '?'
link += "#{prefix}#{@image_parameters.to_query}"
end
# return a content tag
content_tag(:img, nil, src: link.to_s, alt: alt_text, title:... | ruby | def image(link, title, alt_text)
# add the querystring to the image
if @image_parameters.present?
prefix = link.include?('?') ? '&' : '?'
link += "#{prefix}#{@image_parameters.to_query}"
end
# return a content tag
content_tag(:img, nil, src: link.to_s, alt: alt_text, title:... | [
"def",
"image",
"(",
"link",
",",
"title",
",",
"alt_text",
")",
"# add the querystring to the image",
"if",
"@image_parameters",
".",
"present?",
"prefix",
"=",
"link",
".",
"include?",
"(",
"'?'",
")",
"?",
"'&'",
":",
"'?'",
"link",
"+=",
"\"#{prefix}#{@ima... | Image tag wrapper for forwarding Image API options | [
"Image",
"tag",
"wrapper",
"for",
"forwarding",
"Image",
"API",
"options"
] | 6c9b50631c8f9a1ade89dea6736285371d3f7969 | https://github.com/contentful/contentful_rails/blob/6c9b50631c8f9a1ade89dea6736285371d3f7969/lib/contentful_rails/markdown_renderer.rb#L28-L36 |
19,545 | contentful/contentful_rails | lib/contentful_rails/nested_resource.rb | ContentfulRails.NestedResource.get_child_entity_from_path_by | def get_child_entity_from_path_by(field, children)
# the next child in the path
child_value = children.shift
# get the child entity
child = send(:children).find { |c| c.send(field) == child_value }
# we have some recursion to do - we're not at the end of the array
# so call this me... | ruby | def get_child_entity_from_path_by(field, children)
# the next child in the path
child_value = children.shift
# get the child entity
child = send(:children).find { |c| c.send(field) == child_value }
# we have some recursion to do - we're not at the end of the array
# so call this me... | [
"def",
"get_child_entity_from_path_by",
"(",
"field",
",",
"children",
")",
"# the next child in the path",
"child_value",
"=",
"children",
".",
"shift",
"# get the child entity",
"child",
"=",
"send",
"(",
":children",
")",
".",
"find",
"{",
"|",
"c",
"|",
"c",
... | Given a field and an array of child fields, we need to recurse through them to get the last one
@param field [Symbol] the field we need to search for
@param children [Array] an array of field values to match against
@return an entity matching this class, which is the last in the tree | [
"Given",
"a",
"field",
"and",
"an",
"array",
"of",
"child",
"fields",
"we",
"need",
"to",
"recurse",
"through",
"them",
"to",
"get",
"the",
"last",
"one"
] | 6c9b50631c8f9a1ade89dea6736285371d3f7969 | https://github.com/contentful/contentful_rails/blob/6c9b50631c8f9a1ade89dea6736285371d3f7969/lib/contentful_rails/nested_resource.rb#L51-L63 |
19,546 | contentful/contentful_rails | app/helpers/contentful_rails/markdown_helper.rb | ContentfulRails.MarkdownHelper.parse_markdown | def parse_markdown(markdown_string, renderer_options: {}, markdown_options: {}, image_options: {})
markdown_string ||= ''
markdown_opts = {
no_intr_emphasis: true,
tables: true,
fenced_code_blocks: true,
autolink: true,
disable_indented_code_blocks: true,
stri... | ruby | def parse_markdown(markdown_string, renderer_options: {}, markdown_options: {}, image_options: {})
markdown_string ||= ''
markdown_opts = {
no_intr_emphasis: true,
tables: true,
fenced_code_blocks: true,
autolink: true,
disable_indented_code_blocks: true,
stri... | [
"def",
"parse_markdown",
"(",
"markdown_string",
",",
"renderer_options",
":",
"{",
"}",
",",
"markdown_options",
":",
"{",
"}",
",",
"image_options",
":",
"{",
"}",
")",
"markdown_string",
"||=",
"''",
"markdown_opts",
"=",
"{",
"no_intr_emphasis",
":",
"true... | Return HTML which is passed through the Redcarpet markdown processor, using a custom renderer
so that we can manipulate images using contentful's URL-based API.
NOTE that this is super-permissive out of the box. Set options to suit when you call the method.
@param renderer_options [Hash] of options from https://git... | [
"Return",
"HTML",
"which",
"is",
"passed",
"through",
"the",
"Redcarpet",
"markdown",
"processor",
"using",
"a",
"custom",
"renderer",
"so",
"that",
"we",
"can",
"manipulate",
"images",
"using",
"contentful",
"s",
"URL",
"-",
"based",
"API",
".",
"NOTE",
"th... | 6c9b50631c8f9a1ade89dea6736285371d3f7969 | https://github.com/contentful/contentful_rails/blob/6c9b50631c8f9a1ade89dea6736285371d3f7969/app/helpers/contentful_rails/markdown_helper.rb#L11-L47 |
19,547 | contentful/contentful_rails | app/controllers/contentful_rails/webhooks_controller.rb | ContentfulRails.WebhooksController.create | def create
# The only things we need to handle in here (for now at least) are entries.
# If there's been an update or a deletion, we just remove the cached timestamp.
# The updated_at method which is included in ContentfulModel::Base in this gem
# will check the cache first before making the cal... | ruby | def create
# The only things we need to handle in here (for now at least) are entries.
# If there's been an update or a deletion, we just remove the cached timestamp.
# The updated_at method which is included in ContentfulModel::Base in this gem
# will check the cache first before making the cal... | [
"def",
"create",
"# The only things we need to handle in here (for now at least) are entries.",
"# If there's been an update or a deletion, we just remove the cached timestamp.",
"# The updated_at method which is included in ContentfulModel::Base in this gem",
"# will check the cache first before making t... | this is where we receive a webhook, via a POST | [
"this",
"is",
"where",
"we",
"receive",
"a",
"webhook",
"via",
"a",
"POST"
] | 6c9b50631c8f9a1ade89dea6736285371d3f7969 | https://github.com/contentful/contentful_rails/blob/6c9b50631c8f9a1ade89dea6736285371d3f7969/app/controllers/contentful_rails/webhooks_controller.rb#L20-L37 |
19,548 | alphagov/govspeak | lib/govspeak/presenters/attachment_presenter.rb | Govspeak.AttachmentPresenter.references_for_title | def references_for_title
references = []
references << "ISBN: #{attachment[:isbn]}" if attachment[:isbn].present?
references << "Unique reference: #{attachment[:unique_reference]}" if attachment[:unique_reference].present?
references << "Command paper number: #{attachment[:command_paper_number]}... | ruby | def references_for_title
references = []
references << "ISBN: #{attachment[:isbn]}" if attachment[:isbn].present?
references << "Unique reference: #{attachment[:unique_reference]}" if attachment[:unique_reference].present?
references << "Command paper number: #{attachment[:command_paper_number]}... | [
"def",
"references_for_title",
"references",
"=",
"[",
"]",
"references",
"<<",
"\"ISBN: #{attachment[:isbn]}\"",
"if",
"attachment",
"[",
":isbn",
"]",
".",
"present?",
"references",
"<<",
"\"Unique reference: #{attachment[:unique_reference]}\"",
"if",
"attachment",
"[",
... | FIXME this has english in it so will cause problems if the locale is not en | [
"FIXME",
"this",
"has",
"english",
"in",
"it",
"so",
"will",
"cause",
"problems",
"if",
"the",
"locale",
"is",
"not",
"en"
] | f626b20e9e0a742cc4c9f4a946a80c87aa63a8da | https://github.com/alphagov/govspeak/blob/f626b20e9e0a742cc4c9f4a946a80c87aa63a8da/lib/govspeak/presenters/attachment_presenter.rb#L145-L153 |
19,549 | rmodbus/rmodbus | lib/rmodbus/tcp.rb | ModBus.TCP.open_tcp_connection | def open_tcp_connection(ipaddr, port, opts = {})
@ipaddr, @port = ipaddr, port
timeout = opts[:connect_timeout] ||= 1
io = nil
begin
io = Socket.tcp(@ipaddr, @port, nil, nil, connect_timeout: timeout)
rescue Errno::ECONNREFUSED, Errno::ETIMEDOUT
raise ModBusTimeout.new, '... | ruby | def open_tcp_connection(ipaddr, port, opts = {})
@ipaddr, @port = ipaddr, port
timeout = opts[:connect_timeout] ||= 1
io = nil
begin
io = Socket.tcp(@ipaddr, @port, nil, nil, connect_timeout: timeout)
rescue Errno::ECONNREFUSED, Errno::ETIMEDOUT
raise ModBusTimeout.new, '... | [
"def",
"open_tcp_connection",
"(",
"ipaddr",
",",
"port",
",",
"opts",
"=",
"{",
"}",
")",
"@ipaddr",
",",
"@port",
"=",
"ipaddr",
",",
"port",
"timeout",
"=",
"opts",
"[",
":connect_timeout",
"]",
"||=",
"1",
"io",
"=",
"nil",
"begin",
"io",
"=",
"S... | Open TCP socket
@param [String] ipaddr IP address of remote server
@param [Integer] port connection port
@param [Hash] opts options of connection
@option opts [Float, Integer] :connect_timeout seconds timeout for open socket
@return [Socket] socket
@raise [ModBusTimeout] timed out attempting to create connectio... | [
"Open",
"TCP",
"socket"
] | a411958521cb300c9d69edb9ca6cba075303b0dc | https://github.com/rmodbus/rmodbus/blob/a411958521cb300c9d69edb9ca6cba075303b0dc/lib/rmodbus/tcp.rb#L16-L29 |
19,550 | rmodbus/rmodbus | lib/rmodbus/debug.rb | ModBus.Debug.logging_bytes | def logging_bytes(msg)
result = ""
msg.each_byte do |c|
byte = if c < 16
'0' + c.to_s(16)
else
c.to_s(16)
end
result << "[#{byte}]"
end
result
end | ruby | def logging_bytes(msg)
result = ""
msg.each_byte do |c|
byte = if c < 16
'0' + c.to_s(16)
else
c.to_s(16)
end
result << "[#{byte}]"
end
result
end | [
"def",
"logging_bytes",
"(",
"msg",
")",
"result",
"=",
"\"\"",
"msg",
".",
"each_byte",
"do",
"|",
"c",
"|",
"byte",
"=",
"if",
"c",
"<",
"16",
"'0'",
"+",
"c",
".",
"to_s",
"(",
"16",
")",
"else",
"c",
".",
"to_s",
"(",
"16",
")",
"end",
"r... | Convert string of byte to string for log
@example
logging_bytes("\x1\xa\x8") => "[01][0a][08]"
@param [String] msg input string
@return [String] readable string of bytes | [
"Convert",
"string",
"of",
"byte",
"to",
"string",
"for",
"log"
] | a411958521cb300c9d69edb9ca6cba075303b0dc | https://github.com/rmodbus/rmodbus/blob/a411958521cb300c9d69edb9ca6cba075303b0dc/lib/rmodbus/debug.rb#L19-L30 |
19,551 | rmodbus/rmodbus | lib/rmodbus/slave.rb | ModBus.Slave.write_single_coil | def write_single_coil(addr, val)
if val == 0
query("\x5" + addr.to_word + 0.to_word)
else
query("\x5" + addr.to_word + 0xff00.to_word)
end
self
end | ruby | def write_single_coil(addr, val)
if val == 0
query("\x5" + addr.to_word + 0.to_word)
else
query("\x5" + addr.to_word + 0xff00.to_word)
end
self
end | [
"def",
"write_single_coil",
"(",
"addr",
",",
"val",
")",
"if",
"val",
"==",
"0",
"query",
"(",
"\"\\x5\"",
"+",
"addr",
".",
"to_word",
"+",
"0",
".",
"to_word",
")",
"else",
"query",
"(",
"\"\\x5\"",
"+",
"addr",
".",
"to_word",
"+",
"0xff00",
".",... | Write a single coil
@example
write_single_coil(1, 0) => self
@param [Integer] addr address coil
@param [Integer] val value coil (0 or other)
@return self | [
"Write",
"a",
"single",
"coil"
] | a411958521cb300c9d69edb9ca6cba075303b0dc | https://github.com/rmodbus/rmodbus/blob/a411958521cb300c9d69edb9ca6cba075303b0dc/lib/rmodbus/slave.rb#L58-L65 |
19,552 | rmodbus/rmodbus | lib/rmodbus/slave.rb | ModBus.Slave.write_multiple_coils | def write_multiple_coils(addr, vals)
nbyte = ((vals.size-1) >> 3) + 1
sum = 0
(vals.size - 1).downto(0) do |i|
sum = sum << 1
sum |= 1 if vals[i] > 0
end
s_val = ""
nbyte.times do
s_val << (sum & 0xff).chr
sum >>= 8
end
query("\xf" + addr... | ruby | def write_multiple_coils(addr, vals)
nbyte = ((vals.size-1) >> 3) + 1
sum = 0
(vals.size - 1).downto(0) do |i|
sum = sum << 1
sum |= 1 if vals[i] > 0
end
s_val = ""
nbyte.times do
s_val << (sum & 0xff).chr
sum >>= 8
end
query("\xf" + addr... | [
"def",
"write_multiple_coils",
"(",
"addr",
",",
"vals",
")",
"nbyte",
"=",
"(",
"(",
"vals",
".",
"size",
"-",
"1",
")",
">>",
"3",
")",
"+",
"1",
"sum",
"=",
"0",
"(",
"vals",
".",
"size",
"-",
"1",
")",
".",
"downto",
"(",
"0",
")",
"do",
... | Write multiple coils
@example
write_multiple_coils(1, [0,1,0,1]) => self
@param [Integer] addr address first coil
@param [Array] vals written coils | [
"Write",
"multiple",
"coils"
] | a411958521cb300c9d69edb9ca6cba075303b0dc | https://github.com/rmodbus/rmodbus/blob/a411958521cb300c9d69edb9ca6cba075303b0dc/lib/rmodbus/slave.rb#L75-L91 |
19,553 | rmodbus/rmodbus | lib/rmodbus/slave.rb | ModBus.Slave.read_discrete_inputs | def read_discrete_inputs(addr, ninputs)
query("\x2" + addr.to_word + ninputs.to_word).unpack_bits[0..ninputs-1]
end | ruby | def read_discrete_inputs(addr, ninputs)
query("\x2" + addr.to_word + ninputs.to_word).unpack_bits[0..ninputs-1]
end | [
"def",
"read_discrete_inputs",
"(",
"addr",
",",
"ninputs",
")",
"query",
"(",
"\"\\x2\"",
"+",
"addr",
".",
"to_word",
"+",
"ninputs",
".",
"to_word",
")",
".",
"unpack_bits",
"[",
"0",
"..",
"ninputs",
"-",
"1",
"]",
"end"
] | Read discrete inputs
@example
read_discrete_inputs(addr, ninputs) => [1, 0, ..]
@param [Integer] addr address first input
@param[Integer] ninputs number inputs
@return [Array] inputs | [
"Read",
"discrete",
"inputs"
] | a411958521cb300c9d69edb9ca6cba075303b0dc | https://github.com/rmodbus/rmodbus/blob/a411958521cb300c9d69edb9ca6cba075303b0dc/lib/rmodbus/slave.rb#L113-L115 |
19,554 | rmodbus/rmodbus | lib/rmodbus/slave.rb | ModBus.Slave.write_multiple_registers | def write_multiple_registers(addr, vals)
s_val = ""
vals.each do |reg|
s_val << reg.to_word
end
query("\x10" + addr.to_word + vals.size.to_word + (vals.size * 2).chr + s_val)
self
end | ruby | def write_multiple_registers(addr, vals)
s_val = ""
vals.each do |reg|
s_val << reg.to_word
end
query("\x10" + addr.to_word + vals.size.to_word + (vals.size * 2).chr + s_val)
self
end | [
"def",
"write_multiple_registers",
"(",
"addr",
",",
"vals",
")",
"s_val",
"=",
"\"\"",
"vals",
".",
"each",
"do",
"|",
"reg",
"|",
"s_val",
"<<",
"reg",
".",
"to_word",
"end",
"query",
"(",
"\"\\x10\"",
"+",
"addr",
".",
"to_word",
"+",
"vals",
".",
... | Write multiple holding registers
@example
write_multiple_registers(1, [0xaa, 0]) => self
@param [Integer] addr address first registers
@param [Array] val written registers
@return self | [
"Write",
"multiple",
"holding",
"registers"
] | a411958521cb300c9d69edb9ca6cba075303b0dc | https://github.com/rmodbus/rmodbus/blob/a411958521cb300c9d69edb9ca6cba075303b0dc/lib/rmodbus/slave.rb#L191-L199 |
19,555 | rmodbus/rmodbus | lib/rmodbus/slave.rb | ModBus.Slave.mask_write_register | def mask_write_register(addr, and_mask, or_mask)
query("\x16" + addr.to_word + and_mask.to_word + or_mask.to_word)
self
end | ruby | def mask_write_register(addr, and_mask, or_mask)
query("\x16" + addr.to_word + and_mask.to_word + or_mask.to_word)
self
end | [
"def",
"mask_write_register",
"(",
"addr",
",",
"and_mask",
",",
"or_mask",
")",
"query",
"(",
"\"\\x16\"",
"+",
"addr",
".",
"to_word",
"+",
"and_mask",
".",
"to_word",
"+",
"or_mask",
".",
"to_word",
")",
"self",
"end"
] | Mask a holding register
@example
mask_write_register(1, 0xAAAA, 0x00FF) => self
@param [Integer] addr address registers
@param [Integer] and_mask mask for AND operation
@param [Integer] or_mask mask for OR operation | [
"Mask",
"a",
"holding",
"register"
] | a411958521cb300c9d69edb9ca6cba075303b0dc | https://github.com/rmodbus/rmodbus/blob/a411958521cb300c9d69edb9ca6cba075303b0dc/lib/rmodbus/slave.rb#L209-L212 |
19,556 | rmodbus/rmodbus | lib/rmodbus/slave.rb | ModBus.Slave.query | def query(request)
tried = 0
response = ""
begin
::Timeout.timeout(@read_retry_timeout, ModBusTimeout) do
send_pdu(request)
response = read_pdu
end
rescue ModBusTimeout => err
log "Timeout of read operation: (#{@read_retries - tried})"
tried +=... | ruby | def query(request)
tried = 0
response = ""
begin
::Timeout.timeout(@read_retry_timeout, ModBusTimeout) do
send_pdu(request)
response = read_pdu
end
rescue ModBusTimeout => err
log "Timeout of read operation: (#{@read_retries - tried})"
tried +=... | [
"def",
"query",
"(",
"request",
")",
"tried",
"=",
"0",
"response",
"=",
"\"\"",
"begin",
"::",
"Timeout",
".",
"timeout",
"(",
"@read_retry_timeout",
",",
"ModBusTimeout",
")",
"do",
"send_pdu",
"(",
"request",
")",
"response",
"=",
"read_pdu",
"end",
"re... | Request pdu to slave device
@param [String] pdu request to slave
@return [String] received data
@raise [ResponseMismatch] the received echo response differs from the request
@raise [ModBusTimeout] timed out during read attempt
@raise [ModBusException] unknown error
@raise [IllegalFunction] function code receive... | [
"Request",
"pdu",
"to",
"slave",
"device"
] | a411958521cb300c9d69edb9ca6cba075303b0dc | https://github.com/rmodbus/rmodbus/blob/a411958521cb300c9d69edb9ca6cba075303b0dc/lib/rmodbus/slave.rb#L229-L256 |
19,557 | rmodbus/rmodbus | lib/rmodbus/proxy.rb | ModBus.ReadOnlyProxy.[] | def [](key)
if key.instance_of?(0.class)
@slave.send("read_#{@type}", key, 1)
elsif key.instance_of?(Range)
@slave.send("read_#{@type}s", key.first, key.count)
else
raise ModBus::Errors::ProxyException, "Invalid argument, must be integer or range. Was #{key.class}"
end
... | ruby | def [](key)
if key.instance_of?(0.class)
@slave.send("read_#{@type}", key, 1)
elsif key.instance_of?(Range)
@slave.send("read_#{@type}s", key.first, key.count)
else
raise ModBus::Errors::ProxyException, "Invalid argument, must be integer or range. Was #{key.class}"
end
... | [
"def",
"[]",
"(",
"key",
")",
"if",
"key",
".",
"instance_of?",
"(",
"0",
".",
"class",
")",
"@slave",
".",
"send",
"(",
"\"read_#{@type}\"",
",",
"key",
",",
"1",
")",
"elsif",
"key",
".",
"instance_of?",
"(",
"Range",
")",
"@slave",
".",
"send",
... | Initialize a proxy for a slave and a type of operation
Read single or multiple values from a modbus slave depending on whether a Fixnum or a Range was given.
Note that in the case of multiples, a pluralized version of the method is sent to the slave | [
"Initialize",
"a",
"proxy",
"for",
"a",
"slave",
"and",
"a",
"type",
"of",
"operation",
"Read",
"single",
"or",
"multiple",
"values",
"from",
"a",
"modbus",
"slave",
"depending",
"on",
"whether",
"a",
"Fixnum",
"or",
"a",
"Range",
"was",
"given",
".",
"N... | a411958521cb300c9d69edb9ca6cba075303b0dc | https://github.com/rmodbus/rmodbus/blob/a411958521cb300c9d69edb9ca6cba075303b0dc/lib/rmodbus/proxy.rb#L11-L19 |
19,558 | rmodbus/rmodbus | lib/rmodbus/proxy.rb | ModBus.ReadWriteProxy.[]= | def []=(key, val)
if key.instance_of?(0.class)
@slave.send("write_#{@type}", key, val)
elsif key.instance_of?(Range)
if key.count != val.size
raise ModBus::Errors::ProxyException, "The size of the range must match the size of the values (#{key.count} != #{val.size})"
end
... | ruby | def []=(key, val)
if key.instance_of?(0.class)
@slave.send("write_#{@type}", key, val)
elsif key.instance_of?(Range)
if key.count != val.size
raise ModBus::Errors::ProxyException, "The size of the range must match the size of the values (#{key.count} != #{val.size})"
end
... | [
"def",
"[]=",
"(",
"key",
",",
"val",
")",
"if",
"key",
".",
"instance_of?",
"(",
"0",
".",
"class",
")",
"@slave",
".",
"send",
"(",
"\"write_#{@type}\"",
",",
"key",
",",
"val",
")",
"elsif",
"key",
".",
"instance_of?",
"(",
"Range",
")",
"if",
"... | Write single or multiple values to a modbus slave depending on whether a Fixnum or a Range was given.
Note that in the case of multiples, a pluralized version of the method is sent to the slave. Also when
writing multiple values, the number of elements must match the number of registers in the range or an exception i... | [
"Write",
"single",
"or",
"multiple",
"values",
"to",
"a",
"modbus",
"slave",
"depending",
"on",
"whether",
"a",
"Fixnum",
"or",
"a",
"Range",
"was",
"given",
".",
"Note",
"that",
"in",
"the",
"case",
"of",
"multiples",
"a",
"pluralized",
"version",
"of",
... | a411958521cb300c9d69edb9ca6cba075303b0dc | https://github.com/rmodbus/rmodbus/blob/a411958521cb300c9d69edb9ca6cba075303b0dc/lib/rmodbus/proxy.rb#L26-L38 |
19,559 | rmodbus/rmodbus | lib/rmodbus/rtu.rb | ModBus.RTU.read_rtu_response | def read_rtu_response(io)
# Read the slave_id and function code
msg = nil
while msg.nil?
msg = io.read(2)
end
function_code = msg.getbyte(1)
case function_code
when 1,2,3,4 then
# read the third byte to find out how much more
# we need to read + CRC... | ruby | def read_rtu_response(io)
# Read the slave_id and function code
msg = nil
while msg.nil?
msg = io.read(2)
end
function_code = msg.getbyte(1)
case function_code
when 1,2,3,4 then
# read the third byte to find out how much more
# we need to read + CRC... | [
"def",
"read_rtu_response",
"(",
"io",
")",
"# Read the slave_id and function code",
"msg",
"=",
"nil",
"while",
"msg",
".",
"nil?",
"msg",
"=",
"io",
".",
"read",
"(",
"2",
")",
"end",
"function_code",
"=",
"msg",
".",
"getbyte",
"(",
"1",
")",
"case",
... | We have to read specific amounts of numbers of bytes from the network depending on the function code and content | [
"We",
"have",
"to",
"read",
"specific",
"amounts",
"of",
"numbers",
"of",
"bytes",
"from",
"the",
"network",
"depending",
"on",
"the",
"function",
"code",
"and",
"content"
] | a411958521cb300c9d69edb9ca6cba075303b0dc | https://github.com/rmodbus/rmodbus/blob/a411958521cb300c9d69edb9ca6cba075303b0dc/lib/rmodbus/rtu.rb#L6-L30 |
19,560 | rmodbus/rmodbus | lib/rmodbus/rtu.rb | ModBus.RTU.crc16 | def crc16(msg)
crc_lo = 0xff
crc_hi = 0xff
msg.unpack('c*').each do |byte|
i = crc_hi ^ byte
crc_hi = crc_lo ^ CrcHiTable[i]
crc_lo = CrcLoTable[i]
end
return ((crc_hi << 8) + crc_lo)
end | ruby | def crc16(msg)
crc_lo = 0xff
crc_hi = 0xff
msg.unpack('c*').each do |byte|
i = crc_hi ^ byte
crc_hi = crc_lo ^ CrcHiTable[i]
crc_lo = CrcLoTable[i]
end
return ((crc_hi << 8) + crc_lo)
end | [
"def",
"crc16",
"(",
"msg",
")",
"crc_lo",
"=",
"0xff",
"crc_hi",
"=",
"0xff",
"msg",
".",
"unpack",
"(",
"'c*'",
")",
".",
"each",
"do",
"|",
"byte",
"|",
"i",
"=",
"crc_hi",
"^",
"byte",
"crc_hi",
"=",
"crc_lo",
"^",
"CrcHiTable",
"[",
"i",
"]"... | Calc CRC16 for massage | [
"Calc",
"CRC16",
"for",
"massage"
] | a411958521cb300c9d69edb9ca6cba075303b0dc | https://github.com/rmodbus/rmodbus/blob/a411958521cb300c9d69edb9ca6cba075303b0dc/lib/rmodbus/rtu.rb#L111-L122 |
19,561 | ammar/regexp_parser | lib/regexp_parser/expression/methods/traverse.rb | Regexp::Expression.Subexpression.each_expression | def each_expression(include_self = false, &block)
traverse(include_self) do |event, exp, index|
yield(exp, index) unless event == :exit
end
end | ruby | def each_expression(include_self = false, &block)
traverse(include_self) do |event, exp, index|
yield(exp, index) unless event == :exit
end
end | [
"def",
"each_expression",
"(",
"include_self",
"=",
"false",
",",
"&",
"block",
")",
"traverse",
"(",
"include_self",
")",
"do",
"|",
"event",
",",
"exp",
",",
"index",
"|",
"yield",
"(",
"exp",
",",
"index",
")",
"unless",
"event",
"==",
":exit",
"end... | Iterates over the expressions of this expression as an array, passing
the expression and its index within its parent to the given block. | [
"Iterates",
"over",
"the",
"expressions",
"of",
"this",
"expression",
"as",
"an",
"array",
"passing",
"the",
"expression",
"and",
"its",
"index",
"within",
"its",
"parent",
"to",
"the",
"given",
"block",
"."
] | 24cb67d5f6e7ddaab2ff9806e5f60bb6fcb7d5ba | https://github.com/ammar/regexp_parser/blob/24cb67d5f6e7ddaab2ff9806e5f60bb6fcb7d5ba/lib/regexp_parser/expression/methods/traverse.rb#L39-L43 |
19,562 | ammar/regexp_parser | lib/regexp_parser/expression/methods/traverse.rb | Regexp::Expression.Subexpression.flat_map | def flat_map(include_self = false, &block)
result = []
each_expression(include_self) do |exp, index|
if block_given?
result << yield(exp, index)
else
result << [exp, index]
end
end
result
end | ruby | def flat_map(include_self = false, &block)
result = []
each_expression(include_self) do |exp, index|
if block_given?
result << yield(exp, index)
else
result << [exp, index]
end
end
result
end | [
"def",
"flat_map",
"(",
"include_self",
"=",
"false",
",",
"&",
"block",
")",
"result",
"=",
"[",
"]",
"each_expression",
"(",
"include_self",
")",
"do",
"|",
"exp",
",",
"index",
"|",
"if",
"block_given?",
"result",
"<<",
"yield",
"(",
"exp",
",",
"in... | Returns a new array with the results of calling the given block once
for every expression. If a block is not given, returns an array with
each expression and its level index as an array. | [
"Returns",
"a",
"new",
"array",
"with",
"the",
"results",
"of",
"calling",
"the",
"given",
"block",
"once",
"for",
"every",
"expression",
".",
"If",
"a",
"block",
"is",
"not",
"given",
"returns",
"an",
"array",
"with",
"each",
"expression",
"and",
"its",
... | 24cb67d5f6e7ddaab2ff9806e5f60bb6fcb7d5ba | https://github.com/ammar/regexp_parser/blob/24cb67d5f6e7ddaab2ff9806e5f60bb6fcb7d5ba/lib/regexp_parser/expression/methods/traverse.rb#L48-L60 |
19,563 | kobaltz/clamby | lib/clamby/command.rb | Clamby.Command.run | def run(executable, *args)
executable_full = executable_path(executable)
self.command = args | default_args
self.command = command.sort.unshift(executable_full)
system(*self.command, system_options)
end | ruby | def run(executable, *args)
executable_full = executable_path(executable)
self.command = args | default_args
self.command = command.sort.unshift(executable_full)
system(*self.command, system_options)
end | [
"def",
"run",
"(",
"executable",
",",
"*",
"args",
")",
"executable_full",
"=",
"executable_path",
"(",
"executable",
")",
"self",
".",
"command",
"=",
"args",
"|",
"default_args",
"self",
".",
"command",
"=",
"command",
".",
"sort",
".",
"unshift",
"(",
... | Run the given commands via a system call.
The executable must be one of the permitted ClamAV executables.
The arguments will be combined with default arguments if needed.
The arguments are sorted alphabetically before being passed to the system.
Examples:
run('clamscan', file, '--verbose')
run('clamscan', '-... | [
"Run",
"the",
"given",
"commands",
"via",
"a",
"system",
"call",
".",
"The",
"executable",
"must",
"be",
"one",
"of",
"the",
"permitted",
"ClamAV",
"executables",
".",
"The",
"arguments",
"will",
"be",
"combined",
"with",
"default",
"arguments",
"if",
"neede... | 8e04f7c2a467721b9ac2f8b266a228e32f4ccfbe | https://github.com/kobaltz/clamby/blob/8e04f7c2a467721b9ac2f8b266a228e32f4ccfbe/lib/clamby/command.rb#L66-L72 |
19,564 | couchrest/couchrest | lib/couchrest/design.rb | CouchRest.Design.view_on | def view_on db, view_name, query = {}, &block
raise ArgumentError, "View query options must be set as symbols!" if query.keys.find{|k| k.is_a?(String)}
view_name = view_name.to_s
view_slug = "#{name}/#{view_name}"
# Set the default query options
query = view_defaults(view_name).merge(query... | ruby | def view_on db, view_name, query = {}, &block
raise ArgumentError, "View query options must be set as symbols!" if query.keys.find{|k| k.is_a?(String)}
view_name = view_name.to_s
view_slug = "#{name}/#{view_name}"
# Set the default query options
query = view_defaults(view_name).merge(query... | [
"def",
"view_on",
"db",
",",
"view_name",
",",
"query",
"=",
"{",
"}",
",",
"&",
"block",
"raise",
"ArgumentError",
",",
"\"View query options must be set as symbols!\"",
"if",
"query",
".",
"keys",
".",
"find",
"{",
"|",
"k",
"|",
"k",
".",
"is_a?",
"(",
... | Dispatches to any named view in a specific database | [
"Dispatches",
"to",
"any",
"named",
"view",
"in",
"a",
"specific",
"database"
] | cdd3ad30b9fa9aad5464cb4647c18c198b2c48d9 | https://github.com/couchrest/couchrest/blob/cdd3ad30b9fa9aad5464cb4647c18c198b2c48d9/lib/couchrest/design.rb#L43-L53 |
19,565 | couchrest/couchrest | lib/couchrest/helper/attachments.rb | CouchRest.Attachments.put_attachment | def put_attachment(name, file, options={})
raise ArgumentError, "doc must be saved" unless self.rev
raise ArgumentError, "doc.database required to put_attachment" unless database
result = database.put_attachment(self, name, file, options)
self['_rev'] = result['rev']
result['ok']
end | ruby | def put_attachment(name, file, options={})
raise ArgumentError, "doc must be saved" unless self.rev
raise ArgumentError, "doc.database required to put_attachment" unless database
result = database.put_attachment(self, name, file, options)
self['_rev'] = result['rev']
result['ok']
end | [
"def",
"put_attachment",
"(",
"name",
",",
"file",
",",
"options",
"=",
"{",
"}",
")",
"raise",
"ArgumentError",
",",
"\"doc must be saved\"",
"unless",
"self",
".",
"rev",
"raise",
"ArgumentError",
",",
"\"doc.database required to put_attachment\"",
"unless",
"data... | saves an attachment directly to couchdb | [
"saves",
"an",
"attachment",
"directly",
"to",
"couchdb"
] | cdd3ad30b9fa9aad5464cb4647c18c198b2c48d9 | https://github.com/couchrest/couchrest/blob/cdd3ad30b9fa9aad5464cb4647c18c198b2c48d9/lib/couchrest/helper/attachments.rb#L5-L11 |
19,566 | couchrest/couchrest | lib/couchrest/helper/attachments.rb | CouchRest.Attachments.fetch_attachment | def fetch_attachment(name)
raise ArgumentError, "doc must be saved" unless self.rev
raise ArgumentError, "doc.database required to put_attachment" unless database
database.fetch_attachment(self, name)
end | ruby | def fetch_attachment(name)
raise ArgumentError, "doc must be saved" unless self.rev
raise ArgumentError, "doc.database required to put_attachment" unless database
database.fetch_attachment(self, name)
end | [
"def",
"fetch_attachment",
"(",
"name",
")",
"raise",
"ArgumentError",
",",
"\"doc must be saved\"",
"unless",
"self",
".",
"rev",
"raise",
"ArgumentError",
",",
"\"doc.database required to put_attachment\"",
"unless",
"database",
"database",
".",
"fetch_attachment",
"(",... | returns an attachment's data | [
"returns",
"an",
"attachment",
"s",
"data"
] | cdd3ad30b9fa9aad5464cb4647c18c198b2c48d9 | https://github.com/couchrest/couchrest/blob/cdd3ad30b9fa9aad5464cb4647c18c198b2c48d9/lib/couchrest/helper/attachments.rb#L14-L18 |
19,567 | couchrest/couchrest | lib/couchrest/helper/attachments.rb | CouchRest.Attachments.delete_attachment | def delete_attachment(name, force=false)
raise ArgumentError, "doc.database required to delete_attachment" unless database
result = database.delete_attachment(self, name, force)
self['_rev'] = result['rev']
result['ok']
end | ruby | def delete_attachment(name, force=false)
raise ArgumentError, "doc.database required to delete_attachment" unless database
result = database.delete_attachment(self, name, force)
self['_rev'] = result['rev']
result['ok']
end | [
"def",
"delete_attachment",
"(",
"name",
",",
"force",
"=",
"false",
")",
"raise",
"ArgumentError",
",",
"\"doc.database required to delete_attachment\"",
"unless",
"database",
"result",
"=",
"database",
".",
"delete_attachment",
"(",
"self",
",",
"name",
",",
"forc... | deletes an attachment directly from couchdb | [
"deletes",
"an",
"attachment",
"directly",
"from",
"couchdb"
] | cdd3ad30b9fa9aad5464cb4647c18c198b2c48d9 | https://github.com/couchrest/couchrest/blob/cdd3ad30b9fa9aad5464cb4647c18c198b2c48d9/lib/couchrest/helper/attachments.rb#L21-L26 |
19,568 | couchrest/couchrest | lib/couchrest/document.rb | CouchRest.Document.uri | def uri(append_rev = false)
return nil if new?
couch_uri = "#{database.root}/#{CGI.escape(id)}"
if append_rev == true
couch_uri << "?rev=#{rev}"
elsif append_rev.kind_of?(Integer)
couch_uri << "?rev=#{append_rev}"
end
couch_uri
end | ruby | def uri(append_rev = false)
return nil if new?
couch_uri = "#{database.root}/#{CGI.escape(id)}"
if append_rev == true
couch_uri << "?rev=#{rev}"
elsif append_rev.kind_of?(Integer)
couch_uri << "?rev=#{append_rev}"
end
couch_uri
end | [
"def",
"uri",
"(",
"append_rev",
"=",
"false",
")",
"return",
"nil",
"if",
"new?",
"couch_uri",
"=",
"\"#{database.root}/#{CGI.escape(id)}\"",
"if",
"append_rev",
"==",
"true",
"couch_uri",
"<<",
"\"?rev=#{rev}\"",
"elsif",
"append_rev",
".",
"kind_of?",
"(",
"Int... | Returns the CouchDB uri for the document | [
"Returns",
"the",
"CouchDB",
"uri",
"for",
"the",
"document"
] | cdd3ad30b9fa9aad5464cb4647c18c198b2c48d9 | https://github.com/couchrest/couchrest/blob/cdd3ad30b9fa9aad5464cb4647c18c198b2c48d9/lib/couchrest/document.rb#L78-L87 |
19,569 | couchrest/couchrest | lib/couchrest/connection.rb | CouchRest.Connection.clean_uri | def clean_uri(uri)
uri = uri.dup
uri.path = ""
uri.query = nil
uri.fragment = nil
uri
end | ruby | def clean_uri(uri)
uri = uri.dup
uri.path = ""
uri.query = nil
uri.fragment = nil
uri
end | [
"def",
"clean_uri",
"(",
"uri",
")",
"uri",
"=",
"uri",
".",
"dup",
"uri",
".",
"path",
"=",
"\"\"",
"uri",
".",
"query",
"=",
"nil",
"uri",
".",
"fragment",
"=",
"nil",
"uri",
"end"
] | Duplicate and remove excess baggage from the provided URI | [
"Duplicate",
"and",
"remove",
"excess",
"baggage",
"from",
"the",
"provided",
"URI"
] | cdd3ad30b9fa9aad5464cb4647c18c198b2c48d9 | https://github.com/couchrest/couchrest/blob/cdd3ad30b9fa9aad5464cb4647c18c198b2c48d9/lib/couchrest/connection.rb#L102-L108 |
19,570 | couchrest/couchrest | lib/couchrest/connection.rb | CouchRest.Connection.prepare_http_connection | def prepare_http_connection
conn = HTTPClient.new(options[:proxy] || self.class.proxy)
set_http_connection_options(conn, options)
conn
end | ruby | def prepare_http_connection
conn = HTTPClient.new(options[:proxy] || self.class.proxy)
set_http_connection_options(conn, options)
conn
end | [
"def",
"prepare_http_connection",
"conn",
"=",
"HTTPClient",
".",
"new",
"(",
"options",
"[",
":proxy",
"]",
"||",
"self",
".",
"class",
".",
"proxy",
")",
"set_http_connection_options",
"(",
"conn",
",",
"options",
")",
"conn",
"end"
] | Take a look at the options povided and try to apply them to the HTTP conneciton. | [
"Take",
"a",
"look",
"at",
"the",
"options",
"povided",
"and",
"try",
"to",
"apply",
"them",
"to",
"the",
"HTTP",
"conneciton",
"."
] | cdd3ad30b9fa9aad5464cb4647c18c198b2c48d9 | https://github.com/couchrest/couchrest/blob/cdd3ad30b9fa9aad5464cb4647c18c198b2c48d9/lib/couchrest/connection.rb#L111-L115 |
19,571 | couchrest/couchrest | lib/couchrest/connection.rb | CouchRest.Connection.set_http_connection_options | def set_http_connection_options(conn, opts)
# Authentication
unless uri.user.to_s.empty?
conn.force_basic_auth = true
conn.set_auth(uri.to_s, uri.user, uri.password)
end
# SSL Certificate option mapping
if opts.include?(:verify_ssl)
conn.ssl_config.verify_mode = op... | ruby | def set_http_connection_options(conn, opts)
# Authentication
unless uri.user.to_s.empty?
conn.force_basic_auth = true
conn.set_auth(uri.to_s, uri.user, uri.password)
end
# SSL Certificate option mapping
if opts.include?(:verify_ssl)
conn.ssl_config.verify_mode = op... | [
"def",
"set_http_connection_options",
"(",
"conn",
",",
"opts",
")",
"# Authentication",
"unless",
"uri",
".",
"user",
".",
"to_s",
".",
"empty?",
"conn",
".",
"force_basic_auth",
"=",
"true",
"conn",
".",
"set_auth",
"(",
"uri",
".",
"to_s",
",",
"uri",
"... | Prepare the http connection options for HTTPClient.
We try to maintain RestClient compatability in option names as this is what we used before. | [
"Prepare",
"the",
"http",
"connection",
"options",
"for",
"HTTPClient",
".",
"We",
"try",
"to",
"maintain",
"RestClient",
"compatability",
"in",
"option",
"names",
"as",
"this",
"is",
"what",
"we",
"used",
"before",
"."
] | cdd3ad30b9fa9aad5464cb4647c18c198b2c48d9 | https://github.com/couchrest/couchrest/blob/cdd3ad30b9fa9aad5464cb4647c18c198b2c48d9/lib/couchrest/connection.rb#L119-L138 |
19,572 | couchrest/couchrest | lib/couchrest/connection.rb | CouchRest.Connection.send_request | def send_request(req, &block)
@last_response = @http.request(req.delete(:method), req.delete(:uri), req, &block)
end | ruby | def send_request(req, &block)
@last_response = @http.request(req.delete(:method), req.delete(:uri), req, &block)
end | [
"def",
"send_request",
"(",
"req",
",",
"&",
"block",
")",
"@last_response",
"=",
"@http",
".",
"request",
"(",
"req",
".",
"delete",
"(",
":method",
")",
",",
"req",
".",
"delete",
"(",
":uri",
")",
",",
"req",
",",
"block",
")",
"end"
] | Send request, and leave a reference to the response for debugging purposes | [
"Send",
"request",
"and",
"leave",
"a",
"reference",
"to",
"the",
"response",
"for",
"debugging",
"purposes"
] | cdd3ad30b9fa9aad5464cb4647c18c198b2c48d9 | https://github.com/couchrest/couchrest/blob/cdd3ad30b9fa9aad5464cb4647c18c198b2c48d9/lib/couchrest/connection.rb#L178-L180 |
19,573 | couchrest/couchrest | lib/couchrest/connection.rb | CouchRest.Connection.payload_from_doc | def payload_from_doc(req, doc, opts = {})
if doc.is_a?(IO) || doc.is_a?(StringIO) || doc.is_a?(Tempfile) # attachments
req[:header]['Content-Type'] = mime_for(req[:uri].path)
doc
elsif opts[:raw] || doc.nil?
doc
else
MultiJson.encode(doc.respond_to?(:as_couch_json) ? do... | ruby | def payload_from_doc(req, doc, opts = {})
if doc.is_a?(IO) || doc.is_a?(StringIO) || doc.is_a?(Tempfile) # attachments
req[:header]['Content-Type'] = mime_for(req[:uri].path)
doc
elsif opts[:raw] || doc.nil?
doc
else
MultiJson.encode(doc.respond_to?(:as_couch_json) ? do... | [
"def",
"payload_from_doc",
"(",
"req",
",",
"doc",
",",
"opts",
"=",
"{",
"}",
")",
"if",
"doc",
".",
"is_a?",
"(",
"IO",
")",
"||",
"doc",
".",
"is_a?",
"(",
"StringIO",
")",
"||",
"doc",
".",
"is_a?",
"(",
"Tempfile",
")",
"# attachments",
"req",... | Check if the provided doc is nil or special IO device or temp file. If not,
encode it into a string.
The options supported are:
* :raw TrueClass, if true the payload will not be altered. | [
"Check",
"if",
"the",
"provided",
"doc",
"is",
"nil",
"or",
"special",
"IO",
"device",
"or",
"temp",
"file",
".",
"If",
"not",
"encode",
"it",
"into",
"a",
"string",
"."
] | cdd3ad30b9fa9aad5464cb4647c18c198b2c48d9 | https://github.com/couchrest/couchrest/blob/cdd3ad30b9fa9aad5464cb4647c18c198b2c48d9/lib/couchrest/connection.rb#L209-L218 |
19,574 | couchrest/couchrest | lib/couchrest/attributes.rb | CouchRest.Attributes.as_couch_json | def as_couch_json
_attributes.inject({}) {|h, (k,v)| h[k] = v.respond_to?(:as_couch_json) ? v.as_couch_json : v; h}
end | ruby | def as_couch_json
_attributes.inject({}) {|h, (k,v)| h[k] = v.respond_to?(:as_couch_json) ? v.as_couch_json : v; h}
end | [
"def",
"as_couch_json",
"_attributes",
".",
"inject",
"(",
"{",
"}",
")",
"{",
"|",
"h",
",",
"(",
"k",
",",
"v",
")",
"|",
"h",
"[",
"k",
"]",
"=",
"v",
".",
"respond_to?",
"(",
":as_couch_json",
")",
"?",
"v",
".",
"as_couch_json",
":",
"v",
... | Provide JSON data hash that can be stored in the database.
Will go through each attribute value and request the `as_couch_json` method
on each if available, or return the value as-is. | [
"Provide",
"JSON",
"data",
"hash",
"that",
"can",
"be",
"stored",
"in",
"the",
"database",
".",
"Will",
"go",
"through",
"each",
"attribute",
"value",
"and",
"request",
"the",
"as_couch_json",
"method",
"on",
"each",
"if",
"available",
"or",
"return",
"the",... | cdd3ad30b9fa9aad5464cb4647c18c198b2c48d9 | https://github.com/couchrest/couchrest/blob/cdd3ad30b9fa9aad5464cb4647c18c198b2c48d9/lib/couchrest/attributes.rb#L66-L68 |
19,575 | couchrest/couchrest | lib/couchrest/server.rb | CouchRest.Server.database! | def database!(name)
connection.head name # Check if the URL is valid
database(name)
rescue CouchRest::NotFound # Thrown if the HTTP HEAD fails
create_db(name)
end | ruby | def database!(name)
connection.head name # Check if the URL is valid
database(name)
rescue CouchRest::NotFound # Thrown if the HTTP HEAD fails
create_db(name)
end | [
"def",
"database!",
"(",
"name",
")",
"connection",
".",
"head",
"name",
"# Check if the URL is valid",
"database",
"(",
"name",
")",
"rescue",
"CouchRest",
"::",
"NotFound",
"# Thrown if the HTTP HEAD fails",
"create_db",
"(",
"name",
")",
"end"
] | Creates the database if it doesn't exist | [
"Creates",
"the",
"database",
"if",
"it",
"doesn",
"t",
"exist"
] | cdd3ad30b9fa9aad5464cb4647c18c198b2c48d9 | https://github.com/couchrest/couchrest/blob/cdd3ad30b9fa9aad5464cb4647c18c198b2c48d9/lib/couchrest/server.rb#L46-L51 |
19,576 | couchrest/couchrest | lib/couchrest/server.rb | CouchRest.Server.next_uuid | def next_uuid(count = @uuid_batch_count)
if uuids.nil? || uuids.empty?
@uuids = connection.get("_uuids?count=#{count}")["uuids"]
end
uuids.pop
end | ruby | def next_uuid(count = @uuid_batch_count)
if uuids.nil? || uuids.empty?
@uuids = connection.get("_uuids?count=#{count}")["uuids"]
end
uuids.pop
end | [
"def",
"next_uuid",
"(",
"count",
"=",
"@uuid_batch_count",
")",
"if",
"uuids",
".",
"nil?",
"||",
"uuids",
".",
"empty?",
"@uuids",
"=",
"connection",
".",
"get",
"(",
"\"_uuids?count=#{count}\"",
")",
"[",
"\"uuids\"",
"]",
"end",
"uuids",
".",
"pop",
"e... | Retrive an unused UUID from CouchDB. Server instances manage caching a list of unused UUIDs. | [
"Retrive",
"an",
"unused",
"UUID",
"from",
"CouchDB",
".",
"Server",
"instances",
"manage",
"caching",
"a",
"list",
"of",
"unused",
"UUIDs",
"."
] | cdd3ad30b9fa9aad5464cb4647c18c198b2c48d9 | https://github.com/couchrest/couchrest/blob/cdd3ad30b9fa9aad5464cb4647c18c198b2c48d9/lib/couchrest/server.rb#L70-L75 |
19,577 | couchrest/couchrest | lib/couchrest/rest_api.rb | CouchRest.RestAPI.get | def get(url, options = {})
connection(url, options) do |uri, conn|
conn.get(uri.request_uri, options)
end
end | ruby | def get(url, options = {})
connection(url, options) do |uri, conn|
conn.get(uri.request_uri, options)
end
end | [
"def",
"get",
"(",
"url",
",",
"options",
"=",
"{",
"}",
")",
"connection",
"(",
"url",
",",
"options",
")",
"do",
"|",
"uri",
",",
"conn",
"|",
"conn",
".",
"get",
"(",
"uri",
".",
"request_uri",
",",
"options",
")",
"end",
"end"
] | Send a GET request. | [
"Send",
"a",
"GET",
"request",
"."
] | cdd3ad30b9fa9aad5464cb4647c18c198b2c48d9 | https://github.com/couchrest/couchrest/blob/cdd3ad30b9fa9aad5464cb4647c18c198b2c48d9/lib/couchrest/rest_api.rb#L14-L18 |
19,578 | couchrest/couchrest | lib/couchrest/rest_api.rb | CouchRest.RestAPI.put | def put(url, doc = nil, options = {})
connection(url, options) do |uri, conn|
conn.put(uri.request_uri, doc, options)
end
end | ruby | def put(url, doc = nil, options = {})
connection(url, options) do |uri, conn|
conn.put(uri.request_uri, doc, options)
end
end | [
"def",
"put",
"(",
"url",
",",
"doc",
"=",
"nil",
",",
"options",
"=",
"{",
"}",
")",
"connection",
"(",
"url",
",",
"options",
")",
"do",
"|",
"uri",
",",
"conn",
"|",
"conn",
".",
"put",
"(",
"uri",
".",
"request_uri",
",",
"doc",
",",
"optio... | Send a PUT request. | [
"Send",
"a",
"PUT",
"request",
"."
] | cdd3ad30b9fa9aad5464cb4647c18c198b2c48d9 | https://github.com/couchrest/couchrest/blob/cdd3ad30b9fa9aad5464cb4647c18c198b2c48d9/lib/couchrest/rest_api.rb#L21-L25 |
19,579 | couchrest/couchrest | lib/couchrest/rest_api.rb | CouchRest.RestAPI.delete | def delete(url, options = {})
connection(url, options) do |uri, conn|
conn.delete(uri.request_uri, options)
end
end | ruby | def delete(url, options = {})
connection(url, options) do |uri, conn|
conn.delete(uri.request_uri, options)
end
end | [
"def",
"delete",
"(",
"url",
",",
"options",
"=",
"{",
"}",
")",
"connection",
"(",
"url",
",",
"options",
")",
"do",
"|",
"uri",
",",
"conn",
"|",
"conn",
".",
"delete",
"(",
"uri",
".",
"request_uri",
",",
"options",
")",
"end",
"end"
] | Send a DELETE request. | [
"Send",
"a",
"DELETE",
"request",
"."
] | cdd3ad30b9fa9aad5464cb4647c18c198b2c48d9 | https://github.com/couchrest/couchrest/blob/cdd3ad30b9fa9aad5464cb4647c18c198b2c48d9/lib/couchrest/rest_api.rb#L35-L39 |
19,580 | couchrest/couchrest | lib/couchrest/database.rb | CouchRest.Database.replicate_from | def replicate_from(other_db, continuous = false, create_target = false, doc_ids = nil)
replicate(other_db, continuous, :target => name, :create_target => create_target, :doc_ids => doc_ids)
end | ruby | def replicate_from(other_db, continuous = false, create_target = false, doc_ids = nil)
replicate(other_db, continuous, :target => name, :create_target => create_target, :doc_ids => doc_ids)
end | [
"def",
"replicate_from",
"(",
"other_db",
",",
"continuous",
"=",
"false",
",",
"create_target",
"=",
"false",
",",
"doc_ids",
"=",
"nil",
")",
"replicate",
"(",
"other_db",
",",
"continuous",
",",
":target",
"=>",
"name",
",",
":create_target",
"=>",
"creat... | Replicates via "pulling" from another database to this database. Makes no attempt to deal with conflicts. | [
"Replicates",
"via",
"pulling",
"from",
"another",
"database",
"to",
"this",
"database",
".",
"Makes",
"no",
"attempt",
"to",
"deal",
"with",
"conflicts",
"."
] | cdd3ad30b9fa9aad5464cb4647c18c198b2c48d9 | https://github.com/couchrest/couchrest/blob/cdd3ad30b9fa9aad5464cb4647c18c198b2c48d9/lib/couchrest/database.rb#L75-L77 |
19,581 | couchrest/couchrest | lib/couchrest/database.rb | CouchRest.Database.replicate_to | def replicate_to(other_db, continuous = false, create_target = false, doc_ids = nil)
replicate(other_db, continuous, :source => name, :create_target => create_target, :doc_ids => doc_ids)
end | ruby | def replicate_to(other_db, continuous = false, create_target = false, doc_ids = nil)
replicate(other_db, continuous, :source => name, :create_target => create_target, :doc_ids => doc_ids)
end | [
"def",
"replicate_to",
"(",
"other_db",
",",
"continuous",
"=",
"false",
",",
"create_target",
"=",
"false",
",",
"doc_ids",
"=",
"nil",
")",
"replicate",
"(",
"other_db",
",",
"continuous",
",",
":source",
"=>",
"name",
",",
":create_target",
"=>",
"create_... | Replicates via "pushing" to another database. Makes no attempt to deal with conflicts. | [
"Replicates",
"via",
"pushing",
"to",
"another",
"database",
".",
"Makes",
"no",
"attempt",
"to",
"deal",
"with",
"conflicts",
"."
] | cdd3ad30b9fa9aad5464cb4647c18c198b2c48d9 | https://github.com/couchrest/couchrest/blob/cdd3ad30b9fa9aad5464cb4647c18c198b2c48d9/lib/couchrest/database.rb#L80-L82 |
19,582 | couchrest/couchrest | lib/couchrest/database.rb | CouchRest.Database.get! | def get!(id, params = {})
slug = escape_docid(id)
url = CouchRest.paramify_url("#{path}/#{slug}", params)
result = connection.get(url)
return result unless result.is_a?(Hash)
doc = if /^_design/ =~ result["_id"]
Design.new(result)
else
Document.new(result)
end
... | ruby | def get!(id, params = {})
slug = escape_docid(id)
url = CouchRest.paramify_url("#{path}/#{slug}", params)
result = connection.get(url)
return result unless result.is_a?(Hash)
doc = if /^_design/ =~ result["_id"]
Design.new(result)
else
Document.new(result)
end
... | [
"def",
"get!",
"(",
"id",
",",
"params",
"=",
"{",
"}",
")",
"slug",
"=",
"escape_docid",
"(",
"id",
")",
"url",
"=",
"CouchRest",
".",
"paramify_url",
"(",
"\"#{path}/#{slug}\"",
",",
"params",
")",
"result",
"=",
"connection",
".",
"get",
"(",
"url",... | == Retrieving and saving single documents
GET a document from CouchDB, by id. Returns a Document, Design, or raises an exception
if the document does not exist. | [
"==",
"Retrieving",
"and",
"saving",
"single",
"documents",
"GET",
"a",
"document",
"from",
"CouchDB",
"by",
"id",
".",
"Returns",
"a",
"Document",
"Design",
"or",
"raises",
"an",
"exception",
"if",
"the",
"document",
"does",
"not",
"exist",
"."
] | cdd3ad30b9fa9aad5464cb4647c18c198b2c48d9 | https://github.com/couchrest/couchrest/blob/cdd3ad30b9fa9aad5464cb4647c18c198b2c48d9/lib/couchrest/database.rb#L95-L107 |
19,583 | couchrest/couchrest | lib/couchrest/database.rb | CouchRest.Database.bulk_save | def bulk_save(docs = nil, opts = {})
opts = { :use_uuids => true, :all_or_nothing => false }.update(opts)
if docs.nil?
docs = @bulk_save_cache
@bulk_save_cache = []
end
if opts[:use_uuids]
ids, noids = docs.partition{|d|d['_id']}
uuid_count = [noids.length, @serve... | ruby | def bulk_save(docs = nil, opts = {})
opts = { :use_uuids => true, :all_or_nothing => false }.update(opts)
if docs.nil?
docs = @bulk_save_cache
@bulk_save_cache = []
end
if opts[:use_uuids]
ids, noids = docs.partition{|d|d['_id']}
uuid_count = [noids.length, @serve... | [
"def",
"bulk_save",
"(",
"docs",
"=",
"nil",
",",
"opts",
"=",
"{",
"}",
")",
"opts",
"=",
"{",
":use_uuids",
"=>",
"true",
",",
":all_or_nothing",
"=>",
"false",
"}",
".",
"update",
"(",
"opts",
")",
"if",
"docs",
".",
"nil?",
"docs",
"=",
"@bulk_... | POST an array of documents to CouchDB. If any of the documents are
missing ids, supply one from the uuid cache.
If called with no arguments, bulk saves the cache of documents to be bulk saved. | [
"POST",
"an",
"array",
"of",
"documents",
"to",
"CouchDB",
".",
"If",
"any",
"of",
"the",
"documents",
"are",
"missing",
"ids",
"supply",
"one",
"from",
"the",
"uuid",
"cache",
"."
] | cdd3ad30b9fa9aad5464cb4647c18c198b2c48d9 | https://github.com/couchrest/couchrest/blob/cdd3ad30b9fa9aad5464cb4647c18c198b2c48d9/lib/couchrest/database.rb#L187-L209 |
19,584 | couchrest/couchrest | lib/couchrest/database.rb | CouchRest.Database.update_doc | def update_doc(doc_id, params = {}, update_limit = 10)
resp = {'ok' => false}
last_fail = nil
until resp['ok'] or update_limit <= 0
doc = self.get(doc_id, params)
yield doc
begin
resp = self.save_doc doc
rescue CouchRest::RequestFailed => e
if e.htt... | ruby | def update_doc(doc_id, params = {}, update_limit = 10)
resp = {'ok' => false}
last_fail = nil
until resp['ok'] or update_limit <= 0
doc = self.get(doc_id, params)
yield doc
begin
resp = self.save_doc doc
rescue CouchRest::RequestFailed => e
if e.htt... | [
"def",
"update_doc",
"(",
"doc_id",
",",
"params",
"=",
"{",
"}",
",",
"update_limit",
"=",
"10",
")",
"resp",
"=",
"{",
"'ok'",
"=>",
"false",
"}",
"last_fail",
"=",
"nil",
"until",
"resp",
"[",
"'ok'",
"]",
"or",
"update_limit",
"<=",
"0",
"doc",
... | Updates the given doc by yielding the current state of the doc
and trying to update update_limit times. Returns the doc
if successfully updated without hitting the limit.
If the limit is reached, the last execption will be raised. | [
"Updates",
"the",
"given",
"doc",
"by",
"yielding",
"the",
"current",
"state",
"of",
"the",
"doc",
"and",
"trying",
"to",
"update",
"update_limit",
"times",
".",
"Returns",
"the",
"doc",
"if",
"successfully",
"updated",
"without",
"hitting",
"the",
"limit",
... | cdd3ad30b9fa9aad5464cb4647c18c198b2c48d9 | https://github.com/couchrest/couchrest/blob/cdd3ad30b9fa9aad5464cb4647c18c198b2c48d9/lib/couchrest/database.rb#L246-L267 |
19,585 | couchrest/couchrest | lib/couchrest/database.rb | CouchRest.Database.put_attachment | def put_attachment(doc, name, file, options = {})
file = StringIO.new(file) if file.is_a?(String)
connection.put path_for_attachment(doc, name), file, options
end | ruby | def put_attachment(doc, name, file, options = {})
file = StringIO.new(file) if file.is_a?(String)
connection.put path_for_attachment(doc, name), file, options
end | [
"def",
"put_attachment",
"(",
"doc",
",",
"name",
",",
"file",
",",
"options",
"=",
"{",
"}",
")",
"file",
"=",
"StringIO",
".",
"new",
"(",
"file",
")",
"if",
"file",
".",
"is_a?",
"(",
"String",
")",
"connection",
".",
"put",
"path_for_attachment",
... | PUT an attachment directly to CouchDB, expects an IO object, or a string
that will be converted to a StringIO in the 'file' parameter. | [
"PUT",
"an",
"attachment",
"directly",
"to",
"CouchDB",
"expects",
"an",
"IO",
"object",
"or",
"a",
"string",
"that",
"will",
"be",
"converted",
"to",
"a",
"StringIO",
"in",
"the",
"file",
"parameter",
"."
] | cdd3ad30b9fa9aad5464cb4647c18c198b2c48d9 | https://github.com/couchrest/couchrest/blob/cdd3ad30b9fa9aad5464cb4647c18c198b2c48d9/lib/couchrest/database.rb#L341-L344 |
19,586 | couchrest/couchrest | lib/couchrest/database.rb | CouchRest.Database.delete_attachment | def delete_attachment(doc, name, force=false)
attach_path = path_for_attachment(doc, name)
begin
connection.delete(attach_path)
rescue Exception => error
if force
# get over a 409
doc = get(doc['_id'])
attach_path = path_for_attachment(doc, name)
... | ruby | def delete_attachment(doc, name, force=false)
attach_path = path_for_attachment(doc, name)
begin
connection.delete(attach_path)
rescue Exception => error
if force
# get over a 409
doc = get(doc['_id'])
attach_path = path_for_attachment(doc, name)
... | [
"def",
"delete_attachment",
"(",
"doc",
",",
"name",
",",
"force",
"=",
"false",
")",
"attach_path",
"=",
"path_for_attachment",
"(",
"doc",
",",
"name",
")",
"begin",
"connection",
".",
"delete",
"(",
"attach_path",
")",
"rescue",
"Exception",
"=>",
"error"... | DELETE an attachment directly from CouchDB | [
"DELETE",
"an",
"attachment",
"directly",
"from",
"CouchDB"
] | cdd3ad30b9fa9aad5464cb4647c18c198b2c48d9 | https://github.com/couchrest/couchrest/blob/cdd3ad30b9fa9aad5464cb4647c18c198b2c48d9/lib/couchrest/database.rb#L347-L361 |
19,587 | couchrest/couchrest_model | lib/couchrest/model/property.rb | CouchRest::Model.Property.cast_value | def cast_value(parent, value)
if !allow_blank && value.to_s.empty?
nil
else
value = typecast_value(parent, self, value)
associate_casted_value_to_parent(parent, value)
end
end | ruby | def cast_value(parent, value)
if !allow_blank && value.to_s.empty?
nil
else
value = typecast_value(parent, self, value)
associate_casted_value_to_parent(parent, value)
end
end | [
"def",
"cast_value",
"(",
"parent",
",",
"value",
")",
"if",
"!",
"allow_blank",
"&&",
"value",
".",
"to_s",
".",
"empty?",
"nil",
"else",
"value",
"=",
"typecast_value",
"(",
"parent",
",",
"self",
",",
"value",
")",
"associate_casted_value_to_parent",
"(",... | Cast an individual value | [
"Cast",
"an",
"individual",
"value"
] | d30a61f52a8dc4a639105c2235353a41f11aeb53 | https://github.com/couchrest/couchrest_model/blob/d30a61f52a8dc4a639105c2235353a41f11aeb53/lib/couchrest/model/property.rb#L48-L55 |
19,588 | couchrest/couchrest_model | lib/couchrest/model/property.rb | CouchRest::Model.Property.build | def build(*args)
raise StandardError, "Cannot build property without a class" if @type.nil?
if @init_method.is_a?(Proc)
@init_method.call(*args)
else
@type.send(@init_method, *args)
end
end | ruby | def build(*args)
raise StandardError, "Cannot build property without a class" if @type.nil?
if @init_method.is_a?(Proc)
@init_method.call(*args)
else
@type.send(@init_method, *args)
end
end | [
"def",
"build",
"(",
"*",
"args",
")",
"raise",
"StandardError",
",",
"\"Cannot build property without a class\"",
"if",
"@type",
".",
"nil?",
"if",
"@init_method",
".",
"is_a?",
"(",
"Proc",
")",
"@init_method",
".",
"call",
"(",
"args",
")",
"else",
"@type",... | Initialize a new instance of a property's type ready to be
used. If a proc is defined for the init method, it will be used instead of
a normal call to the class. | [
"Initialize",
"a",
"new",
"instance",
"of",
"a",
"property",
"s",
"type",
"ready",
"to",
"be",
"used",
".",
"If",
"a",
"proc",
"is",
"defined",
"for",
"the",
"init",
"method",
"it",
"will",
"be",
"used",
"instead",
"of",
"a",
"normal",
"call",
"to",
... | d30a61f52a8dc4a639105c2235353a41f11aeb53 | https://github.com/couchrest/couchrest_model/blob/d30a61f52a8dc4a639105c2235353a41f11aeb53/lib/couchrest/model/property.rb#L70-L78 |
19,589 | tedconf/front_end_builds | lib/front_end_builds/ext/routes.rb | ActionDispatch::Routing.Mapper.front_end | def front_end(name, path = name, options = {})
defaults = {
app_name: name
}.merge(options)
# Create a new build for this app.
post(
"#{path}" => "front_end_builds/builds#create",
defaults: {
app_name: name
}
)
# Get a build for this ap... | ruby | def front_end(name, path = name, options = {})
defaults = {
app_name: name
}.merge(options)
# Create a new build for this app.
post(
"#{path}" => "front_end_builds/builds#create",
defaults: {
app_name: name
}
)
# Get a build for this ap... | [
"def",
"front_end",
"(",
"name",
",",
"path",
"=",
"name",
",",
"options",
"=",
"{",
"}",
")",
"defaults",
"=",
"{",
"app_name",
":",
"name",
"}",
".",
"merge",
"(",
"options",
")",
"# Create a new build for this app.",
"post",
"(",
"\"#{path}\"",
"=>",
... | Create a front end in your rails router. | [
"Create",
"a",
"front",
"end",
"in",
"your",
"rails",
"router",
"."
] | 98c4ec80b3641fc7c7248e5955ee6b0c3f6c19b6 | https://github.com/tedconf/front_end_builds/blob/98c4ec80b3641fc7c7248e5955ee6b0c3f6c19b6/lib/front_end_builds/ext/routes.rb#L7-L38 |
19,590 | simi/mongoid_paranoia | lib/mongoid/paranoia.rb | Mongoid.Paranoia.restore | def restore(opts = {})
run_callbacks(:restore) do
_paranoia_update("$unset" => { paranoid_field => true })
attributes.delete("deleted_at")
@destroyed = false
restore_relations if opts[:recursive]
true
end
end | ruby | def restore(opts = {})
run_callbacks(:restore) do
_paranoia_update("$unset" => { paranoid_field => true })
attributes.delete("deleted_at")
@destroyed = false
restore_relations if opts[:recursive]
true
end
end | [
"def",
"restore",
"(",
"opts",
"=",
"{",
"}",
")",
"run_callbacks",
"(",
":restore",
")",
"do",
"_paranoia_update",
"(",
"\"$unset\"",
"=>",
"{",
"paranoid_field",
"=>",
"true",
"}",
")",
"attributes",
".",
"delete",
"(",
"\"deleted_at\"",
")",
"@destroyed",... | Restores a previously soft-deleted document. Handles this by removing the
deleted_at flag.
@example Restore the document from deleted state.
document.restore
For resoring associated documents use :recursive => true
@example Restore the associated documents from deleted state.
document.restore(:recursive => ... | [
"Restores",
"a",
"previously",
"soft",
"-",
"deleted",
"document",
".",
"Handles",
"this",
"by",
"removing",
"the",
"deleted_at",
"flag",
"."
] | 8b92c3b41d70f138b40057c28bece54de89d2186 | https://github.com/simi/mongoid_paranoia/blob/8b92c3b41d70f138b40057c28bece54de89d2186/lib/mongoid/paranoia.rb#L147-L155 |
19,591 | pboling/sanitize_email | lib/sanitize_email/overridden_addresses.rb | SanitizeEmail.OverriddenAddresses.good_listize | def good_listize(real_addresses)
good_listed = clean_addresses(real_addresses, :good_list)
good_listed = clean_addresses(good_listed, :bad_list) unless good_listed.empty?
good_listed
end | ruby | def good_listize(real_addresses)
good_listed = clean_addresses(real_addresses, :good_list)
good_listed = clean_addresses(good_listed, :bad_list) unless good_listed.empty?
good_listed
end | [
"def",
"good_listize",
"(",
"real_addresses",
")",
"good_listed",
"=",
"clean_addresses",
"(",
"real_addresses",
",",
":good_list",
")",
"good_listed",
"=",
"clean_addresses",
"(",
"good_listed",
",",
":bad_list",
")",
"unless",
"good_listed",
".",
"empty?",
"good_l... | Replace non-white-listed addresses with these sanitized addresses.
Allow good listed email addresses, and then remove the bad listed addresses | [
"Replace",
"non",
"-",
"white",
"-",
"listed",
"addresses",
"with",
"these",
"sanitized",
"addresses",
".",
"Allow",
"good",
"listed",
"email",
"addresses",
"and",
"then",
"remove",
"the",
"bad",
"listed",
"addresses"
] | d369fe68aaba042645151da2944e1ff28f30beef | https://github.com/pboling/sanitize_email/blob/d369fe68aaba042645151da2944e1ff28f30beef/lib/sanitize_email/overridden_addresses.rb#L38-L42 |
19,592 | domitry/nyaplot | lib/nyaplot/color.rb | Nyaplot.Color.to_html | def to_html
html = '<table><tr>'
@source.each{|color| html.concat("<th>" + color + "</th>")}
html.concat("</tr><tr>")
@source.each{|color| html.concat("<td style=\"background-color:" + color + ";\"> </td>")}
html += '</tr></table>'
return html
end | ruby | def to_html
html = '<table><tr>'
@source.each{|color| html.concat("<th>" + color + "</th>")}
html.concat("</tr><tr>")
@source.each{|color| html.concat("<td style=\"background-color:" + color + ";\"> </td>")}
html += '</tr></table>'
return html
end | [
"def",
"to_html",
"html",
"=",
"'<table><tr>'",
"@source",
".",
"each",
"{",
"|",
"color",
"|",
"html",
".",
"concat",
"(",
"\"<th>\"",
"+",
"color",
"+",
"\"</th>\"",
")",
"}",
"html",
".",
"concat",
"(",
"\"</tr><tr>\"",
")",
"@source",
".",
"each",
... | display colorset on IRuby notebook as a html table
@return [String] generated html | [
"display",
"colorset",
"on",
"IRuby",
"notebook",
"as",
"a",
"html",
"table"
] | 2341ebe730c38abee5d330ef30423cb74a2e2f94 | https://github.com/domitry/nyaplot/blob/2341ebe730c38abee5d330ef30423cb74a2e2f94/lib/nyaplot/color.rb#L70-L77 |
19,593 | domitry/nyaplot | lib/nyaplot/exportable.rb | Nyaplot.Exportable.generate_html | def generate_html(temp_path)
path = File.expand_path(temp_path, __FILE__)
url = Nyaplot.get_url
id = SecureRandom.uuid
model = to_json
template = File.read(path)
ERB.new(template).result(binding)
end | ruby | def generate_html(temp_path)
path = File.expand_path(temp_path, __FILE__)
url = Nyaplot.get_url
id = SecureRandom.uuid
model = to_json
template = File.read(path)
ERB.new(template).result(binding)
end | [
"def",
"generate_html",
"(",
"temp_path",
")",
"path",
"=",
"File",
".",
"expand_path",
"(",
"temp_path",
",",
"__FILE__",
")",
"url",
"=",
"Nyaplot",
".",
"get_url",
"id",
"=",
"SecureRandom",
".",
"uuid",
"model",
"=",
"to_json",
"template",
"=",
"File",... | generate static html file
@return [String] generated html | [
"generate",
"static",
"html",
"file"
] | 2341ebe730c38abee5d330ef30423cb74a2e2f94 | https://github.com/domitry/nyaplot/blob/2341ebe730c38abee5d330ef30423cb74a2e2f94/lib/nyaplot/exportable.rb#L14-L21 |
19,594 | domitry/nyaplot | lib/nyaplot/exportable.rb | Nyaplot.Exportable.export_html | def export_html(path="./plot.html", to_png=false)
path = File.expand_path(path, Dir::pwd)
body = generate_html("../templates/iruby.erb")
temp_path = File.expand_path("../templates/static_html.erb", __FILE__)
template = File.read(temp_path)
num = File.write(path, ERB.new(template).result(bi... | ruby | def export_html(path="./plot.html", to_png=false)
path = File.expand_path(path, Dir::pwd)
body = generate_html("../templates/iruby.erb")
temp_path = File.expand_path("../templates/static_html.erb", __FILE__)
template = File.read(temp_path)
num = File.write(path, ERB.new(template).result(bi... | [
"def",
"export_html",
"(",
"path",
"=",
"\"./plot.html\"",
",",
"to_png",
"=",
"false",
")",
"path",
"=",
"File",
".",
"expand_path",
"(",
"path",
",",
"Dir",
"::",
"pwd",
")",
"body",
"=",
"generate_html",
"(",
"\"../templates/iruby.erb\"",
")",
"temp_path"... | export static html file | [
"export",
"static",
"html",
"file"
] | 2341ebe730c38abee5d330ef30423cb74a2e2f94 | https://github.com/domitry/nyaplot/blob/2341ebe730c38abee5d330ef30423cb74a2e2f94/lib/nyaplot/exportable.rb#L24-L31 |
19,595 | domitry/nyaplot | lib/nyaplot3d/plot3d.rb | Nyaplot.Plot3D.add | def add(type, *data)
df = DataFrame.new({x: data[0], y: data[1], z: data[2]})
return add_with_df(df, type, :x, :y, :z)
end | ruby | def add(type, *data)
df = DataFrame.new({x: data[0], y: data[1], z: data[2]})
return add_with_df(df, type, :x, :y, :z)
end | [
"def",
"add",
"(",
"type",
",",
"*",
"data",
")",
"df",
"=",
"DataFrame",
".",
"new",
"(",
"{",
"x",
":",
"data",
"[",
"0",
"]",
",",
"y",
":",
"data",
"[",
"1",
"]",
",",
"z",
":",
"data",
"[",
"2",
"]",
"}",
")",
"return",
"add_with_df",
... | Add diagram with Array
@param [Symbol] type the type of diagram to add
@param [Array<Array>] *data array from which diagram is created
@example
plot.add(:surface, [0,1,2], [0,1,2], [0,1,2]) | [
"Add",
"diagram",
"with",
"Array"
] | 2341ebe730c38abee5d330ef30423cb74a2e2f94 | https://github.com/domitry/nyaplot/blob/2341ebe730c38abee5d330ef30423cb74a2e2f94/lib/nyaplot3d/plot3d.rb#L25-L28 |
19,596 | domitry/nyaplot | lib/nyaplot3d/plot3d.rb | Nyaplot.Plot3D.add_with_df | def add_with_df(df, type, *labels)
diagram = Diagram3D.new(df, type, labels)
diagrams = get_property(:diagrams)
diagrams.push(diagram)
return diagram
end | ruby | def add_with_df(df, type, *labels)
diagram = Diagram3D.new(df, type, labels)
diagrams = get_property(:diagrams)
diagrams.push(diagram)
return diagram
end | [
"def",
"add_with_df",
"(",
"df",
",",
"type",
",",
"*",
"labels",
")",
"diagram",
"=",
"Diagram3D",
".",
"new",
"(",
"df",
",",
"type",
",",
"labels",
")",
"diagrams",
"=",
"get_property",
"(",
":diagrams",
")",
"diagrams",
".",
"push",
"(",
"diagram",... | Add diagram with DataFrame
@param [DataFrame] DataFrame from which diagram is created
@param [Symbol] type the type of diagram to add
@param [Array<Symbol>] *labels column labels for x, y or some other dimension
@example
df = Nyaplot::DataFrame.new({x: [0,1,2], y: [0,1,2], z: [0,1,2]})
plot.add(df, :surface... | [
"Add",
"diagram",
"with",
"DataFrame"
] | 2341ebe730c38abee5d330ef30423cb74a2e2f94 | https://github.com/domitry/nyaplot/blob/2341ebe730c38abee5d330ef30423cb74a2e2f94/lib/nyaplot3d/plot3d.rb#L37-L42 |
19,597 | domitry/nyaplot | lib/nyaplot3d/plot3d.rb | Nyaplot.Plot3D.export_html | def export_html(path=nil)
require 'securerandom'
path = "./plot-" + SecureRandom.uuid().to_s + ".html" if path.nil?
Frame.new.tap {|f| f.add(self) }.export_html(path)
end | ruby | def export_html(path=nil)
require 'securerandom'
path = "./plot-" + SecureRandom.uuid().to_s + ".html" if path.nil?
Frame.new.tap {|f| f.add(self) }.export_html(path)
end | [
"def",
"export_html",
"(",
"path",
"=",
"nil",
")",
"require",
"'securerandom'",
"path",
"=",
"\"./plot-\"",
"+",
"SecureRandom",
".",
"uuid",
"(",
")",
".",
"to_s",
"+",
"\".html\"",
"if",
"path",
".",
"nil?",
"Frame",
".",
"new",
".",
"tap",
"{",
"|"... | export html file | [
"export",
"html",
"file"
] | 2341ebe730c38abee5d330ef30423cb74a2e2f94 | https://github.com/domitry/nyaplot/blob/2341ebe730c38abee5d330ef30423cb74a2e2f94/lib/nyaplot3d/plot3d.rb#L55-L59 |
19,598 | applicationsonline/librarian | lib/librarian/spec_change_set.rb | Librarian.SpecChangeSet.analyze | def analyze
@analyze ||= begin
debug { "Analyzing spec and lock:" }
if same?
debug { " Same!" }
return lock.manifests
end
debug { " Removed:" } ; removed_dependency_names.each { |name| debug { " #{name}" } }
debug { " ExplicitRemoved:" } ; explic... | ruby | def analyze
@analyze ||= begin
debug { "Analyzing spec and lock:" }
if same?
debug { " Same!" }
return lock.manifests
end
debug { " Removed:" } ; removed_dependency_names.each { |name| debug { " #{name}" } }
debug { " ExplicitRemoved:" } ; explic... | [
"def",
"analyze",
"@analyze",
"||=",
"begin",
"debug",
"{",
"\"Analyzing spec and lock:\"",
"}",
"if",
"same?",
"debug",
"{",
"\" Same!\"",
"}",
"return",
"lock",
".",
"manifests",
"end",
"debug",
"{",
"\" Removed:\"",
"}",
";",
"removed_dependency_names",
".",
... | Returns an array of those manifests from the previous spec which should be kept,
based on inspecting the new spec against the locked resolution from the previous spec. | [
"Returns",
"an",
"array",
"of",
"those",
"manifests",
"from",
"the",
"previous",
"spec",
"which",
"should",
"be",
"kept",
"based",
"on",
"inspecting",
"the",
"new",
"spec",
"against",
"the",
"locked",
"resolution",
"from",
"the",
"previous",
"spec",
"."
] | b968cd91a3955657bf6ea728b922f2cb74843264 | https://github.com/applicationsonline/librarian/blob/b968cd91a3955657bf6ea728b922f2cb74843264/lib/librarian/spec_change_set.rb#L142-L164 |
19,599 | applicationsonline/librarian | lib/librarian/manifest_set.rb | Librarian.ManifestSet.dependencies_of | def dependencies_of(names)
names = Array === names ? names.dup : names.to_a
assert_strings!(names)
deps = Set.new
until names.empty?
name = names.shift
next if deps.include?(name)
deps << name
names.concat index[name].dependencies.map(&:name)
end
dep... | ruby | def dependencies_of(names)
names = Array === names ? names.dup : names.to_a
assert_strings!(names)
deps = Set.new
until names.empty?
name = names.shift
next if deps.include?(name)
deps << name
names.concat index[name].dependencies.map(&:name)
end
dep... | [
"def",
"dependencies_of",
"(",
"names",
")",
"names",
"=",
"Array",
"===",
"names",
"?",
"names",
".",
"dup",
":",
"names",
".",
"to_a",
"assert_strings!",
"(",
"names",
")",
"deps",
"=",
"Set",
".",
"new",
"until",
"names",
".",
"empty?",
"name",
"=",... | Straightforward breadth-first graph traversal algorithm. | [
"Straightforward",
"breadth",
"-",
"first",
"graph",
"traversal",
"algorithm",
"."
] | b968cd91a3955657bf6ea728b922f2cb74843264 | https://github.com/applicationsonline/librarian/blob/b968cd91a3955657bf6ea728b922f2cb74843264/lib/librarian/manifest_set.rb#L130-L143 |
Subsets and Splits
No community queries yet
The top public SQL queries from the community will appear here once available.