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 |
|---|---|---|---|---|---|---|---|---|---|---|---|
6,200 | hokstadconsulting/purecdb | lib/purecdb/reader.rb | PureCDB.Reader.values | def values(key)
h = hash(key)
hoff = @hashes[(h % 256)*2]
hlen = @hashes[(h % 256)*2 + 1]
return [] if hlen == 0
off = (h / 256) % hlen
vals = []
# FIXME: Is this potentially an infinite loop (if full)?
# Easy to avoid by exiting if off reaches the same value twice.
... | ruby | def values(key)
h = hash(key)
hoff = @hashes[(h % 256)*2]
hlen = @hashes[(h % 256)*2 + 1]
return [] if hlen == 0
off = (h / 256) % hlen
vals = []
# FIXME: Is this potentially an infinite loop (if full)?
# Easy to avoid by exiting if off reaches the same value twice.
... | [
"def",
"values",
"(",
"key",
")",
"h",
"=",
"hash",
"(",
"key",
")",
"hoff",
"=",
"@hashes",
"[",
"(",
"h",
"%",
"256",
")",
"*",
"2",
"]",
"hlen",
"=",
"@hashes",
"[",
"(",
"h",
"%",
"256",
")",
"*",
"2",
"+",
"1",
"]",
"return",
"[",
"]... | Returns all values for +key+ in an array | [
"Returns",
"all",
"values",
"for",
"+",
"key",
"+",
"in",
"an",
"array"
] | d19102e5dffbb2f0de4fab4f86c603880c3ffea8 | https://github.com/hokstadconsulting/purecdb/blob/d19102e5dffbb2f0de4fab4f86c603880c3ffea8/lib/purecdb/reader.rb#L107-L136 |
6,201 | notioneer/ncore-ruby | lib/ncore/rails/active_model.rb | NCore.ActiveModel.errors_for_actionpack | def errors_for_actionpack
e0 = ::ActiveModel::Errors.new(self)
@errors.each do |e|
e0.add :base, e
end
e0
end | ruby | def errors_for_actionpack
e0 = ::ActiveModel::Errors.new(self)
@errors.each do |e|
e0.add :base, e
end
e0
end | [
"def",
"errors_for_actionpack",
"e0",
"=",
"::",
"ActiveModel",
"::",
"Errors",
".",
"new",
"(",
"self",
")",
"@errors",
".",
"each",
"do",
"|",
"e",
"|",
"e0",
".",
"add",
":base",
",",
"e",
"end",
"e0",
"end"
] | actionpack 4 requires a more robust Errors object | [
"actionpack",
"4",
"requires",
"a",
"more",
"robust",
"Errors",
"object"
] | f2abd124b9012a402e33aa7c25dabacb7eaffcde | https://github.com/notioneer/ncore-ruby/blob/f2abd124b9012a402e33aa7c25dabacb7eaffcde/lib/ncore/rails/active_model.rb#L33-L39 |
6,202 | davidrichards/gearbox | lib/gearbox/mixins/ad_hoc_properties.rb | Gearbox.AdHocProperties.add_property | def add_property(accessor, predicate, object)
new_property = RDF::Statement.new(bnode, predicate, object)
attributes_list[accessor] = new_property
end | ruby | def add_property(accessor, predicate, object)
new_property = RDF::Statement.new(bnode, predicate, object)
attributes_list[accessor] = new_property
end | [
"def",
"add_property",
"(",
"accessor",
",",
"predicate",
",",
"object",
")",
"new_property",
"=",
"RDF",
"::",
"Statement",
".",
"new",
"(",
"bnode",
",",
"predicate",
",",
"object",
")",
"attributes_list",
"[",
"accessor",
"]",
"=",
"new_property",
"end"
] | Add a property without defining it on the class.
This will stay, will use the subject, and the regular infrastructure.
@param [Symbol] accessor, the new field being created.
@param [RDF::Statement] predicate, the predicate for the new field.
@param [Any] The value to store | [
"Add",
"a",
"property",
"without",
"defining",
"it",
"on",
"the",
"class",
".",
"This",
"will",
"stay",
"will",
"use",
"the",
"subject",
"and",
"the",
"regular",
"infrastructure",
"."
] | 322e1a44394b6323d849c5e65acad66cdf284aac | https://github.com/davidrichards/gearbox/blob/322e1a44394b6323d849c5e65acad66cdf284aac/lib/gearbox/mixins/ad_hoc_properties.rb#L35-L38 |
6,203 | openSUSE/dm-bugzilla-adapter | lib/dm-bugzilla-adapter/update.rb | DataMapper::Adapters.BugzillaAdapter.update | def update(attributes, collection)
each_resource_with_edit_url(collection) do |resource, edit_url|
put_updated_resource(edit_url, resource)
end
# return count
collection.size
end | ruby | def update(attributes, collection)
each_resource_with_edit_url(collection) do |resource, edit_url|
put_updated_resource(edit_url, resource)
end
# return count
collection.size
end | [
"def",
"update",
"(",
"attributes",
",",
"collection",
")",
"each_resource_with_edit_url",
"(",
"collection",
")",
"do",
"|",
"resource",
",",
"edit_url",
"|",
"put_updated_resource",
"(",
"edit_url",
",",
"resource",
")",
"end",
"# return count",
"collection",
".... | Constructs and executes UPDATE statement for given
attributes and a query
@param [Hash(Property => Object)] attributes
hash of attribute values to set, keyed by Property
@param [Collection] collection
collection of records to be updated
@return [Integer]
the number of records updated
@api semipublic | [
"Constructs",
"and",
"executes",
"UPDATE",
"statement",
"for",
"given",
"attributes",
"and",
"a",
"query"
] | d56a64918f315d5038145b3f0d94852fc38bcca2 | https://github.com/openSUSE/dm-bugzilla-adapter/blob/d56a64918f315d5038145b3f0d94852fc38bcca2/lib/dm-bugzilla-adapter/update.rb#L16-L22 |
6,204 | SquareSquash/ios_symbolicator | lib/squash/symbolicator.rb | Squash.Symbolicator.architectures | def architectures
architectures = Hash.new
stdin, stdout, stderr = Open3.popen3('dwarfdump', '-u', @dsym)
stdout.each_line do |line|
if line =~ /^UUID: ([0-9A-F\-]+) \((.+?)\)/
architectures[$2] = $1
end
end
return architectures
end | ruby | def architectures
architectures = Hash.new
stdin, stdout, stderr = Open3.popen3('dwarfdump', '-u', @dsym)
stdout.each_line do |line|
if line =~ /^UUID: ([0-9A-F\-]+) \((.+?)\)/
architectures[$2] = $1
end
end
return architectures
end | [
"def",
"architectures",
"architectures",
"=",
"Hash",
".",
"new",
"stdin",
",",
"stdout",
",",
"stderr",
"=",
"Open3",
".",
"popen3",
"(",
"'dwarfdump'",
",",
"'-u'",
",",
"@dsym",
")",
"stdout",
".",
"each_line",
"do",
"|",
"line",
"|",
"if",
"line",
... | Creates a new symbolicator for a given dSYM file.
@param [String] dsym The path to a dSYM file (or DWARF file within).
@param [String] project_dir The path to a project root that will be removed
from file paths underneath that root.
@return [Hash<String, String>] A hash mapping architectures (such as "i386")
... | [
"Creates",
"a",
"new",
"symbolicator",
"for",
"a",
"given",
"dSYM",
"file",
"."
] | 6b7146b7efed0922d22d80fcb49e8d5964a23967 | https://github.com/SquareSquash/ios_symbolicator/blob/6b7146b7efed0922d22d80fcb49e8d5964a23967/lib/squash/symbolicator.rb#L38-L49 |
6,205 | detroit/detroit-email | lib/detroit-email.rb | Detroit.Email.announce | def announce
apply_environment unless @approved
mailopts = self.mailopts
if mailto.empty?
report "No recipents given."
else
if trial?
subject = mailopts['subject']
mailto = mailopts['to'].flatten.join(", ")
report "email '#{subject}' to #{mailto}"... | ruby | def announce
apply_environment unless @approved
mailopts = self.mailopts
if mailto.empty?
report "No recipents given."
else
if trial?
subject = mailopts['subject']
mailto = mailopts['to'].flatten.join(", ")
report "email '#{subject}' to #{mailto}"... | [
"def",
"announce",
"apply_environment",
"unless",
"@approved",
"mailopts",
"=",
"self",
".",
"mailopts",
"if",
"mailto",
".",
"empty?",
"report",
"\"No recipents given.\"",
"else",
"if",
"trial?",
"subject",
"=",
"mailopts",
"[",
"'subject'",
"]",
"mailto",
"=",
... | Send announcement message. | [
"Send",
"announcement",
"message",
"."
] | 682de790705301f2b83cd6afab585f5aaf59d42b | https://github.com/detroit/detroit-email/blob/682de790705301f2b83cd6afab585f5aaf59d42b/lib/detroit-email.rb#L125-L147 |
6,206 | detroit/detroit-email | lib/detroit-email.rb | Detroit.Email.message | def message
@message ||= (
path = Dir[file].first if file
if path
project.announcement(File.new(file))
else
parts.map{ |part| /^file:\/\// =~ part.to_s ? $' : part }
project.announcement(*parts)
end
)
end | ruby | def message
@message ||= (
path = Dir[file].first if file
if path
project.announcement(File.new(file))
else
parts.map{ |part| /^file:\/\// =~ part.to_s ? $' : part }
project.announcement(*parts)
end
)
end | [
"def",
"message",
"@message",
"||=",
"(",
"path",
"=",
"Dir",
"[",
"file",
"]",
".",
"first",
"if",
"file",
"if",
"path",
"project",
".",
"announcement",
"(",
"File",
".",
"new",
"(",
"file",
")",
")",
"else",
"parts",
".",
"map",
"{",
"|",
"part",... | Message to send. Defaults to a generated release announcement. | [
"Message",
"to",
"send",
".",
"Defaults",
"to",
"a",
"generated",
"release",
"announcement",
"."
] | 682de790705301f2b83cd6afab585f5aaf59d42b | https://github.com/detroit/detroit-email/blob/682de790705301f2b83cd6afab585f5aaf59d42b/lib/detroit-email.rb#L155-L165 |
6,207 | detroit/detroit-email | lib/detroit-email.rb | Detroit.Email.apply_environment | def apply_environment
return if noenv
@server ||= ENV['EMAIL_SERVER']
@from ||= ENV['EMAIL_FROM'] || ENV['EMAIL_ACCOUNT']
@account ||= ENV['EMAIL_ACCOUNT'] || ENV['EMAIL_FROM']
@password ||= ENV['EMAIL_PASSWORD']
@port ||= ENV['EMAIL_PORT']
@domain ||= ENV['EMAI... | ruby | def apply_environment
return if noenv
@server ||= ENV['EMAIL_SERVER']
@from ||= ENV['EMAIL_FROM'] || ENV['EMAIL_ACCOUNT']
@account ||= ENV['EMAIL_ACCOUNT'] || ENV['EMAIL_FROM']
@password ||= ENV['EMAIL_PASSWORD']
@port ||= ENV['EMAIL_PORT']
@domain ||= ENV['EMAI... | [
"def",
"apply_environment",
"return",
"if",
"noenv",
"@server",
"||=",
"ENV",
"[",
"'EMAIL_SERVER'",
"]",
"@from",
"||=",
"ENV",
"[",
"'EMAIL_FROM'",
"]",
"||",
"ENV",
"[",
"'EMAIL_ACCOUNT'",
"]",
"@account",
"||=",
"ENV",
"[",
"'EMAIL_ACCOUNT'",
"]",
"||",
... | Apply environment settings. | [
"Apply",
"environment",
"settings",
"."
] | 682de790705301f2b83cd6afab585f5aaf59d42b | https://github.com/detroit/detroit-email/blob/682de790705301f2b83cd6afab585f5aaf59d42b/lib/detroit-email.rb#L208-L218 |
6,208 | codescrum/bebox | lib/bebox/provision.rb | Bebox.Provision.apply | def apply
started_at = DateTime.now.to_s
# Check if a Puppetfile is neccesary for use/not use librarian-puppet
check_puppetfile_content
# Copy static modules that are not downloaded by librarian-puppet
copy_static_modules
# Apply step and if the process is succesful create the checkp... | ruby | def apply
started_at = DateTime.now.to_s
# Check if a Puppetfile is neccesary for use/not use librarian-puppet
check_puppetfile_content
# Copy static modules that are not downloaded by librarian-puppet
copy_static_modules
# Apply step and if the process is succesful create the checkp... | [
"def",
"apply",
"started_at",
"=",
"DateTime",
".",
"now",
".",
"to_s",
"# Check if a Puppetfile is neccesary for use/not use librarian-puppet",
"check_puppetfile_content",
"# Copy static modules that are not downloaded by librarian-puppet",
"copy_static_modules",
"# Apply step and if the ... | Puppet apply Fundamental step | [
"Puppet",
"apply",
"Fundamental",
"step"
] | 0d19315847103341e599d32837ab0bd75524e5be | https://github.com/codescrum/bebox/blob/0d19315847103341e599d32837ab0bd75524e5be/lib/bebox/provision.rb#L22-L32 |
6,209 | codescrum/bebox | lib/bebox/provision.rb | Bebox.Provision.create_step_checkpoint | def create_step_checkpoint(started_at)
self.node.started_at = started_at
self.node.finished_at = DateTime.now.to_s
Bebox::Environment.create_checkpoint_directories(project_root, environment)
generate_file_from_template("#{Bebox::FilesHelper::templates_path}/node/provisioned_node.yml.erb", "#{sel... | ruby | def create_step_checkpoint(started_at)
self.node.started_at = started_at
self.node.finished_at = DateTime.now.to_s
Bebox::Environment.create_checkpoint_directories(project_root, environment)
generate_file_from_template("#{Bebox::FilesHelper::templates_path}/node/provisioned_node.yml.erb", "#{sel... | [
"def",
"create_step_checkpoint",
"(",
"started_at",
")",
"self",
".",
"node",
".",
"started_at",
"=",
"started_at",
"self",
".",
"node",
".",
"finished_at",
"=",
"DateTime",
".",
"now",
".",
"to_s",
"Bebox",
"::",
"Environment",
".",
"create_checkpoint_directori... | Create checkpoint for step | [
"Create",
"checkpoint",
"for",
"step"
] | 0d19315847103341e599d32837ab0bd75524e5be | https://github.com/codescrum/bebox/blob/0d19315847103341e599d32837ab0bd75524e5be/lib/bebox/provision.rb#L185-L190 |
6,210 | blambeau/yargi | lib/yargi/vertex_set.rb | Yargi.VertexSet.in_edges | def in_edges(filter=nil, &block)
r = self.collect {|v| v.in_edges(filter, &block) }
EdgeSet.new(r).flatten.uniq
end | ruby | def in_edges(filter=nil, &block)
r = self.collect {|v| v.in_edges(filter, &block) }
EdgeSet.new(r).flatten.uniq
end | [
"def",
"in_edges",
"(",
"filter",
"=",
"nil",
",",
"&",
"block",
")",
"r",
"=",
"self",
".",
"collect",
"{",
"|",
"v",
"|",
"v",
".",
"in_edges",
"(",
"filter",
",",
"block",
")",
"}",
"EdgeSet",
".",
"new",
"(",
"r",
")",
".",
"flatten",
".",
... | Walking section
Returns incoming edges of all vertices of this set | [
"Walking",
"section",
"Returns",
"incoming",
"edges",
"of",
"all",
"vertices",
"of",
"this",
"set"
] | 100141e96d245a0a8211cd4f7590909be149bc3c | https://github.com/blambeau/yargi/blob/100141e96d245a0a8211cd4f7590909be149bc3c/lib/yargi/vertex_set.rb#L17-L20 |
6,211 | blambeau/yargi | lib/yargi/vertex_set.rb | Yargi.VertexSet.in_adjacent | def in_adjacent(filter=nil, &block)
r = self.collect {|v| v.in_adjacent(filter, &block) }
VertexSet.new(r).flatten.uniq
end | ruby | def in_adjacent(filter=nil, &block)
r = self.collect {|v| v.in_adjacent(filter, &block) }
VertexSet.new(r).flatten.uniq
end | [
"def",
"in_adjacent",
"(",
"filter",
"=",
"nil",
",",
"&",
"block",
")",
"r",
"=",
"self",
".",
"collect",
"{",
"|",
"v",
"|",
"v",
".",
"in_adjacent",
"(",
"filter",
",",
"block",
")",
"}",
"VertexSet",
".",
"new",
"(",
"r",
")",
".",
"flatten",... | Returns all back-adjacent vertices reachable from this set | [
"Returns",
"all",
"back",
"-",
"adjacent",
"vertices",
"reachable",
"from",
"this",
"set"
] | 100141e96d245a0a8211cd4f7590909be149bc3c | https://github.com/blambeau/yargi/blob/100141e96d245a0a8211cd4f7590909be149bc3c/lib/yargi/vertex_set.rb#L23-L26 |
6,212 | blambeau/yargi | lib/yargi/vertex_set.rb | Yargi.VertexSet.adjacent | def adjacent(filter=nil, &block)
(in_adjacent(filter, &block)+out_adjacent(filter, &block)).uniq
end | ruby | def adjacent(filter=nil, &block)
(in_adjacent(filter, &block)+out_adjacent(filter, &block)).uniq
end | [
"def",
"adjacent",
"(",
"filter",
"=",
"nil",
",",
"&",
"block",
")",
"(",
"in_adjacent",
"(",
"filter",
",",
"block",
")",
"+",
"out_adjacent",
"(",
"filter",
",",
"block",
")",
")",
".",
"uniq",
"end"
] | Returns all adjacent vertices reachable from this set | [
"Returns",
"all",
"adjacent",
"vertices",
"reachable",
"from",
"this",
"set"
] | 100141e96d245a0a8211cd4f7590909be149bc3c | https://github.com/blambeau/yargi/blob/100141e96d245a0a8211cd4f7590909be149bc3c/lib/yargi/vertex_set.rb#L41-L43 |
6,213 | livingsocial/houdah | lib/houdah/job.rb | Houdah.Job.config | def config
@parsed_config ||= Nokogiri::XML(config_xml).xpath("//property").inject({}) { |props, xprop|
props[xprop.xpath("./name").text] = xprop.xpath("./value").text
props
}
end | ruby | def config
@parsed_config ||= Nokogiri::XML(config_xml).xpath("//property").inject({}) { |props, xprop|
props[xprop.xpath("./name").text] = xprop.xpath("./value").text
props
}
end | [
"def",
"config",
"@parsed_config",
"||=",
"Nokogiri",
"::",
"XML",
"(",
"config_xml",
")",
".",
"xpath",
"(",
"\"//property\"",
")",
".",
"inject",
"(",
"{",
"}",
")",
"{",
"|",
"props",
",",
"xprop",
"|",
"props",
"[",
"xprop",
".",
"xpath",
"(",
"\... | Get the job's config, as a Hash | [
"Get",
"the",
"job",
"s",
"config",
"as",
"a",
"Hash"
] | 7ab475ccb34fcb6fd894ae865627f7890979b1fa | https://github.com/livingsocial/houdah/blob/7ab475ccb34fcb6fd894ae865627f7890979b1fa/lib/houdah/job.rb#L20-L25 |
6,214 | Referly/better_sqs | lib/better_sqs/client.rb | BetterSqs.Client.push | def push(queue_name, message_body)
sqs.send_message(queue_url: url_for_queue(queue_name), message_body: message_body)
end | ruby | def push(queue_name, message_body)
sqs.send_message(queue_url: url_for_queue(queue_name), message_body: message_body)
end | [
"def",
"push",
"(",
"queue_name",
",",
"message_body",
")",
"sqs",
".",
"send_message",
"(",
"queue_url",
":",
"url_for_queue",
"(",
"queue_name",
")",
",",
"message_body",
":",
"message_body",
")",
"end"
] | Push a message onto a queue
@param queue_name [String, Symbol] the name of the queue that the message should pushed onto
@param message_body [String] the message as it will be pushed onto the queue, no serialization occurs as
part of this method. You need to encode or serialize your object to a string before sendi... | [
"Push",
"a",
"message",
"onto",
"a",
"queue"
] | c1e20bf5c079df1b65e6ed7702a2449ab2e991ba | https://github.com/Referly/better_sqs/blob/c1e20bf5c079df1b65e6ed7702a2449ab2e991ba/lib/better_sqs/client.rb#L18-L20 |
6,215 | Referly/better_sqs | lib/better_sqs/client.rb | BetterSqs.Client.reserve | def reserve(queue_name)
resp = sqs.receive_message(queue_url: url_for_queue(queue_name), max_number_of_messages: 1)
return nil unless resp.messages.any?
Message.new queue_client: self, queue: queue_name, sqs_message: resp.messages.first
end | ruby | def reserve(queue_name)
resp = sqs.receive_message(queue_url: url_for_queue(queue_name), max_number_of_messages: 1)
return nil unless resp.messages.any?
Message.new queue_client: self, queue: queue_name, sqs_message: resp.messages.first
end | [
"def",
"reserve",
"(",
"queue_name",
")",
"resp",
"=",
"sqs",
".",
"receive_message",
"(",
"queue_url",
":",
"url_for_queue",
"(",
"queue_name",
")",
",",
"max_number_of_messages",
":",
"1",
")",
"return",
"nil",
"unless",
"resp",
".",
"messages",
".",
"any?... | Reserve a message from the specified queue
@param queue_name [String, Symbol] the name of the SQS queue to reserve a message from
@return [Messages::Sqs, NilClass] the message retrieved from the queue | [
"Reserve",
"a",
"message",
"from",
"the",
"specified",
"queue"
] | c1e20bf5c079df1b65e6ed7702a2449ab2e991ba | https://github.com/Referly/better_sqs/blob/c1e20bf5c079df1b65e6ed7702a2449ab2e991ba/lib/better_sqs/client.rb#L26-L30 |
6,216 | Referly/better_sqs | lib/better_sqs/client.rb | BetterSqs.Client.delete | def delete(message)
sqs.delete_message queue_url: url_for_queue(message.queue), receipt_handle: message.receipt_handle
end | ruby | def delete(message)
sqs.delete_message queue_url: url_for_queue(message.queue), receipt_handle: message.receipt_handle
end | [
"def",
"delete",
"(",
"message",
")",
"sqs",
".",
"delete_message",
"queue_url",
":",
"url_for_queue",
"(",
"message",
".",
"queue",
")",
",",
"receipt_handle",
":",
"message",
".",
"receipt_handle",
"end"
] | Delete a message from the queue
@param message [Messages::Sqs] the message that should be deleted | [
"Delete",
"a",
"message",
"from",
"the",
"queue"
] | c1e20bf5c079df1b65e6ed7702a2449ab2e991ba | https://github.com/Referly/better_sqs/blob/c1e20bf5c079df1b65e6ed7702a2449ab2e991ba/lib/better_sqs/client.rb#L35-L37 |
6,217 | Referly/better_sqs | lib/better_sqs/client.rb | BetterSqs.Client.defer_retry | def defer_retry(message)
sqs.change_message_visibility queue_url: url_for_queue(message.queue),
receipt_handle: message.receipt_handle,
visibility_timeout: BetterSqs.configuration.sqs_message_deferral_seconds
end | ruby | def defer_retry(message)
sqs.change_message_visibility queue_url: url_for_queue(message.queue),
receipt_handle: message.receipt_handle,
visibility_timeout: BetterSqs.configuration.sqs_message_deferral_seconds
end | [
"def",
"defer_retry",
"(",
"message",
")",
"sqs",
".",
"change_message_visibility",
"queue_url",
":",
"url_for_queue",
"(",
"message",
".",
"queue",
")",
",",
"receipt_handle",
":",
"message",
".",
"receipt_handle",
",",
"visibility_timeout",
":",
"BetterSqs",
"."... | Updates the message visibility timeout to create some delay before an attempt will be made to reprocess the
message
@param message [Messages::Sqs] the message for which the next retry should be delayed | [
"Updates",
"the",
"message",
"visibility",
"timeout",
"to",
"create",
"some",
"delay",
"before",
"an",
"attempt",
"will",
"be",
"made",
"to",
"reprocess",
"the",
"message"
] | c1e20bf5c079df1b65e6ed7702a2449ab2e991ba | https://github.com/Referly/better_sqs/blob/c1e20bf5c079df1b65e6ed7702a2449ab2e991ba/lib/better_sqs/client.rb#L43-L47 |
6,218 | fugroup/pushfile | lib/pushfile/resize.rb | Pushfile.Resize.resize! | def resize!
begin
image = MiniMagick::Image.open(@file.path)
image.resize("#{@width}x#{@height}")
rescue
# Pass on any error
else
image.write(@file.path) rescue nil
end
end | ruby | def resize!
begin
image = MiniMagick::Image.open(@file.path)
image.resize("#{@width}x#{@height}")
rescue
# Pass on any error
else
image.write(@file.path) rescue nil
end
end | [
"def",
"resize!",
"begin",
"image",
"=",
"MiniMagick",
"::",
"Image",
".",
"open",
"(",
"@file",
".",
"path",
")",
"image",
".",
"resize",
"(",
"\"#{@width}x#{@height}\"",
")",
"rescue",
"# Pass on any error",
"else",
"image",
".",
"write",
"(",
"@file",
"."... | Resize file. Keeping aspect ratio. | [
"Resize",
"file",
".",
"Keeping",
"aspect",
"ratio",
"."
] | dd06bd6b023514a1446544986b1ce85b7bae3f78 | https://github.com/fugroup/pushfile/blob/dd06bd6b023514a1446544986b1ce85b7bae3f78/lib/pushfile/resize.rb#L7-L16 |
6,219 | fugroup/pushfile | lib/pushfile/resize.rb | Pushfile.Resize.thumbnail! | def thumbnail!
begin
image = MiniMagick::Image.open(@file.path)
image.resize("#{Pushfile.settings[:images][:thumb][:width]}x")
rescue
@thumb = nil
else
t = @name.split('.'); ext = t.pop
@thumb = t.join(".").concat("_thumb.#{ext}")
image.write("/tmp/#{@th... | ruby | def thumbnail!
begin
image = MiniMagick::Image.open(@file.path)
image.resize("#{Pushfile.settings[:images][:thumb][:width]}x")
rescue
@thumb = nil
else
t = @name.split('.'); ext = t.pop
@thumb = t.join(".").concat("_thumb.#{ext}")
image.write("/tmp/#{@th... | [
"def",
"thumbnail!",
"begin",
"image",
"=",
"MiniMagick",
"::",
"Image",
".",
"open",
"(",
"@file",
".",
"path",
")",
"image",
".",
"resize",
"(",
"\"#{Pushfile.settings[:images][:thumb][:width]}x\"",
")",
"rescue",
"@thumb",
"=",
"nil",
"else",
"t",
"=",
"@na... | Create thumbnail, same name but with _thumb at the end | [
"Create",
"thumbnail",
"same",
"name",
"but",
"with",
"_thumb",
"at",
"the",
"end"
] | dd06bd6b023514a1446544986b1ce85b7bae3f78 | https://github.com/fugroup/pushfile/blob/dd06bd6b023514a1446544986b1ce85b7bae3f78/lib/pushfile/resize.rb#L19-L30 |
6,220 | wedesoft/multiarray | lib/multiarray/lambda.rb | Hornetseye.Lambda.element | def element(i)
unless i.matched?
unless (0 ... shape.last).member? i
raise "Index must be in 0 ... #{shape.last} (was #{i})"
end
i = INT.new i
end
i.size = @index.size if i.is_a?(Variable) and @index.size.get
@term.subst @index => i
end | ruby | def element(i)
unless i.matched?
unless (0 ... shape.last).member? i
raise "Index must be in 0 ... #{shape.last} (was #{i})"
end
i = INT.new i
end
i.size = @index.size if i.is_a?(Variable) and @index.size.get
@term.subst @index => i
end | [
"def",
"element",
"(",
"i",
")",
"unless",
"i",
".",
"matched?",
"unless",
"(",
"0",
"...",
"shape",
".",
"last",
")",
".",
"member?",
"i",
"raise",
"\"Index must be in 0 ... #{shape.last} (was #{i})\"",
"end",
"i",
"=",
"INT",
".",
"new",
"i",
"end",
"i",... | Get element of this term
Pass +i+ as argument to this lambda object.
@param [Integer,Node] i Index of desired element.
@return [Node,Object] Result of inserting +i+ for lambda argument.
@private | [
"Get",
"element",
"of",
"this",
"term"
] | 1ae1d98bacb4b941d6f406e44ccb184de12f83d9 | https://github.com/wedesoft/multiarray/blob/1ae1d98bacb4b941d6f406e44ccb184de12f83d9/lib/multiarray/lambda.rb#L163-L172 |
6,221 | Adaptavist/confluence_reporter | lib/confluence_reporter.rb | ConfluenceReporter.Reporter.report_event | def report_event(name, parrent_page_id=nil, space=nil)
page = find_page_by_name(name, parrent_page_id)
if page
append_to_page(page["id"], parrent_page_id)
else
create_page(name, space, parrent_page_id)
end
clear_log
end | ruby | def report_event(name, parrent_page_id=nil, space=nil)
page = find_page_by_name(name, parrent_page_id)
if page
append_to_page(page["id"], parrent_page_id)
else
create_page(name, space, parrent_page_id)
end
clear_log
end | [
"def",
"report_event",
"(",
"name",
",",
"parrent_page_id",
"=",
"nil",
",",
"space",
"=",
"nil",
")",
"page",
"=",
"find_page_by_name",
"(",
"name",
",",
"parrent_page_id",
")",
"if",
"page",
"append_to_page",
"(",
"page",
"[",
"\"id\"",
"]",
",",
"parren... | appends the log to confluence page if found, if not creates new page
clears the log | [
"appends",
"the",
"log",
"to",
"confluence",
"page",
"if",
"found",
"if",
"not",
"creates",
"new",
"page",
"clears",
"the",
"log"
] | 533d982096b16cec1fa520352c3abdeb26a11f5e | https://github.com/Adaptavist/confluence_reporter/blob/533d982096b16cec1fa520352c3abdeb26a11f5e/lib/confluence_reporter.rb#L126-L134 |
6,222 | Adaptavist/confluence_reporter | lib/confluence_reporter.rb | ConfluenceReporter.Reporter.create_page | def create_page(title, space, parrent_page_id=nil)
params = { 'type' => 'page',
'title' => title,
'space' => {'key' => space},
'body' => {
'storage' => {
'value' => ("#{ @body_message.to_json.gsub("&&", "&&")... | ruby | def create_page(title, space, parrent_page_id=nil)
params = { 'type' => 'page',
'title' => title,
'space' => {'key' => space},
'body' => {
'storage' => {
'value' => ("#{ @body_message.to_json.gsub("&&", "&&")... | [
"def",
"create_page",
"(",
"title",
",",
"space",
",",
"parrent_page_id",
"=",
"nil",
")",
"params",
"=",
"{",
"'type'",
"=>",
"'page'",
",",
"'title'",
"=>",
"title",
",",
"'space'",
"=>",
"{",
"'key'",
"=>",
"space",
"}",
",",
"'body'",
"=>",
"{",
... | Creates new page with title set,
if parrent_page_id is provided it adjusts ancestor accordingly and
the same space short key | [
"Creates",
"new",
"page",
"with",
"title",
"set",
"if",
"parrent_page_id",
"is",
"provided",
"it",
"adjusts",
"ancestor",
"accordingly",
"and",
"the",
"same",
"space",
"short",
"key"
] | 533d982096b16cec1fa520352c3abdeb26a11f5e | https://github.com/Adaptavist/confluence_reporter/blob/533d982096b16cec1fa520352c3abdeb26a11f5e/lib/confluence_reporter.rb#L139-L172 |
6,223 | jns/Aims | lib/aims/atom.rb | Aims.Atom.constrained? | def constrained?
if self.constrain
if self.constrain == true
true
elsif self.constrain.is_a? String
true
elsif self.constrain.is_a? Array and not self.constrain.empty?
true
else
false
end
else
false
end
end | ruby | def constrained?
if self.constrain
if self.constrain == true
true
elsif self.constrain.is_a? String
true
elsif self.constrain.is_a? Array and not self.constrain.empty?
true
else
false
end
else
false
end
end | [
"def",
"constrained?",
"if",
"self",
".",
"constrain",
"if",
"self",
".",
"constrain",
"==",
"true",
"true",
"elsif",
"self",
".",
"constrain",
".",
"is_a?",
"String",
"true",
"elsif",
"self",
".",
"constrain",
".",
"is_a?",
"Array",
"and",
"not",
"self",
... | Create an atom of the specified species at the given coordinates
@param [Float] x The x coordinate of the atom in angstrom
@param [Float] y The y coordinate of the atom in angstrom
@param [Float] z The z coordinate of the atom in angstrom
@param [String, nil] s The atomic species ex. "C", "Si", "S", etc. (can be ni... | [
"Create",
"an",
"atom",
"of",
"the",
"specified",
"species",
"at",
"the",
"given",
"coordinates"
] | 2dcb6c02cd05b2d0c8ab72be4e85d60375df296c | https://github.com/jns/Aims/blob/2dcb6c02cd05b2d0c8ab72be4e85d60375df296c/lib/aims/atom.rb#L43-L57 |
6,224 | jns/Aims | lib/aims/atom.rb | Aims.Atom.distance_to | def distance_to(atom)
Math.sqrt((self.x - atom.x)**2 + (self.y - atom.y)**2 + (self.z - atom.z)**2)
end | ruby | def distance_to(atom)
Math.sqrt((self.x - atom.x)**2 + (self.y - atom.y)**2 + (self.z - atom.z)**2)
end | [
"def",
"distance_to",
"(",
"atom",
")",
"Math",
".",
"sqrt",
"(",
"(",
"self",
".",
"x",
"-",
"atom",
".",
"x",
")",
"**",
"2",
"+",
"(",
"self",
".",
"y",
"-",
"atom",
".",
"y",
")",
"**",
"2",
"+",
"(",
"self",
".",
"z",
"-",
"atom",
".... | Return the distance to another atom | [
"Return",
"the",
"distance",
"to",
"another",
"atom"
] | 2dcb6c02cd05b2d0c8ab72be4e85d60375df296c | https://github.com/jns/Aims/blob/2dcb6c02cd05b2d0c8ab72be4e85d60375df296c/lib/aims/atom.rb#L93-L95 |
6,225 | jns/Aims | lib/aims/atom.rb | Aims.Atom.displace | def displace(x,y,z)
Atom.new(self.x+x, self.y+y, self.z+z, self.species, self.constrain)
end | ruby | def displace(x,y,z)
Atom.new(self.x+x, self.y+y, self.z+z, self.species, self.constrain)
end | [
"def",
"displace",
"(",
"x",
",",
"y",
",",
"z",
")",
"Atom",
".",
"new",
"(",
"self",
".",
"x",
"+",
"x",
",",
"self",
".",
"y",
"+",
"y",
",",
"self",
".",
"z",
"+",
"z",
",",
"self",
".",
"species",
",",
"self",
".",
"constrain",
")",
... | An exact clone of the atom. Same ID and everything
Return a new atom with the same species and relaxation constraints
but with coordinates displaced by +x+, +y+, +z+ | [
"An",
"exact",
"clone",
"of",
"the",
"atom",
".",
"Same",
"ID",
"and",
"everything",
"Return",
"a",
"new",
"atom",
"with",
"the",
"same",
"species",
"and",
"relaxation",
"constraints",
"but",
"with",
"coordinates",
"displaced",
"by",
"+",
"x",
"+",
"+",
... | 2dcb6c02cd05b2d0c8ab72be4e85d60375df296c | https://github.com/jns/Aims/blob/2dcb6c02cd05b2d0c8ab72be4e85d60375df296c/lib/aims/atom.rb#L112-L114 |
6,226 | jns/Aims | lib/aims/atom.rb | Aims.Atom.displace! | def displace!(x,y,z)
self.x += x
self.y += y
self.z += z
end | ruby | def displace!(x,y,z)
self.x += x
self.y += y
self.z += z
end | [
"def",
"displace!",
"(",
"x",
",",
"y",
",",
"z",
")",
"self",
".",
"x",
"+=",
"x",
"self",
".",
"y",
"+=",
"y",
"self",
".",
"z",
"+=",
"z",
"end"
] | Displace this atom in place | [
"Displace",
"this",
"atom",
"in",
"place"
] | 2dcb6c02cd05b2d0c8ab72be4e85d60375df296c | https://github.com/jns/Aims/blob/2dcb6c02cd05b2d0c8ab72be4e85d60375df296c/lib/aims/atom.rb#L117-L121 |
6,227 | jns/Aims | lib/aims/atom.rb | Aims.Atom.format_geometry_in | def format_geometry_in
line = "atom %16.6f %16.6f %16.6f %s" % [self.x, self.y, self.z, self.species]
if self.constrain
if self.constrain == true
line << "\nconstrain_relaxation .true."
elsif self.constrain.is_a? String
line << "\nconstrain_relaxation #{self.constrain}"
... | ruby | def format_geometry_in
line = "atom %16.6f %16.6f %16.6f %s" % [self.x, self.y, self.z, self.species]
if self.constrain
if self.constrain == true
line << "\nconstrain_relaxation .true."
elsif self.constrain.is_a? String
line << "\nconstrain_relaxation #{self.constrain}"
... | [
"def",
"format_geometry_in",
"line",
"=",
"\"atom %16.6f %16.6f %16.6f %s\"",
"%",
"[",
"self",
".",
"x",
",",
"self",
".",
"y",
",",
"self",
".",
"z",
",",
"self",
".",
"species",
"]",
"if",
"self",
".",
"constrain",
"if",
"self",
".",
"constrain",
"=="... | Print a string representation of this atom formatted in the
geometry.in format used by Aims | [
"Print",
"a",
"string",
"representation",
"of",
"this",
"atom",
"formatted",
"in",
"the",
"geometry",
".",
"in",
"format",
"used",
"by",
"Aims"
] | 2dcb6c02cd05b2d0c8ab72be4e85d60375df296c | https://github.com/jns/Aims/blob/2dcb6c02cd05b2d0c8ab72be4e85d60375df296c/lib/aims/atom.rb#L189-L204 |
6,228 | madwire/trooper | lib/trooper/runner.rb | Trooper.Runner.build_commands | def build_commands(strategy_name, type, action_name)
action = Arsenal.actions[action_name]
if action
options = action.options
case type
when :prerequisite
commands = action.prerequisite_call config
Trooper.logger.action "Prerequisite: #{action.description}"
... | ruby | def build_commands(strategy_name, type, action_name)
action = Arsenal.actions[action_name]
if action
options = action.options
case type
when :prerequisite
commands = action.prerequisite_call config
Trooper.logger.action "Prerequisite: #{action.description}"
... | [
"def",
"build_commands",
"(",
"strategy_name",
",",
"type",
",",
"action_name",
")",
"action",
"=",
"Arsenal",
".",
"actions",
"[",
"action_name",
"]",
"if",
"action",
"options",
"=",
"action",
".",
"options",
"case",
"type",
"when",
":prerequisite",
"commands... | build the commands to be sent to the host object | [
"build",
"the",
"commands",
"to",
"be",
"sent",
"to",
"the",
"host",
"object"
] | ca953f9b78adf1614f7acf82c9076055540ee04c | https://github.com/madwire/trooper/blob/ca953f9b78adf1614f7acf82c9076055540ee04c/lib/trooper/runner.rb#L63-L82 |
6,229 | madwire/trooper | lib/trooper/runner.rb | Trooper.Runner.hosts | def hosts
@hosts ||= begin
r, h, u = [], (config[:hosts] rescue nil), (config[:user] rescue nil)
h.each {|host| r << Host.new(host, u) } if h && u; r
end
end | ruby | def hosts
@hosts ||= begin
r, h, u = [], (config[:hosts] rescue nil), (config[:user] rescue nil)
h.each {|host| r << Host.new(host, u) } if h && u; r
end
end | [
"def",
"hosts",
"@hosts",
"||=",
"begin",
"r",
",",
"h",
",",
"u",
"=",
"[",
"]",
",",
"(",
"config",
"[",
":hosts",
"]",
"rescue",
"nil",
")",
",",
"(",
"config",
"[",
":user",
"]",
"rescue",
"nil",
")",
"h",
".",
"each",
"{",
"|",
"host",
"... | returns an array of host objects | [
"returns",
"an",
"array",
"of",
"host",
"objects"
] | ca953f9b78adf1614f7acf82c9076055540ee04c | https://github.com/madwire/trooper/blob/ca953f9b78adf1614f7acf82c9076055540ee04c/lib/trooper/runner.rb#L85-L90 |
6,230 | madwire/trooper | lib/trooper/runner.rb | Trooper.Runner.runner_execute! | def runner_execute!(host, commands, options = {})
result = host.execute commands, options
if result && result[1] == :stdout
Trooper.logger.info "#{result[2]}\n"
true
else
false
end
end | ruby | def runner_execute!(host, commands, options = {})
result = host.execute commands, options
if result && result[1] == :stdout
Trooper.logger.info "#{result[2]}\n"
true
else
false
end
end | [
"def",
"runner_execute!",
"(",
"host",
",",
"commands",
",",
"options",
"=",
"{",
"}",
")",
"result",
"=",
"host",
".",
"execute",
"commands",
",",
"options",
"if",
"result",
"&&",
"result",
"[",
"1",
"]",
"==",
":stdout",
"Trooper",
".",
"logger",
"."... | runs the commands on a host and deals with output | [
"runs",
"the",
"commands",
"on",
"a",
"host",
"and",
"deals",
"with",
"output"
] | ca953f9b78adf1614f7acf82c9076055540ee04c | https://github.com/madwire/trooper/blob/ca953f9b78adf1614f7acf82c9076055540ee04c/lib/trooper/runner.rb#L93-L101 |
6,231 | jeremyolliver/gvis | lib/gvis/data_table.rb | Gvis.DataTable.add_row | def add_row(row)
size = row.size
raise ArgumentError.new("Given a row of data with #{size} entries, but there are only #{@table_columns.size} columns in the table") unless size == @table_columns.size
@data << row
end | ruby | def add_row(row)
size = row.size
raise ArgumentError.new("Given a row of data with #{size} entries, but there are only #{@table_columns.size} columns in the table") unless size == @table_columns.size
@data << row
end | [
"def",
"add_row",
"(",
"row",
")",
"size",
"=",
"row",
".",
"size",
"raise",
"ArgumentError",
".",
"new",
"(",
"\"Given a row of data with #{size} entries, but there are only #{@table_columns.size} columns in the table\"",
")",
"unless",
"size",
"==",
"@table_columns",
".",... | Adds a single row to the table
@param [Array] row An array with a single row of data for the table. Should have the same number of entries as there are columns | [
"Adds",
"a",
"single",
"row",
"to",
"the",
"table"
] | 2bd3291b43484191f10c0c7eaf333c6105ea2828 | https://github.com/jeremyolliver/gvis/blob/2bd3291b43484191f10c0c7eaf333c6105ea2828/lib/gvis/data_table.rb#L44-L48 |
6,232 | jeremyolliver/gvis | lib/gvis/data_table.rb | Gvis.DataTable.add_rows | def add_rows(rows)
sizes = rows.collect {|r| r.size }.uniq
expected_size = @table_columns.size
errors = sizes.select {|s| s != expected_size }
raise ArgumentError.new("Given a row of data with #{errors.to_sentence} entries, but there are only #{expected_size} columns in the table") if errors.any... | ruby | def add_rows(rows)
sizes = rows.collect {|r| r.size }.uniq
expected_size = @table_columns.size
errors = sizes.select {|s| s != expected_size }
raise ArgumentError.new("Given a row of data with #{errors.to_sentence} entries, but there are only #{expected_size} columns in the table") if errors.any... | [
"def",
"add_rows",
"(",
"rows",
")",
"sizes",
"=",
"rows",
".",
"collect",
"{",
"|",
"r",
"|",
"r",
".",
"size",
"}",
".",
"uniq",
"expected_size",
"=",
"@table_columns",
".",
"size",
"errors",
"=",
"sizes",
".",
"select",
"{",
"|",
"s",
"|",
"s",
... | Adds multiple rows to the table
@param [Array] rows A 2d Array containing multiple rows of data. Each Array should have the same number of entries as the table has columns | [
"Adds",
"multiple",
"rows",
"to",
"the",
"table"
] | 2bd3291b43484191f10c0c7eaf333c6105ea2828 | https://github.com/jeremyolliver/gvis/blob/2bd3291b43484191f10c0c7eaf333c6105ea2828/lib/gvis/data_table.rb#L52-L58 |
6,233 | jeremyolliver/gvis | lib/gvis/data_table.rb | Gvis.DataTable.format_data | def format_data
formatted_rows = []
@data.each do |row|
values = []
row.each_with_index do |entry,index|
values << Gvis::DataCell.new(entry, @column_types.to_a[index][1]).to_js
end
rowstring = "[#{values.join(", ")}]"
formatted_rows << rowstring
end
... | ruby | def format_data
formatted_rows = []
@data.each do |row|
values = []
row.each_with_index do |entry,index|
values << Gvis::DataCell.new(entry, @column_types.to_a[index][1]).to_js
end
rowstring = "[#{values.join(", ")}]"
formatted_rows << rowstring
end
... | [
"def",
"format_data",
"formatted_rows",
"=",
"[",
"]",
"@data",
".",
"each",
"do",
"|",
"row",
"|",
"values",
"=",
"[",
"]",
"row",
".",
"each_with_index",
"do",
"|",
"entry",
",",
"index",
"|",
"values",
"<<",
"Gvis",
"::",
"DataCell",
".",
"new",
"... | Outputs the data within this table as a javascript array ready for use by google.visualization.DataTable
This is where conversions of ruby date objects to javascript Date objects and escaping strings, and formatting options is done
@return [String] a javascript array with the first row defining the table, and subsequ... | [
"Outputs",
"the",
"data",
"within",
"this",
"table",
"as",
"a",
"javascript",
"array",
"ready",
"for",
"use",
"by",
"google",
".",
"visualization",
".",
"DataTable",
"This",
"is",
"where",
"conversions",
"of",
"ruby",
"date",
"objects",
"to",
"javascript",
"... | 2bd3291b43484191f10c0c7eaf333c6105ea2828 | https://github.com/jeremyolliver/gvis/blob/2bd3291b43484191f10c0c7eaf333c6105ea2828/lib/gvis/data_table.rb#L72-L83 |
6,234 | jeremyolliver/gvis | lib/gvis/data_table.rb | Gvis.DataTable.register_column | def register_column(type, name)
type = type.to_s.downcase
raise ArgumentError.new("invalid column type #{type}, permitted types are #{COLUMN_TYPES.join(', ')}") unless COLUMN_TYPES.include?(type)
@table_columns << name.to_s
@column_types.merge!(name.to_s => type)
end | ruby | def register_column(type, name)
type = type.to_s.downcase
raise ArgumentError.new("invalid column type #{type}, permitted types are #{COLUMN_TYPES.join(', ')}") unless COLUMN_TYPES.include?(type)
@table_columns << name.to_s
@column_types.merge!(name.to_s => type)
end | [
"def",
"register_column",
"(",
"type",
",",
"name",
")",
"type",
"=",
"type",
".",
"to_s",
".",
"downcase",
"raise",
"ArgumentError",
".",
"new",
"(",
"\"invalid column type #{type}, permitted types are #{COLUMN_TYPES.join(', ')}\"",
")",
"unless",
"COLUMN_TYPES",
".",
... | Registers each column explicitly, with data type, and a name associated
@param [String] type the type of data column being registered, valid input here are entries from DataTable::COLUMN_TYPES
@param [String] name the column name that will be used as a label on the graph | [
"Registers",
"each",
"column",
"explicitly",
"with",
"data",
"type",
"and",
"a",
"name",
"associated"
] | 2bd3291b43484191f10c0c7eaf333c6105ea2828 | https://github.com/jeremyolliver/gvis/blob/2bd3291b43484191f10c0c7eaf333c6105ea2828/lib/gvis/data_table.rb#L92-L97 |
6,235 | BUEZE/taaze | lib/taaze/collections.rb | Taaze.TaazeCollections.extract_books | def extract_books
booklist = []
if @doc.count != 0
@doc.each do |book_data|
book = {}
book['title'] = book_data['titleMain']
book['book_url'] = BOOK_URL + book_data['prodId']
book['crt_time'] = book_data['crtTime'].split(' ')[0]
booklist << book
... | ruby | def extract_books
booklist = []
if @doc.count != 0
@doc.each do |book_data|
book = {}
book['title'] = book_data['titleMain']
book['book_url'] = BOOK_URL + book_data['prodId']
book['crt_time'] = book_data['crtTime'].split(' ')[0]
booklist << book
... | [
"def",
"extract_books",
"booklist",
"=",
"[",
"]",
"if",
"@doc",
".",
"count",
"!=",
"0",
"@doc",
".",
"each",
"do",
"|",
"book_data",
"|",
"book",
"=",
"{",
"}",
"book",
"[",
"'title'",
"]",
"=",
"book_data",
"[",
"'titleMain'",
"]",
"book",
"[",
... | Return the books in the format specified in spec. | [
"Return",
"the",
"books",
"in",
"the",
"format",
"specified",
"in",
"spec",
"."
] | ef95e1ad71140a7eaf9e2c65830d900f651bc184 | https://github.com/BUEZE/taaze/blob/ef95e1ad71140a7eaf9e2c65830d900f651bc184/lib/taaze/collections.rb#L43-L55 |
6,236 | buren/site_mapper | lib/site_mapper/crawler.rb | SiteMapper.Crawler.collect_urls | def collect_urls
@fetch_queue << @crawl_url.resolved_base_url
until @fetch_queue.empty? || @processed.length >= @options[:max_requests]
url = @fetch_queue.pop
yield(url)
page_urls_for(url)
end
result = @processed + @fetch_queue
Logger.log "Crawling finished:"
... | ruby | def collect_urls
@fetch_queue << @crawl_url.resolved_base_url
until @fetch_queue.empty? || @processed.length >= @options[:max_requests]
url = @fetch_queue.pop
yield(url)
page_urls_for(url)
end
result = @processed + @fetch_queue
Logger.log "Crawling finished:"
... | [
"def",
"collect_urls",
"@fetch_queue",
"<<",
"@crawl_url",
".",
"resolved_base_url",
"until",
"@fetch_queue",
".",
"empty?",
"||",
"@processed",
".",
"length",
">=",
"@options",
"[",
":max_requests",
"]",
"url",
"=",
"@fetch_queue",
".",
"pop",
"yield",
"(",
"ur... | Collects all links on domain for domain.
@return [Array] with links.
@example URLs for example.com
crawler = Crawler.new('example.com')
crawler.collect_urls
@example URLs for example.com with block (executes in its own thread)
crawler = Crawler.new('example.com')
crawler.collect_urls do |new_url|
pu... | [
"Collects",
"all",
"links",
"on",
"domain",
"for",
"domain",
"."
] | a14233229baacfdb87539c8916ad744ee7832709 | https://github.com/buren/site_mapper/blob/a14233229baacfdb87539c8916ad744ee7832709/lib/site_mapper/crawler.rb#L48-L63 |
6,237 | joshwlewis/liner | lib/liner/hashable.rb | Liner.Hashable.liner | def liner
liner_keys.inject({}) { |h,k| h[k] = self[k]; h }.freeze
end | ruby | def liner
liner_keys.inject({}) { |h,k| h[k] = self[k]; h }.freeze
end | [
"def",
"liner",
"liner_keys",
".",
"inject",
"(",
"{",
"}",
")",
"{",
"|",
"h",
",",
"k",
"|",
"h",
"[",
"k",
"]",
"=",
"self",
"[",
"k",
"]",
";",
"h",
"}",
".",
"freeze",
"end"
] | Build a hash of liner attributes
@return [Hash] A hash of liner attributes
@api public | [
"Build",
"a",
"hash",
"of",
"liner",
"attributes"
] | d4a3142521fa04a6c9adda5fedde3e57c4c4e00a | https://github.com/joshwlewis/liner/blob/d4a3142521fa04a6c9adda5fedde3e57c4c4e00a/lib/liner/hashable.rb#L28-L30 |
6,238 | mdub/pith | lib/pith/output.rb | Pith.Output.build | def build
return false if @generated
logger.info("--> #{path}")
@dependencies = Set.new
file.parent.mkpath
if input.template?
evaluate_template
else
copy_resource
end
@generated = true
end | ruby | def build
return false if @generated
logger.info("--> #{path}")
@dependencies = Set.new
file.parent.mkpath
if input.template?
evaluate_template
else
copy_resource
end
@generated = true
end | [
"def",
"build",
"return",
"false",
"if",
"@generated",
"logger",
".",
"info",
"(",
"\"--> #{path}\"",
")",
"@dependencies",
"=",
"Set",
".",
"new",
"file",
".",
"parent",
".",
"mkpath",
"if",
"input",
".",
"template?",
"evaluate_template",
"else",
"copy_resour... | Generate output for this template | [
"Generate",
"output",
"for",
"this",
"template"
] | a78047cf65653172817b0527672bf6df960d510f | https://github.com/mdub/pith/blob/a78047cf65653172817b0527672bf6df960d510f/lib/pith/output.rb#L32-L43 |
6,239 | blambeau/yargi | lib/yargi/digraph.rb | Yargi.Digraph.each_vertex | def each_vertex(filter=nil, &block)
if filter.nil?
@vertices.each &block
else
vertices(filter).each &block
end
end | ruby | def each_vertex(filter=nil, &block)
if filter.nil?
@vertices.each &block
else
vertices(filter).each &block
end
end | [
"def",
"each_vertex",
"(",
"filter",
"=",
"nil",
",",
"&",
"block",
")",
"if",
"filter",
".",
"nil?",
"@vertices",
".",
"each",
"block",
"else",
"vertices",
"(",
"filter",
")",
".",
"each",
"block",
"end",
"end"
] | Calls block on each graph vertex for with the 'filter and block' predicate
evaluates to true. | [
"Calls",
"block",
"on",
"each",
"graph",
"vertex",
"for",
"with",
"the",
"filter",
"and",
"block",
"predicate",
"evaluates",
"to",
"true",
"."
] | 100141e96d245a0a8211cd4f7590909be149bc3c | https://github.com/blambeau/yargi/blob/100141e96d245a0a8211cd4f7590909be149bc3c/lib/yargi/digraph.rb#L53-L59 |
6,240 | blambeau/yargi | lib/yargi/digraph.rb | Yargi.Digraph.remove_vertices | def remove_vertices(*vertices)
vertices = to_vertices(*vertices).sort{|v1,v2| v2<=>v1}
vertices.each do |vertex|
remove_edges(vertex.in_edges+vertex.out_edges)
@vertices.delete_at(vertex.index)
vertex.index=-1
end
@vertices.each_with_index {|v,i| v.index=i}
self
... | ruby | def remove_vertices(*vertices)
vertices = to_vertices(*vertices).sort{|v1,v2| v2<=>v1}
vertices.each do |vertex|
remove_edges(vertex.in_edges+vertex.out_edges)
@vertices.delete_at(vertex.index)
vertex.index=-1
end
@vertices.each_with_index {|v,i| v.index=i}
self
... | [
"def",
"remove_vertices",
"(",
"*",
"vertices",
")",
"vertices",
"=",
"to_vertices",
"(",
"vertices",
")",
".",
"sort",
"{",
"|",
"v1",
",",
"v2",
"|",
"v2",
"<=>",
"v1",
"}",
"vertices",
".",
"each",
"do",
"|",
"vertex",
"|",
"remove_edges",
"(",
"v... | Removes all vertices returned by evaluating the _vertices_ selection
expression. | [
"Removes",
"all",
"vertices",
"returned",
"by",
"evaluating",
"the",
"_vertices_",
"selection",
"expression",
"."
] | 100141e96d245a0a8211cd4f7590909be149bc3c | https://github.com/blambeau/yargi/blob/100141e96d245a0a8211cd4f7590909be149bc3c/lib/yargi/digraph.rb#L89-L98 |
6,241 | blambeau/yargi | lib/yargi/digraph.rb | Yargi.Digraph.each_edge | def each_edge(filter=nil, &block)
if filter.nil?
@edges.each &block
else
edges(filter).each &block
end
end | ruby | def each_edge(filter=nil, &block)
if filter.nil?
@edges.each &block
else
edges(filter).each &block
end
end | [
"def",
"each_edge",
"(",
"filter",
"=",
"nil",
",",
"&",
"block",
")",
"if",
"filter",
".",
"nil?",
"@edges",
".",
"each",
"block",
"else",
"edges",
"(",
"filter",
")",
".",
"each",
"block",
"end",
"end"
] | Calls block on each graph edge for with the 'filter and block' predicate
evaluates to true. | [
"Calls",
"block",
"on",
"each",
"graph",
"edge",
"for",
"with",
"the",
"filter",
"and",
"block",
"predicate",
"evaluates",
"to",
"true",
"."
] | 100141e96d245a0a8211cd4f7590909be149bc3c | https://github.com/blambeau/yargi/blob/100141e96d245a0a8211cd4f7590909be149bc3c/lib/yargi/digraph.rb#L121-L127 |
6,242 | blambeau/yargi | lib/yargi/digraph.rb | Yargi.Digraph.remove_edges | def remove_edges(*edges)
edges = to_edges(edges).sort{|e1,e2| e2<=>e1}
edges.each do |edge|
edge.source.remove_out_edge(edge)
edge.target.remove_in_edge(edge)
@edges.delete_at(edge.index)
edge.index = -1
end
@edges.each_with_index {|edge,i| edge.index=i}
sel... | ruby | def remove_edges(*edges)
edges = to_edges(edges).sort{|e1,e2| e2<=>e1}
edges.each do |edge|
edge.source.remove_out_edge(edge)
edge.target.remove_in_edge(edge)
@edges.delete_at(edge.index)
edge.index = -1
end
@edges.each_with_index {|edge,i| edge.index=i}
sel... | [
"def",
"remove_edges",
"(",
"*",
"edges",
")",
"edges",
"=",
"to_edges",
"(",
"edges",
")",
".",
"sort",
"{",
"|",
"e1",
",",
"e2",
"|",
"e2",
"<=>",
"e1",
"}",
"edges",
".",
"each",
"do",
"|",
"edge",
"|",
"edge",
".",
"source",
".",
"remove_out... | Removes all edges returned by evaluating the _edges_ selection
expression. | [
"Removes",
"all",
"edges",
"returned",
"by",
"evaluating",
"the",
"_edges_",
"selection",
"expression",
"."
] | 100141e96d245a0a8211cd4f7590909be149bc3c | https://github.com/blambeau/yargi/blob/100141e96d245a0a8211cd4f7590909be149bc3c/lib/yargi/digraph.rb#L164-L174 |
6,243 | blambeau/yargi | lib/yargi/digraph.rb | Yargi.Digraph.to_dot | def to_dot(buffer='')
buffer << "digraph G {\n"
buffer << " graph[#{to_dot_attributes(self.to_h(true))}]\n"
each_vertex do |v|
buffer << " V#{v.index} [#{to_dot_attributes(v.to_h(true))}]\n"
end
each_edge do |e|
buffer << " V#{e.source.index} -> V#{e.target.index} [#{to_... | ruby | def to_dot(buffer='')
buffer << "digraph G {\n"
buffer << " graph[#{to_dot_attributes(self.to_h(true))}]\n"
each_vertex do |v|
buffer << " V#{v.index} [#{to_dot_attributes(v.to_h(true))}]\n"
end
each_edge do |e|
buffer << " V#{e.source.index} -> V#{e.target.index} [#{to_... | [
"def",
"to_dot",
"(",
"buffer",
"=",
"''",
")",
"buffer",
"<<",
"\"digraph G {\\n\"",
"buffer",
"<<",
"\" graph[#{to_dot_attributes(self.to_h(true))}]\\n\"",
"each_vertex",
"do",
"|",
"v",
"|",
"buffer",
"<<",
"\" V#{v.index} [#{to_dot_attributes(v.to_h(true))}]\\n\"",
"e... | Standard exports
Encodes this graph for dot graphviz | [
"Standard",
"exports",
"Encodes",
"this",
"graph",
"for",
"dot",
"graphviz"
] | 100141e96d245a0a8211cd4f7590909be149bc3c | https://github.com/blambeau/yargi/blob/100141e96d245a0a8211cd4f7590909be149bc3c/lib/yargi/digraph.rb#L202-L212 |
6,244 | blambeau/yargi | lib/yargi/digraph.rb | Yargi.Digraph.to_dot_attributes | def to_dot_attributes(hash)
# TODO: fix uncompatible key names
# TODO: some values must be encoded (backquoting and the like)
buffer = ""
hash.each_pair do |k,v|
buffer << " " unless buffer.empty?
v = case v
when Array
if v.all?{|elm| Array===elm and elm.len... | ruby | def to_dot_attributes(hash)
# TODO: fix uncompatible key names
# TODO: some values must be encoded (backquoting and the like)
buffer = ""
hash.each_pair do |k,v|
buffer << " " unless buffer.empty?
v = case v
when Array
if v.all?{|elm| Array===elm and elm.len... | [
"def",
"to_dot_attributes",
"(",
"hash",
")",
"# TODO: fix uncompatible key names",
"# TODO: some values must be encoded (backquoting and the like)",
"buffer",
"=",
"\"\"",
"hash",
".",
"each_pair",
"do",
"|",
"k",
",",
"v",
"|",
"buffer",
"<<",
"\" \"",
"unless",
"buff... | Converts a hash to dot attributes | [
"Converts",
"a",
"hash",
"to",
"dot",
"attributes"
] | 100141e96d245a0a8211cd4f7590909be149bc3c | https://github.com/blambeau/yargi/blob/100141e96d245a0a8211cd4f7590909be149bc3c/lib/yargi/digraph.rb#L218-L237 |
6,245 | blambeau/yargi | lib/yargi/digraph.rb | Yargi.Digraph.check_sanity | def check_sanity
@vertices.each_with_index do |v,i|
raise "Removed vertex in vertex list" unless v.index==i
v.in_edges.each do |ine|
raise "Removed edge in vertex incoming edges" if ine.index<0
raise "Vertex and edge don't agree on target" unless ine.target==v
end
... | ruby | def check_sanity
@vertices.each_with_index do |v,i|
raise "Removed vertex in vertex list" unless v.index==i
v.in_edges.each do |ine|
raise "Removed edge in vertex incoming edges" if ine.index<0
raise "Vertex and edge don't agree on target" unless ine.target==v
end
... | [
"def",
"check_sanity",
"@vertices",
".",
"each_with_index",
"do",
"|",
"v",
",",
"i",
"|",
"raise",
"\"Removed vertex in vertex list\"",
"unless",
"v",
".",
"index",
"==",
"i",
"v",
".",
"in_edges",
".",
"each",
"do",
"|",
"ine",
"|",
"raise",
"\"Removed edg... | Checks graph sanity | [
"Checks",
"graph",
"sanity"
] | 100141e96d245a0a8211cd4f7590909be149bc3c | https://github.com/blambeau/yargi/blob/100141e96d245a0a8211cd4f7590909be149bc3c/lib/yargi/digraph.rb#L245-L262 |
6,246 | blambeau/yargi | lib/yargi/digraph.rb | Yargi.Digraph.to_vertices | def to_vertices(*args)
selected = args.collect do |arg|
case arg
when Integer
[@vertices[arg]]
when VertexSet
arg
when Array
arg.collect{|v| to_vertices(v)}.flatten.uniq
when Digraph::Vertex
[arg]
else
... | ruby | def to_vertices(*args)
selected = args.collect do |arg|
case arg
when Integer
[@vertices[arg]]
when VertexSet
arg
when Array
arg.collect{|v| to_vertices(v)}.flatten.uniq
when Digraph::Vertex
[arg]
else
... | [
"def",
"to_vertices",
"(",
"*",
"args",
")",
"selected",
"=",
"args",
".",
"collect",
"do",
"|",
"arg",
"|",
"case",
"arg",
"when",
"Integer",
"[",
"@vertices",
"[",
"arg",
"]",
"]",
"when",
"VertexSet",
"arg",
"when",
"Array",
"arg",
".",
"collect",
... | Applies argument conventions about selection of vertices | [
"Applies",
"argument",
"conventions",
"about",
"selection",
"of",
"vertices"
] | 100141e96d245a0a8211cd4f7590909be149bc3c | https://github.com/blambeau/yargi/blob/100141e96d245a0a8211cd4f7590909be149bc3c/lib/yargi/digraph.rb#L265-L282 |
6,247 | blambeau/yargi | lib/yargi/digraph.rb | Yargi.Digraph.to_edges | def to_edges(*args)
selected = args.collect do |arg|
case arg
when Integer
[@edges[arg]]
when EdgeSet
arg
when Array
arg.collect{|v| to_edges(v)}.flatten.uniq
when Digraph::Edge
[arg]
else
pred = ... | ruby | def to_edges(*args)
selected = args.collect do |arg|
case arg
when Integer
[@edges[arg]]
when EdgeSet
arg
when Array
arg.collect{|v| to_edges(v)}.flatten.uniq
when Digraph::Edge
[arg]
else
pred = ... | [
"def",
"to_edges",
"(",
"*",
"args",
")",
"selected",
"=",
"args",
".",
"collect",
"do",
"|",
"arg",
"|",
"case",
"arg",
"when",
"Integer",
"[",
"@edges",
"[",
"arg",
"]",
"]",
"when",
"EdgeSet",
"arg",
"when",
"Array",
"arg",
".",
"collect",
"{",
... | Applies argument conventions about selection of edges | [
"Applies",
"argument",
"conventions",
"about",
"selection",
"of",
"edges"
] | 100141e96d245a0a8211cd4f7590909be149bc3c | https://github.com/blambeau/yargi/blob/100141e96d245a0a8211cd4f7590909be149bc3c/lib/yargi/digraph.rb#L285-L302 |
6,248 | blambeau/yargi | lib/yargi/digraph.rb | Yargi.Digraph.apply_arg_conventions | def apply_arg_conventions(element, args)
args.each do |arg|
case arg
when Module
element.tag(arg)
when Hash
element.add_marks(arg)
else
raise ArgumentError, "Unable to apply argument conventions on #{arg.inspect}", caller
end
... | ruby | def apply_arg_conventions(element, args)
args.each do |arg|
case arg
when Module
element.tag(arg)
when Hash
element.add_marks(arg)
else
raise ArgumentError, "Unable to apply argument conventions on #{arg.inspect}", caller
end
... | [
"def",
"apply_arg_conventions",
"(",
"element",
",",
"args",
")",
"args",
".",
"each",
"do",
"|",
"arg",
"|",
"case",
"arg",
"when",
"Module",
"element",
".",
"tag",
"(",
"arg",
")",
"when",
"Hash",
"element",
".",
"add_marks",
"(",
"arg",
")",
"else",... | Applies argument conventions on _element_ | [
"Applies",
"argument",
"conventions",
"on",
"_element_"
] | 100141e96d245a0a8211cd4f7590909be149bc3c | https://github.com/blambeau/yargi/blob/100141e96d245a0a8211cd4f7590909be149bc3c/lib/yargi/digraph.rb#L305-L317 |
6,249 | pjb3/curtain | lib/curtain/html_helpers.rb | Curtain.HTMLHelpers.content_tag | def content_tag(name, content=nil, attrs={}, &body)
if content.is_a?(Hash)
attrs = content
content = nil
end
if block_given?
content = capture(&body)
end
tag = tag_opening(name, attrs)
tag << ">".html_safe
tag << content
tag << "</#{name}>".html_... | ruby | def content_tag(name, content=nil, attrs={}, &body)
if content.is_a?(Hash)
attrs = content
content = nil
end
if block_given?
content = capture(&body)
end
tag = tag_opening(name, attrs)
tag << ">".html_safe
tag << content
tag << "</#{name}>".html_... | [
"def",
"content_tag",
"(",
"name",
",",
"content",
"=",
"nil",
",",
"attrs",
"=",
"{",
"}",
",",
"&",
"body",
")",
"if",
"content",
".",
"is_a?",
"(",
"Hash",
")",
"attrs",
"=",
"content",
"content",
"=",
"nil",
"end",
"if",
"block_given?",
"content"... | Generates a with opening and closing tags and potentially content.
@example Tag with no attributes, no content
content_tag(:p) # => "<p></p>"
@example Tag with content
content_tag(:p, "Hello") # => "<p>Hello</p>"
@example Tag with block content
content_tag(:p) { "Hello" } # => "<p>Hello</p>"
@example T... | [
"Generates",
"a",
"with",
"opening",
"and",
"closing",
"tags",
"and",
"potentially",
"content",
"."
] | ab4f3dccea9b887148689084137f1375278f2dcf | https://github.com/pjb3/curtain/blob/ab4f3dccea9b887148689084137f1375278f2dcf/lib/curtain/html_helpers.rb#L50-L64 |
6,250 | barkerest/barkest_core | app/helpers/barkest_core/application_helper.rb | BarkestCore.ApplicationHelper.render_alert | def render_alert(type, message)
if type.to_s.index('safe_')
type = type.to_s[5..-1]
message = message.to_s.html_safe
end
type = type.to_sym
type = :info if type == :notice
type = :danger if type == :alert
return nil unless [:info, :success, :danger, :warning].inclu... | ruby | def render_alert(type, message)
if type.to_s.index('safe_')
type = type.to_s[5..-1]
message = message.to_s.html_safe
end
type = type.to_sym
type = :info if type == :notice
type = :danger if type == :alert
return nil unless [:info, :success, :danger, :warning].inclu... | [
"def",
"render_alert",
"(",
"type",
",",
"message",
")",
"if",
"type",
".",
"to_s",
".",
"index",
"(",
"'safe_'",
")",
"type",
"=",
"type",
".",
"to_s",
"[",
"5",
"..",
"-",
"1",
"]",
"message",
"=",
"message",
".",
"to_s",
".",
"html_safe",
"end",... | Renders an alert message.
* +type+ The type of message [info, success, warn, error, danger, etc]
* +message+ The message to display.
To provide messages including HTML, you need to prefix the type with 'safe_'.
render_alert(safe_info, '<strong>This</strong> is a message containing <code>HTML</code> content.')
... | [
"Renders",
"an",
"alert",
"message",
"."
] | 3eeb025ec870888cacbc9bae252a39ebf9295f61 | https://github.com/barkerest/barkest_core/blob/3eeb025ec870888cacbc9bae252a39ebf9295f61/app/helpers/barkest_core/application_helper.rb#L74-L88 |
6,251 | Democracy-for-America/ActionKitApi | lib/action_kit_api/event_campaign.rb | ActionKitApi.EventCampaign.create_event | def create_event(*args)
raise "EventCampaign needs to be saved before Event creation" if self.id.nil?
(args[0]).merge!(:campaign_id => self.id)
event = ActionKitApi::Event.new(*args)
end | ruby | def create_event(*args)
raise "EventCampaign needs to be saved before Event creation" if self.id.nil?
(args[0]).merge!(:campaign_id => self.id)
event = ActionKitApi::Event.new(*args)
end | [
"def",
"create_event",
"(",
"*",
"args",
")",
"raise",
"\"EventCampaign needs to be saved before Event creation\"",
"if",
"self",
".",
"id",
".",
"nil?",
"(",
"args",
"[",
"0",
"]",
")",
".",
"merge!",
"(",
":campaign_id",
"=>",
"self",
".",
"id",
")",
"even... | Requires at a minimum the creator_id | [
"Requires",
"at",
"a",
"minimum",
"the",
"creator_id"
] | 81a9e1f84c5e3facbfec0203d453377da7034a26 | https://github.com/Democracy-for-America/ActionKitApi/blob/81a9e1f84c5e3facbfec0203d453377da7034a26/lib/action_kit_api/event_campaign.rb#L30-L36 |
6,252 | Democracy-for-America/ActionKitApi | lib/action_kit_api/event_campaign.rb | ActionKitApi.EventCampaign.public_search | def public_search(*args)
(args[0]).merge!(:campaign_id => self.id)
results = ActionKitApi.connection.call("Event.public_search", *args)
results.map do |r|
Event.new(r)
end
results
end | ruby | def public_search(*args)
(args[0]).merge!(:campaign_id => self.id)
results = ActionKitApi.connection.call("Event.public_search", *args)
results.map do |r|
Event.new(r)
end
results
end | [
"def",
"public_search",
"(",
"*",
"args",
")",
"(",
"args",
"[",
"0",
"]",
")",
".",
"merge!",
"(",
":campaign_id",
"=>",
"self",
".",
"id",
")",
"results",
"=",
"ActionKitApi",
".",
"connection",
".",
"call",
"(",
"\"Event.public_search\"",
",",
"args",... | Will not return private events, events that are full, deleted, or in the past
and doesn't return extra fields | [
"Will",
"not",
"return",
"private",
"events",
"events",
"that",
"are",
"full",
"deleted",
"or",
"in",
"the",
"past",
"and",
"doesn",
"t",
"return",
"extra",
"fields"
] | 81a9e1f84c5e3facbfec0203d453377da7034a26 | https://github.com/Democracy-for-America/ActionKitApi/blob/81a9e1f84c5e3facbfec0203d453377da7034a26/lib/action_kit_api/event_campaign.rb#L45-L54 |
6,253 | roberthoner/encrypted_store | lib/encrypted_store/crypto_hash.rb | EncryptedStore.CryptoHash.encrypt | def encrypt(dek, salt, iter_mag=10)
return nil if empty?
raise Errors::InvalidSaltSize, 'too long' if salt.bytes.length > 255
key, iv = _keyiv_gen(dek, salt, iter_mag)
encryptor = OpenSSL::Cipher::AES256.new(:CBC).encrypt
encryptor.key = key
encryptor.iv = iv
data_packet = _... | ruby | def encrypt(dek, salt, iter_mag=10)
return nil if empty?
raise Errors::InvalidSaltSize, 'too long' if salt.bytes.length > 255
key, iv = _keyiv_gen(dek, salt, iter_mag)
encryptor = OpenSSL::Cipher::AES256.new(:CBC).encrypt
encryptor.key = key
encryptor.iv = iv
data_packet = _... | [
"def",
"encrypt",
"(",
"dek",
",",
"salt",
",",
"iter_mag",
"=",
"10",
")",
"return",
"nil",
"if",
"empty?",
"raise",
"Errors",
"::",
"InvalidSaltSize",
",",
"'too long'",
"if",
"salt",
".",
"bytes",
".",
"length",
">",
"255",
"key",
",",
"iv",
"=",
... | Encrypts the hash using the data encryption key and salt.
Returns a blob:
| Byte 0 | Byte 1 | Byte 2 | Bytes 3...S | Bytes S+1...E | Bytes E+1..E+4 |
------------------------------------------------------------------------------------------------
| Version | Salt Length | Iteration Magnitude ... | [
"Encrypts",
"the",
"hash",
"using",
"the",
"data",
"encryption",
"key",
"and",
"salt",
"."
] | 89e78eb19e0cb710b08b71209e42eda085dcaa8a | https://github.com/roberthoner/encrypted_store/blob/89e78eb19e0cb710b08b71209e42eda085dcaa8a/lib/encrypted_store/crypto_hash.rb#L19-L31 |
6,254 | barkerest/incline | lib/incline/user_manager.rb | Incline.UserManager.authenticate | def authenticate(email, password, client_ip)
return nil unless Incline::EmailValidator.valid?(email)
email = email.downcase
# If an engine is registered for the email domain, then use it.
engine = get_auth_engine(email)
if engine
return engine.authenticate(email, password, client_... | ruby | def authenticate(email, password, client_ip)
return nil unless Incline::EmailValidator.valid?(email)
email = email.downcase
# If an engine is registered for the email domain, then use it.
engine = get_auth_engine(email)
if engine
return engine.authenticate(email, password, client_... | [
"def",
"authenticate",
"(",
"email",
",",
"password",
",",
"client_ip",
")",
"return",
"nil",
"unless",
"Incline",
"::",
"EmailValidator",
".",
"valid?",
"(",
"email",
")",
"email",
"=",
"email",
".",
"downcase",
"# If an engine is registered for the email domain, t... | Creates a new user manager.
The user manager itself takes no options, however options will be passed to
any registered authentication engines when they are instantiated.
The options can be used to pre-register engines and provide configuration for them.
The engines will have specific configurations, but the UserM... | [
"Creates",
"a",
"new",
"user",
"manager",
"."
] | 1ff08db7aa8ab7f86b223268b700bc67d15bb8aa | https://github.com/barkerest/incline/blob/1ff08db7aa8ab7f86b223268b700bc67d15bb8aa/lib/incline/user_manager.rb#L81-L109 |
6,255 | barkerest/incline | lib/incline/user_manager.rb | Incline.UserManager.begin_external_authentication | def begin_external_authentication(request)
# We don't have an email domain to work from.
# Instead, we'll call each engine's authenticate_external method.
# If one of them returns a user, then we return that value and skip further processing.
auth_engines.each do |dom,engine|
unless engi... | ruby | def begin_external_authentication(request)
# We don't have an email domain to work from.
# Instead, we'll call each engine's authenticate_external method.
# If one of them returns a user, then we return that value and skip further processing.
auth_engines.each do |dom,engine|
unless engi... | [
"def",
"begin_external_authentication",
"(",
"request",
")",
"# We don't have an email domain to work from.",
"# Instead, we'll call each engine's authenticate_external method.",
"# If one of them returns a user, then we return that value and skip further processing.",
"auth_engines",
".",
"each... | The begin_external_authentication method takes a request object to determine if it should process a login
or return nil. If it decides to process authentication, it should return a URL to redirect to. | [
"The",
"begin_external_authentication",
"method",
"takes",
"a",
"request",
"object",
"to",
"determine",
"if",
"it",
"should",
"process",
"a",
"login",
"or",
"return",
"nil",
".",
"If",
"it",
"decides",
"to",
"process",
"authentication",
"it",
"should",
"return",... | 1ff08db7aa8ab7f86b223268b700bc67d15bb8aa | https://github.com/barkerest/incline/blob/1ff08db7aa8ab7f86b223268b700bc67d15bb8aa/lib/incline/user_manager.rb#L114-L125 |
6,256 | barkerest/incline | lib/incline/user_manager.rb | Incline.UserManager.register_auth_engine | def register_auth_engine(engine, *domains)
unless engine.nil?
unless engine.is_a?(::Incline::AuthEngineBase)
raise ArgumentError, "The 'engine' parameter must be an instance of an auth engine or a class defining an auth engine." unless engine.is_a?(::Class)
engine = engine.new(@options... | ruby | def register_auth_engine(engine, *domains)
unless engine.nil?
unless engine.is_a?(::Incline::AuthEngineBase)
raise ArgumentError, "The 'engine' parameter must be an instance of an auth engine or a class defining an auth engine." unless engine.is_a?(::Class)
engine = engine.new(@options... | [
"def",
"register_auth_engine",
"(",
"engine",
",",
"*",
"domains",
")",
"unless",
"engine",
".",
"nil?",
"unless",
"engine",
".",
"is_a?",
"(",
"::",
"Incline",
"::",
"AuthEngineBase",
")",
"raise",
"ArgumentError",
",",
"\"The 'engine' parameter must be an instance... | Registers an authentication engine for one or more domains.
The +engine+ passed in should take an options hash as the only argument to +initialize+
and should provide an +authenticate+ method that takes the +email+, +password+, and
+client_ip+. You can optionally define an +authenticate_external+ method that takes... | [
"Registers",
"an",
"authentication",
"engine",
"for",
"one",
"or",
"more",
"domains",
"."
] | 1ff08db7aa8ab7f86b223268b700bc67d15bb8aa | https://github.com/barkerest/incline/blob/1ff08db7aa8ab7f86b223268b700bc67d15bb8aa/lib/incline/user_manager.rb#L189-L204 |
6,257 | jomalley2112/controller_scaffolding | lib/generators/controller_generator_base.rb | Generators.ControllerGeneratorBase.copy_view_files | def copy_view_files #do NOT change the name of this method
# it must be overriding an existing one in a parent class
base_path = File.join("app/views", class_path, file_name)
#binding.pry
empty_directory base_path
@actions = actions.nil? || actions.empty? ? %w(index new ... | ruby | def copy_view_files #do NOT change the name of this method
# it must be overriding an existing one in a parent class
base_path = File.join("app/views", class_path, file_name)
#binding.pry
empty_directory base_path
@actions = actions.nil? || actions.empty? ? %w(index new ... | [
"def",
"copy_view_files",
"#do NOT change the name of this method ",
"# it must be overriding an existing one in a parent class",
"base_path",
"=",
"File",
".",
"join",
"(",
"\"app/views\"",
",",
"class_path",
",",
"file_name",
")",
"#binding.pry",
"empty_directory",
"base_path",... | This method seems to always get run first | [
"This",
"method",
"seems",
"to",
"always",
"get",
"run",
"first"
] | 380d37962fa84d0911e86fe01a8bca158c0b6b10 | https://github.com/jomalley2112/controller_scaffolding/blob/380d37962fa84d0911e86fe01a8bca158c0b6b10/lib/generators/controller_generator_base.rb#L15-L33 |
6,258 | hopsoft/footing | lib/footing/hash.rb | Footing.Hash.to_h | def to_h
copied_object.each_with_object({}) do |pair, memo|
value = pair.last
if value.is_a?(Footing::Hash)
memo[pair.first] = value.to_h
elsif value.is_a?(::Array)
memo[pair.first] = value.map do |val|
if val.is_a?(Footing::Hash)
val.to_h
... | ruby | def to_h
copied_object.each_with_object({}) do |pair, memo|
value = pair.last
if value.is_a?(Footing::Hash)
memo[pair.first] = value.to_h
elsif value.is_a?(::Array)
memo[pair.first] = value.map do |val|
if val.is_a?(Footing::Hash)
val.to_h
... | [
"def",
"to_h",
"copied_object",
".",
"each_with_object",
"(",
"{",
"}",
")",
"do",
"|",
"pair",
",",
"memo",
"|",
"value",
"=",
"pair",
".",
"last",
"if",
"value",
".",
"is_a?",
"(",
"Footing",
"::",
"Hash",
")",
"memo",
"[",
"pair",
".",
"first",
... | Returns a standard ruby Hash representation of the wrapped Hash.
@return [Hash] | [
"Returns",
"a",
"standard",
"ruby",
"Hash",
"representation",
"of",
"the",
"wrapped",
"Hash",
"."
] | fa37cbde4a75b774f65c3367245c41a8607fe67a | https://github.com/hopsoft/footing/blob/fa37cbde4a75b774f65c3367245c41a8607fe67a/lib/footing/hash.rb#L18-L35 |
6,259 | eyecuelab/smarteru | lib/smarteru/client.rb | Smarteru.Client.request | def request(operation, data)
opts = {
method: :post,
url: api_url,
payload: { 'Package' => body(operation, data) },
content_type: :xml,
verify_ssl: verify_ssl,
ssl_ca_file: ssl_ca_file }
response = RestClient::Request.execute(opts)
... | ruby | def request(operation, data)
opts = {
method: :post,
url: api_url,
payload: { 'Package' => body(operation, data) },
content_type: :xml,
verify_ssl: verify_ssl,
ssl_ca_file: ssl_ca_file }
response = RestClient::Request.execute(opts)
... | [
"def",
"request",
"(",
"operation",
",",
"data",
")",
"opts",
"=",
"{",
"method",
":",
":post",
",",
"url",
":",
"api_url",
",",
"payload",
":",
"{",
"'Package'",
"=>",
"body",
"(",
"operation",
",",
"data",
")",
"}",
",",
"content_type",
":",
":xml"... | Create an instance of an API client
==== Attributes
* +options+ - Access credentials and options hash, required keys are: account_api_key, user_api_key
==== Example
client = Smarteru::Client.new({account_api_key: 'abc', user_api_key: 'abc'})
Make an API request
==== Attributes
* +operation+ - Operation method... | [
"Create",
"an",
"instance",
"of",
"an",
"API",
"client"
] | a5b1c92f2d938d29b032520dcfdb9eb7be5fa020 | https://github.com/eyecuelab/smarteru/blob/a5b1c92f2d938d29b032520dcfdb9eb7be5fa020/lib/smarteru/client.rb#L33-L49 |
6,260 | eyecuelab/smarteru | lib/smarteru/client.rb | Smarteru.Client.body_parameters | def body_parameters(parameters)
parameters_xml = ''
parameters.each_pair do |k, v|
key = parameter_key(k)
val = case v
when Hash
body_parameters(v)
when Array
v.map { |i| body_parameters(i) }.join('')
when nil
''
else
"... | ruby | def body_parameters(parameters)
parameters_xml = ''
parameters.each_pair do |k, v|
key = parameter_key(k)
val = case v
when Hash
body_parameters(v)
when Array
v.map { |i| body_parameters(i) }.join('')
when nil
''
else
"... | [
"def",
"body_parameters",
"(",
"parameters",
")",
"parameters_xml",
"=",
"''",
"parameters",
".",
"each_pair",
"do",
"|",
"k",
",",
"v",
"|",
"key",
"=",
"parameter_key",
"(",
"k",
")",
"val",
"=",
"case",
"v",
"when",
"Hash",
"body_parameters",
"(",
"v"... | Build body parameteres xml
==== Attributes
* +parameters+ - Parameters hash | [
"Build",
"body",
"parameteres",
"xml"
] | a5b1c92f2d938d29b032520dcfdb9eb7be5fa020 | https://github.com/eyecuelab/smarteru/blob/a5b1c92f2d938d29b032520dcfdb9eb7be5fa020/lib/smarteru/client.rb#L78-L98 |
6,261 | eyecuelab/smarteru | lib/smarteru/client.rb | Smarteru.Client.parameter_key | def parameter_key(term)
string = term.to_s
string = string.sub(/^[a-z\d]*/) { $&.capitalize }
string.gsub!(/(?:_|(\/))([a-z\d]*)/i) { "#{$1}#{$2.capitalize}" }
string
end | ruby | def parameter_key(term)
string = term.to_s
string = string.sub(/^[a-z\d]*/) { $&.capitalize }
string.gsub!(/(?:_|(\/))([a-z\d]*)/i) { "#{$1}#{$2.capitalize}" }
string
end | [
"def",
"parameter_key",
"(",
"term",
")",
"string",
"=",
"term",
".",
"to_s",
"string",
"=",
"string",
".",
"sub",
"(",
"/",
"\\d",
"/",
")",
"{",
"$&",
".",
"capitalize",
"}",
"string",
".",
"gsub!",
"(",
"/",
"\\/",
"\\d",
"/i",
")",
"{",
"\"#{... | Prepare parameter key
==== Attributes
* +parameters+ - Parameters hash | [
"Prepare",
"parameter",
"key"
] | a5b1c92f2d938d29b032520dcfdb9eb7be5fa020 | https://github.com/eyecuelab/smarteru/blob/a5b1c92f2d938d29b032520dcfdb9eb7be5fa020/lib/smarteru/client.rb#L104-L109 |
6,262 | jns/Aims | lib/aims/zinc_blende.rb | Aims.ZincBlende.get_bulk | def get_bulk
b = 0.25*self.lattice_const
a1 = Atom.new(0, 0, 0, self.cation)
a2 = Atom.new(b, b, b, self.anion)
v1 = Vector[0.5, 0.5, 0.0]*self.lattice_const
v2 = Vector[0.5, 0.0, 0.5]*self.lattice_const
v3 = Vector[0.0, 0.5, 0.5]*self.lattice_const
zb = Geometry.new([a1... | ruby | def get_bulk
b = 0.25*self.lattice_const
a1 = Atom.new(0, 0, 0, self.cation)
a2 = Atom.new(b, b, b, self.anion)
v1 = Vector[0.5, 0.5, 0.0]*self.lattice_const
v2 = Vector[0.5, 0.0, 0.5]*self.lattice_const
v3 = Vector[0.0, 0.5, 0.5]*self.lattice_const
zb = Geometry.new([a1... | [
"def",
"get_bulk",
"b",
"=",
"0.25",
"*",
"self",
".",
"lattice_const",
"a1",
"=",
"Atom",
".",
"new",
"(",
"0",
",",
"0",
",",
"0",
",",
"self",
".",
"cation",
")",
"a2",
"=",
"Atom",
".",
"new",
"(",
"b",
",",
"b",
",",
"b",
",",
"self",
... | Initialize the zinc-blende Geometry
cation and anion are the atomic
species occupying the two different sub-lattices.
lattice_const specifies the lattice constant
Return the traditional unit cell of bulk zinc blende | [
"Initialize",
"the",
"zinc",
"-",
"blende",
"Geometry",
"cation",
"and",
"anion",
"are",
"the",
"atomic",
"species",
"occupying",
"the",
"two",
"different",
"sub",
"-",
"lattices",
".",
"lattice_const",
"specifies",
"the",
"lattice",
"constant",
"Return",
"the",... | 2dcb6c02cd05b2d0c8ab72be4e85d60375df296c | https://github.com/jns/Aims/blob/2dcb6c02cd05b2d0c8ab72be4e85d60375df296c/lib/aims/zinc_blende.rb#L29-L46 |
6,263 | jns/Aims | lib/aims/zinc_blende.rb | Aims.ZincBlende.fill_volume | def fill_volume(volume)
# First fill a cube that bounds the volume
max = volume.max_point
min = volume.min_point
dx = max[0] - min[0]
dy = max[1] - min[1]
dz = max[2] - min[2]
bulk = get_bulk
# This inverse matrix gives the number of repetition... | ruby | def fill_volume(volume)
# First fill a cube that bounds the volume
max = volume.max_point
min = volume.min_point
dx = max[0] - min[0]
dy = max[1] - min[1]
dz = max[2] - min[2]
bulk = get_bulk
# This inverse matrix gives the number of repetition... | [
"def",
"fill_volume",
"(",
"volume",
")",
"# First fill a cube that bounds the volume",
"max",
"=",
"volume",
".",
"max_point",
"min",
"=",
"volume",
".",
"min_point",
"dx",
"=",
"max",
"[",
"0",
"]",
"-",
"min",
"[",
"0",
"]",
"dy",
"=",
"max",
"[",
"1"... | Fill the given volume with atoms | [
"Fill",
"the",
"given",
"volume",
"with",
"atoms"
] | 2dcb6c02cd05b2d0c8ab72be4e85d60375df296c | https://github.com/jns/Aims/blob/2dcb6c02cd05b2d0c8ab72be4e85d60375df296c/lib/aims/zinc_blende.rb#L49-L85 |
6,264 | jns/Aims | lib/aims/zinc_blende.rb | Aims.ZincBlende.get_001_surface | def get_001_surface(monolayers, vacuum, constrain_layers = 0)
anion = Atom.new(0,0,0,self.cation)
cation = Atom.new(0.25*self.lattice_const, 0.25*self.lattice_const, 0.25*self.lattice_const, self.anion)
v1 = Vector[0.5, 0.5, 0]*self.lattice_const
v2 = Vector[-0.5,0.5,0]*self.lattice_const
... | ruby | def get_001_surface(monolayers, vacuum, constrain_layers = 0)
anion = Atom.new(0,0,0,self.cation)
cation = Atom.new(0.25*self.lattice_const, 0.25*self.lattice_const, 0.25*self.lattice_const, self.anion)
v1 = Vector[0.5, 0.5, 0]*self.lattice_const
v2 = Vector[-0.5,0.5,0]*self.lattice_const
... | [
"def",
"get_001_surface",
"(",
"monolayers",
",",
"vacuum",
",",
"constrain_layers",
"=",
"0",
")",
"anion",
"=",
"Atom",
".",
"new",
"(",
"0",
",",
"0",
",",
"0",
",",
"self",
".",
"cation",
")",
"cation",
"=",
"Atom",
".",
"new",
"(",
"0.25",
"*"... | Return a unit cell for a slab of 001
Specify the number of atomic monolayers,
the vacuum thickness in angstrom,
and the number of layers to constrain at the base of the slab | [
"Return",
"a",
"unit",
"cell",
"for",
"a",
"slab",
"of",
"001",
"Specify",
"the",
"number",
"of",
"atomic",
"monolayers",
"the",
"vacuum",
"thickness",
"in",
"angstrom",
"and",
"the",
"number",
"of",
"layers",
"to",
"constrain",
"at",
"the",
"base",
"of",
... | 2dcb6c02cd05b2d0c8ab72be4e85d60375df296c | https://github.com/jns/Aims/blob/2dcb6c02cd05b2d0c8ab72be4e85d60375df296c/lib/aims/zinc_blende.rb#L91-L132 |
6,265 | jns/Aims | lib/aims/zinc_blende.rb | Aims.ZincBlende.get_111_surface | def get_111_surface(dir, monolayers, vacuum, constrain_layers = 0)
if dir == "A"
top_atom = self.anion
bot_atom = self.cation
elsif dir == "B"
top_atom = self.cation
bot_atom = self.anion
else
raise "Direction must be either A or B"
end
# The... | ruby | def get_111_surface(dir, monolayers, vacuum, constrain_layers = 0)
if dir == "A"
top_atom = self.anion
bot_atom = self.cation
elsif dir == "B"
top_atom = self.cation
bot_atom = self.anion
else
raise "Direction must be either A or B"
end
# The... | [
"def",
"get_111_surface",
"(",
"dir",
",",
"monolayers",
",",
"vacuum",
",",
"constrain_layers",
"=",
"0",
")",
"if",
"dir",
"==",
"\"A\"",
"top_atom",
"=",
"self",
".",
"anion",
"bot_atom",
"=",
"self",
".",
"cation",
"elsif",
"dir",
"==",
"\"B\"",
"top... | Return a unit cell for a slab of 111
dir is either "A" or "B" for the cation or anion terminated slab
specify the number of atomic monolayers
and the vacuum thickness in angstrom | [
"Return",
"a",
"unit",
"cell",
"for",
"a",
"slab",
"of",
"111",
"dir",
"is",
"either",
"A",
"or",
"B",
"for",
"the",
"cation",
"or",
"anion",
"terminated",
"slab",
"specify",
"the",
"number",
"of",
"atomic",
"monolayers",
"and",
"the",
"vacuum",
"thickne... | 2dcb6c02cd05b2d0c8ab72be4e85d60375df296c | https://github.com/jns/Aims/blob/2dcb6c02cd05b2d0c8ab72be4e85d60375df296c/lib/aims/zinc_blende.rb#L157-L218 |
6,266 | jns/Aims | lib/aims/zinc_blende.rb | Aims.ZincBlende.get_112_surface | def get_112_surface(monolayers, vacuum=0, constrain_layers = 0)
atom1 = Atom.new(0,0,0,self.cation)
atom2 = Atom.new(self.lattice_const*sqrt(3)/2, 0, 0, self.anion)
v1 = Vector[sqrt(3), 0, 0]*self.lattice_const
v2 = Vector[0, sqrt(2)/2, 0]*self.lattice_const
v3 = Vector[1/sqrt(3), 1... | ruby | def get_112_surface(monolayers, vacuum=0, constrain_layers = 0)
atom1 = Atom.new(0,0,0,self.cation)
atom2 = Atom.new(self.lattice_const*sqrt(3)/2, 0, 0, self.anion)
v1 = Vector[sqrt(3), 0, 0]*self.lattice_const
v2 = Vector[0, sqrt(2)/2, 0]*self.lattice_const
v3 = Vector[1/sqrt(3), 1... | [
"def",
"get_112_surface",
"(",
"monolayers",
",",
"vacuum",
"=",
"0",
",",
"constrain_layers",
"=",
"0",
")",
"atom1",
"=",
"Atom",
".",
"new",
"(",
"0",
",",
"0",
",",
"0",
",",
"self",
".",
"cation",
")",
"atom2",
"=",
"Atom",
".",
"new",
"(",
... | return a unit cell for a slab of 112
specify the number of atomic monolayers and the vacuum thickness in angstrom | [
"return",
"a",
"unit",
"cell",
"for",
"a",
"slab",
"of",
"112",
"specify",
"the",
"number",
"of",
"atomic",
"monolayers",
"and",
"the",
"vacuum",
"thickness",
"in",
"angstrom"
] | 2dcb6c02cd05b2d0c8ab72be4e85d60375df296c | https://github.com/jns/Aims/blob/2dcb6c02cd05b2d0c8ab72be4e85d60375df296c/lib/aims/zinc_blende.rb#L222-L260 |
6,267 | jns/Aims | lib/aims/zinc_blende.rb | Aims.ZincBlende.get_110_surface | def get_110_surface(monolayers, vacuum=0, constrain_layers = 0)
# The atoms on a FCC
atom1 = Atom.new(0,0,0,self.cation)
atom2 = Atom.new(self.lattice_const*1/(2*sqrt(2)), self.lattice_const*0.25, 0.0, self.anion)
# The lattice Vectors
v1 = Vector[1/sqrt(2), 0.0, 0.0]*self.lattice_const... | ruby | def get_110_surface(monolayers, vacuum=0, constrain_layers = 0)
# The atoms on a FCC
atom1 = Atom.new(0,0,0,self.cation)
atom2 = Atom.new(self.lattice_const*1/(2*sqrt(2)), self.lattice_const*0.25, 0.0, self.anion)
# The lattice Vectors
v1 = Vector[1/sqrt(2), 0.0, 0.0]*self.lattice_const... | [
"def",
"get_110_surface",
"(",
"monolayers",
",",
"vacuum",
"=",
"0",
",",
"constrain_layers",
"=",
"0",
")",
"# The atoms on a FCC ",
"atom1",
"=",
"Atom",
".",
"new",
"(",
"0",
",",
"0",
",",
"0",
",",
"self",
".",
"cation",
")",
"atom2",
"=",
"Atom"... | Return a unit cell for a slab of 110
specify the number of atomic monolayers
and the vacuum thickness in angstrom | [
"Return",
"a",
"unit",
"cell",
"for",
"a",
"slab",
"of",
"110",
"specify",
"the",
"number",
"of",
"atomic",
"monolayers",
"and",
"the",
"vacuum",
"thickness",
"in",
"angstrom"
] | 2dcb6c02cd05b2d0c8ab72be4e85d60375df296c | https://github.com/jns/Aims/blob/2dcb6c02cd05b2d0c8ab72be4e85d60375df296c/lib/aims/zinc_blende.rb#L266-L308 |
6,268 | jinx/core | lib/jinx/helpers/collection.rb | Jinx.Collection.to_compact_hash_with_index | def to_compact_hash_with_index
hash = {}
self.each_with_index do |item, index|
next if item.nil?
value = yield(item, index)
next if value.nil_or_empty?
hash[item] = value
end
hash
end | ruby | def to_compact_hash_with_index
hash = {}
self.each_with_index do |item, index|
next if item.nil?
value = yield(item, index)
next if value.nil_or_empty?
hash[item] = value
end
hash
end | [
"def",
"to_compact_hash_with_index",
"hash",
"=",
"{",
"}",
"self",
".",
"each_with_index",
"do",
"|",
"item",
",",
"index",
"|",
"next",
"if",
"item",
".",
"nil?",
"value",
"=",
"yield",
"(",
"item",
",",
"index",
")",
"next",
"if",
"value",
".",
"nil... | Returns a new Hash generated from this Collection with a block whose arguments include the enumerated item
and its index. Every value which is nil or empty is excluded.
@example
[1, 2, 3].to_compact_hash_with_index { |item, index| item + index } #=> { 1 => 1, 2 => 3, 3 => 5 }
@yield [item, index] the hash value
... | [
"Returns",
"a",
"new",
"Hash",
"generated",
"from",
"this",
"Collection",
"with",
"a",
"block",
"whose",
"arguments",
"include",
"the",
"enumerated",
"item",
"and",
"its",
"index",
".",
"Every",
"value",
"which",
"is",
"nil",
"or",
"empty",
"is",
"excluded",... | 964a274cc9d7ab74613910e8375e12ed210a434d | https://github.com/jinx/core/blob/964a274cc9d7ab74613910e8375e12ed210a434d/lib/jinx/helpers/collection.rb#L46-L55 |
6,269 | jinx/core | lib/jinx/helpers/collection.rb | Jinx.Collection.partial_sort! | def partial_sort!
unless block_given? then return partial_sort! { |item1, item2| item1 <=> item2 } end
# The comparison hash
h = Hash.new { |h, k| h[k] = Hash.new }
sort! do |a, b|
# * If a and b are comparable, then use the comparison result.
# * Otherwise, if there is a member ... | ruby | def partial_sort!
unless block_given? then return partial_sort! { |item1, item2| item1 <=> item2 } end
# The comparison hash
h = Hash.new { |h, k| h[k] = Hash.new }
sort! do |a, b|
# * If a and b are comparable, then use the comparison result.
# * Otherwise, if there is a member ... | [
"def",
"partial_sort!",
"unless",
"block_given?",
"then",
"return",
"partial_sort!",
"{",
"|",
"item1",
",",
"item2",
"|",
"item1",
"<=>",
"item2",
"}",
"end",
"# The comparison hash",
"h",
"=",
"Hash",
".",
"new",
"{",
"|",
"h",
",",
"k",
"|",
"h",
"[",... | Sorts this collection in-place with a partial sort operator block
@see #partial_sort
@yield (see #partial_sort)
@yieldparam (see #partial_sort)
@raise [NoMethodError] if this Collection does not support the +sort!+ sort in-place method | [
"Sorts",
"this",
"collection",
"in",
"-",
"place",
"with",
"a",
"partial",
"sort",
"operator",
"block"
] | 964a274cc9d7ab74613910e8375e12ed210a434d | https://github.com/jinx/core/blob/964a274cc9d7ab74613910e8375e12ed210a434d/lib/jinx/helpers/collection.rb#L252-L263 |
6,270 | jinx/core | lib/jinx/resource/inversible.rb | Jinx.Inversible.set_inverse | def set_inverse(other, writer, inv_writer)
other.send(inv_writer, self) if other
send(writer, other)
end | ruby | def set_inverse(other, writer, inv_writer)
other.send(inv_writer, self) if other
send(writer, other)
end | [
"def",
"set_inverse",
"(",
"other",
",",
"writer",
",",
"inv_writer",
")",
"other",
".",
"send",
"(",
"inv_writer",
",",
"self",
")",
"if",
"other",
"send",
"(",
"writer",
",",
"other",
")",
"end"
] | Sets an attribute inverse by calling the attribute writer method with the other argument.
If other is non-nil, then the inverse writer method is called on self.
@param other [Resource] the attribute value to set
@param [Symbol] writer the attribute writer method
@param [Symbol] inv_writer the attribute inverse wri... | [
"Sets",
"an",
"attribute",
"inverse",
"by",
"calling",
"the",
"attribute",
"writer",
"method",
"with",
"the",
"other",
"argument",
".",
"If",
"other",
"is",
"non",
"-",
"nil",
"then",
"the",
"inverse",
"writer",
"method",
"is",
"called",
"on",
"self",
"."
... | 964a274cc9d7ab74613910e8375e12ed210a434d | https://github.com/jinx/core/blob/964a274cc9d7ab74613910e8375e12ed210a434d/lib/jinx/resource/inversible.rb#L12-L15 |
6,271 | jinx/core | lib/jinx/resource/inversible.rb | Jinx.Inversible.set_inversible_noncollection_attribute | def set_inversible_noncollection_attribute(newval, accessors, inverse_writer)
rdr, wtr = accessors
# the previous value
oldval = send(rdr)
# bail if no change
return newval if newval.equal?(oldval)
# clear the previous inverse
logger.debug { "Moving #{qp} from #{oldval.qp} to ... | ruby | def set_inversible_noncollection_attribute(newval, accessors, inverse_writer)
rdr, wtr = accessors
# the previous value
oldval = send(rdr)
# bail if no change
return newval if newval.equal?(oldval)
# clear the previous inverse
logger.debug { "Moving #{qp} from #{oldval.qp} to ... | [
"def",
"set_inversible_noncollection_attribute",
"(",
"newval",
",",
"accessors",
",",
"inverse_writer",
")",
"rdr",
",",
"wtr",
"=",
"accessors",
"# the previous value",
"oldval",
"=",
"send",
"(",
"rdr",
")",
"# bail if no change",
"return",
"newval",
"if",
"newva... | Sets a non-collection attribute value in a way which enforces inverse integrity.
@param [Object] newval the value to set
@param [(Symbol, Symbol)] accessors the reader and writer methods to use in setting the
attribute
@param [Symbol] inverse_writer the inverse attribute writer method
@private | [
"Sets",
"a",
"non",
"-",
"collection",
"attribute",
"value",
"in",
"a",
"way",
"which",
"enforces",
"inverse",
"integrity",
"."
] | 964a274cc9d7ab74613910e8375e12ed210a434d | https://github.com/jinx/core/blob/964a274cc9d7ab74613910e8375e12ed210a434d/lib/jinx/resource/inversible.rb#L24-L48 |
6,272 | jinx/core | lib/jinx/resource/inversible.rb | Jinx.Inversible.add_to_inverse_collection | def add_to_inverse_collection(newval, accessors, inverse)
rdr, wtr = accessors
# the current inverse
oldval = send(rdr)
# no-op if no change
return newval if newval == oldval
# delete self from the current inverse reference collection
if oldval then
coll = oldval.send(... | ruby | def add_to_inverse_collection(newval, accessors, inverse)
rdr, wtr = accessors
# the current inverse
oldval = send(rdr)
# no-op if no change
return newval if newval == oldval
# delete self from the current inverse reference collection
if oldval then
coll = oldval.send(... | [
"def",
"add_to_inverse_collection",
"(",
"newval",
",",
"accessors",
",",
"inverse",
")",
"rdr",
",",
"wtr",
"=",
"accessors",
"# the current inverse",
"oldval",
"=",
"send",
"(",
"rdr",
")",
"# no-op if no change",
"return",
"newval",
"if",
"newval",
"==",
"old... | Sets a collection attribute value in a way which enforces inverse integrity.
The inverse of the attribute is a collection accessed by calling inverse on newval.
@param [Resource] newval the new attribute reference value
@param [(Symbol, Symbol)] accessors the reader and writer to use in setting
the attribute
@p... | [
"Sets",
"a",
"collection",
"attribute",
"value",
"in",
"a",
"way",
"which",
"enforces",
"inverse",
"integrity",
".",
"The",
"inverse",
"of",
"the",
"attribute",
"is",
"a",
"collection",
"accessed",
"by",
"calling",
"inverse",
"on",
"newval",
"."
] | 964a274cc9d7ab74613910e8375e12ed210a434d | https://github.com/jinx/core/blob/964a274cc9d7ab74613910e8375e12ed210a434d/lib/jinx/resource/inversible.rb#L60-L92 |
6,273 | riddopic/garcun | lib/garcon/core_ext/pathname.rb | Garcon.Pathref.expand_pathseg | def expand_pathseg(handle)
return handle unless handle.is_a?(Symbol)
pathsegs = ROOT_PATHS[handle] or raise ArgumentError,
"Don't know how to expand path reference '#{handle.inspect}'."
pathsegs.map { |ps| expand_pathseg(ps) }.flatten
end | ruby | def expand_pathseg(handle)
return handle unless handle.is_a?(Symbol)
pathsegs = ROOT_PATHS[handle] or raise ArgumentError,
"Don't know how to expand path reference '#{handle.inspect}'."
pathsegs.map { |ps| expand_pathseg(ps) }.flatten
end | [
"def",
"expand_pathseg",
"(",
"handle",
")",
"return",
"handle",
"unless",
"handle",
".",
"is_a?",
"(",
"Symbol",
")",
"pathsegs",
"=",
"ROOT_PATHS",
"[",
"handle",
"]",
"or",
"raise",
"ArgumentError",
",",
"\"Don't know how to expand path reference '#{handle.inspect}... | A T T E N Z I O N E A R E A P R O T E T T A
Recursively expand a path handle.
@return [Array<String>]
An array of path segments, suitable for .join
@api public | [
"A",
"T",
"T",
"E",
"N",
"Z",
"I",
"O",
"N",
"E",
"A",
"R",
"E",
"A",
"P",
"R",
"O",
"T",
"E",
"T",
"T",
"A",
"Recursively",
"expand",
"a",
"path",
"handle",
"."
] | c2409bd8cf9c14b967a719810dab5269d69b42de | https://github.com/riddopic/garcun/blob/c2409bd8cf9c14b967a719810dab5269d69b42de/lib/garcon/core_ext/pathname.rb#L112-L117 |
6,274 | riddopic/garcun | lib/garcon/task/count_down_latch.rb | Garcon.MutexCountDownLatch.wait | def wait(timeout = nil)
@mutex.synchronize do
remaining = Condition::Result.new(timeout)
while @count > 0 && remaining.can_wait?
remaining = @condition.wait(@mutex, remaining.remaining_time)
end
@count == 0
end
end | ruby | def wait(timeout = nil)
@mutex.synchronize do
remaining = Condition::Result.new(timeout)
while @count > 0 && remaining.can_wait?
remaining = @condition.wait(@mutex, remaining.remaining_time)
end
@count == 0
end
end | [
"def",
"wait",
"(",
"timeout",
"=",
"nil",
")",
"@mutex",
".",
"synchronize",
"do",
"remaining",
"=",
"Condition",
"::",
"Result",
".",
"new",
"(",
"timeout",
")",
"while",
"@count",
">",
"0",
"&&",
"remaining",
".",
"can_wait?",
"remaining",
"=",
"@cond... | Create a new `CountDownLatch` with the initial `count`.
@param [Fixnum] count
The initial count
@raise [ArgumentError]
If `count` is not an integer or is less than zero.
Block on the latch until the counter reaches zero or until `timeout` is
reached.
@param [Fixnum] timeout
The number of seconds to wa... | [
"Create",
"a",
"new",
"CountDownLatch",
"with",
"the",
"initial",
"count",
"."
] | c2409bd8cf9c14b967a719810dab5269d69b42de | https://github.com/riddopic/garcun/blob/c2409bd8cf9c14b967a719810dab5269d69b42de/lib/garcon/task/count_down_latch.rb#L61-L69 |
6,275 | karthikv/model_schema | lib/model_schema/schema_error.rb | ModelSchema.SchemaError.dump_extra_diffs | def dump_extra_diffs(field)
extra_diffs = diffs_by_field_type(field, TYPE_EXTRA)
if extra_diffs.length > 0
header = "Table #{@table_name} has extra #{field}:\n"
diff_str = extra_diffs.map do |diff|
dump_single(field, diff[:generator], diff[:elem])
end.join("\n\t")
... | ruby | def dump_extra_diffs(field)
extra_diffs = diffs_by_field_type(field, TYPE_EXTRA)
if extra_diffs.length > 0
header = "Table #{@table_name} has extra #{field}:\n"
diff_str = extra_diffs.map do |diff|
dump_single(field, diff[:generator], diff[:elem])
end.join("\n\t")
... | [
"def",
"dump_extra_diffs",
"(",
"field",
")",
"extra_diffs",
"=",
"diffs_by_field_type",
"(",
"field",
",",
"TYPE_EXTRA",
")",
"if",
"extra_diffs",
".",
"length",
">",
"0",
"header",
"=",
"\"Table #{@table_name} has extra #{field}:\\n\"",
"diff_str",
"=",
"extra_diffs... | Dumps all diffs that have the given field and are of TYPE_EXTRA. | [
"Dumps",
"all",
"diffs",
"that",
"have",
"the",
"given",
"field",
"and",
"are",
"of",
"TYPE_EXTRA",
"."
] | d73f7d9f8b5240ad878a01d1fe7a0e01f66cf979 | https://github.com/karthikv/model_schema/blob/d73f7d9f8b5240ad878a01d1fe7a0e01f66cf979/lib/model_schema/schema_error.rb#L54-L65 |
6,276 | karthikv/model_schema | lib/model_schema/schema_error.rb | ModelSchema.SchemaError.dump_missing_diffs | def dump_missing_diffs(field)
missing_diffs = diffs_by_field_type(field, TYPE_MISSING)
if missing_diffs.length > 0
header = "Table #{@table_name} is missing #{field}:\n"
diff_str = missing_diffs.map do |diff|
dump_single(field, diff[:generator], diff[:elem])
end.join("\n\t... | ruby | def dump_missing_diffs(field)
missing_diffs = diffs_by_field_type(field, TYPE_MISSING)
if missing_diffs.length > 0
header = "Table #{@table_name} is missing #{field}:\n"
diff_str = missing_diffs.map do |diff|
dump_single(field, diff[:generator], diff[:elem])
end.join("\n\t... | [
"def",
"dump_missing_diffs",
"(",
"field",
")",
"missing_diffs",
"=",
"diffs_by_field_type",
"(",
"field",
",",
"TYPE_MISSING",
")",
"if",
"missing_diffs",
".",
"length",
">",
"0",
"header",
"=",
"\"Table #{@table_name} is missing #{field}:\\n\"",
"diff_str",
"=",
"mi... | Dumps all diffs that have the given field and are of TYPE_MISSING. | [
"Dumps",
"all",
"diffs",
"that",
"have",
"the",
"given",
"field",
"and",
"are",
"of",
"TYPE_MISSING",
"."
] | d73f7d9f8b5240ad878a01d1fe7a0e01f66cf979 | https://github.com/karthikv/model_schema/blob/d73f7d9f8b5240ad878a01d1fe7a0e01f66cf979/lib/model_schema/schema_error.rb#L68-L79 |
6,277 | karthikv/model_schema | lib/model_schema/schema_error.rb | ModelSchema.SchemaError.dump_mismatch_diffs | def dump_mismatch_diffs(field)
mismatch_diffs = diffs_by_field_type(field, TYPE_MISMATCH)
if mismatch_diffs.length > 0
header = "Table #{@table_name} has mismatched #{field}:\n"
diff_str = mismatch_diffs.map do |diff|
"actual: #{dump_single(field, diff[:db_generator], diff[:db_... | ruby | def dump_mismatch_diffs(field)
mismatch_diffs = diffs_by_field_type(field, TYPE_MISMATCH)
if mismatch_diffs.length > 0
header = "Table #{@table_name} has mismatched #{field}:\n"
diff_str = mismatch_diffs.map do |diff|
"actual: #{dump_single(field, diff[:db_generator], diff[:db_... | [
"def",
"dump_mismatch_diffs",
"(",
"field",
")",
"mismatch_diffs",
"=",
"diffs_by_field_type",
"(",
"field",
",",
"TYPE_MISMATCH",
")",
"if",
"mismatch_diffs",
".",
"length",
">",
"0",
"header",
"=",
"\"Table #{@table_name} has mismatched #{field}:\\n\"",
"diff_str",
"=... | Dumps all diffs that have the given field and are of TYPE_MISMATCH. | [
"Dumps",
"all",
"diffs",
"that",
"have",
"the",
"given",
"field",
"and",
"are",
"of",
"TYPE_MISMATCH",
"."
] | d73f7d9f8b5240ad878a01d1fe7a0e01f66cf979 | https://github.com/karthikv/model_schema/blob/d73f7d9f8b5240ad878a01d1fe7a0e01f66cf979/lib/model_schema/schema_error.rb#L82-L94 |
6,278 | karthikv/model_schema | lib/model_schema/schema_error.rb | ModelSchema.SchemaError.to_s | def to_s
parts = FIELDS.flat_map do |field|
[dump_extra_diffs(field),
dump_missing_diffs(field),
dump_mismatch_diffs(field)]
end
[
"Table #{@table_name} does not match the expected schema.\n\n",
parts.compact.join("\n"),
"\nYou may disable schema chec... | ruby | def to_s
parts = FIELDS.flat_map do |field|
[dump_extra_diffs(field),
dump_missing_diffs(field),
dump_mismatch_diffs(field)]
end
[
"Table #{@table_name} does not match the expected schema.\n\n",
parts.compact.join("\n"),
"\nYou may disable schema chec... | [
"def",
"to_s",
"parts",
"=",
"FIELDS",
".",
"flat_map",
"do",
"|",
"field",
"|",
"[",
"dump_extra_diffs",
"(",
"field",
")",
",",
"dump_missing_diffs",
"(",
"field",
")",
",",
"dump_mismatch_diffs",
"(",
"field",
")",
"]",
"end",
"[",
"\"Table #{@table_name}... | Combines all dumps into one cohesive error message. | [
"Combines",
"all",
"dumps",
"into",
"one",
"cohesive",
"error",
"message",
"."
] | d73f7d9f8b5240ad878a01d1fe7a0e01f66cf979 | https://github.com/karthikv/model_schema/blob/d73f7d9f8b5240ad878a01d1fe7a0e01f66cf979/lib/model_schema/schema_error.rb#L97-L110 |
6,279 | jinx/core | lib/jinx/helpers/visitor.rb | Jinx.Visitor.filter | def filter
raise ArgumentError.new("A filter block is not given to the visitor filter method") unless block_given?
self.class.new(@options) { |node| yield(node, node_children(node)) }
end | ruby | def filter
raise ArgumentError.new("A filter block is not given to the visitor filter method") unless block_given?
self.class.new(@options) { |node| yield(node, node_children(node)) }
end | [
"def",
"filter",
"raise",
"ArgumentError",
".",
"new",
"(",
"\"A filter block is not given to the visitor filter method\"",
")",
"unless",
"block_given?",
"self",
".",
"class",
".",
"new",
"(",
"@options",
")",
"{",
"|",
"node",
"|",
"yield",
"(",
"node",
",",
"... | Returns a new Visitor which determines which nodes to visit by applying the given block
to this visitor. The filter block arguments consist of a parent node and an array of
children nodes for the parent. The block can return nil, a single node to visit or a
collection of nodes to visit.
@example
visitor = Jinx:... | [
"Returns",
"a",
"new",
"Visitor",
"which",
"determines",
"which",
"nodes",
"to",
"visit",
"by",
"applying",
"the",
"given",
"block",
"to",
"this",
"visitor",
".",
"The",
"filter",
"block",
"arguments",
"consist",
"of",
"a",
"parent",
"node",
"and",
"an",
"... | 964a274cc9d7ab74613910e8375e12ed210a434d | https://github.com/jinx/core/blob/964a274cc9d7ab74613910e8375e12ed210a434d/lib/jinx/helpers/visitor.rb#L186-L189 |
6,280 | jinx/core | lib/jinx/helpers/visitor.rb | Jinx.Visitor.node_children | def node_children(node)
children = @navigator.call(node)
return Array::EMPTY_ARRAY if children.nil?
Enumerable === children ? children.to_a.compact : [children]
end | ruby | def node_children(node)
children = @navigator.call(node)
return Array::EMPTY_ARRAY if children.nil?
Enumerable === children ? children.to_a.compact : [children]
end | [
"def",
"node_children",
"(",
"node",
")",
"children",
"=",
"@navigator",
".",
"call",
"(",
"node",
")",
"return",
"Array",
"::",
"EMPTY_ARRAY",
"if",
"children",
".",
"nil?",
"Enumerable",
"===",
"children",
"?",
"children",
".",
"to_a",
".",
"compact",
":... | Returns the children to visit for the given node. | [
"Returns",
"the",
"children",
"to",
"visit",
"for",
"the",
"given",
"node",
"."
] | 964a274cc9d7ab74613910e8375e12ed210a434d | https://github.com/jinx/core/blob/964a274cc9d7ab74613910e8375e12ed210a434d/lib/jinx/helpers/visitor.rb#L202-L206 |
6,281 | jinx/core | lib/jinx/helpers/visitor.rb | Jinx.Visitor.visit_root | def visit_root(node, &operator)
clear
# Exclude cycles if the prune cycles flag is set.
@exclude.merge!(cyclic_nodes(node)) if @prune_cycle_flag
# Visit the root node.
result = visit_recursive(node, &operator)
# Reset the exclusions if the prune cycles flag is set.
@exclude.c... | ruby | def visit_root(node, &operator)
clear
# Exclude cycles if the prune cycles flag is set.
@exclude.merge!(cyclic_nodes(node)) if @prune_cycle_flag
# Visit the root node.
result = visit_recursive(node, &operator)
# Reset the exclusions if the prune cycles flag is set.
@exclude.c... | [
"def",
"visit_root",
"(",
"node",
",",
"&",
"operator",
")",
"clear",
"# Exclude cycles if the prune cycles flag is set. ",
"@exclude",
".",
"merge!",
"(",
"cyclic_nodes",
"(",
"node",
")",
")",
"if",
"@prune_cycle_flag",
"# Visit the root node.",
"result",
"=",
"visi... | Visits the root node and all descendants. | [
"Visits",
"the",
"root",
"node",
"and",
"all",
"descendants",
"."
] | 964a274cc9d7ab74613910e8375e12ed210a434d | https://github.com/jinx/core/blob/964a274cc9d7ab74613910e8375e12ed210a434d/lib/jinx/helpers/visitor.rb#L216-L225 |
6,282 | jinx/core | lib/jinx/helpers/visitor.rb | Jinx.Visitor.cyclic_nodes | def cyclic_nodes(root)
copts = @options.reject { |k, v| k == :prune_cycle }
cyclic = Set.new
cycler = Visitor.new(copts) do |parent|
children = @navigator.call(parent)
# Look for a cycle back to the child.
children.each do |child|
index = cycler.lineage.index(child)
... | ruby | def cyclic_nodes(root)
copts = @options.reject { |k, v| k == :prune_cycle }
cyclic = Set.new
cycler = Visitor.new(copts) do |parent|
children = @navigator.call(parent)
# Look for a cycle back to the child.
children.each do |child|
index = cycler.lineage.index(child)
... | [
"def",
"cyclic_nodes",
"(",
"root",
")",
"copts",
"=",
"@options",
".",
"reject",
"{",
"|",
"k",
",",
"v",
"|",
"k",
"==",
":prune_cycle",
"}",
"cyclic",
"=",
"Set",
".",
"new",
"cycler",
"=",
"Visitor",
".",
"new",
"(",
"copts",
")",
"do",
"|",
... | Returns the nodes which occur within a cycle, excluding the cycle entry point.
@example
graph.paths #=> a -> b -> a, a -> c -> d -> c
Visitor.new(graph, &navigator).cyclic_nodes(a) #=> [b, d]
@param root the node to visit
@return [Array] the nodes within visit cycles | [
"Returns",
"the",
"nodes",
"which",
"occur",
"within",
"a",
"cycle",
"excluding",
"the",
"cycle",
"entry",
"point",
"."
] | 964a274cc9d7ab74613910e8375e12ed210a434d | https://github.com/jinx/core/blob/964a274cc9d7ab74613910e8375e12ed210a434d/lib/jinx/helpers/visitor.rb#L234-L252 |
6,283 | rubyworks/richunits | work/deprecated/duration.rb | RichUnits.Numeric.duration | def duration(part = nil, klass = Duration)
if [:years, :months, :weeks, :days, :hours, :minutes, :seconds].include? part
klass.new(part => self)
else
klass.new(self)
end
end | ruby | def duration(part = nil, klass = Duration)
if [:years, :months, :weeks, :days, :hours, :minutes, :seconds].include? part
klass.new(part => self)
else
klass.new(self)
end
end | [
"def",
"duration",
"(",
"part",
"=",
"nil",
",",
"klass",
"=",
"Duration",
")",
"if",
"[",
":years",
",",
":months",
",",
":weeks",
",",
":days",
",",
":hours",
",",
":minutes",
",",
":seconds",
"]",
".",
"include?",
"part",
"klass",
".",
"new",
"(",... | Create a Duration object using self where self could represent weeks, days,
hours, minutes, and seconds.
*Example*
10.duration(:weeks)
=> #<Duration: 10 weeks>
10.duration
=> #<Duration: 10 seconds> | [
"Create",
"a",
"Duration",
"object",
"using",
"self",
"where",
"self",
"could",
"represent",
"weeks",
"days",
"hours",
"minutes",
"and",
"seconds",
"."
] | c92bec173fc63798013defdd9a1727b0d1d65d46 | https://github.com/rubyworks/richunits/blob/c92bec173fc63798013defdd9a1727b0d1d65d46/work/deprecated/duration.rb#L466-L472 |
6,284 | rubyworks/richunits | work/deprecated/duration.rb | RichUnits.Duration.seconds | def seconds(part = nil)
# Table mapping
h = {:weeks => WEEK, :days => DAY, :hours => HOUR, :minutes => MINUTE}
if [:weeks, :days, :hours, :minutes].include? part
__send__(part) * h[part]
else
@seconds
end
end | ruby | def seconds(part = nil)
# Table mapping
h = {:weeks => WEEK, :days => DAY, :hours => HOUR, :minutes => MINUTE}
if [:weeks, :days, :hours, :minutes].include? part
__send__(part) * h[part]
else
@seconds
end
end | [
"def",
"seconds",
"(",
"part",
"=",
"nil",
")",
"# Table mapping",
"h",
"=",
"{",
":weeks",
"=>",
"WEEK",
",",
":days",
"=>",
"DAY",
",",
":hours",
"=>",
"HOUR",
",",
":minutes",
"=>",
"MINUTE",
"}",
"if",
"[",
":weeks",
",",
":days",
",",
":hours",
... | Get the number of seconds of a given part, or simply just get the number of
seconds.
*Example*
d = Duration.new(:weeks => 1, :days => 1, :hours => 1, :seconds => 30)
=> #<Duration: 1 week, 1 day, 1 hour and 30 seconds>
d.seconds(:weeks)
=> 604800
d.seconds(:days)
=> 86400
d.second... | [
"Get",
"the",
"number",
"of",
"seconds",
"of",
"a",
"given",
"part",
"or",
"simply",
"just",
"get",
"the",
"number",
"of",
"seconds",
"."
] | c92bec173fc63798013defdd9a1727b0d1d65d46 | https://github.com/rubyworks/richunits/blob/c92bec173fc63798013defdd9a1727b0d1d65d46/work/deprecated/duration.rb#L134-L143 |
6,285 | rubyworks/richunits | work/deprecated/duration.rb | RichUnits.Duration.to_s | def to_s
str = ''
each do |part, time|
# Skip any zero times.
next if time.zero?
# Concatenate the part of the time and the time itself.
str << "#{time} #{time == 1 ? part[0..-2] : part}, "
end
str.chomp(', ').sub(/(.+), ... | ruby | def to_s
str = ''
each do |part, time|
# Skip any zero times.
next if time.zero?
# Concatenate the part of the time and the time itself.
str << "#{time} #{time == 1 ? part[0..-2] : part}, "
end
str.chomp(', ').sub(/(.+), ... | [
"def",
"to_s",
"str",
"=",
"''",
"each",
"do",
"|",
"part",
",",
"time",
"|",
"# Skip any zero times.",
"next",
"if",
"time",
".",
"zero?",
"# Concatenate the part of the time and the time itself.",
"str",
"<<",
"\"#{time} #{time == 1 ? part[0..-2] : part}, \"",
"end",
... | Friendly, human-readable string representation of the duration.
*Example*
d = Duration.new(:seconds => 140)
=> #<Duration: 2 minutes and 20 seconds>
d.to_s
=> "2 minutes and 20 seconds" | [
"Friendly",
"human",
"-",
"readable",
"string",
"representation",
"of",
"the",
"duration",
"."
] | c92bec173fc63798013defdd9a1727b0d1d65d46 | https://github.com/rubyworks/richunits/blob/c92bec173fc63798013defdd9a1727b0d1d65d46/work/deprecated/duration.rb#L258-L270 |
6,286 | syborg/mme_tools | lib/mme_tools/config.rb | MMETools.Config.dump | def dump(filename)
File.open(filename,'w') do |f|
YAML.dump(self.to_hash,f)
end
end | ruby | def dump(filename)
File.open(filename,'w') do |f|
YAML.dump(self.to_hash,f)
end
end | [
"def",
"dump",
"(",
"filename",
")",
"File",
".",
"open",
"(",
"filename",
",",
"'w'",
")",
"do",
"|",
"f",
"|",
"YAML",
".",
"dump",
"(",
"self",
".",
"to_hash",
",",
"f",
")",
"end",
"end"
] | saves configuration into a _yaml_ file named +filename+ | [
"saves",
"configuration",
"into",
"a",
"_yaml_",
"file",
"named",
"+",
"filename",
"+"
] | e93919f7fcfb408b941d6144290991a7feabaa7d | https://github.com/syborg/mme_tools/blob/e93919f7fcfb408b941d6144290991a7feabaa7d/lib/mme_tools/config.rb#L101-L105 |
6,287 | OHSU-FM/reindeer-etl | lib/reindeer-etl/sources/multi_source.rb | ReindeerETL::Sources.MultiSource.each | def each
rows = []
all_keys = Set.new
@sources.each_with_index do |source, source_idx|
first_row = false
source.each do |row|
unless row.keys.include? @key
raise ReindeerETL::Errors::RecordInvalid.new("Path#1 missing key: #{@key}")
end
if sour... | ruby | def each
rows = []
all_keys = Set.new
@sources.each_with_index do |source, source_idx|
first_row = false
source.each do |row|
unless row.keys.include? @key
raise ReindeerETL::Errors::RecordInvalid.new("Path#1 missing key: #{@key}")
end
if sour... | [
"def",
"each",
"rows",
"=",
"[",
"]",
"all_keys",
"=",
"Set",
".",
"new",
"@sources",
".",
"each_with_index",
"do",
"|",
"source",
",",
"source_idx",
"|",
"first_row",
"=",
"false",
"source",
".",
"each",
"do",
"|",
"row",
"|",
"unless",
"row",
".",
... | helper methods have h_ prefix
@param key [String] col name (present in all sources) to join on
@param paths [Array[String]] list of file paths. note: order is important
@param klass [String] namespaced class name of ReindeerETL source
@param path_opts [Array[Hash]] list of hashes (count equal to the
number of so... | [
"helper",
"methods",
"have",
"h_",
"prefix"
] | bff48c999b17850681346d500f2a05900252e21f | https://github.com/OHSU-FM/reindeer-etl/blob/bff48c999b17850681346d500f2a05900252e21f/lib/reindeer-etl/sources/multi_source.rb#L36-L81 |
6,288 | akerl/logcabin | lib/logcabin/setcollection.rb | LogCabin.SetCollection.find | def find(name)
cache(name) { @children.find { |x| safe_find(x, name) } || failure }
end | ruby | def find(name)
cache(name) { @children.find { |x| safe_find(x, name) } || failure }
end | [
"def",
"find",
"(",
"name",
")",
"cache",
"(",
"name",
")",
"{",
"@children",
".",
"find",
"{",
"|",
"x",
"|",
"safe_find",
"(",
"x",
",",
"name",
")",
"}",
"||",
"failure",
"}",
"end"
] | Method for finding modules to load | [
"Method",
"for",
"finding",
"modules",
"to",
"load"
] | a0c793f4047f3a80fd232c582ecce55139092b8e | https://github.com/akerl/logcabin/blob/a0c793f4047f3a80fd232c582ecce55139092b8e/lib/logcabin/setcollection.rb#L13-L15 |
6,289 | knuedge/off_the_grid | lib/off_the_grid/user.rb | OffTheGrid.User.add | def add
Tempfile.open do |tmpfile|
tmpfile.puts render(Templates::User::ERB)
tmpfile.flush
system("qconf -Auser #{tmpfile.path}")
sleep 5
end
end | ruby | def add
Tempfile.open do |tmpfile|
tmpfile.puts render(Templates::User::ERB)
tmpfile.flush
system("qconf -Auser #{tmpfile.path}")
sleep 5
end
end | [
"def",
"add",
"Tempfile",
".",
"open",
"do",
"|",
"tmpfile",
"|",
"tmpfile",
".",
"puts",
"render",
"(",
"Templates",
"::",
"User",
"::",
"ERB",
")",
"tmpfile",
".",
"flush",
"system",
"(",
"\"qconf -Auser #{tmpfile.path}\"",
")",
"sleep",
"5",
"end",
"end... | Add an SGE user | [
"Add",
"an",
"SGE",
"user"
] | cf367b6d22de5c73da2e2550e1f45e103a219a51 | https://github.com/knuedge/off_the_grid/blob/cf367b6d22de5c73da2e2550e1f45e103a219a51/lib/off_the_grid/user.rb#L49-L56 |
6,290 | JotaSe/undecided | lib/undecided/decider.rb | Undecided.Decider.decide | def decide(rule, values, strict = true)
rule = rule.clone
values = values.clone
error unless Undecided::Evaluator.valid?(rule, values, strict)
# Sanitize data
# Eval rules and values after process it, with safe data
final_expression = Converter.replacing_variables(rule, values)
... | ruby | def decide(rule, values, strict = true)
rule = rule.clone
values = values.clone
error unless Undecided::Evaluator.valid?(rule, values, strict)
# Sanitize data
# Eval rules and values after process it, with safe data
final_expression = Converter.replacing_variables(rule, values)
... | [
"def",
"decide",
"(",
"rule",
",",
"values",
",",
"strict",
"=",
"true",
")",
"rule",
"=",
"rule",
".",
"clone",
"values",
"=",
"values",
".",
"clone",
"error",
"unless",
"Undecided",
"::",
"Evaluator",
".",
"valid?",
"(",
"rule",
",",
"values",
",",
... | Given a boolean expression and data to replace, return result | [
"Given",
"a",
"boolean",
"expression",
"and",
"data",
"to",
"replace",
"return",
"result"
] | 80255277d0aadb74e98835af01a3427e11c73649 | https://github.com/JotaSe/undecided/blob/80255277d0aadb74e98835af01a3427e11c73649/lib/undecided/decider.rb#L7-L18 |
6,291 | xmatters/sensu-plugins-xmatters | lib/xmatters-sensu.rb | XMSensu.XMClient.get_default_properties | def get_default_properties(event)
client = event['client']
check = event['check']
{
server_name: client['name'],
server_ip: client['address'],
subscriptions: client['subscriptions'].join(';'),
environment: client['environment'],
check_name: check['name'],
... | ruby | def get_default_properties(event)
client = event['client']
check = event['check']
{
server_name: client['name'],
server_ip: client['address'],
subscriptions: client['subscriptions'].join(';'),
environment: client['environment'],
check_name: check['name'],
... | [
"def",
"get_default_properties",
"(",
"event",
")",
"client",
"=",
"event",
"[",
"'client'",
"]",
"check",
"=",
"event",
"[",
"'check'",
"]",
"{",
"server_name",
":",
"client",
"[",
"'name'",
"]",
",",
"server_ip",
":",
"client",
"[",
"'address'",
"]",
"... | Gets a default set of properties from the event | [
"Gets",
"a",
"default",
"set",
"of",
"properties",
"from",
"the",
"event"
] | eb21b1aa6c9c5b31142dd596b01ebeade4f6638f | https://github.com/xmatters/sensu-plugins-xmatters/blob/eb21b1aa6c9c5b31142dd596b01ebeade4f6638f/lib/xmatters-sensu.rb#L46-L59 |
6,292 | riddopic/garcun | lib/garcon/chef/secret_bag.rb | Garcon.SecretBag.data_bag_config_for | def data_bag_config_for(environment, source)
data_bag_item = encrypted_data_bag_for(environment, DATA_BAG)
if data_bag_item.has_key?(source)
data_bag_item[source]
elsif DATA_BAG == source
data_bag_item
else
{}
end
end | ruby | def data_bag_config_for(environment, source)
data_bag_item = encrypted_data_bag_for(environment, DATA_BAG)
if data_bag_item.has_key?(source)
data_bag_item[source]
elsif DATA_BAG == source
data_bag_item
else
{}
end
end | [
"def",
"data_bag_config_for",
"(",
"environment",
",",
"source",
")",
"data_bag_item",
"=",
"encrypted_data_bag_for",
"(",
"environment",
",",
"DATA_BAG",
")",
"if",
"data_bag_item",
".",
"has_key?",
"(",
"source",
")",
"data_bag_item",
"[",
"source",
"]",
"elsif"... | Loads the encrypted data bag item and returns credentials for the
environment or for a default key.
@param [String] environment
The environment
@param [String] source
The deployment source to load configuration for
@return [Chef::DataBagItem]
The data bag item | [
"Loads",
"the",
"encrypted",
"data",
"bag",
"item",
"and",
"returns",
"credentials",
"for",
"the",
"environment",
"or",
"for",
"a",
"default",
"key",
"."
] | c2409bd8cf9c14b967a719810dab5269d69b42de | https://github.com/riddopic/garcun/blob/c2409bd8cf9c14b967a719810dab5269d69b42de/lib/garcon/chef/secret_bag.rb#L129-L139 |
6,293 | riddopic/garcun | lib/garcon/chef/secret_bag.rb | Garcon.SecretBag.encrypted_data_bag_for | def encrypted_data_bag_for(environment, data_bag)
@encrypted_data_bags = {} unless @encrypted_data_bags
if encrypted_data_bags[data_bag]
return get_from_data_bags_cache(data_bag)
else
data_bag_item = encrypted_data_bag_item(data_bag, environment)
data_bag_item ||= encrypted_da... | ruby | def encrypted_data_bag_for(environment, data_bag)
@encrypted_data_bags = {} unless @encrypted_data_bags
if encrypted_data_bags[data_bag]
return get_from_data_bags_cache(data_bag)
else
data_bag_item = encrypted_data_bag_item(data_bag, environment)
data_bag_item ||= encrypted_da... | [
"def",
"encrypted_data_bag_for",
"(",
"environment",
",",
"data_bag",
")",
"@encrypted_data_bags",
"=",
"{",
"}",
"unless",
"@encrypted_data_bags",
"if",
"encrypted_data_bags",
"[",
"data_bag",
"]",
"return",
"get_from_data_bags_cache",
"(",
"data_bag",
")",
"else",
"... | Looks for the given data bag in the cache and if not found, will load a
data bag item named for the chef_environment, or '_wildcard' value.
@param [String] environment
The environment.
@param [String] data_bag
The data bag to load.
@return [Chef::Mash]
The data bag item in Mash form. | [
"Looks",
"for",
"the",
"given",
"data",
"bag",
"in",
"the",
"cache",
"and",
"if",
"not",
"found",
"will",
"load",
"a",
"data",
"bag",
"item",
"named",
"for",
"the",
"chef_environment",
"or",
"_wildcard",
"value",
"."
] | c2409bd8cf9c14b967a719810dab5269d69b42de | https://github.com/riddopic/garcun/blob/c2409bd8cf9c14b967a719810dab5269d69b42de/lib/garcon/chef/secret_bag.rb#L153-L165 |
6,294 | magiclabs/attachment_magic | lib/attachment_magic.rb | AttachmentMagic.ClassMethods.copy_to_temp_file | def copy_to_temp_file(file, temp_base_name)
Tempfile.new(temp_base_name, AttachmentMagic.tempfile_path).tap do |tmp|
tmp.close
FileUtils.cp file, tmp.path
end
end | ruby | def copy_to_temp_file(file, temp_base_name)
Tempfile.new(temp_base_name, AttachmentMagic.tempfile_path).tap do |tmp|
tmp.close
FileUtils.cp file, tmp.path
end
end | [
"def",
"copy_to_temp_file",
"(",
"file",
",",
"temp_base_name",
")",
"Tempfile",
".",
"new",
"(",
"temp_base_name",
",",
"AttachmentMagic",
".",
"tempfile_path",
")",
".",
"tap",
"do",
"|",
"tmp",
"|",
"tmp",
".",
"close",
"FileUtils",
".",
"cp",
"file",
"... | Copies the given file path to a new tempfile, returning the closed tempfile. | [
"Copies",
"the",
"given",
"file",
"path",
"to",
"a",
"new",
"tempfile",
"returning",
"the",
"closed",
"tempfile",
"."
] | 98f2d897f108352e53a7b8d05a475111d1a6f2a1 | https://github.com/magiclabs/attachment_magic/blob/98f2d897f108352e53a7b8d05a475111d1a6f2a1/lib/attachment_magic.rb#L130-L135 |
6,295 | magiclabs/attachment_magic | lib/attachment_magic.rb | AttachmentMagic.ClassMethods.write_to_temp_file | def write_to_temp_file(data, temp_base_name)
Tempfile.new(temp_base_name, AttachmentMagic.tempfile_path).tap do |tmp|
tmp.binmode
tmp.write data
tmp.close
end
end | ruby | def write_to_temp_file(data, temp_base_name)
Tempfile.new(temp_base_name, AttachmentMagic.tempfile_path).tap do |tmp|
tmp.binmode
tmp.write data
tmp.close
end
end | [
"def",
"write_to_temp_file",
"(",
"data",
",",
"temp_base_name",
")",
"Tempfile",
".",
"new",
"(",
"temp_base_name",
",",
"AttachmentMagic",
".",
"tempfile_path",
")",
".",
"tap",
"do",
"|",
"tmp",
"|",
"tmp",
".",
"binmode",
"tmp",
".",
"write",
"data",
"... | Writes the given data to a new tempfile, returning the closed tempfile. | [
"Writes",
"the",
"given",
"data",
"to",
"a",
"new",
"tempfile",
"returning",
"the",
"closed",
"tempfile",
"."
] | 98f2d897f108352e53a7b8d05a475111d1a6f2a1 | https://github.com/magiclabs/attachment_magic/blob/98f2d897f108352e53a7b8d05a475111d1a6f2a1/lib/attachment_magic.rb#L138-L144 |
6,296 | magiclabs/attachment_magic | lib/attachment_magic.rb | AttachmentMagic.InstanceMethods.uploaded_data= | def uploaded_data=(file_data)
if file_data.respond_to?(:content_type)
return nil if file_data.size == 0
self.content_type = detect_mimetype(file_data)
self.filename = file_data.original_filename if respond_to?(:filename)
else
return nil if file_data.blank? || file_data['s... | ruby | def uploaded_data=(file_data)
if file_data.respond_to?(:content_type)
return nil if file_data.size == 0
self.content_type = detect_mimetype(file_data)
self.filename = file_data.original_filename if respond_to?(:filename)
else
return nil if file_data.blank? || file_data['s... | [
"def",
"uploaded_data",
"=",
"(",
"file_data",
")",
"if",
"file_data",
".",
"respond_to?",
"(",
":content_type",
")",
"return",
"nil",
"if",
"file_data",
".",
"size",
"==",
"0",
"self",
".",
"content_type",
"=",
"detect_mimetype",
"(",
"file_data",
")",
"sel... | This method handles the uploaded file object. If you set the field name to uploaded_data, you don't need
any special code in your controller.
<% form_for :attachment, :html => { :multipart => true } do |f| -%>
<p><%= f.file_field :uploaded_data %></p>
<p><%= submit_tag :Save %>
<% end -%>
@attach... | [
"This",
"method",
"handles",
"the",
"uploaded",
"file",
"object",
".",
"If",
"you",
"set",
"the",
"field",
"name",
"to",
"uploaded_data",
"you",
"don",
"t",
"need",
"any",
"special",
"code",
"in",
"your",
"controller",
"."
] | 98f2d897f108352e53a7b8d05a475111d1a6f2a1 | https://github.com/magiclabs/attachment_magic/blob/98f2d897f108352e53a7b8d05a475111d1a6f2a1/lib/attachment_magic.rb#L189-L206 |
6,297 | magiclabs/attachment_magic | lib/attachment_magic.rb | AttachmentMagic.InstanceMethods.attachment_attributes_valid? | def attachment_attributes_valid?
[:size, :content_type].each do |attr_name|
enum = attachment_options[attr_name]
errors.add attr_name, I18n.translate("activerecord.errors.messages.inclusion", attr_name => enum) unless enum.nil? || enum.include?(send(attr_name))
end
end | ruby | def attachment_attributes_valid?
[:size, :content_type].each do |attr_name|
enum = attachment_options[attr_name]
errors.add attr_name, I18n.translate("activerecord.errors.messages.inclusion", attr_name => enum) unless enum.nil? || enum.include?(send(attr_name))
end
end | [
"def",
"attachment_attributes_valid?",
"[",
":size",
",",
":content_type",
"]",
".",
"each",
"do",
"|",
"attr_name",
"|",
"enum",
"=",
"attachment_options",
"[",
"attr_name",
"]",
"errors",
".",
"add",
"attr_name",
",",
"I18n",
".",
"translate",
"(",
"\"active... | validates the size and content_type attributes according to the current model's options | [
"validates",
"the",
"size",
"and",
"content_type",
"attributes",
"according",
"to",
"the",
"current",
"model",
"s",
"options"
] | 98f2d897f108352e53a7b8d05a475111d1a6f2a1 | https://github.com/magiclabs/attachment_magic/blob/98f2d897f108352e53a7b8d05a475111d1a6f2a1/lib/attachment_magic.rb#L270-L275 |
6,298 | chrisjones-tripletri/action_command | lib/action_command/pretty_print_log_action.rb | ActionCommand.PrettyPrintLogAction.execute_internal | def execute_internal(_result)
item = LogMessage.new
parser = LogParser.new(@source, @sequence)
sequences = {}
# keep track of sequences, and when you complete one, then print out the
# entire thing at once.
while parser.next(item)
if item.kind?(ActionCommand::LOG_KIND_COMMAN... | ruby | def execute_internal(_result)
item = LogMessage.new
parser = LogParser.new(@source, @sequence)
sequences = {}
# keep track of sequences, and when you complete one, then print out the
# entire thing at once.
while parser.next(item)
if item.kind?(ActionCommand::LOG_KIND_COMMAN... | [
"def",
"execute_internal",
"(",
"_result",
")",
"item",
"=",
"LogMessage",
".",
"new",
"parser",
"=",
"LogParser",
".",
"new",
"(",
"@source",
",",
"@sequence",
")",
"sequences",
"=",
"{",
"}",
"# keep track of sequences, and when you complete one, then print out the ... | Say hello to the specified person. | [
"Say",
"hello",
"to",
"the",
"specified",
"person",
"."
] | 9b9a8ba30e407ca6d88a62a164d1dc22ba149874 | https://github.com/chrisjones-tripletri/action_command/blob/9b9a8ba30e407ca6d88a62a164d1dc22ba149874/lib/action_command/pretty_print_log_action.rb#L28-L45 |
6,299 | cloudhead/mutter | lib/mutter/mutterer.rb | Mutter.Mutterer.load | def load styles
styles += '.yml' unless styles =~ /\.ya?ml$/
styles = File.join(File.dirname(__FILE__), "styles", styles) unless File.exist? styles
YAML.load_file(styles).inject({}) do |h, (key, value)|
value = { :match => value['match'], :style => value['style'] }
h.merge key.to_sym =... | ruby | def load styles
styles += '.yml' unless styles =~ /\.ya?ml$/
styles = File.join(File.dirname(__FILE__), "styles", styles) unless File.exist? styles
YAML.load_file(styles).inject({}) do |h, (key, value)|
value = { :match => value['match'], :style => value['style'] }
h.merge key.to_sym =... | [
"def",
"load",
"styles",
"styles",
"+=",
"'.yml'",
"unless",
"styles",
"=~",
"/",
"\\.",
"/",
"styles",
"=",
"File",
".",
"join",
"(",
"File",
".",
"dirname",
"(",
"__FILE__",
")",
",",
"\"styles\"",
",",
"styles",
")",
"unless",
"File",
".",
"exist?",... | Loads styles from a YAML style-sheet,
and converts the keys to symbols | [
"Loads",
"styles",
"from",
"a",
"YAML",
"style",
"-",
"sheet",
"and",
"converts",
"the",
"keys",
"to",
"symbols"
] | 08a422552027d5a7b30b60206384c11698cf903d | https://github.com/cloudhead/mutter/blob/08a422552027d5a7b30b60206384c11698cf903d/lib/mutter/mutterer.rb#L64-L71 |
Subsets and Splits
No community queries yet
The top public SQL queries from the community will appear here once available.