repo
stringlengths 5
58
| path
stringlengths 9
168
| func_name
stringlengths 9
130
| original_string
stringlengths 66
10.5k
| language
stringclasses 1
value | code
stringlengths 66
10.5k
| code_tokens
sequence | docstring
stringlengths 8
16k
| docstring_tokens
sequence | sha
stringlengths 40
40
| url
stringlengths 94
266
| partition
stringclasses 1
value |
---|---|---|---|---|---|---|---|---|---|---|---|
ibaralf/site_prism_plus | lib/site_prism_plus/page.rb | SitePrismPlus.Page.load_and_verify | def load_and_verify(verify_element, url_hash = nil)
result = true
@metrics.start_time
if url_hash.nil?
load
else
load(url_hash)
end
if verify_element
result = wait_till_element_visible(verify_element, 3)
end
@metrics.log_metric(@page_name, 'load', verify_element)
result
end | ruby | def load_and_verify(verify_element, url_hash = nil)
result = true
@metrics.start_time
if url_hash.nil?
load
else
load(url_hash)
end
if verify_element
result = wait_till_element_visible(verify_element, 3)
end
@metrics.log_metric(@page_name, 'load', verify_element)
result
end | [
"def",
"load_and_verify",
"(",
"verify_element",
",",
"url_hash",
"=",
"nil",
")",
"result",
"=",
"true",
"@metrics",
".",
"start_time",
"if",
"url_hash",
".",
"nil?",
"load",
"else",
"load",
"(",
"url_hash",
")",
"end",
"if",
"verify_element",
"result",
"=",
"wait_till_element_visible",
"(",
"verify_element",
",",
"3",
")",
"end",
"@metrics",
".",
"log_metric",
"(",
"@page_name",
",",
"'load'",
",",
"verify_element",
")",
"result",
"end"
] | Page loads typically takes longer. | [
"Page",
"loads",
"typically",
"takes",
"longer",
"."
] | cfa56006122ed7ed62889cbcda97e8c406e06f01 | https://github.com/ibaralf/site_prism_plus/blob/cfa56006122ed7ed62889cbcda97e8c406e06f01/lib/site_prism_plus/page.rb#L24-L37 | train |
alexrothenberg/motion-addressbook | motion/address_book/ios/person.rb | AddressBook.Person.load_ab_person | def load_ab_person
@attributes ||= {}
Person.single_value_property_map.each do |ab_property, attr_key|
if attributes[attr_key]
set_field(ab_property, attributes[attr_key])
else
remove_field(ab_property)
end
end
if attributes[:is_org]
set_field(KABPersonKindProperty, KABPersonKindOrganization)
else
set_field(KABPersonKindProperty, KABPersonKindPerson)
end
Person.multi_value_property_map.each do |ab_property, attr_key|
if attributes[attr_key]
set_multi_valued(ab_property, attributes[attr_key])
else
remove_field(ab_property)
end
end
ab_person
end | ruby | def load_ab_person
@attributes ||= {}
Person.single_value_property_map.each do |ab_property, attr_key|
if attributes[attr_key]
set_field(ab_property, attributes[attr_key])
else
remove_field(ab_property)
end
end
if attributes[:is_org]
set_field(KABPersonKindProperty, KABPersonKindOrganization)
else
set_field(KABPersonKindProperty, KABPersonKindPerson)
end
Person.multi_value_property_map.each do |ab_property, attr_key|
if attributes[attr_key]
set_multi_valued(ab_property, attributes[attr_key])
else
remove_field(ab_property)
end
end
ab_person
end | [
"def",
"load_ab_person",
"@attributes",
"||=",
"{",
"}",
"Person",
".",
"single_value_property_map",
".",
"each",
"do",
"|",
"ab_property",
",",
"attr_key",
"|",
"if",
"attributes",
"[",
"attr_key",
"]",
"set_field",
"(",
"ab_property",
",",
"attributes",
"[",
"attr_key",
"]",
")",
"else",
"remove_field",
"(",
"ab_property",
")",
"end",
"end",
"if",
"attributes",
"[",
":is_org",
"]",
"set_field",
"(",
"KABPersonKindProperty",
",",
"KABPersonKindOrganization",
")",
"else",
"set_field",
"(",
"KABPersonKindProperty",
",",
"KABPersonKindPerson",
")",
"end",
"Person",
".",
"multi_value_property_map",
".",
"each",
"do",
"|",
"ab_property",
",",
"attr_key",
"|",
"if",
"attributes",
"[",
"attr_key",
"]",
"set_multi_valued",
"(",
"ab_property",
",",
"attributes",
"[",
"attr_key",
"]",
")",
"else",
"remove_field",
"(",
"ab_property",
")",
"end",
"end",
"ab_person",
"end"
] | instantiates ABPerson record from attributes | [
"instantiates",
"ABPerson",
"record",
"from",
"attributes"
] | 6f1cfb486d27397da48dc202d79e61f4b0c295af | https://github.com/alexrothenberg/motion-addressbook/blob/6f1cfb486d27397da48dc202d79e61f4b0c295af/motion/address_book/ios/person.rb#L373-L399 | train |
jmettraux/rufus-rtm | lib/rufus/rtm/resources.rb | Rufus::RTM.Task.tags= | def tags= (tags)
tags = tags.split(',') if tags.is_a?(String)
@tags = TagArray.new(list_id, tags)
queue_operation('setTasks', tags.join(','))
end | ruby | def tags= (tags)
tags = tags.split(',') if tags.is_a?(String)
@tags = TagArray.new(list_id, tags)
queue_operation('setTasks', tags.join(','))
end | [
"def",
"tags",
"=",
"(",
"tags",
")",
"tags",
"=",
"tags",
".",
"split",
"(",
"','",
")",
"if",
"tags",
".",
"is_a?",
"(",
"String",
")",
"@tags",
"=",
"TagArray",
".",
"new",
"(",
"list_id",
",",
"tags",
")",
"queue_operation",
"(",
"'setTasks'",
",",
"tags",
".",
"join",
"(",
"','",
")",
")",
"end"
] | Sets the tags for the task. | [
"Sets",
"the",
"tags",
"for",
"the",
"task",
"."
] | b5e36129f92325749d131391558e93e109ed0e61 | https://github.com/jmettraux/rufus-rtm/blob/b5e36129f92325749d131391558e93e109ed0e61/lib/rufus/rtm/resources.rb#L179-L186 | train |
rhenium/plum | lib/plum/client/response.rb | Plum.Response.on_chunk | def on_chunk(&block)
raise "Body already read" if @on_chunk
raise ArgumentError, "block must be given" unless block_given?
@on_chunk = block
unless @body.empty?
@body.each(&block)
@body.clear
end
self
end | ruby | def on_chunk(&block)
raise "Body already read" if @on_chunk
raise ArgumentError, "block must be given" unless block_given?
@on_chunk = block
unless @body.empty?
@body.each(&block)
@body.clear
end
self
end | [
"def",
"on_chunk",
"(",
"&",
"block",
")",
"raise",
"\"Body already read\"",
"if",
"@on_chunk",
"raise",
"ArgumentError",
",",
"\"block must be given\"",
"unless",
"block_given?",
"@on_chunk",
"=",
"block",
"unless",
"@body",
".",
"empty?",
"@body",
".",
"each",
"(",
"&",
"block",
")",
"@body",
".",
"clear",
"end",
"self",
"end"
] | Set callback that will be called when received a chunk of response body.
@yield [chunk] A chunk of the response body. | [
"Set",
"callback",
"that",
"will",
"be",
"called",
"when",
"received",
"a",
"chunk",
"of",
"response",
"body",
"."
] | 9190801a092d46c7079ccee201b212b2d7985952 | https://github.com/rhenium/plum/blob/9190801a092d46c7079ccee201b212b2d7985952/lib/plum/client/response.rb#L57-L66 | train |
dmacvicar/bicho | lib/bicho/client.rb | Bicho.Client.create_bug | def create_bug(product, component, summary, version, **kwargs)
params = {}
params = params.merge(kwargs)
params[:product] = product
params[:component] = component
params[:summary] = summary
params[:version] = version
ret = @client.call('Bug.create', params)
handle_faults(ret)
ret['id']
end | ruby | def create_bug(product, component, summary, version, **kwargs)
params = {}
params = params.merge(kwargs)
params[:product] = product
params[:component] = component
params[:summary] = summary
params[:version] = version
ret = @client.call('Bug.create', params)
handle_faults(ret)
ret['id']
end | [
"def",
"create_bug",
"(",
"product",
",",
"component",
",",
"summary",
",",
"version",
",",
"**",
"kwargs",
")",
"params",
"=",
"{",
"}",
"params",
"=",
"params",
".",
"merge",
"(",
"kwargs",
")",
"params",
"[",
":product",
"]",
"=",
"product",
"params",
"[",
":component",
"]",
"=",
"component",
"params",
"[",
":summary",
"]",
"=",
"summary",
"params",
"[",
":version",
"]",
"=",
"version",
"ret",
"=",
"@client",
".",
"call",
"(",
"'Bug.create'",
",",
"params",
")",
"handle_faults",
"(",
"ret",
")",
"ret",
"[",
"'id'",
"]",
"end"
] | Create a bug
@param product - the name of the product the bug is being filed against
@param component - the name of a component in the product above.
@param summary - a brief description of the bug being filed.
@param version - version of the product above; the version the bug was found in.
@param **kwargs - keyword-args containing optional/defaulted params
Return the new bug ID | [
"Create",
"a",
"bug"
] | fff403fcc5b1e1b6c81defd7c6434e9499aa1a63 | https://github.com/dmacvicar/bicho/blob/fff403fcc5b1e1b6c81defd7c6434e9499aa1a63/lib/bicho/client.rb#L198-L208 | train |
dmacvicar/bicho | lib/bicho/client.rb | Bicho.Client.search_bugs | def search_bugs(query)
# allow plain strings to be passed, interpretting them
query = Query.new.summary(query) if query.is_a?(String)
ret = @client.call('Bug.search', query.query_map)
handle_faults(ret)
bugs = []
ret['bugs'].each do |bug_data|
bugs << Bug.new(self, bug_data)
end
bugs
end | ruby | def search_bugs(query)
# allow plain strings to be passed, interpretting them
query = Query.new.summary(query) if query.is_a?(String)
ret = @client.call('Bug.search', query.query_map)
handle_faults(ret)
bugs = []
ret['bugs'].each do |bug_data|
bugs << Bug.new(self, bug_data)
end
bugs
end | [
"def",
"search_bugs",
"(",
"query",
")",
"query",
"=",
"Query",
".",
"new",
".",
"summary",
"(",
"query",
")",
"if",
"query",
".",
"is_a?",
"(",
"String",
")",
"ret",
"=",
"@client",
".",
"call",
"(",
"'Bug.search'",
",",
"query",
".",
"query_map",
")",
"handle_faults",
"(",
"ret",
")",
"bugs",
"=",
"[",
"]",
"ret",
"[",
"'bugs'",
"]",
".",
"each",
"do",
"|",
"bug_data",
"|",
"bugs",
"<<",
"Bug",
".",
"new",
"(",
"self",
",",
"bug_data",
")",
"end",
"bugs",
"end"
] | Search for a bug
+query+ has to be either a +Query+ object or
a +String+ that will be searched in the summary
of the bugs. | [
"Search",
"for",
"a",
"bug"
] | fff403fcc5b1e1b6c81defd7c6434e9499aa1a63 | https://github.com/dmacvicar/bicho/blob/fff403fcc5b1e1b6c81defd7c6434e9499aa1a63/lib/bicho/client.rb#L216-L227 | train |
dmacvicar/bicho | lib/bicho/client.rb | Bicho.Client.expand_named_query | def expand_named_query(what)
url = @api_url.clone
url.path = '/buglist.cgi'
url.query = "cmdtype=runnamed&namedcmd=#{URI.escape(what)}&ctype=atom"
logger.info("Expanding named query: '#{what}' to #{url.request_uri}")
fetch_named_query_url(url, 5)
end | ruby | def expand_named_query(what)
url = @api_url.clone
url.path = '/buglist.cgi'
url.query = "cmdtype=runnamed&namedcmd=#{URI.escape(what)}&ctype=atom"
logger.info("Expanding named query: '#{what}' to #{url.request_uri}")
fetch_named_query_url(url, 5)
end | [
"def",
"expand_named_query",
"(",
"what",
")",
"url",
"=",
"@api_url",
".",
"clone",
"url",
".",
"path",
"=",
"'/buglist.cgi'",
"url",
".",
"query",
"=",
"\"cmdtype=runnamed&namedcmd=#{URI.escape(what)}&ctype=atom\"",
"logger",
".",
"info",
"(",
"\"Expanding named query: '#{what}' to #{url.request_uri}\"",
")",
"fetch_named_query_url",
"(",
"url",
",",
"5",
")",
"end"
] | Given a named query's name, runs it
on the server
@returns [Array<String>] list of bugs | [
"Given",
"a",
"named",
"query",
"s",
"name",
"runs",
"it",
"on",
"the",
"server"
] | fff403fcc5b1e1b6c81defd7c6434e9499aa1a63 | https://github.com/dmacvicar/bicho/blob/fff403fcc5b1e1b6c81defd7c6434e9499aa1a63/lib/bicho/client.rb#L232-L238 | train |
dmacvicar/bicho | lib/bicho/client.rb | Bicho.Client.fetch_named_query_url | def fetch_named_query_url(url, redirects_left)
raise 'You need to be authenticated to use named queries' unless @userid
http = Net::HTTP.new(@api_url.host, @api_url.port)
http.set_debug_output(Bicho::LoggerIODevice.new)
http.verify_mode = OpenSSL::SSL::VERIFY_NONE
http.use_ssl = (@api_url.scheme == 'https')
# request = Net::HTTP::Get.new(url.request_uri, {'Cookie' => self.cookie})
request = Net::HTTP::Get.new(url.request_uri)
request.basic_auth @api_url.user, @api_url.password
response = http.request(request)
case response
when Net::HTTPSuccess
bugs = []
begin
xml = Nokogiri::XML.parse(response.body)
xml.root.xpath('//xmlns:entry/xmlns:link/@href', xml.root.namespace).each do |attr|
uri = URI.parse attr.value
bugs << uri.query.split('=')[1]
end
return bugs
rescue Nokogiri::XML::XPath::SyntaxError
raise "Named query '#{url.request_uri}' not found"
end
when Net::HTTPRedirection
location = response['location']
if redirects_left.zero?
raise "Maximum redirects exceeded (redirected to #{location})"
end
new_location_uri = URI.parse(location)
logger.debug("Moved to #{new_location_uri}")
fetch_named_query_url(new_location_uri, redirects_left - 1)
else
raise "Error when expanding named query '#{url.request_uri}': #{response}"
end
end | ruby | def fetch_named_query_url(url, redirects_left)
raise 'You need to be authenticated to use named queries' unless @userid
http = Net::HTTP.new(@api_url.host, @api_url.port)
http.set_debug_output(Bicho::LoggerIODevice.new)
http.verify_mode = OpenSSL::SSL::VERIFY_NONE
http.use_ssl = (@api_url.scheme == 'https')
# request = Net::HTTP::Get.new(url.request_uri, {'Cookie' => self.cookie})
request = Net::HTTP::Get.new(url.request_uri)
request.basic_auth @api_url.user, @api_url.password
response = http.request(request)
case response
when Net::HTTPSuccess
bugs = []
begin
xml = Nokogiri::XML.parse(response.body)
xml.root.xpath('//xmlns:entry/xmlns:link/@href', xml.root.namespace).each do |attr|
uri = URI.parse attr.value
bugs << uri.query.split('=')[1]
end
return bugs
rescue Nokogiri::XML::XPath::SyntaxError
raise "Named query '#{url.request_uri}' not found"
end
when Net::HTTPRedirection
location = response['location']
if redirects_left.zero?
raise "Maximum redirects exceeded (redirected to #{location})"
end
new_location_uri = URI.parse(location)
logger.debug("Moved to #{new_location_uri}")
fetch_named_query_url(new_location_uri, redirects_left - 1)
else
raise "Error when expanding named query '#{url.request_uri}': #{response}"
end
end | [
"def",
"fetch_named_query_url",
"(",
"url",
",",
"redirects_left",
")",
"raise",
"'You need to be authenticated to use named queries'",
"unless",
"@userid",
"http",
"=",
"Net",
"::",
"HTTP",
".",
"new",
"(",
"@api_url",
".",
"host",
",",
"@api_url",
".",
"port",
")",
"http",
".",
"set_debug_output",
"(",
"Bicho",
"::",
"LoggerIODevice",
".",
"new",
")",
"http",
".",
"verify_mode",
"=",
"OpenSSL",
"::",
"SSL",
"::",
"VERIFY_NONE",
"http",
".",
"use_ssl",
"=",
"(",
"@api_url",
".",
"scheme",
"==",
"'https'",
")",
"request",
"=",
"Net",
"::",
"HTTP",
"::",
"Get",
".",
"new",
"(",
"url",
".",
"request_uri",
")",
"request",
".",
"basic_auth",
"@api_url",
".",
"user",
",",
"@api_url",
".",
"password",
"response",
"=",
"http",
".",
"request",
"(",
"request",
")",
"case",
"response",
"when",
"Net",
"::",
"HTTPSuccess",
"bugs",
"=",
"[",
"]",
"begin",
"xml",
"=",
"Nokogiri",
"::",
"XML",
".",
"parse",
"(",
"response",
".",
"body",
")",
"xml",
".",
"root",
".",
"xpath",
"(",
"'//xmlns:entry/xmlns:link/@href'",
",",
"xml",
".",
"root",
".",
"namespace",
")",
".",
"each",
"do",
"|",
"attr",
"|",
"uri",
"=",
"URI",
".",
"parse",
"attr",
".",
"value",
"bugs",
"<<",
"uri",
".",
"query",
".",
"split",
"(",
"'='",
")",
"[",
"1",
"]",
"end",
"return",
"bugs",
"rescue",
"Nokogiri",
"::",
"XML",
"::",
"XPath",
"::",
"SyntaxError",
"raise",
"\"Named query '#{url.request_uri}' not found\"",
"end",
"when",
"Net",
"::",
"HTTPRedirection",
"location",
"=",
"response",
"[",
"'location'",
"]",
"if",
"redirects_left",
".",
"zero?",
"raise",
"\"Maximum redirects exceeded (redirected to #{location})\"",
"end",
"new_location_uri",
"=",
"URI",
".",
"parse",
"(",
"location",
")",
"logger",
".",
"debug",
"(",
"\"Moved to #{new_location_uri}\"",
")",
"fetch_named_query_url",
"(",
"new_location_uri",
",",
"redirects_left",
"-",
"1",
")",
"else",
"raise",
"\"Error when expanding named query '#{url.request_uri}': #{response}\"",
"end",
"end"
] | Fetches a named query by its full url
@private
@returns [Array<String>] list of bugs | [
"Fetches",
"a",
"named",
"query",
"by",
"its",
"full",
"url"
] | fff403fcc5b1e1b6c81defd7c6434e9499aa1a63 | https://github.com/dmacvicar/bicho/blob/fff403fcc5b1e1b6c81defd7c6434e9499aa1a63/lib/bicho/client.rb#L258-L292 | train |
dmacvicar/bicho | lib/bicho/client.rb | Bicho.Client.get_bugs | def get_bugs(*ids)
params = {}
params[:ids] = normalize_ids ids
bugs = []
ret = @client.call('Bug.get', params)
handle_faults(ret)
ret['bugs'].each do |bug_data|
bugs << Bug.new(self, bug_data)
end
bugs
end | ruby | def get_bugs(*ids)
params = {}
params[:ids] = normalize_ids ids
bugs = []
ret = @client.call('Bug.get', params)
handle_faults(ret)
ret['bugs'].each do |bug_data|
bugs << Bug.new(self, bug_data)
end
bugs
end | [
"def",
"get_bugs",
"(",
"*",
"ids",
")",
"params",
"=",
"{",
"}",
"params",
"[",
":ids",
"]",
"=",
"normalize_ids",
"ids",
"bugs",
"=",
"[",
"]",
"ret",
"=",
"@client",
".",
"call",
"(",
"'Bug.get'",
",",
"params",
")",
"handle_faults",
"(",
"ret",
")",
"ret",
"[",
"'bugs'",
"]",
".",
"each",
"do",
"|",
"bug_data",
"|",
"bugs",
"<<",
"Bug",
".",
"new",
"(",
"self",
",",
"bug_data",
")",
"end",
"bugs",
"end"
] | Retrieves one or more bugs by id
@return [Array<Bug>] a list of bugs | [
"Retrieves",
"one",
"or",
"more",
"bugs",
"by",
"id"
] | fff403fcc5b1e1b6c81defd7c6434e9499aa1a63 | https://github.com/dmacvicar/bicho/blob/fff403fcc5b1e1b6c81defd7c6434e9499aa1a63/lib/bicho/client.rb#L302-L313 | train |
dmacvicar/bicho | lib/bicho/client.rb | Bicho.Client.add_attachment | def add_attachment(summary, file, *ids, **kwargs)
params = {}
params[:ids] = ids
params[:summary] = summary
params[:content_type] = kwargs.fetch(:content_type, 'application/octet-stream')
params[:file_name] = kwargs.fetch(:file_name, File.basename(file))
params[:is_patch] = kwargs[:patch?] if kwargs[:patch?]
params[:is_private] = kwargs[:private?] if kwargs[:private?]
params[:comment] = kwargs[:comment] if kwargs[:comment]
params[:data] = XMLRPC::Base64.new(file.read)
ret = @client.call('Bug.add_attachment', params)
handle_faults(ret)
ret['ids']
end | ruby | def add_attachment(summary, file, *ids, **kwargs)
params = {}
params[:ids] = ids
params[:summary] = summary
params[:content_type] = kwargs.fetch(:content_type, 'application/octet-stream')
params[:file_name] = kwargs.fetch(:file_name, File.basename(file))
params[:is_patch] = kwargs[:patch?] if kwargs[:patch?]
params[:is_private] = kwargs[:private?] if kwargs[:private?]
params[:comment] = kwargs[:comment] if kwargs[:comment]
params[:data] = XMLRPC::Base64.new(file.read)
ret = @client.call('Bug.add_attachment', params)
handle_faults(ret)
ret['ids']
end | [
"def",
"add_attachment",
"(",
"summary",
",",
"file",
",",
"*",
"ids",
",",
"**",
"kwargs",
")",
"params",
"=",
"{",
"}",
"params",
"[",
":ids",
"]",
"=",
"ids",
"params",
"[",
":summary",
"]",
"=",
"summary",
"params",
"[",
":content_type",
"]",
"=",
"kwargs",
".",
"fetch",
"(",
":content_type",
",",
"'application/octet-stream'",
")",
"params",
"[",
":file_name",
"]",
"=",
"kwargs",
".",
"fetch",
"(",
":file_name",
",",
"File",
".",
"basename",
"(",
"file",
")",
")",
"params",
"[",
":is_patch",
"]",
"=",
"kwargs",
"[",
":patch?",
"]",
"if",
"kwargs",
"[",
":patch?",
"]",
"params",
"[",
":is_private",
"]",
"=",
"kwargs",
"[",
":private?",
"]",
"if",
"kwargs",
"[",
":private?",
"]",
"params",
"[",
":comment",
"]",
"=",
"kwargs",
"[",
":comment",
"]",
"if",
"kwargs",
"[",
":comment",
"]",
"params",
"[",
":data",
"]",
"=",
"XMLRPC",
"::",
"Base64",
".",
"new",
"(",
"file",
".",
"read",
")",
"ret",
"=",
"@client",
".",
"call",
"(",
"'Bug.add_attachment'",
",",
"params",
")",
"handle_faults",
"(",
"ret",
")",
"ret",
"[",
"'ids'",
"]",
"end"
] | Add an attachment to bugs with given ids
Params:
@param summary - a short string describing the attachment
@param file - [File] object to attach
@param *ids - a list of bug ids to which the attachment will be added
@param **kwargs - optional keyword-args that may contain:
- content_type - content type of the attachment (if ommited,
'application/octet-stream' will be used)
- file_name - name of the file (if ommited, the base name of the
provided file will be used)
- patch? - flag saying that the attachment is a patch
- private? - flag saying that the attachment is private
- comment
@return [Array<ID>] a list of the attachment id(s) created. | [
"Add",
"an",
"attachment",
"to",
"bugs",
"with",
"given",
"ids"
] | fff403fcc5b1e1b6c81defd7c6434e9499aa1a63 | https://github.com/dmacvicar/bicho/blob/fff403fcc5b1e1b6c81defd7c6434e9499aa1a63/lib/bicho/client.rb#L363-L376 | train |
GomaaK/sshez | lib/sshez/exec.rb | Sshez.Exec.connect | def connect(alias_name, options)
file = File.open(FILE_PATH, 'r')
servers = all_hosts_in(file)
if servers.include?alias_name
PRINTER.verbose_print "Connecting to #{alias_name}"
exec "ssh #{alias_name}"
else
PRINTER.print "Could not find host `#{alias_name}`"
end
end | ruby | def connect(alias_name, options)
file = File.open(FILE_PATH, 'r')
servers = all_hosts_in(file)
if servers.include?alias_name
PRINTER.verbose_print "Connecting to #{alias_name}"
exec "ssh #{alias_name}"
else
PRINTER.print "Could not find host `#{alias_name}`"
end
end | [
"def",
"connect",
"(",
"alias_name",
",",
"options",
")",
"file",
"=",
"File",
".",
"open",
"(",
"FILE_PATH",
",",
"'r'",
")",
"servers",
"=",
"all_hosts_in",
"(",
"file",
")",
"if",
"servers",
".",
"include?",
"alias_name",
"PRINTER",
".",
"verbose_print",
"\"Connecting to #{alias_name}\"",
"exec",
"\"ssh #{alias_name}\"",
"else",
"PRINTER",
".",
"print",
"\"Could not find host `#{alias_name}`\"",
"end",
"end"
] | connects to host using alias | [
"connects",
"to",
"host",
"using",
"alias"
] | 6771012c2b29c2f28fdaf42372f93f70dbcbb291 | https://github.com/GomaaK/sshez/blob/6771012c2b29c2f28fdaf42372f93f70dbcbb291/lib/sshez/exec.rb#L42-L51 | train |
GomaaK/sshez | lib/sshez/exec.rb | Sshez.Exec.add | def add(alias_name, user, host, options)
begin
PRINTER.verbose_print "Adding\n"
config_append = form(alias_name, user, host, options)
PRINTER.verbose_print config_append
unless options.test
file = File.open(FILE_PATH, 'a+')
file.write(config_append)
file.close
# causes a bug in fedore if permission was not updated to 0600
File.chmod(0600, FILE_PATH)
# system "chmod 600 #{FILE_PATH}"
end
rescue
return permission_error
end
PRINTER.verbose_print "to #{FILE_PATH}"
PRINTER.print "Successfully added `#{alias_name}` as an alias for `#{user}@#{host}`"
PRINTER.print "Try sshez connect #{alias_name}"
finish_exec
end | ruby | def add(alias_name, user, host, options)
begin
PRINTER.verbose_print "Adding\n"
config_append = form(alias_name, user, host, options)
PRINTER.verbose_print config_append
unless options.test
file = File.open(FILE_PATH, 'a+')
file.write(config_append)
file.close
# causes a bug in fedore if permission was not updated to 0600
File.chmod(0600, FILE_PATH)
# system "chmod 600 #{FILE_PATH}"
end
rescue
return permission_error
end
PRINTER.verbose_print "to #{FILE_PATH}"
PRINTER.print "Successfully added `#{alias_name}` as an alias for `#{user}@#{host}`"
PRINTER.print "Try sshez connect #{alias_name}"
finish_exec
end | [
"def",
"add",
"(",
"alias_name",
",",
"user",
",",
"host",
",",
"options",
")",
"begin",
"PRINTER",
".",
"verbose_print",
"\"Adding\\n\"",
"config_append",
"=",
"form",
"(",
"alias_name",
",",
"user",
",",
"host",
",",
"options",
")",
"PRINTER",
".",
"verbose_print",
"config_append",
"unless",
"options",
".",
"test",
"file",
"=",
"File",
".",
"open",
"(",
"FILE_PATH",
",",
"'a+'",
")",
"file",
".",
"write",
"(",
"config_append",
")",
"file",
".",
"close",
"File",
".",
"chmod",
"(",
"0600",
",",
"FILE_PATH",
")",
"end",
"rescue",
"return",
"permission_error",
"end",
"PRINTER",
".",
"verbose_print",
"\"to #{FILE_PATH}\"",
"PRINTER",
".",
"print",
"\"Successfully added `#{alias_name}` as an alias for `#{user}@#{host}`\"",
"PRINTER",
".",
"print",
"\"Try sshez connect #{alias_name}\"",
"finish_exec",
"end"
] | append an alias for the given user@host with the options passed | [
"append",
"an",
"alias",
"for",
"the",
"given",
"user"
] | 6771012c2b29c2f28fdaf42372f93f70dbcbb291 | https://github.com/GomaaK/sshez/blob/6771012c2b29c2f28fdaf42372f93f70dbcbb291/lib/sshez/exec.rb#L56-L78 | train |
GomaaK/sshez | lib/sshez/exec.rb | Sshez.Exec.all_hosts_in | def all_hosts_in(file)
servers = []
file.each do |line|
if line.include?('Host ')
servers << line.sub('Host ', '').strip
end
end
servers
end | ruby | def all_hosts_in(file)
servers = []
file.each do |line|
if line.include?('Host ')
servers << line.sub('Host ', '').strip
end
end
servers
end | [
"def",
"all_hosts_in",
"(",
"file",
")",
"servers",
"=",
"[",
"]",
"file",
".",
"each",
"do",
"|",
"line",
"|",
"if",
"line",
".",
"include?",
"(",
"'Host '",
")",
"servers",
"<<",
"line",
".",
"sub",
"(",
"'Host '",
",",
"''",
")",
".",
"strip",
"end",
"end",
"servers",
"end"
] | Returns all the alias names of in the file | [
"Returns",
"all",
"the",
"alias",
"names",
"of",
"in",
"the",
"file"
] | 6771012c2b29c2f28fdaf42372f93f70dbcbb291 | https://github.com/GomaaK/sshez/blob/6771012c2b29c2f28fdaf42372f93f70dbcbb291/lib/sshez/exec.rb#L170-L178 | train |
propublica/thinner | lib/thinner/command_line.rb | Thinner.CommandLine.options! | def options!
@options = {}
@option_parser = OptionParser.new(BANNER) do |opts|
opts.on("-b", "--batch_length BATCH", "Number of urls to purge at once") do |b|
@options[:batch_length] = b.to_i
end
opts.on("-t", "--sleep_time SLEEP", "Time to wait in between batches") do |t|
@options[:sleep_time] = t.to_i
end
opts.on("-e", "--stdin", "Use stdin for urls") do
@urls = []
ARGF.each_line do |url|
@urls << url.chomp
end
end
opts.on("-s", "--server SERVER", "Varnish url, e.g. 127.0.0.1:6082") do |s|
@options[:server] = s
end
opts.on("-o", "--log_file LOG_PATH", "Log file to output to (default: Standard Out") do |o|
@options[:log_file] = o
end
opts.on("-n", "--no-kill", "Don't kill the running purgers if they exist") do |n|
@options[:no_kill] = n
end
opts.on_tail("-h", "--help", "Display this help message") do
puts opts.help
exit
end
end
begin
@option_parser.parse!(ARGV)
rescue OptionParser::InvalidOption => e
puts e.message
exit(1)
end
end | ruby | def options!
@options = {}
@option_parser = OptionParser.new(BANNER) do |opts|
opts.on("-b", "--batch_length BATCH", "Number of urls to purge at once") do |b|
@options[:batch_length] = b.to_i
end
opts.on("-t", "--sleep_time SLEEP", "Time to wait in between batches") do |t|
@options[:sleep_time] = t.to_i
end
opts.on("-e", "--stdin", "Use stdin for urls") do
@urls = []
ARGF.each_line do |url|
@urls << url.chomp
end
end
opts.on("-s", "--server SERVER", "Varnish url, e.g. 127.0.0.1:6082") do |s|
@options[:server] = s
end
opts.on("-o", "--log_file LOG_PATH", "Log file to output to (default: Standard Out") do |o|
@options[:log_file] = o
end
opts.on("-n", "--no-kill", "Don't kill the running purgers if they exist") do |n|
@options[:no_kill] = n
end
opts.on_tail("-h", "--help", "Display this help message") do
puts opts.help
exit
end
end
begin
@option_parser.parse!(ARGV)
rescue OptionParser::InvalidOption => e
puts e.message
exit(1)
end
end | [
"def",
"options!",
"@options",
"=",
"{",
"}",
"@option_parser",
"=",
"OptionParser",
".",
"new",
"(",
"BANNER",
")",
"do",
"|",
"opts",
"|",
"opts",
".",
"on",
"(",
"\"-b\"",
",",
"\"--batch_length BATCH\"",
",",
"\"Number of urls to purge at once\"",
")",
"do",
"|",
"b",
"|",
"@options",
"[",
":batch_length",
"]",
"=",
"b",
".",
"to_i",
"end",
"opts",
".",
"on",
"(",
"\"-t\"",
",",
"\"--sleep_time SLEEP\"",
",",
"\"Time to wait in between batches\"",
")",
"do",
"|",
"t",
"|",
"@options",
"[",
":sleep_time",
"]",
"=",
"t",
".",
"to_i",
"end",
"opts",
".",
"on",
"(",
"\"-e\"",
",",
"\"--stdin\"",
",",
"\"Use stdin for urls\"",
")",
"do",
"@urls",
"=",
"[",
"]",
"ARGF",
".",
"each_line",
"do",
"|",
"url",
"|",
"@urls",
"<<",
"url",
".",
"chomp",
"end",
"end",
"opts",
".",
"on",
"(",
"\"-s\"",
",",
"\"--server SERVER\"",
",",
"\"Varnish url, e.g. 127.0.0.1:6082\"",
")",
"do",
"|",
"s",
"|",
"@options",
"[",
":server",
"]",
"=",
"s",
"end",
"opts",
".",
"on",
"(",
"\"-o\"",
",",
"\"--log_file LOG_PATH\"",
",",
"\"Log file to output to (default: Standard Out\"",
")",
"do",
"|",
"o",
"|",
"@options",
"[",
":log_file",
"]",
"=",
"o",
"end",
"opts",
".",
"on",
"(",
"\"-n\"",
",",
"\"--no-kill\"",
",",
"\"Don't kill the running purgers if they exist\"",
")",
"do",
"|",
"n",
"|",
"@options",
"[",
":no_kill",
"]",
"=",
"n",
"end",
"opts",
".",
"on_tail",
"(",
"\"-h\"",
",",
"\"--help\"",
",",
"\"Display this help message\"",
")",
"do",
"puts",
"opts",
".",
"help",
"exit",
"end",
"end",
"begin",
"@option_parser",
".",
"parse!",
"(",
"ARGV",
")",
"rescue",
"OptionParser",
"::",
"InvalidOption",
"=>",
"e",
"puts",
"e",
".",
"message",
"exit",
"(",
"1",
")",
"end",
"end"
] | Parse the command line options using OptionParser. | [
"Parse",
"the",
"command",
"line",
"options",
"using",
"OptionParser",
"."
] | 6fd2a676c379aed8b59e2677fa7650975a83037f | https://github.com/propublica/thinner/blob/6fd2a676c379aed8b59e2677fa7650975a83037f/lib/thinner/command_line.rb#L40-L76 | train |
kristianmandrup/cancan-permits | lib/cancan-permits/permit/base.rb | Permit.Base.licenses | def licenses *names
names.to_strings.each do |name|
begin
module_name = "#{name.camelize}License"
clazz = module_name.constantize
rescue
raise "License #{module_name} is not defined"
end
begin
clazz.new(self).enforce!
rescue
raise "License #{clazz} could not be enforced using #{self.inspect}"
end
end
end | ruby | def licenses *names
names.to_strings.each do |name|
begin
module_name = "#{name.camelize}License"
clazz = module_name.constantize
rescue
raise "License #{module_name} is not defined"
end
begin
clazz.new(self).enforce!
rescue
raise "License #{clazz} could not be enforced using #{self.inspect}"
end
end
end | [
"def",
"licenses",
"*",
"names",
"names",
".",
"to_strings",
".",
"each",
"do",
"|",
"name",
"|",
"begin",
"module_name",
"=",
"\"#{name.camelize}License\"",
"clazz",
"=",
"module_name",
".",
"constantize",
"rescue",
"raise",
"\"License #{module_name} is not defined\"",
"end",
"begin",
"clazz",
".",
"new",
"(",
"self",
")",
".",
"enforce!",
"rescue",
"raise",
"\"License #{clazz} could not be enforced using #{self.inspect}\"",
"end",
"end",
"end"
] | where and how is this used??? | [
"where",
"and",
"how",
"is",
"this",
"used???"
] | cbc56d299751118b5b6629af0f77917b3d762d61 | https://github.com/kristianmandrup/cancan-permits/blob/cbc56d299751118b5b6629af0f77917b3d762d61/lib/cancan-permits/permit/base.rb#L46-L61 | train |
kristianmandrup/cancan-permits | lib/cancan-permits/permit/base.rb | Permit.Base.executor | def executor(user_account, options = {})
@executor ||= case self.class.name
when /System/
then Permit::Executor::System.new self, user_account, options
else
Permit::Executor::Base.new self, user_account, options
end
end | ruby | def executor(user_account, options = {})
@executor ||= case self.class.name
when /System/
then Permit::Executor::System.new self, user_account, options
else
Permit::Executor::Base.new self, user_account, options
end
end | [
"def",
"executor",
"(",
"user_account",
",",
"options",
"=",
"{",
"}",
")",
"@executor",
"||=",
"case",
"self",
".",
"class",
".",
"name",
"when",
"/",
"/",
"then",
"Permit",
"::",
"Executor",
"::",
"System",
".",
"new",
"self",
",",
"user_account",
",",
"options",
"else",
"Permit",
"::",
"Executor",
"::",
"Base",
".",
"new",
"self",
",",
"user_account",
",",
"options",
"end",
"end"
] | return the executor used to execute the permit | [
"return",
"the",
"executor",
"used",
"to",
"execute",
"the",
"permit"
] | cbc56d299751118b5b6629af0f77917b3d762d61 | https://github.com/kristianmandrup/cancan-permits/blob/cbc56d299751118b5b6629af0f77917b3d762d61/lib/cancan-permits/permit/base.rb#L95-L102 | train |
awead/solr_ead | lib/solr_ead/indexer.rb | SolrEad.Indexer.update | def update file
solr_doc = om_document(File.new(file)).to_solr
delete solr_doc["id"]
solr.add solr_doc
add_components(file) unless options[:simple]
solr.commit
end | ruby | def update file
solr_doc = om_document(File.new(file)).to_solr
delete solr_doc["id"]
solr.add solr_doc
add_components(file) unless options[:simple]
solr.commit
end | [
"def",
"update",
"file",
"solr_doc",
"=",
"om_document",
"(",
"File",
".",
"new",
"(",
"file",
")",
")",
".",
"to_solr",
"delete",
"solr_doc",
"[",
"\"id\"",
"]",
"solr",
".",
"add",
"solr_doc",
"add_components",
"(",
"file",
")",
"unless",
"options",
"[",
":simple",
"]",
"solr",
".",
"commit",
"end"
] | Updates your ead from a given file by first deleting the existing ead document and
any component documents, then creating a new index from the supplied file.
This method will also commit the results to your solr server when complete. | [
"Updates",
"your",
"ead",
"from",
"a",
"given",
"file",
"by",
"first",
"deleting",
"the",
"existing",
"ead",
"document",
"and",
"any",
"component",
"documents",
"then",
"creating",
"a",
"new",
"index",
"from",
"the",
"supplied",
"file",
".",
"This",
"method",
"will",
"also",
"commit",
"the",
"results",
"to",
"your",
"solr",
"server",
"when",
"complete",
"."
] | 54a5f5217152882946be6d4ee6deda0e1c80263c | https://github.com/awead/solr_ead/blob/54a5f5217152882946be6d4ee6deda0e1c80263c/lib/solr_ead/indexer.rb#L57-L63 | train |
awead/solr_ead | lib/solr_ead/indexer.rb | SolrEad.Indexer.om_document | def om_document file
options[:document] ? options[:document].from_xml(File.new(file)) : SolrEad::Document.from_xml(File.new(file))
end | ruby | def om_document file
options[:document] ? options[:document].from_xml(File.new(file)) : SolrEad::Document.from_xml(File.new(file))
end | [
"def",
"om_document",
"file",
"options",
"[",
":document",
"]",
"?",
"options",
"[",
":document",
"]",
".",
"from_xml",
"(",
"File",
".",
"new",
"(",
"file",
")",
")",
":",
"SolrEad",
"::",
"Document",
".",
"from_xml",
"(",
"File",
".",
"new",
"(",
"file",
")",
")",
"end"
] | Returns an OM document from a given file.
Determines if you have specified a custom definition for your ead document.
If you've defined a class CustomDocument, and have passed it as an option
to your indexer, then SolrEad will use that class instead of SolrEad::Document. | [
"Returns",
"an",
"OM",
"document",
"from",
"a",
"given",
"file",
"."
] | 54a5f5217152882946be6d4ee6deda0e1c80263c | https://github.com/awead/solr_ead/blob/54a5f5217152882946be6d4ee6deda0e1c80263c/lib/solr_ead/indexer.rb#L79-L81 | train |
awead/solr_ead | lib/solr_ead/indexer.rb | SolrEad.Indexer.om_component_from_node | def om_component_from_node node
options[:component] ? options[:component].from_xml(prep(node)) : SolrEad::Component.from_xml(prep(node))
end | ruby | def om_component_from_node node
options[:component] ? options[:component].from_xml(prep(node)) : SolrEad::Component.from_xml(prep(node))
end | [
"def",
"om_component_from_node",
"node",
"options",
"[",
":component",
"]",
"?",
"options",
"[",
":component",
"]",
".",
"from_xml",
"(",
"prep",
"(",
"node",
")",
")",
":",
"SolrEad",
"::",
"Component",
".",
"from_xml",
"(",
"prep",
"(",
"node",
")",
")",
"end"
] | Returns an OM document from a given Nokogiri node
Determines if you have specified a custom definition for your ead component.
If you've defined a class CustomComponent, and have passed it as an option
to your indexer, then SolrEad will use that class instead of SolrEad::Component. | [
"Returns",
"an",
"OM",
"document",
"from",
"a",
"given",
"Nokogiri",
"node"
] | 54a5f5217152882946be6d4ee6deda0e1c80263c | https://github.com/awead/solr_ead/blob/54a5f5217152882946be6d4ee6deda0e1c80263c/lib/solr_ead/indexer.rb#L88-L90 | train |
awead/solr_ead | lib/solr_ead/indexer.rb | SolrEad.Indexer.solr_url | def solr_url
if defined?(Rails.root)
::YAML.load(ERB.new(File.read(File.join(Rails.root,"config","solr.yml"))).result)[Rails.env]['url']
elsif ENV['RAILS_ENV']
::YAML.load(ERB.new(File.read("config/solr.yml")).result)[ENV['RAILS_ENV']]['url']
else
::YAML.load(ERB.new(File.read("config/solr.yml")).result)['development']['url']
end
end | ruby | def solr_url
if defined?(Rails.root)
::YAML.load(ERB.new(File.read(File.join(Rails.root,"config","solr.yml"))).result)[Rails.env]['url']
elsif ENV['RAILS_ENV']
::YAML.load(ERB.new(File.read("config/solr.yml")).result)[ENV['RAILS_ENV']]['url']
else
::YAML.load(ERB.new(File.read("config/solr.yml")).result)['development']['url']
end
end | [
"def",
"solr_url",
"if",
"defined?",
"(",
"Rails",
".",
"root",
")",
"::",
"YAML",
".",
"load",
"(",
"ERB",
".",
"new",
"(",
"File",
".",
"read",
"(",
"File",
".",
"join",
"(",
"Rails",
".",
"root",
",",
"\"config\"",
",",
"\"solr.yml\"",
")",
")",
")",
".",
"result",
")",
"[",
"Rails",
".",
"env",
"]",
"[",
"'url'",
"]",
"elsif",
"ENV",
"[",
"'RAILS_ENV'",
"]",
"::",
"YAML",
".",
"load",
"(",
"ERB",
".",
"new",
"(",
"File",
".",
"read",
"(",
"\"config/solr.yml\"",
")",
")",
".",
"result",
")",
"[",
"ENV",
"[",
"'RAILS_ENV'",
"]",
"]",
"[",
"'url'",
"]",
"else",
"::",
"YAML",
".",
"load",
"(",
"ERB",
".",
"new",
"(",
"File",
".",
"read",
"(",
"\"config/solr.yml\"",
")",
")",
".",
"result",
")",
"[",
"'development'",
"]",
"[",
"'url'",
"]",
"end",
"end"
] | Determines the url to our solr service by consulting yaml files | [
"Determines",
"the",
"url",
"to",
"our",
"solr",
"service",
"by",
"consulting",
"yaml",
"files"
] | 54a5f5217152882946be6d4ee6deda0e1c80263c | https://github.com/awead/solr_ead/blob/54a5f5217152882946be6d4ee6deda0e1c80263c/lib/solr_ead/indexer.rb#L124-L132 | train |
propublica/thinner | lib/thinner/client.rb | Thinner.Client.purge_urls | def purge_urls
@current_job.each do |url|
begin
@varnish.start if @varnish.stopped?
while([email protected]?) do sleep 0.1 end
if @varnish.purge :url, url
@logger.info "Purged url: #{url}"
@purged_urls << url
else
@logger.warn "Could not purge: #{url}"
end
rescue *ERRORS => e
@logger.warn "Error on url: #{url}, message: #{e}"
sleep @timeout
end
end
end | ruby | def purge_urls
@current_job.each do |url|
begin
@varnish.start if @varnish.stopped?
while([email protected]?) do sleep 0.1 end
if @varnish.purge :url, url
@logger.info "Purged url: #{url}"
@purged_urls << url
else
@logger.warn "Could not purge: #{url}"
end
rescue *ERRORS => e
@logger.warn "Error on url: #{url}, message: #{e}"
sleep @timeout
end
end
end | [
"def",
"purge_urls",
"@current_job",
".",
"each",
"do",
"|",
"url",
"|",
"begin",
"@varnish",
".",
"start",
"if",
"@varnish",
".",
"stopped?",
"while",
"(",
"!",
"@varnish",
".",
"running?",
")",
"do",
"sleep",
"0.1",
"end",
"if",
"@varnish",
".",
"purge",
":url",
",",
"url",
"@logger",
".",
"info",
"\"Purged url: #{url}\"",
"@purged_urls",
"<<",
"url",
"else",
"@logger",
".",
"warn",
"\"Could not purge: #{url}\"",
"end",
"rescue",
"*",
"ERRORS",
"=>",
"e",
"@logger",
".",
"warn",
"\"Error on url: #{url}, message: #{e}\"",
"sleep",
"@timeout",
"end",
"end",
"end"
] | Once a batch is ready the Client fires off purge requests on the list of
urls. | [
"Once",
"a",
"batch",
"is",
"ready",
"the",
"Client",
"fires",
"off",
"purge",
"requests",
"on",
"the",
"list",
"of",
"urls",
"."
] | 6fd2a676c379aed8b59e2677fa7650975a83037f | https://github.com/propublica/thinner/blob/6fd2a676c379aed8b59e2677fa7650975a83037f/lib/thinner/client.rb#L46-L62 | train |
propublica/thinner | lib/thinner/client.rb | Thinner.Client.handle_errors | def handle_errors
trap('HUP') { }
trap('TERM') { close_log; Process.exit! }
trap('KILL') { close_log; Process.exit! }
trap('INT') { close_log; Process.exit! }
end | ruby | def handle_errors
trap('HUP') { }
trap('TERM') { close_log; Process.exit! }
trap('KILL') { close_log; Process.exit! }
trap('INT') { close_log; Process.exit! }
end | [
"def",
"handle_errors",
"trap",
"(",
"'HUP'",
")",
"{",
"}",
"trap",
"(",
"'TERM'",
")",
"{",
"close_log",
";",
"Process",
".",
"exit!",
"}",
"trap",
"(",
"'KILL'",
")",
"{",
"close_log",
";",
"Process",
".",
"exit!",
"}",
"trap",
"(",
"'INT'",
")",
"{",
"close_log",
";",
"Process",
".",
"exit!",
"}",
"end"
] | Trap certain signals so the Client can report back the progress of the
job and close the log. | [
"Trap",
"certain",
"signals",
"so",
"the",
"Client",
"can",
"report",
"back",
"the",
"progress",
"of",
"the",
"job",
"and",
"close",
"the",
"log",
"."
] | 6fd2a676c379aed8b59e2677fa7650975a83037f | https://github.com/propublica/thinner/blob/6fd2a676c379aed8b59e2677fa7650975a83037f/lib/thinner/client.rb#L66-L71 | train |
propublica/thinner | lib/thinner/client.rb | Thinner.Client.logger | def logger
if !@log_file.respond_to?(:write)
STDOUT.reopen(File.open(@log_file, (File::WRONLY | File::APPEND | File::CREAT)))
end
@logger = Logger.new(STDOUT)
end | ruby | def logger
if !@log_file.respond_to?(:write)
STDOUT.reopen(File.open(@log_file, (File::WRONLY | File::APPEND | File::CREAT)))
end
@logger = Logger.new(STDOUT)
end | [
"def",
"logger",
"if",
"!",
"@log_file",
".",
"respond_to?",
"(",
":write",
")",
"STDOUT",
".",
"reopen",
"(",
"File",
".",
"open",
"(",
"@log_file",
",",
"(",
"File",
"::",
"WRONLY",
"|",
"File",
"::",
"APPEND",
"|",
"File",
"::",
"CREAT",
")",
")",
")",
"end",
"@logger",
"=",
"Logger",
".",
"new",
"(",
"STDOUT",
")",
"end"
] | The logger redirects all STDOUT writes to a logger instance. | [
"The",
"logger",
"redirects",
"all",
"STDOUT",
"writes",
"to",
"a",
"logger",
"instance",
"."
] | 6fd2a676c379aed8b59e2677fa7650975a83037f | https://github.com/propublica/thinner/blob/6fd2a676c379aed8b59e2677fa7650975a83037f/lib/thinner/client.rb#L74-L79 | train |
kevintyll/resque_manager | app/helpers/resque_manager/resque_helper.rb | ResqueManager.ResqueHelper.time_filter | def time_filter(id, name, value)
html = "<select id=\"#{id}\" name=\"#{name}\">"
html += "<option value=\"\">-</option>"
[1, 3, 6, 12, 24].each do |h|
selected = h.to_s == value ? 'selected="selected"' : ''
html += "<option #{selected} value=\"#{h}\">#{h} #{h==1 ? "hour" : "hours"} ago</option>"
end
[3, 7, 14, 28].each do |d|
selected = (d*24).to_s == value ? 'selected="selected"' : ''
html += "<option #{selected} value=\"#{d*24}\">#{d} days ago</option>"
end
html += "</select>"
html.html_safe
end | ruby | def time_filter(id, name, value)
html = "<select id=\"#{id}\" name=\"#{name}\">"
html += "<option value=\"\">-</option>"
[1, 3, 6, 12, 24].each do |h|
selected = h.to_s == value ? 'selected="selected"' : ''
html += "<option #{selected} value=\"#{h}\">#{h} #{h==1 ? "hour" : "hours"} ago</option>"
end
[3, 7, 14, 28].each do |d|
selected = (d*24).to_s == value ? 'selected="selected"' : ''
html += "<option #{selected} value=\"#{d*24}\">#{d} days ago</option>"
end
html += "</select>"
html.html_safe
end | [
"def",
"time_filter",
"(",
"id",
",",
"name",
",",
"value",
")",
"html",
"=",
"\"<select id=\\\"#{id}\\\" name=\\\"#{name}\\\">\"",
"html",
"+=",
"\"<option value=\\\"\\\">-</option>\"",
"[",
"1",
",",
"3",
",",
"6",
",",
"12",
",",
"24",
"]",
".",
"each",
"do",
"|",
"h",
"|",
"selected",
"=",
"h",
".",
"to_s",
"==",
"value",
"?",
"'selected=\"selected\"'",
":",
"''",
"html",
"+=",
"\"<option #{selected} value=\\\"#{h}\\\">#{h} #{h==1 ? \"hour\" : \"hours\"} ago</option>\"",
"end",
"[",
"3",
",",
"7",
",",
"14",
",",
"28",
"]",
".",
"each",
"do",
"|",
"d",
"|",
"selected",
"=",
"(",
"d",
"*",
"24",
")",
".",
"to_s",
"==",
"value",
"?",
"'selected=\"selected\"'",
":",
"''",
"html",
"+=",
"\"<option #{selected} value=\\\"#{d*24}\\\">#{d} days ago</option>\"",
"end",
"html",
"+=",
"\"</select>\"",
"html",
".",
"html_safe",
"end"
] | resque-cleaner helpers | [
"resque",
"-",
"cleaner",
"helpers"
] | 470e1a79232dcdd9820ee45e5371fe57309883b1 | https://github.com/kevintyll/resque_manager/blob/470e1a79232dcdd9820ee45e5371fe57309883b1/app/helpers/resque_manager/resque_helper.rb#L105-L118 | train |
rhenium/plum | lib/plum/stream.rb | Plum.Stream.receive_frame | def receive_frame(frame)
validate_received_frame(frame)
consume_recv_window(frame)
case frame
when Frame::Data then receive_data(frame)
when Frame::Headers then receive_headers(frame)
when Frame::Priority then receive_priority(frame)
when Frame::RstStream then receive_rst_stream(frame)
when Frame::WindowUpdate then receive_window_update(frame)
when Frame::Continuation then receive_continuation(frame)
when Frame::PushPromise then receive_push_promise(frame)
when Frame::Ping, Frame::Goaway, Frame::Settings
raise RemoteConnectionError.new(:protocol_error) # stream_id MUST be 0x00
else
# MUST ignore unknown frame
end
rescue RemoteStreamError => e
callback(:stream_error, e)
send_immediately Frame::RstStream.new(id, e.http2_error_type)
close
end | ruby | def receive_frame(frame)
validate_received_frame(frame)
consume_recv_window(frame)
case frame
when Frame::Data then receive_data(frame)
when Frame::Headers then receive_headers(frame)
when Frame::Priority then receive_priority(frame)
when Frame::RstStream then receive_rst_stream(frame)
when Frame::WindowUpdate then receive_window_update(frame)
when Frame::Continuation then receive_continuation(frame)
when Frame::PushPromise then receive_push_promise(frame)
when Frame::Ping, Frame::Goaway, Frame::Settings
raise RemoteConnectionError.new(:protocol_error) # stream_id MUST be 0x00
else
# MUST ignore unknown frame
end
rescue RemoteStreamError => e
callback(:stream_error, e)
send_immediately Frame::RstStream.new(id, e.http2_error_type)
close
end | [
"def",
"receive_frame",
"(",
"frame",
")",
"validate_received_frame",
"(",
"frame",
")",
"consume_recv_window",
"(",
"frame",
")",
"case",
"frame",
"when",
"Frame",
"::",
"Data",
"then",
"receive_data",
"(",
"frame",
")",
"when",
"Frame",
"::",
"Headers",
"then",
"receive_headers",
"(",
"frame",
")",
"when",
"Frame",
"::",
"Priority",
"then",
"receive_priority",
"(",
"frame",
")",
"when",
"Frame",
"::",
"RstStream",
"then",
"receive_rst_stream",
"(",
"frame",
")",
"when",
"Frame",
"::",
"WindowUpdate",
"then",
"receive_window_update",
"(",
"frame",
")",
"when",
"Frame",
"::",
"Continuation",
"then",
"receive_continuation",
"(",
"frame",
")",
"when",
"Frame",
"::",
"PushPromise",
"then",
"receive_push_promise",
"(",
"frame",
")",
"when",
"Frame",
"::",
"Ping",
",",
"Frame",
"::",
"Goaway",
",",
"Frame",
"::",
"Settings",
"raise",
"RemoteConnectionError",
".",
"new",
"(",
":protocol_error",
")",
"else",
"end",
"rescue",
"RemoteStreamError",
"=>",
"e",
"callback",
"(",
":stream_error",
",",
"e",
")",
"send_immediately",
"Frame",
"::",
"RstStream",
".",
"new",
"(",
"id",
",",
"e",
".",
"http2_error_type",
")",
"close",
"end"
] | Processes received frames for this stream. Internal use.
@private | [
"Processes",
"received",
"frames",
"for",
"this",
"stream",
".",
"Internal",
"use",
"."
] | 9190801a092d46c7079ccee201b212b2d7985952 | https://github.com/rhenium/plum/blob/9190801a092d46c7079ccee201b212b2d7985952/lib/plum/stream.rb#L30-L51 | train |
rhenium/plum | lib/plum/stream.rb | Plum.Stream.promise | def promise(headers)
stream = @connection.reserve_stream(weight: self.weight + 1, parent: self)
encoded = @connection.hpack_encoder.encode(headers)
frame = Frame::PushPromise.new(id, stream.id, encoded, end_headers: true)
send frame
stream
end | ruby | def promise(headers)
stream = @connection.reserve_stream(weight: self.weight + 1, parent: self)
encoded = @connection.hpack_encoder.encode(headers)
frame = Frame::PushPromise.new(id, stream.id, encoded, end_headers: true)
send frame
stream
end | [
"def",
"promise",
"(",
"headers",
")",
"stream",
"=",
"@connection",
".",
"reserve_stream",
"(",
"weight",
":",
"self",
".",
"weight",
"+",
"1",
",",
"parent",
":",
"self",
")",
"encoded",
"=",
"@connection",
".",
"hpack_encoder",
".",
"encode",
"(",
"headers",
")",
"frame",
"=",
"Frame",
"::",
"PushPromise",
".",
"new",
"(",
"id",
",",
"stream",
".",
"id",
",",
"encoded",
",",
"end_headers",
":",
"true",
")",
"send",
"frame",
"stream",
"end"
] | Reserves a stream to server push. Sends PUSH_PROMISE and create new stream.
@param headers [Enumerable<String, String>] The *request* headers. It must contain all of them: ':authority', ':method', ':scheme' and ':path'.
@return [Stream] The stream to send push response. | [
"Reserves",
"a",
"stream",
"to",
"server",
"push",
".",
"Sends",
"PUSH_PROMISE",
"and",
"create",
"new",
"stream",
"."
] | 9190801a092d46c7079ccee201b212b2d7985952 | https://github.com/rhenium/plum/blob/9190801a092d46c7079ccee201b212b2d7985952/lib/plum/stream.rb#L90-L96 | train |
rhenium/plum | lib/plum/stream.rb | Plum.Stream.send_data | def send_data(data = "", end_stream: true)
max = @connection.remote_settings[:max_frame_size]
if data.is_a?(IO)
until data.eof?
fragment = data.readpartial(max)
send Frame::Data.new(id, fragment, end_stream: end_stream && data.eof?)
end
else
send Frame::Data.new(id, data, end_stream: end_stream)
end
@state = :half_closed_local if end_stream
end | ruby | def send_data(data = "", end_stream: true)
max = @connection.remote_settings[:max_frame_size]
if data.is_a?(IO)
until data.eof?
fragment = data.readpartial(max)
send Frame::Data.new(id, fragment, end_stream: end_stream && data.eof?)
end
else
send Frame::Data.new(id, data, end_stream: end_stream)
end
@state = :half_closed_local if end_stream
end | [
"def",
"send_data",
"(",
"data",
"=",
"\"\"",
",",
"end_stream",
":",
"true",
")",
"max",
"=",
"@connection",
".",
"remote_settings",
"[",
":max_frame_size",
"]",
"if",
"data",
".",
"is_a?",
"(",
"IO",
")",
"until",
"data",
".",
"eof?",
"fragment",
"=",
"data",
".",
"readpartial",
"(",
"max",
")",
"send",
"Frame",
"::",
"Data",
".",
"new",
"(",
"id",
",",
"fragment",
",",
"end_stream",
":",
"end_stream",
"&&",
"data",
".",
"eof?",
")",
"end",
"else",
"send",
"Frame",
"::",
"Data",
".",
"new",
"(",
"id",
",",
"data",
",",
"end_stream",
":",
"end_stream",
")",
"end",
"@state",
"=",
":half_closed_local",
"if",
"end_stream",
"end"
] | Sends DATA frame. If the data is larger than MAX_FRAME_SIZE, DATA frame will be splitted.
@param data [String, IO] The data to send.
@param end_stream [Boolean] Set END_STREAM flag or not. | [
"Sends",
"DATA",
"frame",
".",
"If",
"the",
"data",
"is",
"larger",
"than",
"MAX_FRAME_SIZE",
"DATA",
"frame",
"will",
"be",
"splitted",
"."
] | 9190801a092d46c7079ccee201b212b2d7985952 | https://github.com/rhenium/plum/blob/9190801a092d46c7079ccee201b212b2d7985952/lib/plum/stream.rb#L111-L122 | train |
christinedraper/knife-topo | lib/chef/knife/topo_delete.rb | KnifeTopo.TopoDelete.remove_node_from_topology | def remove_node_from_topology(node_name)
# load then update and save the node
node = Chef::Node.load(node_name)
if node['topo'] && node['topo']['name'] == @topo_name
node.rm('topo', 'name')
ui.info "Removing node #{node.name} from topology"
node.save
end
node
rescue Net::HTTPServerException => e
raise unless e.to_s =~ /^404/
# Node has not been created
end | ruby | def remove_node_from_topology(node_name)
# load then update and save the node
node = Chef::Node.load(node_name)
if node['topo'] && node['topo']['name'] == @topo_name
node.rm('topo', 'name')
ui.info "Removing node #{node.name} from topology"
node.save
end
node
rescue Net::HTTPServerException => e
raise unless e.to_s =~ /^404/
# Node has not been created
end | [
"def",
"remove_node_from_topology",
"(",
"node_name",
")",
"node",
"=",
"Chef",
"::",
"Node",
".",
"load",
"(",
"node_name",
")",
"if",
"node",
"[",
"'topo'",
"]",
"&&",
"node",
"[",
"'topo'",
"]",
"[",
"'name'",
"]",
"==",
"@topo_name",
"node",
".",
"rm",
"(",
"'topo'",
",",
"'name'",
")",
"ui",
".",
"info",
"\"Removing node #{node.name} from topology\"",
"node",
".",
"save",
"end",
"node",
"rescue",
"Net",
"::",
"HTTPServerException",
"=>",
"e",
"raise",
"unless",
"e",
".",
"to_s",
"=~",
"/",
"/",
"end"
] | Remove the topo name attribute from all nodes, so topo search
knows they are not in the topology | [
"Remove",
"the",
"topo",
"name",
"attribute",
"from",
"all",
"nodes",
"so",
"topo",
"search",
"knows",
"they",
"are",
"not",
"in",
"the",
"topology"
] | 323f5767a6ed98212629888323c4e694fec820ca | https://github.com/christinedraper/knife-topo/blob/323f5767a6ed98212629888323c4e694fec820ca/lib/chef/knife/topo_delete.rb#L82-L96 | train |
edraut/coney_island | lib/coney_island/jobs_cache.rb | ConeyIsland.JobsCache.caching_jobs | def caching_jobs(&blk)
_was_caching = caching_jobs?
cache_jobs
blk.call
flush_jobs
self.is_caching_jobs = _was_caching
self
end | ruby | def caching_jobs(&blk)
_was_caching = caching_jobs?
cache_jobs
blk.call
flush_jobs
self.is_caching_jobs = _was_caching
self
end | [
"def",
"caching_jobs",
"(",
"&",
"blk",
")",
"_was_caching",
"=",
"caching_jobs?",
"cache_jobs",
"blk",
".",
"call",
"flush_jobs",
"self",
".",
"is_caching_jobs",
"=",
"_was_caching",
"self",
"end"
] | Caches jobs for the duration of the block, flushes them at the end. | [
"Caches",
"jobs",
"for",
"the",
"duration",
"of",
"the",
"block",
"flushes",
"them",
"at",
"the",
"end",
"."
] | 73994b7d0c85d37879c1def70dcc02959a2c43bf | https://github.com/edraut/coney_island/blob/73994b7d0c85d37879c1def70dcc02959a2c43bf/lib/coney_island/jobs_cache.rb#L31-L38 | train |
edraut/coney_island | lib/coney_island/jobs_cache.rb | ConeyIsland.JobsCache.flush_jobs | def flush_jobs
# Get all the jobs, one at a time, pulling from the list
while job = self.cached_jobs.shift
# Map the array to the right things
job_id, args = *job
# Submit! takes care of rescuing, error logging, etc and never caches
submit! args, job_id
end
self
end | ruby | def flush_jobs
# Get all the jobs, one at a time, pulling from the list
while job = self.cached_jobs.shift
# Map the array to the right things
job_id, args = *job
# Submit! takes care of rescuing, error logging, etc and never caches
submit! args, job_id
end
self
end | [
"def",
"flush_jobs",
"while",
"job",
"=",
"self",
".",
"cached_jobs",
".",
"shift",
"job_id",
",",
"args",
"=",
"*",
"job",
"submit!",
"args",
",",
"job_id",
"end",
"self",
"end"
] | Publish all the cached jobs | [
"Publish",
"all",
"the",
"cached",
"jobs"
] | 73994b7d0c85d37879c1def70dcc02959a2c43bf | https://github.com/edraut/coney_island/blob/73994b7d0c85d37879c1def70dcc02959a2c43bf/lib/coney_island/jobs_cache.rb#L47-L56 | train |
NingenUA/seafile-api | lib/seafile-api/directory.rb | SeafileApi.Connect.share_dir | def share_dir(email,path,perm="r",repo=self.repo,s_type="d")
post_share_dir(repo,{"email"=> email, "path"=> path,"s_type"=> s_type,"perm"=> perm})
end | ruby | def share_dir(email,path,perm="r",repo=self.repo,s_type="d")
post_share_dir(repo,{"email"=> email, "path"=> path,"s_type"=> s_type,"perm"=> perm})
end | [
"def",
"share_dir",
"(",
"email",
",",
"path",
",",
"perm",
"=",
"\"r\"",
",",
"repo",
"=",
"self",
".",
"repo",
",",
"s_type",
"=",
"\"d\"",
")",
"post_share_dir",
"(",
"repo",
",",
"{",
"\"email\"",
"=>",
"email",
",",
"\"path\"",
"=>",
"path",
",",
"\"s_type\"",
"=>",
"s_type",
",",
"\"perm\"",
"=>",
"perm",
"}",
")",
"end"
] | You do not have permission to perform this action | [
"You",
"do",
"not",
"have",
"permission",
"to",
"perform",
"this",
"action"
] | b5fb16e7fca21d9241f92fbd22500e8d488b7464 | https://github.com/NingenUA/seafile-api/blob/b5fb16e7fca21d9241f92fbd22500e8d488b7464/lib/seafile-api/directory.rb#L19-L21 | train |
artemk/syntaxer | lib/syntaxer/checker.rb | Syntaxer.RepoChecker.process | def process
@rule_files.each do |rule_name, rule|
if rule[:rule].deferred
@deferred_process << rule
else
rule[:files].each do |file|
full_path = File.join(@runner.options.root_path,file)
check(rule[:rule], full_path)
end
end
end
@deferred_process.each do |rule|
rule[:rule].exec_rule.run(@runner.options.root_path, rule[:files])
end
self
end | ruby | def process
@rule_files.each do |rule_name, rule|
if rule[:rule].deferred
@deferred_process << rule
else
rule[:files].each do |file|
full_path = File.join(@runner.options.root_path,file)
check(rule[:rule], full_path)
end
end
end
@deferred_process.each do |rule|
rule[:rule].exec_rule.run(@runner.options.root_path, rule[:files])
end
self
end | [
"def",
"process",
"@rule_files",
".",
"each",
"do",
"|",
"rule_name",
",",
"rule",
"|",
"if",
"rule",
"[",
":rule",
"]",
".",
"deferred",
"@deferred_process",
"<<",
"rule",
"else",
"rule",
"[",
":files",
"]",
".",
"each",
"do",
"|",
"file",
"|",
"full_path",
"=",
"File",
".",
"join",
"(",
"@runner",
".",
"options",
".",
"root_path",
",",
"file",
")",
"check",
"(",
"rule",
"[",
":rule",
"]",
",",
"full_path",
")",
"end",
"end",
"end",
"@deferred_process",
".",
"each",
"do",
"|",
"rule",
"|",
"rule",
"[",
":rule",
"]",
".",
"exec_rule",
".",
"run",
"(",
"@runner",
".",
"options",
".",
"root_path",
",",
"rule",
"[",
":files",
"]",
")",
"end",
"self",
"end"
] | Check syntax in repository directory
@see Checker#process | [
"Check",
"syntax",
"in",
"repository",
"directory"
] | 7557318e9ab1554b38cb8df9d00f2ff4acc701cb | https://github.com/artemk/syntaxer/blob/7557318e9ab1554b38cb8df9d00f2ff4acc701cb/lib/syntaxer/checker.rb#L84-L101 | train |
artemk/syntaxer | lib/syntaxer/checker.rb | Syntaxer.PlainChecker.process | def process
@deferred_process = []
@reader.rules.each do |rule|
if rule.deferred
@deferred_process << rule
else
rule.files_list(@runner.options.root_path).each do |file|
check(rule, file)
end
end
end
@deferred_process.each do |rule|
rule.exec_rule.run(@runner.options.root_path, rule.files_list(@runner.options.root_path))
end
self
end | ruby | def process
@deferred_process = []
@reader.rules.each do |rule|
if rule.deferred
@deferred_process << rule
else
rule.files_list(@runner.options.root_path).each do |file|
check(rule, file)
end
end
end
@deferred_process.each do |rule|
rule.exec_rule.run(@runner.options.root_path, rule.files_list(@runner.options.root_path))
end
self
end | [
"def",
"process",
"@deferred_process",
"=",
"[",
"]",
"@reader",
".",
"rules",
".",
"each",
"do",
"|",
"rule",
"|",
"if",
"rule",
".",
"deferred",
"@deferred_process",
"<<",
"rule",
"else",
"rule",
".",
"files_list",
"(",
"@runner",
".",
"options",
".",
"root_path",
")",
".",
"each",
"do",
"|",
"file",
"|",
"check",
"(",
"rule",
",",
"file",
")",
"end",
"end",
"end",
"@deferred_process",
".",
"each",
"do",
"|",
"rule",
"|",
"rule",
".",
"exec_rule",
".",
"run",
"(",
"@runner",
".",
"options",
".",
"root_path",
",",
"rule",
".",
"files_list",
"(",
"@runner",
".",
"options",
".",
"root_path",
")",
")",
"end",
"self",
"end"
] | Check syntax in indicated directory
@see Checker#process | [
"Check",
"syntax",
"in",
"indicated",
"directory"
] | 7557318e9ab1554b38cb8df9d00f2ff4acc701cb | https://github.com/artemk/syntaxer/blob/7557318e9ab1554b38cb8df9d00f2ff4acc701cb/lib/syntaxer/checker.rb#L119-L136 | train |
roverdotcom/danger-jira_sync | lib/jira_sync/plugin.rb | Danger.DangerJiraSync.configure | def configure(jira_url:, jira_username:, jira_api_token:)
warn "danger-jira_sync plugin configuration is missing jira_url" if jira_url.blank?
warn "danger-jira_sync plugin configuration is missing jira_username" if jira_username.blank?
warn "danger-jira_sync plugin configuration is missing jira_api_token" if jira_api_token.blank?
@jira_client = JIRA::Client.new(
site: jira_url,
username: jira_username,
password: jira_api_token,
context_path: "",
auth_type: :basic
)
end | ruby | def configure(jira_url:, jira_username:, jira_api_token:)
warn "danger-jira_sync plugin configuration is missing jira_url" if jira_url.blank?
warn "danger-jira_sync plugin configuration is missing jira_username" if jira_username.blank?
warn "danger-jira_sync plugin configuration is missing jira_api_token" if jira_api_token.blank?
@jira_client = JIRA::Client.new(
site: jira_url,
username: jira_username,
password: jira_api_token,
context_path: "",
auth_type: :basic
)
end | [
"def",
"configure",
"(",
"jira_url",
":",
",",
"jira_username",
":",
",",
"jira_api_token",
":",
")",
"warn",
"\"danger-jira_sync plugin configuration is missing jira_url\"",
"if",
"jira_url",
".",
"blank?",
"warn",
"\"danger-jira_sync plugin configuration is missing jira_username\"",
"if",
"jira_username",
".",
"blank?",
"warn",
"\"danger-jira_sync plugin configuration is missing jira_api_token\"",
"if",
"jira_api_token",
".",
"blank?",
"@jira_client",
"=",
"JIRA",
"::",
"Client",
".",
"new",
"(",
"site",
":",
"jira_url",
",",
"username",
":",
"jira_username",
",",
"password",
":",
"jira_api_token",
",",
"context_path",
":",
"\"\"",
",",
"auth_type",
":",
":basic",
")",
"end"
] | Configures the Jira REST Client with your credentials
@param jira_url [String] The full url to your Jira instance, e.g.,
"https://myjirainstance.atlassian.net"
@param jira_username [String] The username to use for accessing the Jira
instance. Commonly, this is an email address.
@param jira_api_token [String] The API key to use to access the Jira
instance. Generate one here: https://id.atlassian.com/manage/api-tokens
@return [JIRA::Client] The underlying jira-ruby JIRA::Client instance | [
"Configures",
"the",
"Jira",
"REST",
"Client",
"with",
"your",
"credentials"
] | 0cb6a3c74fcde3c2b2fee7ff339f84c48b46c2fb | https://github.com/roverdotcom/danger-jira_sync/blob/0cb6a3c74fcde3c2b2fee7ff339f84c48b46c2fb/lib/jira_sync/plugin.rb#L45-L57 | train |
roverdotcom/danger-jira_sync | lib/jira_sync/plugin.rb | Danger.DangerJiraSync.autolabel_pull_request | def autolabel_pull_request(issue_prefixes, project: true, components: true, labels: false)
raise NotConfiguredError unless @jira_client
raise(ArgumentError, "issue_prefixes cannot be empty") if issue_prefixes.empty?
issue_keys = extract_issue_keys_from_pull_request(issue_prefixes)
return if issue_keys.empty?
labels = fetch_labels_from_issues(
issue_keys,
project: project,
components: components,
labels: labels
)
return if labels.empty?
create_missing_github_labels(labels)
add_labels_to_issue(labels)
labels
end | ruby | def autolabel_pull_request(issue_prefixes, project: true, components: true, labels: false)
raise NotConfiguredError unless @jira_client
raise(ArgumentError, "issue_prefixes cannot be empty") if issue_prefixes.empty?
issue_keys = extract_issue_keys_from_pull_request(issue_prefixes)
return if issue_keys.empty?
labels = fetch_labels_from_issues(
issue_keys,
project: project,
components: components,
labels: labels
)
return if labels.empty?
create_missing_github_labels(labels)
add_labels_to_issue(labels)
labels
end | [
"def",
"autolabel_pull_request",
"(",
"issue_prefixes",
",",
"project",
":",
"true",
",",
"components",
":",
"true",
",",
"labels",
":",
"false",
")",
"raise",
"NotConfiguredError",
"unless",
"@jira_client",
"raise",
"(",
"ArgumentError",
",",
"\"issue_prefixes cannot be empty\"",
")",
"if",
"issue_prefixes",
".",
"empty?",
"issue_keys",
"=",
"extract_issue_keys_from_pull_request",
"(",
"issue_prefixes",
")",
"return",
"if",
"issue_keys",
".",
"empty?",
"labels",
"=",
"fetch_labels_from_issues",
"(",
"issue_keys",
",",
"project",
":",
"project",
",",
"components",
":",
"components",
",",
"labels",
":",
"labels",
")",
"return",
"if",
"labels",
".",
"empty?",
"create_missing_github_labels",
"(",
"labels",
")",
"add_labels_to_issue",
"(",
"labels",
")",
"labels",
"end"
] | Labels the Pull Request with Jira Project Keys and Component Names
@param issue_prefixes [Array<String>] An array of issue key prefixes;
this is often the project key. These must be present in the title or
body of the Pull Request
@param project [Boolean] Label using the Jira Ticket's Project Key?
@param components [Boolean] Label using the Jira Ticket's Component Names?
@param labels [Boolean] Label using the Jira Ticket's Labels?
@return [Array<String>, nil] The list of project & component labels
that were applied or nil if no issue or labels were found | [
"Labels",
"the",
"Pull",
"Request",
"with",
"Jira",
"Project",
"Keys",
"and",
"Component",
"Names"
] | 0cb6a3c74fcde3c2b2fee7ff339f84c48b46c2fb | https://github.com/roverdotcom/danger-jira_sync/blob/0cb6a3c74fcde3c2b2fee7ff339f84c48b46c2fb/lib/jira_sync/plugin.rb#L71-L90 | train |
kevintyll/resque_manager | lib/resque_manager/overrides/resque/worker.rb | Resque.Worker.startup | def startup
enable_gc_optimizations
if Thread.current == Thread.main
register_signal_handlers
prune_dead_workers
end
run_hook :before_first_fork
register_worker
# Fix buffering so we can `rake resque:work > resque.log` and
# get output from the child in there.
$stdout.sync = true
end | ruby | def startup
enable_gc_optimizations
if Thread.current == Thread.main
register_signal_handlers
prune_dead_workers
end
run_hook :before_first_fork
register_worker
# Fix buffering so we can `rake resque:work > resque.log` and
# get output from the child in there.
$stdout.sync = true
end | [
"def",
"startup",
"enable_gc_optimizations",
"if",
"Thread",
".",
"current",
"==",
"Thread",
".",
"main",
"register_signal_handlers",
"prune_dead_workers",
"end",
"run_hook",
":before_first_fork",
"register_worker",
"$stdout",
".",
"sync",
"=",
"true",
"end"
] | Runs all the methods needed when a worker begins its lifecycle.
OVERRIDE for multithreaded workers | [
"Runs",
"all",
"the",
"methods",
"needed",
"when",
"a",
"worker",
"begins",
"its",
"lifecycle",
".",
"OVERRIDE",
"for",
"multithreaded",
"workers"
] | 470e1a79232dcdd9820ee45e5371fe57309883b1 | https://github.com/kevintyll/resque_manager/blob/470e1a79232dcdd9820ee45e5371fe57309883b1/lib/resque_manager/overrides/resque/worker.rb#L63-L75 | train |
kevintyll/resque_manager | lib/resque_manager/overrides/resque/worker.rb | Resque.Worker.reconnect | def reconnect
tries = 0
begin
redis.synchronize do |client|
client.reconnect
end
rescue Redis::BaseConnectionError
if (tries += 1) <= 3
log "Error reconnecting to Redis; retrying"
sleep(tries)
retry
else
log "Error reconnecting to Redis; quitting"
raise
end
end
end | ruby | def reconnect
tries = 0
begin
redis.synchronize do |client|
client.reconnect
end
rescue Redis::BaseConnectionError
if (tries += 1) <= 3
log "Error reconnecting to Redis; retrying"
sleep(tries)
retry
else
log "Error reconnecting to Redis; quitting"
raise
end
end
end | [
"def",
"reconnect",
"tries",
"=",
"0",
"begin",
"redis",
".",
"synchronize",
"do",
"|",
"client",
"|",
"client",
".",
"reconnect",
"end",
"rescue",
"Redis",
"::",
"BaseConnectionError",
"if",
"(",
"tries",
"+=",
"1",
")",
"<=",
"3",
"log",
"\"Error reconnecting to Redis; retrying\"",
"sleep",
"(",
"tries",
")",
"retry",
"else",
"log",
"\"Error reconnecting to Redis; quitting\"",
"raise",
"end",
"end",
"end"
] | override so we can synchronize the client on the reconnect for multithreaded workers. | [
"override",
"so",
"we",
"can",
"synchronize",
"the",
"client",
"on",
"the",
"reconnect",
"for",
"multithreaded",
"workers",
"."
] | 470e1a79232dcdd9820ee45e5371fe57309883b1 | https://github.com/kevintyll/resque_manager/blob/470e1a79232dcdd9820ee45e5371fe57309883b1/lib/resque_manager/overrides/resque/worker.rb#L187-L203 | train |
GomaaK/sshez | lib/sshez/parser.rb | Sshez.Parser.options_for_add | def options_for_add(opts, options)
opts.on('-p', '--port PORT',
'Specify a port') do |port|
options.file_content.port_text = " Port #{port}\n"
end
opts.on('-i', '--identity_file [key]',
'Add identity') do |key_path|
options.file_content.identity_file_text =
" IdentityFile #{key_path}\n"
end
opts.on('-b', '--batch_mode', 'Batch Mode') do
options.file_content.batch_mode_text = " BatchMode yes\n"
end
end | ruby | def options_for_add(opts, options)
opts.on('-p', '--port PORT',
'Specify a port') do |port|
options.file_content.port_text = " Port #{port}\n"
end
opts.on('-i', '--identity_file [key]',
'Add identity') do |key_path|
options.file_content.identity_file_text =
" IdentityFile #{key_path}\n"
end
opts.on('-b', '--batch_mode', 'Batch Mode') do
options.file_content.batch_mode_text = " BatchMode yes\n"
end
end | [
"def",
"options_for_add",
"(",
"opts",
",",
"options",
")",
"opts",
".",
"on",
"(",
"'-p'",
",",
"'--port PORT'",
",",
"'Specify a port'",
")",
"do",
"|",
"port",
"|",
"options",
".",
"file_content",
".",
"port_text",
"=",
"\" Port #{port}\\n\"",
"end",
"opts",
".",
"on",
"(",
"'-i'",
",",
"'--identity_file [key]'",
",",
"'Add identity'",
")",
"do",
"|",
"key_path",
"|",
"options",
".",
"file_content",
".",
"identity_file_text",
"=",
"\" IdentityFile #{key_path}\\n\"",
"end",
"opts",
".",
"on",
"(",
"'-b'",
",",
"'--batch_mode'",
",",
"'Batch Mode'",
")",
"do",
"options",
".",
"file_content",
".",
"batch_mode_text",
"=",
"\" BatchMode yes\\n\"",
"end",
"end"
] | Returns the options specifice to the add command only | [
"Returns",
"the",
"options",
"specifice",
"to",
"the",
"add",
"command",
"only"
] | 6771012c2b29c2f28fdaf42372f93f70dbcbb291 | https://github.com/GomaaK/sshez/blob/6771012c2b29c2f28fdaf42372f93f70dbcbb291/lib/sshez/parser.rb#L66-L81 | train |
GomaaK/sshez | lib/sshez/parser.rb | Sshez.Parser.common_options | def common_options(opts, options)
opts.separator ''
opts.separator 'Common options:'
# Another typical switch to print the version.
opts.on('-v', '--version', 'Show version') do
PRINTER.print Sshez.version
options.halt = true
end
opts.on('-z', '--verbose', 'Verbose Output') do
PRINTER.verbose!
end
# Prints everything
opts.on_tail('-h', '--help', 'Show this message') do
PRINTER.print opts
options.halt = true
end
end | ruby | def common_options(opts, options)
opts.separator ''
opts.separator 'Common options:'
# Another typical switch to print the version.
opts.on('-v', '--version', 'Show version') do
PRINTER.print Sshez.version
options.halt = true
end
opts.on('-z', '--verbose', 'Verbose Output') do
PRINTER.verbose!
end
# Prints everything
opts.on_tail('-h', '--help', 'Show this message') do
PRINTER.print opts
options.halt = true
end
end | [
"def",
"common_options",
"(",
"opts",
",",
"options",
")",
"opts",
".",
"separator",
"''",
"opts",
".",
"separator",
"'Common options:'",
"opts",
".",
"on",
"(",
"'-v'",
",",
"'--version'",
",",
"'Show version'",
")",
"do",
"PRINTER",
".",
"print",
"Sshez",
".",
"version",
"options",
".",
"halt",
"=",
"true",
"end",
"opts",
".",
"on",
"(",
"'-z'",
",",
"'--verbose'",
",",
"'Verbose Output'",
")",
"do",
"PRINTER",
".",
"verbose!",
"end",
"opts",
".",
"on_tail",
"(",
"'-h'",
",",
"'--help'",
",",
"'Show this message'",
")",
"do",
"PRINTER",
".",
"print",
"opts",
"options",
".",
"halt",
"=",
"true",
"end",
"end"
] | Returns the standard options | [
"Returns",
"the",
"standard",
"options"
] | 6771012c2b29c2f28fdaf42372f93f70dbcbb291 | https://github.com/GomaaK/sshez/blob/6771012c2b29c2f28fdaf42372f93f70dbcbb291/lib/sshez/parser.rb#L86-L102 | train |
christinedraper/knife-topo | lib/chef/knife/topo_export.rb | KnifeTopo.TopoExport.node_export | def node_export(node_name)
load_node_data(node_name, config[:min_priority])
rescue Net::HTTPServerException => e
raise unless e.to_s =~ /^404/
empty_node(node_name)
end | ruby | def node_export(node_name)
load_node_data(node_name, config[:min_priority])
rescue Net::HTTPServerException => e
raise unless e.to_s =~ /^404/
empty_node(node_name)
end | [
"def",
"node_export",
"(",
"node_name",
")",
"load_node_data",
"(",
"node_name",
",",
"config",
"[",
":min_priority",
"]",
")",
"rescue",
"Net",
"::",
"HTTPServerException",
"=>",
"e",
"raise",
"unless",
"e",
".",
"to_s",
"=~",
"/",
"/",
"empty_node",
"(",
"node_name",
")",
"end"
] | get actual node properties for export | [
"get",
"actual",
"node",
"properties",
"for",
"export"
] | 323f5767a6ed98212629888323c4e694fec820ca | https://github.com/christinedraper/knife-topo/blob/323f5767a6ed98212629888323c4e694fec820ca/lib/chef/knife/topo_export.rb#L131-L136 | train |
christinedraper/knife-topo | lib/chef/knife/topo_export.rb | KnifeTopo.TopoExport.update_nodes! | def update_nodes!(nodes)
@node_names.each do |node_name|
# find out if the node is already in the array
found = nodes.index { |n| n['name'] == node_name }
if found.nil?
nodes.push(node_export(node_name))
else
nodes[found] = node_export(node_name)
end
end
end | ruby | def update_nodes!(nodes)
@node_names.each do |node_name|
# find out if the node is already in the array
found = nodes.index { |n| n['name'] == node_name }
if found.nil?
nodes.push(node_export(node_name))
else
nodes[found] = node_export(node_name)
end
end
end | [
"def",
"update_nodes!",
"(",
"nodes",
")",
"@node_names",
".",
"each",
"do",
"|",
"node_name",
"|",
"found",
"=",
"nodes",
".",
"index",
"{",
"|",
"n",
"|",
"n",
"[",
"'name'",
"]",
"==",
"node_name",
"}",
"if",
"found",
".",
"nil?",
"nodes",
".",
"push",
"(",
"node_export",
"(",
"node_name",
")",
")",
"else",
"nodes",
"[",
"found",
"]",
"=",
"node_export",
"(",
"node_name",
")",
"end",
"end",
"end"
] | put node details in node array, overwriting existing details | [
"put",
"node",
"details",
"in",
"node",
"array",
"overwriting",
"existing",
"details"
] | 323f5767a6ed98212629888323c4e694fec820ca | https://github.com/christinedraper/knife-topo/blob/323f5767a6ed98212629888323c4e694fec820ca/lib/chef/knife/topo_export.rb#L139-L149 | train |
dmacvicar/bicho | lib/bicho/cli/commands/attachments.rb | Bicho::CLI::Commands.Attachments.download | def download(bug, supportconfig_only)
bug.attachments.each do |attachment|
filename = "bsc#{bug.id}-#{attachment.id}-#{attachment.props['file_name']}"
if supportconfig_only
next unless attachment.content_type == 'application/x-gzip' ||
attachment.content_type == 'application/x-bzip-compressed-tar'
next unless attachment.summary =~ /supportconfig/i
end
t.say("Downloading to #{t.color(filename, :even_row)}")
begin
data = attachment.data
File.open(filename, 'w') do |f|
f.write data.read
end
rescue StandardError => e
t.say("#{t.color('Error:', :error)} Download of #{filename} failed: #{e}")
raise
end
end
end | ruby | def download(bug, supportconfig_only)
bug.attachments.each do |attachment|
filename = "bsc#{bug.id}-#{attachment.id}-#{attachment.props['file_name']}"
if supportconfig_only
next unless attachment.content_type == 'application/x-gzip' ||
attachment.content_type == 'application/x-bzip-compressed-tar'
next unless attachment.summary =~ /supportconfig/i
end
t.say("Downloading to #{t.color(filename, :even_row)}")
begin
data = attachment.data
File.open(filename, 'w') do |f|
f.write data.read
end
rescue StandardError => e
t.say("#{t.color('Error:', :error)} Download of #{filename} failed: #{e}")
raise
end
end
end | [
"def",
"download",
"(",
"bug",
",",
"supportconfig_only",
")",
"bug",
".",
"attachments",
".",
"each",
"do",
"|",
"attachment",
"|",
"filename",
"=",
"\"bsc#{bug.id}-#{attachment.id}-#{attachment.props['file_name']}\"",
"if",
"supportconfig_only",
"next",
"unless",
"attachment",
".",
"content_type",
"==",
"'application/x-gzip'",
"||",
"attachment",
".",
"content_type",
"==",
"'application/x-bzip-compressed-tar'",
"next",
"unless",
"attachment",
".",
"summary",
"=~",
"/",
"/i",
"end",
"t",
".",
"say",
"(",
"\"Downloading to #{t.color(filename, :even_row)}\"",
")",
"begin",
"data",
"=",
"attachment",
".",
"data",
"File",
".",
"open",
"(",
"filename",
",",
"'w'",
")",
"do",
"|",
"f",
"|",
"f",
".",
"write",
"data",
".",
"read",
"end",
"rescue",
"StandardError",
"=>",
"e",
"t",
".",
"say",
"(",
"\"#{t.color('Error:', :error)} Download of #{filename} failed: #{e}\"",
")",
"raise",
"end",
"end",
"end"
] | check for supportconfigs and download | [
"check",
"for",
"supportconfigs",
"and",
"download"
] | fff403fcc5b1e1b6c81defd7c6434e9499aa1a63 | https://github.com/dmacvicar/bicho/blob/fff403fcc5b1e1b6c81defd7c6434e9499aa1a63/lib/bicho/cli/commands/attachments.rb#L35-L54 | train |
mikemackintosh/ruby-qualys | lib/qualys/config.rb | Qualys.Config.load! | def load!(path)
settings = YAML.safe_load(ERB.new(File.new(path).read).result)['api']
from_hash(settings) if settings.is_a? Hash
end | ruby | def load!(path)
settings = YAML.safe_load(ERB.new(File.new(path).read).result)['api']
from_hash(settings) if settings.is_a? Hash
end | [
"def",
"load!",
"(",
"path",
")",
"settings",
"=",
"YAML",
".",
"safe_load",
"(",
"ERB",
".",
"new",
"(",
"File",
".",
"new",
"(",
"path",
")",
".",
"read",
")",
".",
"result",
")",
"[",
"'api'",
"]",
"from_hash",
"(",
"settings",
")",
"if",
"settings",
".",
"is_a?",
"Hash",
"end"
] | Load the settings from a compliant Qualys.yml file. This can be used for
easy setup with frameworks other than Rails.
@example Configure Qualys.
Qualys.load!("/path/to/qualys.yml")
@param [ String ] path The path to the file. | [
"Load",
"the",
"settings",
"from",
"a",
"compliant",
"Qualys",
".",
"yml",
"file",
".",
"This",
"can",
"be",
"used",
"for",
"easy",
"setup",
"with",
"frameworks",
"other",
"than",
"Rails",
"."
] | 6479d72fdd60ada7ef8245bf3161ef09c282eca8 | https://github.com/mikemackintosh/ruby-qualys/blob/6479d72fdd60ada7ef8245bf3161ef09c282eca8/lib/qualys/config.rb#L28-L31 | train |
imathis/esvg | lib/esvg/svgs.rb | Esvg.Svgs.embed_script | def embed_script(names=nil)
if production?
embeds = buildable_svgs(names).map(&:embed)
else
embeds = find_svgs(names).map(&:embed)
end
write_cache if cache_stale?
if !embeds.empty?
"<script>#{js(embeds.join("\n"))}</script>"
end
end | ruby | def embed_script(names=nil)
if production?
embeds = buildable_svgs(names).map(&:embed)
else
embeds = find_svgs(names).map(&:embed)
end
write_cache if cache_stale?
if !embeds.empty?
"<script>#{js(embeds.join("\n"))}</script>"
end
end | [
"def",
"embed_script",
"(",
"names",
"=",
"nil",
")",
"if",
"production?",
"embeds",
"=",
"buildable_svgs",
"(",
"names",
")",
".",
"map",
"(",
"&",
":embed",
")",
"else",
"embeds",
"=",
"find_svgs",
"(",
"names",
")",
".",
"map",
"(",
"&",
":embed",
")",
"end",
"write_cache",
"if",
"cache_stale?",
"if",
"!",
"embeds",
".",
"empty?",
"\"<script>#{js(embeds.join(\"\\n\"))}</script>\"",
"end",
"end"
] | Embed svg symbols | [
"Embed",
"svg",
"symbols"
] | 0a555daaf6b6860c0a85865461c64e241bc92842 | https://github.com/imathis/esvg/blob/0a555daaf6b6860c0a85865461c64e241bc92842/lib/esvg/svgs.rb#L128-L141 | train |
flippa/ralexa | lib/ralexa/url_info.rb | Ralexa.UrlInfo.get | def get(url, params = {})
result({"ResponseGroup" => "Related,TrafficData,ContentData", "Url" => url}, params) do |doc|
@document = doc
{
speed_median_load_time: speed_median_load_time,
speed_load_percentile: speed_load_percentile,
link_count: link_count,
ranking: ranking,
ranking_delta: ranking_delta,
reach_rank: reach_rank,
reach_rank_delta: reach_rank_delta,
reach_per_million: reach_per_million,
reach_per_million_delta: reach_per_million_delta,
page_views_rank: page_views_rank,
page_views_rank_delta: page_views_rank_delta,
page_views_per_million: page_views_per_million,
page_views_per_million_delta: page_views_per_million_delta,
page_views_per_user: page_views_per_user,
page_views_per_user_delta: page_views_per_user_delta
}
end
end | ruby | def get(url, params = {})
result({"ResponseGroup" => "Related,TrafficData,ContentData", "Url" => url}, params) do |doc|
@document = doc
{
speed_median_load_time: speed_median_load_time,
speed_load_percentile: speed_load_percentile,
link_count: link_count,
ranking: ranking,
ranking_delta: ranking_delta,
reach_rank: reach_rank,
reach_rank_delta: reach_rank_delta,
reach_per_million: reach_per_million,
reach_per_million_delta: reach_per_million_delta,
page_views_rank: page_views_rank,
page_views_rank_delta: page_views_rank_delta,
page_views_per_million: page_views_per_million,
page_views_per_million_delta: page_views_per_million_delta,
page_views_per_user: page_views_per_user,
page_views_per_user_delta: page_views_per_user_delta
}
end
end | [
"def",
"get",
"(",
"url",
",",
"params",
"=",
"{",
"}",
")",
"result",
"(",
"{",
"\"ResponseGroup\"",
"=>",
"\"Related,TrafficData,ContentData\"",
",",
"\"Url\"",
"=>",
"url",
"}",
",",
"params",
")",
"do",
"|",
"doc",
"|",
"@document",
"=",
"doc",
"{",
"speed_median_load_time",
":",
"speed_median_load_time",
",",
"speed_load_percentile",
":",
"speed_load_percentile",
",",
"link_count",
":",
"link_count",
",",
"ranking",
":",
"ranking",
",",
"ranking_delta",
":",
"ranking_delta",
",",
"reach_rank",
":",
"reach_rank",
",",
"reach_rank_delta",
":",
"reach_rank_delta",
",",
"reach_per_million",
":",
"reach_per_million",
",",
"reach_per_million_delta",
":",
"reach_per_million_delta",
",",
"page_views_rank",
":",
"page_views_rank",
",",
"page_views_rank_delta",
":",
"page_views_rank_delta",
",",
"page_views_per_million",
":",
"page_views_per_million",
",",
"page_views_per_million_delta",
":",
"page_views_per_million_delta",
",",
"page_views_per_user",
":",
"page_views_per_user",
",",
"page_views_per_user_delta",
":",
"page_views_per_user_delta",
"}",
"end",
"end"
] | Alexa data for an individual site | [
"Alexa",
"data",
"for",
"an",
"individual",
"site"
] | fd5bdff102fe52f5c2898b1f917a12a1f17f25de | https://github.com/flippa/ralexa/blob/fd5bdff102fe52f5c2898b1f917a12a1f17f25de/lib/ralexa/url_info.rb#L5-L27 | train |
magoosh/motion_record | lib/motion_record/persistence.rb | MotionRecord.Persistence.apply_persistence_timestamps | def apply_persistence_timestamps
self.updated_at = Time.now if self.class.attribute_names.include?(:updated_at)
self.created_at ||= Time.now if self.class.attribute_names.include?(:created_at)
end | ruby | def apply_persistence_timestamps
self.updated_at = Time.now if self.class.attribute_names.include?(:updated_at)
self.created_at ||= Time.now if self.class.attribute_names.include?(:created_at)
end | [
"def",
"apply_persistence_timestamps",
"self",
".",
"updated_at",
"=",
"Time",
".",
"now",
"if",
"self",
".",
"class",
".",
"attribute_names",
".",
"include?",
"(",
":updated_at",
")",
"self",
".",
"created_at",
"||=",
"Time",
".",
"now",
"if",
"self",
".",
"class",
".",
"attribute_names",
".",
"include?",
"(",
":created_at",
")",
"end"
] | Update persistence auto-timestamp attributes | [
"Update",
"persistence",
"auto",
"-",
"timestamp",
"attributes"
] | 843958568853464a205ae8c446960affcba82387 | https://github.com/magoosh/motion_record/blob/843958568853464a205ae8c446960affcba82387/lib/motion_record/persistence.rb#L59-L62 | train |
romainberger/shop | lib/shop/shopconfig.rb | Shop.ShopConfig.get | def get(namespace = false, key = false, defaultValue = '')
if namespace && key
value = @config[namespace][key]
if value
return value
else
return defaultValue
end
end
return @config if [email protected]?
get_config
end | ruby | def get(namespace = false, key = false, defaultValue = '')
if namespace && key
value = @config[namespace][key]
if value
return value
else
return defaultValue
end
end
return @config if [email protected]?
get_config
end | [
"def",
"get",
"(",
"namespace",
"=",
"false",
",",
"key",
"=",
"false",
",",
"defaultValue",
"=",
"''",
")",
"if",
"namespace",
"&&",
"key",
"value",
"=",
"@config",
"[",
"namespace",
"]",
"[",
"key",
"]",
"if",
"value",
"return",
"value",
"else",
"return",
"defaultValue",
"end",
"end",
"return",
"@config",
"if",
"!",
"@config",
".",
"empty?",
"get_config",
"end"
] | Returns the whole config or a specific value
namespace - the namespace where the key is searched
key - the key neede
defaultValue - default value to return if the value is nil | [
"Returns",
"the",
"whole",
"config",
"or",
"a",
"specific",
"value"
] | 0cbfdf098027c7d5bb049f5181c5bbb3854cb543 | https://github.com/romainberger/shop/blob/0cbfdf098027c7d5bb049f5181c5bbb3854cb543/lib/shop/shopconfig.rb#L20-L33 | train |
bamnet/attachable | lib/attachable.rb | Attachable.ClassMethods.attachable | def attachable(options = {})
# Store the default prefix for file data
# Defaults to "file"
cattr_accessor :attachment_file_prefix
self.attachment_file_prefix = (options[:file_prefix] || :file).to_s
# Setup the default scope so the file data isn't included by default.
# Generate the default scope, which includes every column except for the data column.
# We use this so queries, by default, don't include the file data which could be quite large.
default_scope { select(column_names.reject { |n| n == "#{attachment_file_prefix}_data" }.collect {|n| "#{table_name}.#{n}" }.join(',')) }
# Include all the important stuff
include InstanceMethods
end | ruby | def attachable(options = {})
# Store the default prefix for file data
# Defaults to "file"
cattr_accessor :attachment_file_prefix
self.attachment_file_prefix = (options[:file_prefix] || :file).to_s
# Setup the default scope so the file data isn't included by default.
# Generate the default scope, which includes every column except for the data column.
# We use this so queries, by default, don't include the file data which could be quite large.
default_scope { select(column_names.reject { |n| n == "#{attachment_file_prefix}_data" }.collect {|n| "#{table_name}.#{n}" }.join(',')) }
# Include all the important stuff
include InstanceMethods
end | [
"def",
"attachable",
"(",
"options",
"=",
"{",
"}",
")",
"cattr_accessor",
":attachment_file_prefix",
"self",
".",
"attachment_file_prefix",
"=",
"(",
"options",
"[",
":file_prefix",
"]",
"||",
":file",
")",
".",
"to_s",
"default_scope",
"{",
"select",
"(",
"column_names",
".",
"reject",
"{",
"|",
"n",
"|",
"n",
"==",
"\"#{attachment_file_prefix}_data\"",
"}",
".",
"collect",
"{",
"|",
"n",
"|",
"\"#{table_name}.#{n}\"",
"}",
".",
"join",
"(",
"','",
")",
")",
"}",
"include",
"InstanceMethods",
"end"
] | Loads the attachable methods, scope, and config into the model. | [
"Loads",
"the",
"attachable",
"methods",
"scope",
"and",
"config",
"into",
"the",
"model",
"."
] | 64592900db2790cc11d279ee131c1b25fbd11b15 | https://github.com/bamnet/attachable/blob/64592900db2790cc11d279ee131c1b25fbd11b15/lib/attachable.rb#L12-L25 | train |
hollingberry/texmath-ruby | lib/texmath/converter.rb | TeXMath.Converter.convert | def convert(data)
Open3.popen3(command) do |stdin, stdout, stderr|
stdin.puts(data)
stdin.close
output = stdout.read
error = stderr.read
raise ConversionError, error unless error.empty?
return output.strip
end
rescue Errno::ENOENT
raise NoExecutableError, "Can't find the '#{executable}' executable."
end | ruby | def convert(data)
Open3.popen3(command) do |stdin, stdout, stderr|
stdin.puts(data)
stdin.close
output = stdout.read
error = stderr.read
raise ConversionError, error unless error.empty?
return output.strip
end
rescue Errno::ENOENT
raise NoExecutableError, "Can't find the '#{executable}' executable."
end | [
"def",
"convert",
"(",
"data",
")",
"Open3",
".",
"popen3",
"(",
"command",
")",
"do",
"|",
"stdin",
",",
"stdout",
",",
"stderr",
"|",
"stdin",
".",
"puts",
"(",
"data",
")",
"stdin",
".",
"close",
"output",
"=",
"stdout",
".",
"read",
"error",
"=",
"stderr",
".",
"read",
"raise",
"ConversionError",
",",
"error",
"unless",
"error",
".",
"empty?",
"return",
"output",
".",
"strip",
"end",
"rescue",
"Errno",
"::",
"ENOENT",
"raise",
"NoExecutableError",
",",
"\"Can't find the '#{executable}' executable.\"",
"end"
] | Convert `data` between formats.
@return [String] the converted data | [
"Convert",
"data",
"between",
"formats",
"."
] | 7a4cdb6cf7200e84bca371b03836c0498a813dd4 | https://github.com/hollingberry/texmath-ruby/blob/7a4cdb6cf7200e84bca371b03836c0498a813dd4/lib/texmath/converter.rb#L47-L58 | train |
hallison/sinatra-mapping | lib/sinatra/mapping.rb | Sinatra.Mapping.map | def map(name, path = nil)
@locations ||= {}
if name.to_sym == :root
@locations[:root] = cleanup_paths("/#{path}/")
self.class.class_eval do
define_method "#{name}_path" do |*paths|
cleanup_paths("/#{@locations[:root]}/?")
end
end
else
@locations[name.to_sym] = cleanup_paths(path || name.to_s)
self.class.class_eval do
define_method("#{name}_path") do |*paths|
map_path_to(@locations[name.to_sym], paths << "/?")
end
end
end
Delegator.delegate "#{name}_path"
end | ruby | def map(name, path = nil)
@locations ||= {}
if name.to_sym == :root
@locations[:root] = cleanup_paths("/#{path}/")
self.class.class_eval do
define_method "#{name}_path" do |*paths|
cleanup_paths("/#{@locations[:root]}/?")
end
end
else
@locations[name.to_sym] = cleanup_paths(path || name.to_s)
self.class.class_eval do
define_method("#{name}_path") do |*paths|
map_path_to(@locations[name.to_sym], paths << "/?")
end
end
end
Delegator.delegate "#{name}_path"
end | [
"def",
"map",
"(",
"name",
",",
"path",
"=",
"nil",
")",
"@locations",
"||=",
"{",
"}",
"if",
"name",
".",
"to_sym",
"==",
":root",
"@locations",
"[",
":root",
"]",
"=",
"cleanup_paths",
"(",
"\"/#{path}/\"",
")",
"self",
".",
"class",
".",
"class_eval",
"do",
"define_method",
"\"#{name}_path\"",
"do",
"|",
"*",
"paths",
"|",
"cleanup_paths",
"(",
"\"/#{@locations[:root]}/?\"",
")",
"end",
"end",
"else",
"@locations",
"[",
"name",
".",
"to_sym",
"]",
"=",
"cleanup_paths",
"(",
"path",
"||",
"name",
".",
"to_s",
")",
"self",
".",
"class",
".",
"class_eval",
"do",
"define_method",
"(",
"\"#{name}_path\"",
")",
"do",
"|",
"*",
"paths",
"|",
"map_path_to",
"(",
"@locations",
"[",
"name",
".",
"to_sym",
"]",
",",
"paths",
"<<",
"\"/?\"",
")",
"end",
"end",
"end",
"Delegator",
".",
"delegate",
"\"#{name}_path\"",
"end"
] | Write URL path method for use in HTTP methods.
The map method most be used by following syntax:
map <name>, <path>
If name is equal :root, then returns path ended by slash "/".
map :root, "tasks" #=> /tasks/
map :changes, "last-changes #=> /tasks/last-changes | [
"Write",
"URL",
"path",
"method",
"for",
"use",
"in",
"HTTP",
"methods",
"."
] | 693ce820304f5aea8e9af879d89c96b8b3fa02ed | https://github.com/hallison/sinatra-mapping/blob/693ce820304f5aea8e9af879d89c96b8b3fa02ed/lib/sinatra/mapping.rb#L27-L45 | train |
hallison/sinatra-mapping | lib/sinatra/mapping.rb | Sinatra.Mapping.map_path_to | def map_path_to(*args)
script_name = args.shift if args.first.to_s =~ %r{^/\w.*}
path_mapped(script_name, *locations_get_from(*args))
end | ruby | def map_path_to(*args)
script_name = args.shift if args.first.to_s =~ %r{^/\w.*}
path_mapped(script_name, *locations_get_from(*args))
end | [
"def",
"map_path_to",
"(",
"*",
"args",
")",
"script_name",
"=",
"args",
".",
"shift",
"if",
"args",
".",
"first",
".",
"to_s",
"=~",
"%r{",
"\\w",
"}",
"path_mapped",
"(",
"script_name",
",",
"*",
"locations_get_from",
"(",
"*",
"args",
")",
")",
"end"
] | Check arguments. If argument is a symbol and exist map path before
setted, then return path mapped by symbol name. | [
"Check",
"arguments",
".",
"If",
"argument",
"is",
"a",
"symbol",
"and",
"exist",
"map",
"path",
"before",
"setted",
"then",
"return",
"path",
"mapped",
"by",
"symbol",
"name",
"."
] | 693ce820304f5aea8e9af879d89c96b8b3fa02ed | https://github.com/hallison/sinatra-mapping/blob/693ce820304f5aea8e9af879d89c96b8b3fa02ed/lib/sinatra/mapping.rb#L94-L97 | train |
hallison/sinatra-mapping | lib/sinatra/mapping.rb | Sinatra.Mapping.path_mapped | def path_mapped(script_name, *args)
return cleanup_paths("/#{script_name}/#{@locations[:root]}") if args.empty?
a = replace_symbols(script_name, *args)
cleanup_paths("/#{script_name}/#{@locations[:root]}/#{a.join('/')}")
end | ruby | def path_mapped(script_name, *args)
return cleanup_paths("/#{script_name}/#{@locations[:root]}") if args.empty?
a = replace_symbols(script_name, *args)
cleanup_paths("/#{script_name}/#{@locations[:root]}/#{a.join('/')}")
end | [
"def",
"path_mapped",
"(",
"script_name",
",",
"*",
"args",
")",
"return",
"cleanup_paths",
"(",
"\"/#{script_name}/#{@locations[:root]}\"",
")",
"if",
"args",
".",
"empty?",
"a",
"=",
"replace_symbols",
"(",
"script_name",
",",
"*",
"args",
")",
"cleanup_paths",
"(",
"\"/#{script_name}/#{@locations[:root]}/#{a.join('/')}\"",
")",
"end"
] | Returns all paths mapped by root path in prefix. | [
"Returns",
"all",
"paths",
"mapped",
"by",
"root",
"path",
"in",
"prefix",
"."
] | 693ce820304f5aea8e9af879d89c96b8b3fa02ed | https://github.com/hallison/sinatra-mapping/blob/693ce820304f5aea8e9af879d89c96b8b3fa02ed/lib/sinatra/mapping.rb#L100-L104 | train |
hallison/sinatra-mapping | lib/sinatra/mapping.rb | Sinatra.Mapping.replace_symbols | def replace_symbols(script_name, *args)
args_new = []
args_copy = args.clone
url = args[0].clone
modifiers = args_copy[1]
if modifiers.class == Hash
modifiers.delete_if do |key, value|
delete = url.include? (":" + key.to_s)
if delete
url.sub!( (":" + key.to_s), value.to_s )
end
delete
end
end
i = 1
result = [url]
while args_copy[i]
unless args_copy[i].empty?
if args_copy[i].class == Array
value = args_copy[i]
else
value = [args_copy[i]]
end
if args_copy[i] != '/?' && url =~ /\*/
url.sub!("*", value.join(''))
else
result.concat(value)
end
end
i+= 1
end
result
end | ruby | def replace_symbols(script_name, *args)
args_new = []
args_copy = args.clone
url = args[0].clone
modifiers = args_copy[1]
if modifiers.class == Hash
modifiers.delete_if do |key, value|
delete = url.include? (":" + key.to_s)
if delete
url.sub!( (":" + key.to_s), value.to_s )
end
delete
end
end
i = 1
result = [url]
while args_copy[i]
unless args_copy[i].empty?
if args_copy[i].class == Array
value = args_copy[i]
else
value = [args_copy[i]]
end
if args_copy[i] != '/?' && url =~ /\*/
url.sub!("*", value.join(''))
else
result.concat(value)
end
end
i+= 1
end
result
end | [
"def",
"replace_symbols",
"(",
"script_name",
",",
"*",
"args",
")",
"args_new",
"=",
"[",
"]",
"args_copy",
"=",
"args",
".",
"clone",
"url",
"=",
"args",
"[",
"0",
"]",
".",
"clone",
"modifiers",
"=",
"args_copy",
"[",
"1",
"]",
"if",
"modifiers",
".",
"class",
"==",
"Hash",
"modifiers",
".",
"delete_if",
"do",
"|",
"key",
",",
"value",
"|",
"delete",
"=",
"url",
".",
"include?",
"(",
"\":\"",
"+",
"key",
".",
"to_s",
")",
"if",
"delete",
"url",
".",
"sub!",
"(",
"(",
"\":\"",
"+",
"key",
".",
"to_s",
")",
",",
"value",
".",
"to_s",
")",
"end",
"delete",
"end",
"end",
"i",
"=",
"1",
"result",
"=",
"[",
"url",
"]",
"while",
"args_copy",
"[",
"i",
"]",
"unless",
"args_copy",
"[",
"i",
"]",
".",
"empty?",
"if",
"args_copy",
"[",
"i",
"]",
".",
"class",
"==",
"Array",
"value",
"=",
"args_copy",
"[",
"i",
"]",
"else",
"value",
"=",
"[",
"args_copy",
"[",
"i",
"]",
"]",
"end",
"if",
"args_copy",
"[",
"i",
"]",
"!=",
"'/?'",
"&&",
"url",
"=~",
"/",
"\\*",
"/",
"url",
".",
"sub!",
"(",
"\"*\"",
",",
"value",
".",
"join",
"(",
"''",
")",
")",
"else",
"result",
".",
"concat",
"(",
"value",
")",
"end",
"end",
"i",
"+=",
"1",
"end",
"result",
"end"
] | Replace simbols in url for | [
"Replace",
"simbols",
"in",
"url",
"for"
] | 693ce820304f5aea8e9af879d89c96b8b3fa02ed | https://github.com/hallison/sinatra-mapping/blob/693ce820304f5aea8e9af879d89c96b8b3fa02ed/lib/sinatra/mapping.rb#L108-L145 | train |
hallison/sinatra-mapping | lib/sinatra/mapping.rb | Sinatra.Mapping.locations_get_from | def locations_get_from(*args)
args.flatten.reject do |path|
path == :root
end.collect do |path|
@locations[path] || path
end
end | ruby | def locations_get_from(*args)
args.flatten.reject do |path|
path == :root
end.collect do |path|
@locations[path] || path
end
end | [
"def",
"locations_get_from",
"(",
"*",
"args",
")",
"args",
".",
"flatten",
".",
"reject",
"do",
"|",
"path",
"|",
"path",
"==",
":root",
"end",
".",
"collect",
"do",
"|",
"path",
"|",
"@locations",
"[",
"path",
"]",
"||",
"path",
"end",
"end"
] | Get paths from location maps. | [
"Get",
"paths",
"from",
"location",
"maps",
"."
] | 693ce820304f5aea8e9af879d89c96b8b3fa02ed | https://github.com/hallison/sinatra-mapping/blob/693ce820304f5aea8e9af879d89c96b8b3fa02ed/lib/sinatra/mapping.rb#L148-L154 | train |
rhenium/plum | lib/plum/server/connection.rb | Plum.ServerConnection.reserve_stream | def reserve_stream(**args)
next_id = @max_stream_ids[0] + 2
stream = stream(next_id)
stream.set_state(:reserved_local)
stream.update_dependency(**args)
stream
end | ruby | def reserve_stream(**args)
next_id = @max_stream_ids[0] + 2
stream = stream(next_id)
stream.set_state(:reserved_local)
stream.update_dependency(**args)
stream
end | [
"def",
"reserve_stream",
"(",
"**",
"args",
")",
"next_id",
"=",
"@max_stream_ids",
"[",
"0",
"]",
"+",
"2",
"stream",
"=",
"stream",
"(",
"next_id",
")",
"stream",
".",
"set_state",
"(",
":reserved_local",
")",
"stream",
".",
"update_dependency",
"(",
"**",
"args",
")",
"stream",
"end"
] | Reserves a new stream to server push.
@param args [Hash] The argument to pass to Stram.new. | [
"Reserves",
"a",
"new",
"stream",
"to",
"server",
"push",
"."
] | 9190801a092d46c7079ccee201b212b2d7985952 | https://github.com/rhenium/plum/blob/9190801a092d46c7079ccee201b212b2d7985952/lib/plum/server/connection.rb#L14-L20 | train |
GomaaK/sshez | lib/sshez/runner.rb | Sshez.Runner.process | def process(args)
parser = Parser.new(Exec.new(self))
parser.parse(args)
PRINTER.output
end | ruby | def process(args)
parser = Parser.new(Exec.new(self))
parser.parse(args)
PRINTER.output
end | [
"def",
"process",
"(",
"args",
")",
"parser",
"=",
"Parser",
".",
"new",
"(",
"Exec",
".",
"new",
"(",
"self",
")",
")",
"parser",
".",
"parse",
"(",
"args",
")",
"PRINTER",
".",
"output",
"end"
] | Main method of the application
takes un processed ARGS and pass it to our parser to start our processing | [
"Main",
"method",
"of",
"the",
"application",
"takes",
"un",
"processed",
"ARGS",
"and",
"pass",
"it",
"to",
"our",
"parser",
"to",
"start",
"our",
"processing"
] | 6771012c2b29c2f28fdaf42372f93f70dbcbb291 | https://github.com/GomaaK/sshez/blob/6771012c2b29c2f28fdaf42372f93f70dbcbb291/lib/sshez/runner.rb#L23-L27 | train |
twg/bootstrap_builder | lib/bootstrap_builder/builder.rb | BootstrapBuilder.Builder.element | def element(label = ' ', value = '', type = 'text_field', &block)
value += @template.capture(&block) if block_given?
%{
<div class='control-group'>
<label class='control-label'>#{label}</label>
<div class='controls'>
#{value}
</div>
</div>
}.html_safe
end | ruby | def element(label = ' ', value = '', type = 'text_field', &block)
value += @template.capture(&block) if block_given?
%{
<div class='control-group'>
<label class='control-label'>#{label}</label>
<div class='controls'>
#{value}
</div>
</div>
}.html_safe
end | [
"def",
"element",
"(",
"label",
"=",
"' '",
",",
"value",
"=",
"''",
",",
"type",
"=",
"'text_field'",
",",
"&",
"block",
")",
"value",
"+=",
"@template",
".",
"capture",
"(",
"&",
"block",
")",
"if",
"block_given?",
"%{ <div class='control-group'> <label class='control-label'>#{label}</label> <div class='controls'> #{value} </div> </div> }",
".",
"html_safe",
"end"
] | generic container for all things form | [
"generic",
"container",
"for",
"all",
"things",
"form"
] | 6af08e205f4581705673e225868c831f26b64573 | https://github.com/twg/bootstrap_builder/blob/6af08e205f4581705673e225868c831f26b64573/lib/bootstrap_builder/builder.rb#L134-L144 | train |
twg/bootstrap_builder | lib/bootstrap_builder/builder.rb | BootstrapBuilder.Builder.render_field | def render_field(field_name, method, options={}, html_options={}, &block)
case field_name
when 'check_box'
template = field_name
else
template = 'default_field'
end
@template.render(:partial => "#{BootstrapBuilder.config.template_folder}/#{template}", :locals => {
:builder => self,
:method => method,
:field => @template.capture(&block),
:label_text => label_text(method, html_options[:label]),
:required => html_options[:required],
:prepend => html_options[:prepend],
:append => html_options[:append],
:help_block => html_options[:help_block],
:error_messages => error_messages_for(method)
})
end | ruby | def render_field(field_name, method, options={}, html_options={}, &block)
case field_name
when 'check_box'
template = field_name
else
template = 'default_field'
end
@template.render(:partial => "#{BootstrapBuilder.config.template_folder}/#{template}", :locals => {
:builder => self,
:method => method,
:field => @template.capture(&block),
:label_text => label_text(method, html_options[:label]),
:required => html_options[:required],
:prepend => html_options[:prepend],
:append => html_options[:append],
:help_block => html_options[:help_block],
:error_messages => error_messages_for(method)
})
end | [
"def",
"render_field",
"(",
"field_name",
",",
"method",
",",
"options",
"=",
"{",
"}",
",",
"html_options",
"=",
"{",
"}",
",",
"&",
"block",
")",
"case",
"field_name",
"when",
"'check_box'",
"template",
"=",
"field_name",
"else",
"template",
"=",
"'default_field'",
"end",
"@template",
".",
"render",
"(",
":partial",
"=>",
"\"#{BootstrapBuilder.config.template_folder}/#{template}\"",
",",
":locals",
"=>",
"{",
":builder",
"=>",
"self",
",",
":method",
"=>",
"method",
",",
":field",
"=>",
"@template",
".",
"capture",
"(",
"&",
"block",
")",
",",
":label_text",
"=>",
"label_text",
"(",
"method",
",",
"html_options",
"[",
":label",
"]",
")",
",",
":required",
"=>",
"html_options",
"[",
":required",
"]",
",",
":prepend",
"=>",
"html_options",
"[",
":prepend",
"]",
",",
":append",
"=>",
"html_options",
"[",
":append",
"]",
",",
":help_block",
"=>",
"html_options",
"[",
":help_block",
"]",
",",
":error_messages",
"=>",
"error_messages_for",
"(",
"method",
")",
"}",
")",
"end"
] | Main rendering method | [
"Main",
"rendering",
"method"
] | 6af08e205f4581705673e225868c831f26b64573 | https://github.com/twg/bootstrap_builder/blob/6af08e205f4581705673e225868c831f26b64573/lib/bootstrap_builder/builder.rb#L171-L189 | train |
christinedraper/knife-topo | lib/chef/knife/topo/command_helper.rb | KnifeTopo.CommandHelper.initialize_cmd_args | def initialize_cmd_args(args, name_args, new_name_args)
args = args.dup
args.shift(2 + name_args.length)
new_name_args + args
end | ruby | def initialize_cmd_args(args, name_args, new_name_args)
args = args.dup
args.shift(2 + name_args.length)
new_name_args + args
end | [
"def",
"initialize_cmd_args",
"(",
"args",
",",
"name_args",
",",
"new_name_args",
")",
"args",
"=",
"args",
".",
"dup",
"args",
".",
"shift",
"(",
"2",
"+",
"name_args",
".",
"length",
")",
"new_name_args",
"+",
"args",
"end"
] | initialize args for another knife command | [
"initialize",
"args",
"for",
"another",
"knife",
"command"
] | 323f5767a6ed98212629888323c4e694fec820ca | https://github.com/christinedraper/knife-topo/blob/323f5767a6ed98212629888323c4e694fec820ca/lib/chef/knife/topo/command_helper.rb#L25-L29 | train |
christinedraper/knife-topo | lib/chef/knife/topo/command_helper.rb | KnifeTopo.CommandHelper.run_cmd | def run_cmd(command_class, args)
command = command_class.new(args)
command.config[:config_file] = config[:config_file]
command.configure_chef
command_class.load_deps
command.run
command
end | ruby | def run_cmd(command_class, args)
command = command_class.new(args)
command.config[:config_file] = config[:config_file]
command.configure_chef
command_class.load_deps
command.run
command
end | [
"def",
"run_cmd",
"(",
"command_class",
",",
"args",
")",
"command",
"=",
"command_class",
".",
"new",
"(",
"args",
")",
"command",
".",
"config",
"[",
":config_file",
"]",
"=",
"config",
"[",
":config_file",
"]",
"command",
".",
"configure_chef",
"command_class",
".",
"load_deps",
"command",
".",
"run",
"command",
"end"
] | run another knife command | [
"run",
"another",
"knife",
"command"
] | 323f5767a6ed98212629888323c4e694fec820ca | https://github.com/christinedraper/knife-topo/blob/323f5767a6ed98212629888323c4e694fec820ca/lib/chef/knife/topo/command_helper.rb#L32-L40 | train |
christinedraper/knife-topo | lib/chef/knife/topo/command_helper.rb | KnifeTopo.CommandHelper.resource_exists? | def resource_exists?(relative_path)
rest.get_rest(relative_path)
true
rescue Net::HTTPServerException => e
raise unless e.response.code == '404'
false
end | ruby | def resource_exists?(relative_path)
rest.get_rest(relative_path)
true
rescue Net::HTTPServerException => e
raise unless e.response.code == '404'
false
end | [
"def",
"resource_exists?",
"(",
"relative_path",
")",
"rest",
".",
"get_rest",
"(",
"relative_path",
")",
"true",
"rescue",
"Net",
"::",
"HTTPServerException",
"=>",
"e",
"raise",
"unless",
"e",
".",
"response",
".",
"code",
"==",
"'404'",
"false",
"end"
] | check if resource exists | [
"check",
"if",
"resource",
"exists"
] | 323f5767a6ed98212629888323c4e694fec820ca | https://github.com/christinedraper/knife-topo/blob/323f5767a6ed98212629888323c4e694fec820ca/lib/chef/knife/topo/command_helper.rb#L43-L49 | train |
christinedraper/knife-topo | lib/chef/knife/topo/command_helper.rb | KnifeTopo.CommandHelper.check_chef_env | def check_chef_env(chef_env_name)
return unless chef_env_name
Chef::Environment.load(chef_env_name) if chef_env_name
rescue Net::HTTPServerException => e
raise unless e.to_s =~ /^404/
ui.info 'Creating chef environment ' + chef_env_name
chef_env = Chef::Environment.new
chef_env.name(chef_env_name)
chef_env.create
chef_env
end | ruby | def check_chef_env(chef_env_name)
return unless chef_env_name
Chef::Environment.load(chef_env_name) if chef_env_name
rescue Net::HTTPServerException => e
raise unless e.to_s =~ /^404/
ui.info 'Creating chef environment ' + chef_env_name
chef_env = Chef::Environment.new
chef_env.name(chef_env_name)
chef_env.create
chef_env
end | [
"def",
"check_chef_env",
"(",
"chef_env_name",
")",
"return",
"unless",
"chef_env_name",
"Chef",
"::",
"Environment",
".",
"load",
"(",
"chef_env_name",
")",
"if",
"chef_env_name",
"rescue",
"Net",
"::",
"HTTPServerException",
"=>",
"e",
"raise",
"unless",
"e",
".",
"to_s",
"=~",
"/",
"/",
"ui",
".",
"info",
"'Creating chef environment '",
"+",
"chef_env_name",
"chef_env",
"=",
"Chef",
"::",
"Environment",
".",
"new",
"chef_env",
".",
"name",
"(",
"chef_env_name",
")",
"chef_env",
".",
"create",
"chef_env",
"end"
] | make sure the chef environment exists | [
"make",
"sure",
"the",
"chef",
"environment",
"exists"
] | 323f5767a6ed98212629888323c4e694fec820ca | https://github.com/christinedraper/knife-topo/blob/323f5767a6ed98212629888323c4e694fec820ca/lib/chef/knife/topo/command_helper.rb#L52-L62 | train |
flippa/ralexa | lib/ralexa/abstract_service.rb | Ralexa.AbstractService.result | def result(*params, &parser)
Result.new(
@client,
host,
path,
merged_params(*params),
&parser
).result
end | ruby | def result(*params, &parser)
Result.new(
@client,
host,
path,
merged_params(*params),
&parser
).result
end | [
"def",
"result",
"(",
"*",
"params",
",",
"&",
"parser",
")",
"Result",
".",
"new",
"(",
"@client",
",",
"host",
",",
"path",
",",
"merged_params",
"(",
"*",
"params",
")",
",",
"&",
"parser",
")",
".",
"result",
"end"
] | a single result value | [
"a",
"single",
"result",
"value"
] | fd5bdff102fe52f5c2898b1f917a12a1f17f25de | https://github.com/flippa/ralexa/blob/fd5bdff102fe52f5c2898b1f917a12a1f17f25de/lib/ralexa/abstract_service.rb#L11-L19 | train |
flippa/ralexa | lib/ralexa/abstract_service.rb | Ralexa.AbstractService.collection | def collection(*params, &parser)
LazyCollection.new(
@client,
host,
path,
merged_params(*params),
&parser
)
end | ruby | def collection(*params, &parser)
LazyCollection.new(
@client,
host,
path,
merged_params(*params),
&parser
)
end | [
"def",
"collection",
"(",
"*",
"params",
",",
"&",
"parser",
")",
"LazyCollection",
".",
"new",
"(",
"@client",
",",
"host",
",",
"path",
",",
"merged_params",
"(",
"*",
"params",
")",
",",
"&",
"parser",
")",
"end"
] | A lazy collection which fetches records on demand. | [
"A",
"lazy",
"collection",
"which",
"fetches",
"records",
"on",
"demand",
"."
] | fd5bdff102fe52f5c2898b1f917a12a1f17f25de | https://github.com/flippa/ralexa/blob/fd5bdff102fe52f5c2898b1f917a12a1f17f25de/lib/ralexa/abstract_service.rb#L22-L30 | train |
flippa/ralexa | lib/ralexa/abstract_service.rb | Ralexa.AbstractService.merged_params | def merged_params(*params)
params.reduce(default_params) do |merged, params|
merged.merge(params)
end
end | ruby | def merged_params(*params)
params.reduce(default_params) do |merged, params|
merged.merge(params)
end
end | [
"def",
"merged_params",
"(",
"*",
"params",
")",
"params",
".",
"reduce",
"(",
"default_params",
")",
"do",
"|",
"merged",
",",
"params",
"|",
"merged",
".",
"merge",
"(",
"params",
")",
"end",
"end"
] | A hash of the provided params hashes merged into the default_params. | [
"A",
"hash",
"of",
"the",
"provided",
"params",
"hashes",
"merged",
"into",
"the",
"default_params",
"."
] | fd5bdff102fe52f5c2898b1f917a12a1f17f25de | https://github.com/flippa/ralexa/blob/fd5bdff102fe52f5c2898b1f917a12a1f17f25de/lib/ralexa/abstract_service.rb#L45-L49 | train |
romainberger/shop | lib/shop/template.rb | Shop.Template.custom_template_path | def custom_template_path(name)
config = ShopConfig.new
custom_path = config.get('template', 'path')
if File.exists?("#{custom_path}/#{name}")
"#{custom_path}/#{name}"
else
false
end
end | ruby | def custom_template_path(name)
config = ShopConfig.new
custom_path = config.get('template', 'path')
if File.exists?("#{custom_path}/#{name}")
"#{custom_path}/#{name}"
else
false
end
end | [
"def",
"custom_template_path",
"(",
"name",
")",
"config",
"=",
"ShopConfig",
".",
"new",
"custom_path",
"=",
"config",
".",
"get",
"(",
"'template'",
",",
"'path'",
")",
"if",
"File",
".",
"exists?",
"(",
"\"#{custom_path}/#{name}\"",
")",
"\"#{custom_path}/#{name}\"",
"else",
"false",
"end",
"end"
] | Returns the path to the custom template if it exists | [
"Returns",
"the",
"path",
"to",
"the",
"custom",
"template",
"if",
"it",
"exists"
] | 0cbfdf098027c7d5bb049f5181c5bbb3854cb543 | https://github.com/romainberger/shop/blob/0cbfdf098027c7d5bb049f5181c5bbb3854cb543/lib/shop/template.rb#L5-L13 | train |
romainberger/shop | lib/shop/template.rb | Shop.Template.template_path | def template_path(name=false)
custom_path = custom_template_path(name)
if custom_path
custom_path
else
path = File.expand_path File.dirname(__FILE__)
return "#{path}/../../templates/#{name}" if name
"#{path}/../../templates"
end
end | ruby | def template_path(name=false)
custom_path = custom_template_path(name)
if custom_path
custom_path
else
path = File.expand_path File.dirname(__FILE__)
return "#{path}/../../templates/#{name}" if name
"#{path}/../../templates"
end
end | [
"def",
"template_path",
"(",
"name",
"=",
"false",
")",
"custom_path",
"=",
"custom_template_path",
"(",
"name",
")",
"if",
"custom_path",
"custom_path",
"else",
"path",
"=",
"File",
".",
"expand_path",
"File",
".",
"dirname",
"(",
"__FILE__",
")",
"return",
"\"#{path}/../../templates/#{name}\"",
"if",
"name",
"\"#{path}/../../templates\"",
"end",
"end"
] | Returns the path to the templates directory
Returns string | [
"Returns",
"the",
"path",
"to",
"the",
"templates",
"directory"
] | 0cbfdf098027c7d5bb049f5181c5bbb3854cb543 | https://github.com/romainberger/shop/blob/0cbfdf098027c7d5bb049f5181c5bbb3854cb543/lib/shop/template.rb#L18-L29 | train |
romainberger/shop | lib/shop/template.rb | Shop.Template.template | def template(name, datas)
file = template_path(name)
content = File.read(file)
datas.each do |k, v|
k = "<%= #{k} %>"
content = content.gsub(k, v)
end
return content
end | ruby | def template(name, datas)
file = template_path(name)
content = File.read(file)
datas.each do |k, v|
k = "<%= #{k} %>"
content = content.gsub(k, v)
end
return content
end | [
"def",
"template",
"(",
"name",
",",
"datas",
")",
"file",
"=",
"template_path",
"(",
"name",
")",
"content",
"=",
"File",
".",
"read",
"(",
"file",
")",
"datas",
".",
"each",
"do",
"|",
"k",
",",
"v",
"|",
"k",
"=",
"\"<%= #{k} %>\"",
"content",
"=",
"content",
".",
"gsub",
"(",
"k",
",",
"v",
")",
"end",
"return",
"content",
"end"
] | Replace the placeholders by the variables
name: template name
datas: hash containing the values
Returns string | [
"Replace",
"the",
"placeholders",
"by",
"the",
"variables"
] | 0cbfdf098027c7d5bb049f5181c5bbb3854cb543 | https://github.com/romainberger/shop/blob/0cbfdf098027c7d5bb049f5181c5bbb3854cb543/lib/shop/template.rb#L37-L46 | train |
sauspiel/rbarman | lib/rbarman/cli_command.rb | RBarman.CliCommand.binary= | def binary=(path)
raise(ArgumentError, "binary doesn't exist") if !File.exists?(path)
raise(ArgumentError, "binary isn't called \'barman\'") if File.basename(path) != 'barman'
@binary = path
end | ruby | def binary=(path)
raise(ArgumentError, "binary doesn't exist") if !File.exists?(path)
raise(ArgumentError, "binary isn't called \'barman\'") if File.basename(path) != 'barman'
@binary = path
end | [
"def",
"binary",
"=",
"(",
"path",
")",
"raise",
"(",
"ArgumentError",
",",
"\"binary doesn't exist\"",
")",
"if",
"!",
"File",
".",
"exists?",
"(",
"path",
")",
"raise",
"(",
"ArgumentError",
",",
"\"binary isn't called \\'barman\\'\"",
")",
"if",
"File",
".",
"basename",
"(",
"path",
")",
"!=",
"'barman'",
"@binary",
"=",
"path",
"end"
] | Creates a new instance of CliCommand
@param [String] path_to_binary see {#binary}. If nil, it will be initialized from {Configuration}
@param [String] path_to_barman_home see {#barman_home}. If nil, it will be initialized from {Configuration} | [
"Creates",
"a",
"new",
"instance",
"of",
"CliCommand"
] | 89723b5e051bafb1c30848e4f431b9d058871e3f | https://github.com/sauspiel/rbarman/blob/89723b5e051bafb1c30848e4f431b9d058871e3f/lib/rbarman/cli_command.rb#L33-L37 | train |
sauspiel/rbarman | lib/rbarman/cli_command.rb | RBarman.CliCommand.backup | def backup(server, backup_id, opts = {})
raise(ArgumentError, "backup id must not be nil!") if backup_id.nil?
opts[:backup_id] = backup_id
return backups(server, opts)[0]
end | ruby | def backup(server, backup_id, opts = {})
raise(ArgumentError, "backup id must not be nil!") if backup_id.nil?
opts[:backup_id] = backup_id
return backups(server, opts)[0]
end | [
"def",
"backup",
"(",
"server",
",",
"backup_id",
",",
"opts",
"=",
"{",
"}",
")",
"raise",
"(",
"ArgumentError",
",",
"\"backup id must not be nil!\"",
")",
"if",
"backup_id",
".",
"nil?",
"opts",
"[",
":backup_id",
"]",
"=",
"backup_id",
"return",
"backups",
"(",
"server",
",",
"opts",
")",
"[",
"0",
"]",
"end"
] | Instructs barman to get information about a specific backup
@param [String] server server name
@param [String] backup_id id of the backup
@param [Hash] opts options for creating a {Backup}
@option opts [Boolean] :with_wal_files whether to include {WalFiles} in each {Backup}
@return [Backup] a new {Backup} object
@raise [ArgumentError] if backup_id is nil | [
"Instructs",
"barman",
"to",
"get",
"information",
"about",
"a",
"specific",
"backup"
] | 89723b5e051bafb1c30848e4f431b9d058871e3f | https://github.com/sauspiel/rbarman/blob/89723b5e051bafb1c30848e4f431b9d058871e3f/lib/rbarman/cli_command.rb#L51-L55 | train |
sauspiel/rbarman | lib/rbarman/cli_command.rb | RBarman.CliCommand.server | def server(name, opts = {})
lines = run_barman_command("show-server #{name}")
server = parse_show_server_lines(name, lines)
lines = run_barman_command("check #{name}", { :abort_on_error => false })
parse_check_lines(server, lines)
server.backups = backups(server.name, opts) if opts[:with_backups]
return server
end | ruby | def server(name, opts = {})
lines = run_barman_command("show-server #{name}")
server = parse_show_server_lines(name, lines)
lines = run_barman_command("check #{name}", { :abort_on_error => false })
parse_check_lines(server, lines)
server.backups = backups(server.name, opts) if opts[:with_backups]
return server
end | [
"def",
"server",
"(",
"name",
",",
"opts",
"=",
"{",
"}",
")",
"lines",
"=",
"run_barman_command",
"(",
"\"show-server #{name}\"",
")",
"server",
"=",
"parse_show_server_lines",
"(",
"name",
",",
"lines",
")",
"lines",
"=",
"run_barman_command",
"(",
"\"check #{name}\"",
",",
"{",
":abort_on_error",
"=>",
"false",
"}",
")",
"parse_check_lines",
"(",
"server",
",",
"lines",
")",
"server",
".",
"backups",
"=",
"backups",
"(",
"server",
".",
"name",
",",
"opts",
")",
"if",
"opts",
"[",
":with_backups",
"]",
"return",
"server",
"end"
] | Instructs barman to get information about a server
@param [String] name name of the server
@param [Hash] opts options for creating {Server}
@option opts [Boolean] :with_backups whether to include {Backups} in {Server}
@option opts [Boolean] :with_wal_files whether to include {WalFiles} in each {Backup}
@return [Server] a new {Server} | [
"Instructs",
"barman",
"to",
"get",
"information",
"about",
"a",
"server"
] | 89723b5e051bafb1c30848e4f431b9d058871e3f | https://github.com/sauspiel/rbarman/blob/89723b5e051bafb1c30848e4f431b9d058871e3f/lib/rbarman/cli_command.rb#L87-L94 | train |
sauspiel/rbarman | lib/rbarman/cli_command.rb | RBarman.CliCommand.servers | def servers(opts = {})
result = Servers.new
lines = run_barman_command("list-server")
server_names = parse_list_server_lines(lines)
server_names.each do |name|
result << server(name, opts)
end
return result
end | ruby | def servers(opts = {})
result = Servers.new
lines = run_barman_command("list-server")
server_names = parse_list_server_lines(lines)
server_names.each do |name|
result << server(name, opts)
end
return result
end | [
"def",
"servers",
"(",
"opts",
"=",
"{",
"}",
")",
"result",
"=",
"Servers",
".",
"new",
"lines",
"=",
"run_barman_command",
"(",
"\"list-server\"",
")",
"server_names",
"=",
"parse_list_server_lines",
"(",
"lines",
")",
"server_names",
".",
"each",
"do",
"|",
"name",
"|",
"result",
"<<",
"server",
"(",
"name",
",",
"opts",
")",
"end",
"return",
"result",
"end"
] | Instructs barman to get information about all servers
@param [Hash] opts options for creating {Servers}
@option opts [Boolean] :with_backups whether to include {Backups}
@option opts [Boolean] :with_wal_files whether to include {WalFiles}
@return [Servers] an array of {Server} | [
"Instructs",
"barman",
"to",
"get",
"information",
"about",
"all",
"servers"
] | 89723b5e051bafb1c30848e4f431b9d058871e3f | https://github.com/sauspiel/rbarman/blob/89723b5e051bafb1c30848e4f431b9d058871e3f/lib/rbarman/cli_command.rb#L101-L109 | train |
sauspiel/rbarman | lib/rbarman/cli_command.rb | RBarman.CliCommand.wal_files | def wal_files(server, backup_id)
lines = run_barman_command("list-files --target wal #{server} #{backup_id}")
wal_files = parse_wal_files_list(lines)
xlog_db = read_xlog_db(server)
wal_files.each do |w|
wal = "#{w.timeline}#{w.xlog}#{w.segment}"
entry = xlog_db[wal]
w.size = entry[:size]
w.compression = entry[:compression]
w.created = entry[:created].to_i
end
return wal_files
end | ruby | def wal_files(server, backup_id)
lines = run_barman_command("list-files --target wal #{server} #{backup_id}")
wal_files = parse_wal_files_list(lines)
xlog_db = read_xlog_db(server)
wal_files.each do |w|
wal = "#{w.timeline}#{w.xlog}#{w.segment}"
entry = xlog_db[wal]
w.size = entry[:size]
w.compression = entry[:compression]
w.created = entry[:created].to_i
end
return wal_files
end | [
"def",
"wal_files",
"(",
"server",
",",
"backup_id",
")",
"lines",
"=",
"run_barman_command",
"(",
"\"list-files --target wal #{server} #{backup_id}\"",
")",
"wal_files",
"=",
"parse_wal_files_list",
"(",
"lines",
")",
"xlog_db",
"=",
"read_xlog_db",
"(",
"server",
")",
"wal_files",
".",
"each",
"do",
"|",
"w",
"|",
"wal",
"=",
"\"#{w.timeline}#{w.xlog}#{w.segment}\"",
"entry",
"=",
"xlog_db",
"[",
"wal",
"]",
"w",
".",
"size",
"=",
"entry",
"[",
":size",
"]",
"w",
".",
"compression",
"=",
"entry",
"[",
":compression",
"]",
"w",
".",
"created",
"=",
"entry",
"[",
":created",
"]",
".",
"to_i",
"end",
"return",
"wal_files",
"end"
] | Instructs barman to list all wal files for a specific backup id
@param [String] server server name
@param [String] backup_id id of the backup
@return [WalFiles] an array of {WalFile}
@raise [RuntimeError] if wal file duplicates are found in xlog.db
@raise [RuntimeError] if barman lists a wal file but no information could be found in xlog.db | [
"Instructs",
"barman",
"to",
"list",
"all",
"wal",
"files",
"for",
"a",
"specific",
"backup",
"id"
] | 89723b5e051bafb1c30848e4f431b9d058871e3f | https://github.com/sauspiel/rbarman/blob/89723b5e051bafb1c30848e4f431b9d058871e3f/lib/rbarman/cli_command.rb#L117-L129 | train |
sauspiel/rbarman | lib/rbarman/cli_command.rb | RBarman.CliCommand.parse_list_server_lines | def parse_list_server_lines(lines)
result = Array.new
lines.each do |l|
result << l.split("-")[0].strip
end
return result
end | ruby | def parse_list_server_lines(lines)
result = Array.new
lines.each do |l|
result << l.split("-")[0].strip
end
return result
end | [
"def",
"parse_list_server_lines",
"(",
"lines",
")",
"result",
"=",
"Array",
".",
"new",
"lines",
".",
"each",
"do",
"|",
"l",
"|",
"result",
"<<",
"l",
".",
"split",
"(",
"\"-\"",
")",
"[",
"0",
"]",
".",
"strip",
"end",
"return",
"result",
"end"
] | Parses lines reported by barman's `list-server`
@param [Array<String>] lines an array of lines from output of barman's `list-server` cmd
@return [Array<String>] an array of server names | [
"Parses",
"lines",
"reported",
"by",
"barman",
"s",
"list",
"-",
"server"
] | 89723b5e051bafb1c30848e4f431b9d058871e3f | https://github.com/sauspiel/rbarman/blob/89723b5e051bafb1c30848e4f431b9d058871e3f/lib/rbarman/cli_command.rb#L135-L141 | train |
sauspiel/rbarman | lib/rbarman/cli_command.rb | RBarman.CliCommand.create_recovery_cmd_args | def create_recovery_cmd_args(opts={})
args = Array.new
args << "--remote-ssh-command='#{opts[:remote_ssh_cmd]}'" if opts[:remote_ssh_cmd]
args << "--target-time '#{opts[:target_time].to_s}'" if opts[:target_time]
args << "--target-xid #{opts[:target_xid]}" if opts[:target_xid]
args << "--exclusive" if opts[:exclusive]
return args.join(" ")
end | ruby | def create_recovery_cmd_args(opts={})
args = Array.new
args << "--remote-ssh-command='#{opts[:remote_ssh_cmd]}'" if opts[:remote_ssh_cmd]
args << "--target-time '#{opts[:target_time].to_s}'" if opts[:target_time]
args << "--target-xid #{opts[:target_xid]}" if opts[:target_xid]
args << "--exclusive" if opts[:exclusive]
return args.join(" ")
end | [
"def",
"create_recovery_cmd_args",
"(",
"opts",
"=",
"{",
"}",
")",
"args",
"=",
"Array",
".",
"new",
"args",
"<<",
"\"--remote-ssh-command='#{opts[:remote_ssh_cmd]}'\"",
"if",
"opts",
"[",
":remote_ssh_cmd",
"]",
"args",
"<<",
"\"--target-time '#{opts[:target_time].to_s}'\"",
"if",
"opts",
"[",
":target_time",
"]",
"args",
"<<",
"\"--target-xid #{opts[:target_xid]}\"",
"if",
"opts",
"[",
":target_xid",
"]",
"args",
"<<",
"\"--exclusive\"",
"if",
"opts",
"[",
":exclusive",
"]",
"return",
"args",
".",
"join",
"(",
"\" \"",
")",
"end"
] | Creates an argument string for barman recovery command based on opts Hash
@param [Hash] opts options for creating the arguments
@option opts [String] :remote_ssh_cmd the ssh command to be used for remote recovery
@option opts [String, Time] :target_time the timestamp as recovery target
@option opts [String] :target_xid the transaction ID as recovery target
@option opts [Boolean] :exclusive whether to stop immediately before or immediately after the recovery target
@return [String] the arguments
@since 0.0.3 | [
"Creates",
"an",
"argument",
"string",
"for",
"barman",
"recovery",
"command",
"based",
"on",
"opts",
"Hash"
] | 89723b5e051bafb1c30848e4f431b9d058871e3f | https://github.com/sauspiel/rbarman/blob/89723b5e051bafb1c30848e4f431b9d058871e3f/lib/rbarman/cli_command.rb#L335-L342 | train |
christinedraper/knife-topo | lib/chef/knife/topo/node_update_helper.rb | KnifeTopo.NodeUpdateHelper.update_node | def update_node(node_updates, merge = false)
config[:disable_editing] = true
begin
# load then update and save the node
node = Chef::Node.load(node_updates['name'])
env = node_updates['chef_environment']
check_chef_env(env) unless env == node['chef_environment']
do_node_updates(node, node_updates, merge)
rescue Net::HTTPServerException => e
raise unless e.to_s =~ /^404/
# Node has not been created
end
node
end | ruby | def update_node(node_updates, merge = false)
config[:disable_editing] = true
begin
# load then update and save the node
node = Chef::Node.load(node_updates['name'])
env = node_updates['chef_environment']
check_chef_env(env) unless env == node['chef_environment']
do_node_updates(node, node_updates, merge)
rescue Net::HTTPServerException => e
raise unless e.to_s =~ /^404/
# Node has not been created
end
node
end | [
"def",
"update_node",
"(",
"node_updates",
",",
"merge",
"=",
"false",
")",
"config",
"[",
":disable_editing",
"]",
"=",
"true",
"begin",
"node",
"=",
"Chef",
"::",
"Node",
".",
"load",
"(",
"node_updates",
"[",
"'name'",
"]",
")",
"env",
"=",
"node_updates",
"[",
"'chef_environment'",
"]",
"check_chef_env",
"(",
"env",
")",
"unless",
"env",
"==",
"node",
"[",
"'chef_environment'",
"]",
"do_node_updates",
"(",
"node",
",",
"node_updates",
",",
"merge",
")",
"rescue",
"Net",
"::",
"HTTPServerException",
"=>",
"e",
"raise",
"unless",
"e",
".",
"to_s",
"=~",
"/",
"/",
"end",
"node",
"end"
] | Update an existing node | [
"Update",
"an",
"existing",
"node"
] | 323f5767a6ed98212629888323c4e694fec820ca | https://github.com/christinedraper/knife-topo/blob/323f5767a6ed98212629888323c4e694fec820ca/lib/chef/knife/topo/node_update_helper.rb#L28-L45 | train |
christinedraper/knife-topo | lib/chef/knife/topo/node_update_helper.rb | KnifeTopo.NodeUpdateHelper.update_node_with_values | def update_node_with_values(node, updates, merge = false)
updated = []
# merge the normal attributes (but not tags)
updated << 'normal' if update_attrs(node, updates['normal'], merge)
# update runlist
updated << 'run_list' if update_runlist(node, updates['run_list'])
# update chef env
if update_chef_env(node, updates['chef_environment'])
updated << 'chef_environment'
end
# merge tags
updated << 'tags' if update_tags(node, updates['tags'])
# return false if no updates, else return array of property names
!updated.empty? && updated
end | ruby | def update_node_with_values(node, updates, merge = false)
updated = []
# merge the normal attributes (but not tags)
updated << 'normal' if update_attrs(node, updates['normal'], merge)
# update runlist
updated << 'run_list' if update_runlist(node, updates['run_list'])
# update chef env
if update_chef_env(node, updates['chef_environment'])
updated << 'chef_environment'
end
# merge tags
updated << 'tags' if update_tags(node, updates['tags'])
# return false if no updates, else return array of property names
!updated.empty? && updated
end | [
"def",
"update_node_with_values",
"(",
"node",
",",
"updates",
",",
"merge",
"=",
"false",
")",
"updated",
"=",
"[",
"]",
"updated",
"<<",
"'normal'",
"if",
"update_attrs",
"(",
"node",
",",
"updates",
"[",
"'normal'",
"]",
",",
"merge",
")",
"updated",
"<<",
"'run_list'",
"if",
"update_runlist",
"(",
"node",
",",
"updates",
"[",
"'run_list'",
"]",
")",
"if",
"update_chef_env",
"(",
"node",
",",
"updates",
"[",
"'chef_environment'",
"]",
")",
"updated",
"<<",
"'chef_environment'",
"end",
"updated",
"<<",
"'tags'",
"if",
"update_tags",
"(",
"node",
",",
"updates",
"[",
"'tags'",
"]",
")",
"!",
"updated",
".",
"empty?",
"&&",
"updated",
"end"
] | Update original node, return list of updated properties. | [
"Update",
"original",
"node",
"return",
"list",
"of",
"updated",
"properties",
"."
] | 323f5767a6ed98212629888323c4e694fec820ca | https://github.com/christinedraper/knife-topo/blob/323f5767a6ed98212629888323c4e694fec820ca/lib/chef/knife/topo/node_update_helper.rb#L59-L78 | train |
christinedraper/knife-topo | lib/chef/knife/topo/node_update_helper.rb | KnifeTopo.NodeUpdateHelper.update_attrs | def update_attrs(node, attrs, merge = false)
return false unless attrs
# keep the current tags
attrs['tags'] = node.normal.tags || []
original = Marshal.load(Marshal.dump(node.normal))
node.normal = if merge
Chef::Mixin::DeepMerge.merge(node.normal, attrs)
else
attrs
end
original != node.normal
end | ruby | def update_attrs(node, attrs, merge = false)
return false unless attrs
# keep the current tags
attrs['tags'] = node.normal.tags || []
original = Marshal.load(Marshal.dump(node.normal))
node.normal = if merge
Chef::Mixin::DeepMerge.merge(node.normal, attrs)
else
attrs
end
original != node.normal
end | [
"def",
"update_attrs",
"(",
"node",
",",
"attrs",
",",
"merge",
"=",
"false",
")",
"return",
"false",
"unless",
"attrs",
"attrs",
"[",
"'tags'",
"]",
"=",
"node",
".",
"normal",
".",
"tags",
"||",
"[",
"]",
"original",
"=",
"Marshal",
".",
"load",
"(",
"Marshal",
".",
"dump",
"(",
"node",
".",
"normal",
")",
")",
"node",
".",
"normal",
"=",
"if",
"merge",
"Chef",
"::",
"Mixin",
"::",
"DeepMerge",
".",
"merge",
"(",
"node",
".",
"normal",
",",
"attrs",
")",
"else",
"attrs",
"end",
"original",
"!=",
"node",
".",
"normal",
"end"
] | Update methods all return true if an actual update is made | [
"Update",
"methods",
"all",
"return",
"true",
"if",
"an",
"actual",
"update",
"is",
"made"
] | 323f5767a6ed98212629888323c4e694fec820ca | https://github.com/christinedraper/knife-topo/blob/323f5767a6ed98212629888323c4e694fec820ca/lib/chef/knife/topo/node_update_helper.rb#L81-L92 | train |
marks/truevault.rb | lib/truevault/user.rb | TrueVault.User.create | def create(options = {})
query = {
query: {
username: options[:username],
password: options[:password],
attributes: hash_to_base64_json(options[:attributes])
}
}
new_options = default_options_to_merge_with.merge(query)
self.class.post("/#{@api_ver}/users", new_options)
end | ruby | def create(options = {})
query = {
query: {
username: options[:username],
password: options[:password],
attributes: hash_to_base64_json(options[:attributes])
}
}
new_options = default_options_to_merge_with.merge(query)
self.class.post("/#{@api_ver}/users", new_options)
end | [
"def",
"create",
"(",
"options",
"=",
"{",
"}",
")",
"query",
"=",
"{",
"query",
":",
"{",
"username",
":",
"options",
"[",
":username",
"]",
",",
"password",
":",
"options",
"[",
":password",
"]",
",",
"attributes",
":",
"hash_to_base64_json",
"(",
"options",
"[",
":attributes",
"]",
")",
"}",
"}",
"new_options",
"=",
"default_options_to_merge_with",
".",
"merge",
"(",
"query",
")",
"self",
".",
"class",
".",
"post",
"(",
"\"/#{@api_ver}/users\"",
",",
"new_options",
")",
"end"
] | USER API Methods
creates a user
TVUser.create_user(
username: "bar",
password: "foo",
attributes: {
"id": "000",
"name": "John",
"type": "patient"
}
}
) | [
"USER",
"API",
"Methods"
] | d0d22fc0945de324e45e7d300a37542949ee67b9 | https://github.com/marks/truevault.rb/blob/d0d22fc0945de324e45e7d300a37542949ee67b9/lib/truevault/user.rb#L21-L31 | train |
marks/truevault.rb | lib/truevault/user.rb | TrueVault.User.all | def all(read_attributes="01")
options = default_options_to_merge_with.merge({ query: { full: read_attributes} })
self.class.get("/#{@api_ver}/users", options)
end | ruby | def all(read_attributes="01")
options = default_options_to_merge_with.merge({ query: { full: read_attributes} })
self.class.get("/#{@api_ver}/users", options)
end | [
"def",
"all",
"(",
"read_attributes",
"=",
"\"01\"",
")",
"options",
"=",
"default_options_to_merge_with",
".",
"merge",
"(",
"{",
"query",
":",
"{",
"full",
":",
"read_attributes",
"}",
"}",
")",
"self",
".",
"class",
".",
"get",
"(",
"\"/#{@api_ver}/users\"",
",",
"options",
")",
"end"
] | list all users
TVUser.list_users | [
"list",
"all",
"users",
"TVUser",
".",
"list_users"
] | d0d22fc0945de324e45e7d300a37542949ee67b9 | https://github.com/marks/truevault.rb/blob/d0d22fc0945de324e45e7d300a37542949ee67b9/lib/truevault/user.rb#L44-L47 | train |
paradox460/le_meme | lib/le_meme/meme_lib.rb | LeMeme.MemeLib.load_directory! | def load_directory!(dir)
paths = Dir.glob(dir).grep LeMeme::IMAGE_EXTENSIONS
@memes.merge!(paths.reduce({}) do |images, path|
path = File.expand_path(path)
name = path.split.last.sub(LeMeme::IMAGE_EXTENSIONS, '').to_s
images.merge(name => path)
end)
end | ruby | def load_directory!(dir)
paths = Dir.glob(dir).grep LeMeme::IMAGE_EXTENSIONS
@memes.merge!(paths.reduce({}) do |images, path|
path = File.expand_path(path)
name = path.split.last.sub(LeMeme::IMAGE_EXTENSIONS, '').to_s
images.merge(name => path)
end)
end | [
"def",
"load_directory!",
"(",
"dir",
")",
"paths",
"=",
"Dir",
".",
"glob",
"(",
"dir",
")",
".",
"grep",
"LeMeme",
"::",
"IMAGE_EXTENSIONS",
"@memes",
".",
"merge!",
"(",
"paths",
".",
"reduce",
"(",
"{",
"}",
")",
"do",
"|",
"images",
",",
"path",
"|",
"path",
"=",
"File",
".",
"expand_path",
"(",
"path",
")",
"name",
"=",
"path",
".",
"split",
".",
"last",
".",
"sub",
"(",
"LeMeme",
"::",
"IMAGE_EXTENSIONS",
",",
"''",
")",
".",
"to_s",
"images",
".",
"merge",
"(",
"name",
"=>",
"path",
")",
"end",
")",
"end"
] | Loads a directory into the MemeLib, for template consumption
Clobbers any existing templates
@param [String] dir Directory glob pattern to meme templates
@return [Hash] Hash of all templates and their filepaths | [
"Loads",
"a",
"directory",
"into",
"the",
"MemeLib",
"for",
"template",
"consumption",
"Clobbers",
"any",
"existing",
"templates"
] | cd625df2e29c2c619511dedd5ef0014c2b731696 | https://github.com/paradox460/le_meme/blob/cd625df2e29c2c619511dedd5ef0014c2b731696/lib/le_meme/meme_lib.rb#L27-L34 | train |
paradox460/le_meme | lib/le_meme/meme_lib.rb | LeMeme.MemeLib.meme | def meme(template: nil, top: nil, bottom: nil, watermark: nil)
path = template.nil? ? @memes.values.sample : @memes[template]
Meme.new(path, top: top, bottom: bottom, watermark: watermark)
end | ruby | def meme(template: nil, top: nil, bottom: nil, watermark: nil)
path = template.nil? ? @memes.values.sample : @memes[template]
Meme.new(path, top: top, bottom: bottom, watermark: watermark)
end | [
"def",
"meme",
"(",
"template",
":",
"nil",
",",
"top",
":",
"nil",
",",
"bottom",
":",
"nil",
",",
"watermark",
":",
"nil",
")",
"path",
"=",
"template",
".",
"nil?",
"?",
"@memes",
".",
"values",
".",
"sample",
":",
"@memes",
"[",
"template",
"]",
"Meme",
".",
"new",
"(",
"path",
",",
"top",
":",
"top",
",",
"bottom",
":",
"bottom",
",",
"watermark",
":",
"watermark",
")",
"end"
] | Create a meme from a template
@param [String] template: nil The template to use. Omit for random template
@param [String] top: nil
@param [String] bottom: nil
@param [String] watermark: nil
@return [LeMeme::Meme] | [
"Create",
"a",
"meme",
"from",
"a",
"template"
] | cd625df2e29c2c619511dedd5ef0014c2b731696 | https://github.com/paradox460/le_meme/blob/cd625df2e29c2c619511dedd5ef0014c2b731696/lib/le_meme/meme_lib.rb#L43-L47 | train |
kristianmandrup/cancan-permits | lib/cancan-permits/permits/ability.rb | Permits.Ability.role_groups | def role_groups
groups = []
user_account_class.role_groups.map{|k,v| groups << k if user_account.has_any_role?(v)}
groups
end | ruby | def role_groups
groups = []
user_account_class.role_groups.map{|k,v| groups << k if user_account.has_any_role?(v)}
groups
end | [
"def",
"role_groups",
"groups",
"=",
"[",
"]",
"user_account_class",
".",
"role_groups",
".",
"map",
"{",
"|",
"k",
",",
"v",
"|",
"groups",
"<<",
"k",
"if",
"user_account",
".",
"has_any_role?",
"(",
"v",
")",
"}",
"groups",
"end"
] | return list of symbols for role groups the user belongs to | [
"return",
"list",
"of",
"symbols",
"for",
"role",
"groups",
"the",
"user",
"belongs",
"to"
] | cbc56d299751118b5b6629af0f77917b3d762d61 | https://github.com/kristianmandrup/cancan-permits/blob/cbc56d299751118b5b6629af0f77917b3d762d61/lib/cancan-permits/permits/ability.rb#L55-L59 | train |
rhenium/plum | lib/plum/flow_control.rb | Plum.FlowControl.send | def send(frame)
if Frame::Data === frame
@send_buffer << frame
if @send_remaining_window < frame.length
if Stream === self
connection.callback(:send_deferred, self, frame)
else
callback(:send_deferred, self, frame)
end
else
consume_send_buffer
end
else
send_immediately frame
end
end | ruby | def send(frame)
if Frame::Data === frame
@send_buffer << frame
if @send_remaining_window < frame.length
if Stream === self
connection.callback(:send_deferred, self, frame)
else
callback(:send_deferred, self, frame)
end
else
consume_send_buffer
end
else
send_immediately frame
end
end | [
"def",
"send",
"(",
"frame",
")",
"if",
"Frame",
"::",
"Data",
"===",
"frame",
"@send_buffer",
"<<",
"frame",
"if",
"@send_remaining_window",
"<",
"frame",
".",
"length",
"if",
"Stream",
"===",
"self",
"connection",
".",
"callback",
"(",
":send_deferred",
",",
"self",
",",
"frame",
")",
"else",
"callback",
"(",
":send_deferred",
",",
"self",
",",
"frame",
")",
"end",
"else",
"consume_send_buffer",
"end",
"else",
"send_immediately",
"frame",
"end",
"end"
] | Sends frame respecting inner-stream flow control.
@param frame [Frame] The frame to be sent. | [
"Sends",
"frame",
"respecting",
"inner",
"-",
"stream",
"flow",
"control",
"."
] | 9190801a092d46c7079ccee201b212b2d7985952 | https://github.com/rhenium/plum/blob/9190801a092d46c7079ccee201b212b2d7985952/lib/plum/flow_control.rb#L11-L26 | train |
rhenium/plum | lib/plum/flow_control.rb | Plum.FlowControl.window_update | def window_update(wsi)
@recv_remaining_window += wsi
sid = (Stream === self) ? self.id : 0
send_immediately Frame::WindowUpdate.new(sid, wsi)
end | ruby | def window_update(wsi)
@recv_remaining_window += wsi
sid = (Stream === self) ? self.id : 0
send_immediately Frame::WindowUpdate.new(sid, wsi)
end | [
"def",
"window_update",
"(",
"wsi",
")",
"@recv_remaining_window",
"+=",
"wsi",
"sid",
"=",
"(",
"Stream",
"===",
"self",
")",
"?",
"self",
".",
"id",
":",
"0",
"send_immediately",
"Frame",
"::",
"WindowUpdate",
".",
"new",
"(",
"sid",
",",
"wsi",
")",
"end"
] | Increases receiving window size. Sends WINDOW_UPDATE frame to the peer.
@param wsi [Integer] The amount to increase receiving window size. The legal range is 1 to 2^32-1. | [
"Increases",
"receiving",
"window",
"size",
".",
"Sends",
"WINDOW_UPDATE",
"frame",
"to",
"the",
"peer",
"."
] | 9190801a092d46c7079ccee201b212b2d7985952 | https://github.com/rhenium/plum/blob/9190801a092d46c7079ccee201b212b2d7985952/lib/plum/flow_control.rb#L30-L34 | train |
dmacvicar/bicho | lib/bicho/bug.rb | Bicho.Bug.add_attachment | def add_attachment(summary, file, **kwargs)
@client.add_attachment(summary, file, id, **kwargs).first
end | ruby | def add_attachment(summary, file, **kwargs)
@client.add_attachment(summary, file, id, **kwargs).first
end | [
"def",
"add_attachment",
"(",
"summary",
",",
"file",
",",
"**",
"kwargs",
")",
"@client",
".",
"add_attachment",
"(",
"summary",
",",
"file",
",",
"id",
",",
"**",
"kwargs",
")",
".",
"first",
"end"
] | Add an attachment to the bug
For the params description, see the Client.add_attachment method.
@return [ID] of the new attachment | [
"Add",
"an",
"attachment",
"to",
"the",
"bug",
"For",
"the",
"params",
"description",
"see",
"the",
"Client",
".",
"add_attachment",
"method",
"."
] | fff403fcc5b1e1b6c81defd7c6434e9499aa1a63 | https://github.com/dmacvicar/bicho/blob/fff403fcc5b1e1b6c81defd7c6434e9499aa1a63/lib/bicho/bug.rb#L108-L110 | train |
TwP/pixel_pi | lib/pixel_pi/fake_leds.rb | PixelPi.Leds.show | def show
closed!
if @debug
ary = @leds.map { |value| Rainbow(@debug).color(*to_rgb(value)) }
$stdout.print "\r#{ary.join}"
end
self
end | ruby | def show
closed!
if @debug
ary = @leds.map { |value| Rainbow(@debug).color(*to_rgb(value)) }
$stdout.print "\r#{ary.join}"
end
self
end | [
"def",
"show",
"closed!",
"if",
"@debug",
"ary",
"=",
"@leds",
".",
"map",
"{",
"|",
"value",
"|",
"Rainbow",
"(",
"@debug",
")",
".",
"color",
"(",
"*",
"to_rgb",
"(",
"value",
")",
")",
"}",
"$stdout",
".",
"print",
"\"\\r#{ary.join}\"",
"end",
"self",
"end"
] | Update the display with the data from the LED buffer. This is a noop method
for the fake LEDs. | [
"Update",
"the",
"display",
"with",
"the",
"data",
"from",
"the",
"LED",
"buffer",
".",
"This",
"is",
"a",
"noop",
"method",
"for",
"the",
"fake",
"LEDs",
"."
] | e0a63e337f378f48ecf4df20b2e55d87d84a2a5c | https://github.com/TwP/pixel_pi/blob/e0a63e337f378f48ecf4df20b2e55d87d84a2a5c/lib/pixel_pi/fake_leds.rb#L65-L72 | train |
TwP/pixel_pi | lib/pixel_pi/fake_leds.rb | PixelPi.Leds.[]= | def []=( num, value )
closed!
if (num < 0 || num >= @leds.length)
raise IndexError, "index #{num} is outside of LED range: 0...#{@leds.length-1}"
end
@leds[num] = to_color(value)
end | ruby | def []=( num, value )
closed!
if (num < 0 || num >= @leds.length)
raise IndexError, "index #{num} is outside of LED range: 0...#{@leds.length-1}"
end
@leds[num] = to_color(value)
end | [
"def",
"[]=",
"(",
"num",
",",
"value",
")",
"closed!",
"if",
"(",
"num",
"<",
"0",
"||",
"num",
">=",
"@leds",
".",
"length",
")",
"raise",
"IndexError",
",",
"\"index #{num} is outside of LED range: 0...#{@leds.length-1}\"",
"end",
"@leds",
"[",
"num",
"]",
"=",
"to_color",
"(",
"value",
")",
"end"
] | Set the LED at position `num` to the provided 24-bit RGB color value.
Returns the 24-bit RGB color value. | [
"Set",
"the",
"LED",
"at",
"position",
"num",
"to",
"the",
"provided",
"24",
"-",
"bit",
"RGB",
"color",
"value",
"."
] | e0a63e337f378f48ecf4df20b2e55d87d84a2a5c | https://github.com/TwP/pixel_pi/blob/e0a63e337f378f48ecf4df20b2e55d87d84a2a5c/lib/pixel_pi/fake_leds.rb#L97-L103 | train |
TwP/pixel_pi | lib/pixel_pi/fake_leds.rb | PixelPi.Leds.replace | def replace( ary )
closed!
@leds.length.times do |ii|
@leds[ii] = Integer(ary[ii])
end
self
end | ruby | def replace( ary )
closed!
@leds.length.times do |ii|
@leds[ii] = Integer(ary[ii])
end
self
end | [
"def",
"replace",
"(",
"ary",
")",
"closed!",
"@leds",
".",
"length",
".",
"times",
"do",
"|",
"ii",
"|",
"@leds",
"[",
"ii",
"]",
"=",
"Integer",
"(",
"ary",
"[",
"ii",
"]",
")",
"end",
"self",
"end"
] | Replace the LED colors with the 24-bit RGB color values found in the `ary`.
If the `ary` is longer than the LED string then the extra color values will
be ignored. If the `ary` is shorter than the LED string then only the LEDS
up to `ary.length` will be changed.
You must call `show` for the new colors to be displayed.
Returns this PixelPi::Leds instance. | [
"Replace",
"the",
"LED",
"colors",
"with",
"the",
"24",
"-",
"bit",
"RGB",
"color",
"values",
"found",
"in",
"the",
"ary",
".",
"If",
"the",
"ary",
"is",
"longer",
"than",
"the",
"LED",
"string",
"then",
"the",
"extra",
"color",
"values",
"will",
"be",
"ignored",
".",
"If",
"the",
"ary",
"is",
"shorter",
"than",
"the",
"LED",
"string",
"then",
"only",
"the",
"LEDS",
"up",
"to",
"ary",
".",
"length",
"will",
"be",
"changed",
"."
] | e0a63e337f378f48ecf4df20b2e55d87d84a2a5c | https://github.com/TwP/pixel_pi/blob/e0a63e337f378f48ecf4df20b2e55d87d84a2a5c/lib/pixel_pi/fake_leds.rb#L133-L139 | train |
TwP/pixel_pi | lib/pixel_pi/fake_leds.rb | PixelPi.Leds.fill | def fill( *args )
closed!
if block_given?
@leds.fill do |ii|
value = yield(ii)
to_color(value)
end
else
value = to_color(args.shift)
@leds.fill(value, *args)
end
self
end | ruby | def fill( *args )
closed!
if block_given?
@leds.fill do |ii|
value = yield(ii)
to_color(value)
end
else
value = to_color(args.shift)
@leds.fill(value, *args)
end
self
end | [
"def",
"fill",
"(",
"*",
"args",
")",
"closed!",
"if",
"block_given?",
"@leds",
".",
"fill",
"do",
"|",
"ii",
"|",
"value",
"=",
"yield",
"(",
"ii",
")",
"to_color",
"(",
"value",
")",
"end",
"else",
"value",
"=",
"to_color",
"(",
"args",
".",
"shift",
")",
"@leds",
".",
"fill",
"(",
"value",
",",
"*",
"args",
")",
"end",
"self",
"end"
] | Set the selected LEDs to the given `color`. The `color` msut be given as a
24-bit RGB value. You can also supply a block that receives an LED index and
returns a 24-bit RGB color.
Examples:
leds.fill( 0x00FF00 )
leds.fill( 0xFF0000, 2, 2 )
leds.fill( 0x0000FF, (4...8) )
leds.fill { |i| 256 << i }
Returns this PixelPi::Leds instance. | [
"Set",
"the",
"selected",
"LEDs",
"to",
"the",
"given",
"color",
".",
"The",
"color",
"msut",
"be",
"given",
"as",
"a",
"24",
"-",
"bit",
"RGB",
"value",
".",
"You",
"can",
"also",
"supply",
"a",
"block",
"that",
"receives",
"an",
"LED",
"index",
"and",
"returns",
"a",
"24",
"-",
"bit",
"RGB",
"color",
"."
] | e0a63e337f378f48ecf4df20b2e55d87d84a2a5c | https://github.com/TwP/pixel_pi/blob/e0a63e337f378f48ecf4df20b2e55d87d84a2a5c/lib/pixel_pi/fake_leds.rb#L172-L184 | train |
dmacvicar/bicho | lib/bicho/query.rb | Bicho.Query.each | def each
ret = Bicho.client.search_bugs(self)
return ret.each unless block_given?
ret.each { |bug| yield bug }
end | ruby | def each
ret = Bicho.client.search_bugs(self)
return ret.each unless block_given?
ret.each { |bug| yield bug }
end | [
"def",
"each",
"ret",
"=",
"Bicho",
".",
"client",
".",
"search_bugs",
"(",
"self",
")",
"return",
"ret",
".",
"each",
"unless",
"block_given?",
"ret",
".",
"each",
"{",
"|",
"bug",
"|",
"yield",
"bug",
"}",
"end"
] | Iterates through the result of the current query.
@note Requires Bicho.client to be set
@yield [Bicho::Bug] | [
"Iterates",
"through",
"the",
"result",
"of",
"the",
"current",
"query",
"."
] | fff403fcc5b1e1b6c81defd7c6434e9499aa1a63 | https://github.com/dmacvicar/bicho/blob/fff403fcc5b1e1b6c81defd7c6434e9499aa1a63/lib/bicho/query.rb#L40-L44 | train |
dmacvicar/bicho | lib/bicho/query.rb | Bicho.Query.method_missing | def method_missing(method_name, *args)
return super unless Bicho::SEARCH_FIELDS
.map(&:first)
.include?(method_name)
args.each do |arg|
append_query(method_name.to_s, arg)
end
self
end | ruby | def method_missing(method_name, *args)
return super unless Bicho::SEARCH_FIELDS
.map(&:first)
.include?(method_name)
args.each do |arg|
append_query(method_name.to_s, arg)
end
self
end | [
"def",
"method_missing",
"(",
"method_name",
",",
"*",
"args",
")",
"return",
"super",
"unless",
"Bicho",
"::",
"SEARCH_FIELDS",
".",
"map",
"(",
"&",
":first",
")",
".",
"include?",
"(",
"method_name",
")",
"args",
".",
"each",
"do",
"|",
"arg",
"|",
"append_query",
"(",
"method_name",
".",
"to_s",
",",
"arg",
")",
"end",
"self",
"end"
] | Create a query.
@example query from a hash containing the attributes:
q = Query.new({:summary => "substring", :assigned_to => "[email protected]"})
@example using chainable methods:
q = Query.new.assigned_to("[email protected]@).summary("some text")
Query responds to all the bug search attributes.
@see {Bug.where Allowed attributes} | [
"Create",
"a",
"query",
"."
] | fff403fcc5b1e1b6c81defd7c6434e9499aa1a63 | https://github.com/dmacvicar/bicho/blob/fff403fcc5b1e1b6c81defd7c6434e9499aa1a63/lib/bicho/query.rb#L65-L73 | train |
dmacvicar/bicho | lib/bicho/query.rb | Bicho.Query.append_query | def append_query(param, value)
@query_map[param] = [] unless @query_map.key?(param)
@query_map[param] = [@query_map[param], value].flatten
end | ruby | def append_query(param, value)
@query_map[param] = [] unless @query_map.key?(param)
@query_map[param] = [@query_map[param], value].flatten
end | [
"def",
"append_query",
"(",
"param",
",",
"value",
")",
"@query_map",
"[",
"param",
"]",
"=",
"[",
"]",
"unless",
"@query_map",
".",
"key?",
"(",
"param",
")",
"@query_map",
"[",
"param",
"]",
"=",
"[",
"@query_map",
"[",
"param",
"]",
",",
"value",
"]",
".",
"flatten",
"end"
] | Appends a parameter to the query map
Only used internally.
If the parameter already exists that parameter is converted to an
array of values
@private | [
"Appends",
"a",
"parameter",
"to",
"the",
"query",
"map"
] | fff403fcc5b1e1b6c81defd7c6434e9499aa1a63 | https://github.com/dmacvicar/bicho/blob/fff403fcc5b1e1b6c81defd7c6434e9499aa1a63/lib/bicho/query.rb#L101-L104 | train |
davetron5000/moocow | lib/moocow/moocow.rb | RTM.RTMMethodSpace.method_missing | def method_missing(symbol,*args)
if (@name == 'tasks' && symbol.to_s == 'notes')
return RTMMethodSpace.new("tasks.notes",@endpoint)
else
rtm_method = "rtm.#{@name}.#{symbol.to_s.rtmize}"
@endpoint.call_method(rtm_method,*args)
end
end | ruby | def method_missing(symbol,*args)
if (@name == 'tasks' && symbol.to_s == 'notes')
return RTMMethodSpace.new("tasks.notes",@endpoint)
else
rtm_method = "rtm.#{@name}.#{symbol.to_s.rtmize}"
@endpoint.call_method(rtm_method,*args)
end
end | [
"def",
"method_missing",
"(",
"symbol",
",",
"*",
"args",
")",
"if",
"(",
"@name",
"==",
"'tasks'",
"&&",
"symbol",
".",
"to_s",
"==",
"'notes'",
")",
"return",
"RTMMethodSpace",
".",
"new",
"(",
"\"tasks.notes\"",
",",
"@endpoint",
")",
"else",
"rtm_method",
"=",
"\"rtm.#{@name}.#{symbol.to_s.rtmize}\"",
"@endpoint",
".",
"call_method",
"(",
"rtm_method",
",",
"*",
"args",
")",
"end",
"end"
] | Create an RTMMethodSpace
[name] the name of this method space, e.g. 'tasks'
[endpoint] an endpoing to RTM
Calls the method on RTM in most cases. The only exception is if this RTMMethodSpace is 'tasks' and you
call the 'notes' method on it: a new RTMMethodSpace is returned for the 'rtm.tasks.notes' method-space.
This returns a response object as from HTTParty, dereferenced into <rsp>. So, for example, if you called
the 'tasks.getList' method, you would get a hash that could be accessed via response['tasks'].
This object is a Hash and Array structure that mimcs the XML returned by RTM. One quirk is that for methods that could return 1 or more
of the same item (tasks.getList is a good example; it will return multilple <list> elements unless you restrict by list, in which case
it returns only one <list> element). Because HTTParty doesn't understand this, you may find it convienient to convert such
results to arrays. the to_array extension on Hash and Array accomplish this:
response = rtm.tasks.getList(:filter => 'list:Work')
response['tasks']['list'].as_array.each do |list|
list['taskseries'].as_array.each do |task|
puts task['name']
end
end
So, call to_array on anything you expect to be a list.
This method raises either a BadResponseException if you got a bad or garbled response from RTM or a VerificationException
if you got a non-OK response. | [
"Create",
"an",
"RTMMethodSpace"
] | 92377d31d76728097fe505a5d0bf5dd7f034c9d5 | https://github.com/davetron5000/moocow/blob/92377d31d76728097fe505a5d0bf5dd7f034c9d5/lib/moocow/moocow.rb#L124-L131 | train |
kojnapp/bitstamp | lib/bitstamp/model.rb | Bitstamp.Model.attributes= | def attributes=(attributes = {})
attributes.each do |name, value|
begin
send("#{name}=", value)
rescue NoMethodError => e
puts "Unable to assign #{name}. No such method."
end
end
end | ruby | def attributes=(attributes = {})
attributes.each do |name, value|
begin
send("#{name}=", value)
rescue NoMethodError => e
puts "Unable to assign #{name}. No such method."
end
end
end | [
"def",
"attributes",
"=",
"(",
"attributes",
"=",
"{",
"}",
")",
"attributes",
".",
"each",
"do",
"|",
"name",
",",
"value",
"|",
"begin",
"send",
"(",
"\"#{name}=\"",
",",
"value",
")",
"rescue",
"NoMethodError",
"=>",
"e",
"puts",
"\"Unable to assign #{name}. No such method.\"",
"end",
"end",
"end"
] | Set the attributes based on the given hash | [
"Set",
"the",
"attributes",
"based",
"on",
"the",
"given",
"hash"
] | aa7460beb4fa7c412f2906c6ad7b0ad78026f579 | https://github.com/kojnapp/bitstamp/blob/aa7460beb4fa7c412f2906c6ad7b0ad78026f579/lib/bitstamp/model.rb#L14-L22 | train |
rhenium/plum | lib/plum/client.rb | Plum.Client.start | def start(&block)
raise IOError, "Session already started" if @started
_start
if block_given?
begin
ret = yield(self)
resume
return ret
ensure
close
end
end
self
end | ruby | def start(&block)
raise IOError, "Session already started" if @started
_start
if block_given?
begin
ret = yield(self)
resume
return ret
ensure
close
end
end
self
end | [
"def",
"start",
"(",
"&",
"block",
")",
"raise",
"IOError",
",",
"\"Session already started\"",
"if",
"@started",
"_start",
"if",
"block_given?",
"begin",
"ret",
"=",
"yield",
"(",
"self",
")",
"resume",
"return",
"ret",
"ensure",
"close",
"end",
"end",
"self",
"end"
] | Creates a new HTTP client.
@param host [String | IO] the host to connect, or IO object.
@param port [Integer] the port number to connect
@param config [Hash<Symbol, Object>] the client configuration
Starts communication.
If block passed, waits for asynchronous requests and closes the connection after calling the block. | [
"Creates",
"a",
"new",
"HTTP",
"client",
"."
] | 9190801a092d46c7079ccee201b212b2d7985952 | https://github.com/rhenium/plum/blob/9190801a092d46c7079ccee201b212b2d7985952/lib/plum/client.rb#L43-L56 | train |
rhenium/plum | lib/plum/client.rb | Plum.Client.request | def request(headers, body, options = {}, &block)
raise ArgumentError, ":method and :path headers are required" unless headers[":method"] && headers[":path"]
@session.request(headers, body, @config.merge(options), &block)
end | ruby | def request(headers, body, options = {}, &block)
raise ArgumentError, ":method and :path headers are required" unless headers[":method"] && headers[":path"]
@session.request(headers, body, @config.merge(options), &block)
end | [
"def",
"request",
"(",
"headers",
",",
"body",
",",
"options",
"=",
"{",
"}",
",",
"&",
"block",
")",
"raise",
"ArgumentError",
",",
"\":method and :path headers are required\"",
"unless",
"headers",
"[",
"\":method\"",
"]",
"&&",
"headers",
"[",
"\":path\"",
"]",
"@session",
".",
"request",
"(",
"headers",
",",
"body",
",",
"@config",
".",
"merge",
"(",
"options",
")",
",",
"&",
"block",
")",
"end"
] | Creates a new HTTP request.
@param headers [Hash<String, String>] the request headers
@param body [String] the request body
@param options [Hash<Symbol, Object>] request options
@param block [Proc] if passed, it will be called when received response headers. | [
"Creates",
"a",
"new",
"HTTP",
"request",
"."
] | 9190801a092d46c7079ccee201b212b2d7985952 | https://github.com/rhenium/plum/blob/9190801a092d46c7079ccee201b212b2d7985952/lib/plum/client.rb#L75-L78 | train |
scrapper/perobs | lib/perobs/FlatFile.rb | PEROBS.FlatFile.open | def open
file_name = File.join(@db_dir, 'database.blobs')
new_db_created = false
begin
if File.exist?(file_name)
@f = File.open(file_name, 'rb+')
else
PEROBS.log.info "New FlatFile database '#{file_name}' created"
@f = File.open(file_name, 'wb+')
new_db_created = true
end
rescue IOError => e
PEROBS.log.fatal "Cannot open FlatFile database #{file_name}: " +
e.message
end
unless @f.flock(File::LOCK_NB | File::LOCK_EX)
PEROBS.log.fatal "FlatFile database '#{file_name}' is locked by " +
"another process"
end
@f.sync = true
open_index_files(!new_db_created)
end | ruby | def open
file_name = File.join(@db_dir, 'database.blobs')
new_db_created = false
begin
if File.exist?(file_name)
@f = File.open(file_name, 'rb+')
else
PEROBS.log.info "New FlatFile database '#{file_name}' created"
@f = File.open(file_name, 'wb+')
new_db_created = true
end
rescue IOError => e
PEROBS.log.fatal "Cannot open FlatFile database #{file_name}: " +
e.message
end
unless @f.flock(File::LOCK_NB | File::LOCK_EX)
PEROBS.log.fatal "FlatFile database '#{file_name}' is locked by " +
"another process"
end
@f.sync = true
open_index_files(!new_db_created)
end | [
"def",
"open",
"file_name",
"=",
"File",
".",
"join",
"(",
"@db_dir",
",",
"'database.blobs'",
")",
"new_db_created",
"=",
"false",
"begin",
"if",
"File",
".",
"exist?",
"(",
"file_name",
")",
"@f",
"=",
"File",
".",
"open",
"(",
"file_name",
",",
"'rb+'",
")",
"else",
"PEROBS",
".",
"log",
".",
"info",
"\"New FlatFile database '#{file_name}' created\"",
"@f",
"=",
"File",
".",
"open",
"(",
"file_name",
",",
"'wb+'",
")",
"new_db_created",
"=",
"true",
"end",
"rescue",
"IOError",
"=>",
"e",
"PEROBS",
".",
"log",
".",
"fatal",
"\"Cannot open FlatFile database #{file_name}: \"",
"+",
"e",
".",
"message",
"end",
"unless",
"@f",
".",
"flock",
"(",
"File",
"::",
"LOCK_NB",
"|",
"File",
"::",
"LOCK_EX",
")",
"PEROBS",
".",
"log",
".",
"fatal",
"\"FlatFile database '#{file_name}' is locked by \"",
"+",
"\"another process\"",
"end",
"@f",
".",
"sync",
"=",
"true",
"open_index_files",
"(",
"!",
"new_db_created",
")",
"end"
] | Create a new FlatFile object for a database in the given path.
@param dir [String] Directory path for the data base file
Open the flat file for reading and writing. | [
"Create",
"a",
"new",
"FlatFile",
"object",
"for",
"a",
"database",
"in",
"the",
"given",
"path",
"."
] | 1c9327656912cf96683849f92d260546af856adf | https://github.com/scrapper/perobs/blob/1c9327656912cf96683849f92d260546af856adf/lib/perobs/FlatFile.rb#L58-L80 | train |
scrapper/perobs | lib/perobs/FlatFile.rb | PEROBS.FlatFile.close | def close
@space_list.close if @space_list.is_open?
@index.close if @index.is_open?
if @marks
@marks.erase
@marks = nil
end
if @f
@f.flush
@f.flock(File::LOCK_UN)
@f.fsync
@f.close
@f = nil
end
end | ruby | def close
@space_list.close if @space_list.is_open?
@index.close if @index.is_open?
if @marks
@marks.erase
@marks = nil
end
if @f
@f.flush
@f.flock(File::LOCK_UN)
@f.fsync
@f.close
@f = nil
end
end | [
"def",
"close",
"@space_list",
".",
"close",
"if",
"@space_list",
".",
"is_open?",
"@index",
".",
"close",
"if",
"@index",
".",
"is_open?",
"if",
"@marks",
"@marks",
".",
"erase",
"@marks",
"=",
"nil",
"end",
"if",
"@f",
"@f",
".",
"flush",
"@f",
".",
"flock",
"(",
"File",
"::",
"LOCK_UN",
")",
"@f",
".",
"fsync",
"@f",
".",
"close",
"@f",
"=",
"nil",
"end",
"end"
] | Close the flat file. This method must be called to ensure that all data
is really written into the filesystem. | [
"Close",
"the",
"flat",
"file",
".",
"This",
"method",
"must",
"be",
"called",
"to",
"ensure",
"that",
"all",
"data",
"is",
"really",
"written",
"into",
"the",
"filesystem",
"."
] | 1c9327656912cf96683849f92d260546af856adf | https://github.com/scrapper/perobs/blob/1c9327656912cf96683849f92d260546af856adf/lib/perobs/FlatFile.rb#L84-L100 | train |
scrapper/perobs | lib/perobs/FlatFile.rb | PEROBS.FlatFile.sync | def sync
begin
@f.flush
@f.fsync
rescue IOError => e
PEROBS.log.fatal "Cannot sync flat file database: #{e.message}"
end
@index.sync
@space_list.sync
end | ruby | def sync
begin
@f.flush
@f.fsync
rescue IOError => e
PEROBS.log.fatal "Cannot sync flat file database: #{e.message}"
end
@index.sync
@space_list.sync
end | [
"def",
"sync",
"begin",
"@f",
".",
"flush",
"@f",
".",
"fsync",
"rescue",
"IOError",
"=>",
"e",
"PEROBS",
".",
"log",
".",
"fatal",
"\"Cannot sync flat file database: #{e.message}\"",
"end",
"@index",
".",
"sync",
"@space_list",
".",
"sync",
"end"
] | Force outstanding data to be written to the filesystem. | [
"Force",
"outstanding",
"data",
"to",
"be",
"written",
"to",
"the",
"filesystem",
"."
] | 1c9327656912cf96683849f92d260546af856adf | https://github.com/scrapper/perobs/blob/1c9327656912cf96683849f92d260546af856adf/lib/perobs/FlatFile.rb#L103-L112 | train |
Subsets and Splits
No community queries yet
The top public SQL queries from the community will appear here once available.