repo stringlengths 5 58 | path stringlengths 9 168 | func_name stringlengths 9 130 | original_string stringlengths 66 10.5k | language stringclasses 1
value | code stringlengths 66 10.5k | code_tokens list | docstring stringlengths 8 16k | docstring_tokens list | sha stringlengths 40 40 | url stringlengths 94 266 | partition stringclasses 1
value |
|---|---|---|---|---|---|---|---|---|---|---|---|
ccsalespro/meta_enum | lib/meta_enum/type.rb | MetaEnum.Type.[] | def [](key)
case key
when Element, MissingElement
raise ArgumentError, "wrong type" unless key.type == self
key
when Symbol
elements_by_name.fetch(key)
else
key = normalize_value(key)
elements_by_value.fetch(key) { MissingElement.new key, self }
end
... | ruby | def [](key)
case key
when Element, MissingElement
raise ArgumentError, "wrong type" unless key.type == self
key
when Symbol
elements_by_name.fetch(key)
else
key = normalize_value(key)
elements_by_value.fetch(key) { MissingElement.new key, self }
end
... | [
"def",
"[]",
"(",
"key",
")",
"case",
"key",
"when",
"Element",
",",
"MissingElement",
"raise",
"ArgumentError",
",",
"\"wrong type\"",
"unless",
"key",
".",
"type",
"==",
"self",
"key",
"when",
"Symbol",
"elements_by_name",
".",
"fetch",
"(",
"key",
")",
... | Initialize takes a single hash of name to value.
e.g. MetaEnum::Type.new(red: 0, green: 1, blue: 2)
Additional data can also be associated with each value by passing an array
of [value, extra data]. This can be used for additional description or
any other reason.
e.g. MetaEnum::Type.new(small: [0, "Less than 10... | [
"Initialize",
"takes",
"a",
"single",
"hash",
"of",
"name",
"to",
"value",
"."
] | 988147e7f730625bb9e1693c06415888d4732188 | https://github.com/ccsalespro/meta_enum/blob/988147e7f730625bb9e1693c06415888d4732188/lib/meta_enum/type.rb#L80-L91 | train |
riddopic/hoodie | lib/hoodie/utils/url_helper.rb | Hoodie.UrlHelper.unshorten | def unshorten(url, opts= {})
options = {
max_level: opts.fetch(:max_level, 10),
timeout: opts.fetch(:timeout, 2),
use_cache: opts.fetch(:use_cache, true)
}
url = (url =~ /^https?:/i) ? url : "http://#{url}"
__unshorten__(url, options)
end | ruby | def unshorten(url, opts= {})
options = {
max_level: opts.fetch(:max_level, 10),
timeout: opts.fetch(:timeout, 2),
use_cache: opts.fetch(:use_cache, true)
}
url = (url =~ /^https?:/i) ? url : "http://#{url}"
__unshorten__(url, options)
end | [
"def",
"unshorten",
"(",
"url",
",",
"opts",
"=",
"{",
"}",
")",
"options",
"=",
"{",
"max_level",
":",
"opts",
".",
"fetch",
"(",
":max_level",
",",
"10",
")",
",",
"timeout",
":",
"opts",
".",
"fetch",
"(",
":timeout",
",",
"2",
")",
",",
"use_... | Unshorten a shortened URL.
@param url [String] A shortened URL
@param [Hash] opts
@option opts [Integer] :max_level
max redirect times
@option opts [Integer] :timeout
timeout in seconds, for every request
@option opts [Boolean] :use_cache
use cached result if available
@return Original url, a url t... | [
"Unshorten",
"a",
"shortened",
"URL",
"."
] | 921601dd4849845d3f5d3765dafcf00178b2aa66 | https://github.com/riddopic/hoodie/blob/921601dd4849845d3f5d3765dafcf00178b2aa66/lib/hoodie/utils/url_helper.rb#L61-L69 | train |
thomis/eventhub-processor | lib/eventhub/helper.rb | EventHub.Helper.format_string | def format_string(message,max_characters=80)
max_characters = 5 if max_characters < 5
m = message.gsub(/\r\n|\n|\r/m,";")
return (m[0..max_characters-4] + "...") if m.size > max_characters
return m
end | ruby | def format_string(message,max_characters=80)
max_characters = 5 if max_characters < 5
m = message.gsub(/\r\n|\n|\r/m,";")
return (m[0..max_characters-4] + "...") if m.size > max_characters
return m
end | [
"def",
"format_string",
"(",
"message",
",",
"max_characters",
"=",
"80",
")",
"max_characters",
"=",
"5",
"if",
"max_characters",
"<",
"5",
"m",
"=",
"message",
".",
"gsub",
"(",
"/",
"\\r",
"\\n",
"\\n",
"\\r",
"/m",
",",
"\";\"",
")",
"return",
"(",... | replaces CR, LF, CRLF with ";" and cut's string to requied length by adding "..." if string would be longer | [
"replaces",
"CR",
"LF",
"CRLF",
"with",
";",
"and",
"cut",
"s",
"string",
"to",
"requied",
"length",
"by",
"adding",
"...",
"if",
"string",
"would",
"be",
"longer"
] | 113ecd3aeb592e185716a7f80b0aefab57092c8c | https://github.com/thomis/eventhub-processor/blob/113ecd3aeb592e185716a7f80b0aefab57092c8c/lib/eventhub/helper.rb#L11-L16 | train |
thededlier/WatsonNLPWrapper | lib/WatsonNLPWrapper.rb | WatsonNLPWrapper.WatsonNLPApi.analyze | def analyze(text, features = default_features)
if text.nil? || features.nil?
raise ArgumentError.new(NIL_ARGUMENT_ERROR)
end
response = self.class.post(
"#{@url}/analyze?version=#{@version}",
body: {
text: text.to_s,
features: features
}.to_json,
... | ruby | def analyze(text, features = default_features)
if text.nil? || features.nil?
raise ArgumentError.new(NIL_ARGUMENT_ERROR)
end
response = self.class.post(
"#{@url}/analyze?version=#{@version}",
body: {
text: text.to_s,
features: features
}.to_json,
... | [
"def",
"analyze",
"(",
"text",
",",
"features",
"=",
"default_features",
")",
"if",
"text",
".",
"nil?",
"||",
"features",
".",
"nil?",
"raise",
"ArgumentError",
".",
"new",
"(",
"NIL_ARGUMENT_ERROR",
")",
"end",
"response",
"=",
"self",
".",
"class",
".",... | Initialize instance variables for use later
Sends a POST request to analyze text with certain features enabled | [
"Initialize",
"instance",
"variables",
"for",
"use",
"later",
"Sends",
"a",
"POST",
"request",
"to",
"analyze",
"text",
"with",
"certain",
"features",
"enabled"
] | c5b9118e7f7d91dbd95d9991bd499e1f70e26a25 | https://github.com/thededlier/WatsonNLPWrapper/blob/c5b9118e7f7d91dbd95d9991bd499e1f70e26a25/lib/WatsonNLPWrapper.rb#L23-L41 | train |
thededlier/WatsonNLPWrapper | lib/WatsonNLPWrapper.rb | WatsonNLPWrapper.WatsonNLPApi.default_features | def default_features
{
entities: {
emotion: true,
sentiment: true,
limit: 2
},
keywords: {
emotion: true,
sentiment: true,
limit: 2
}
}
end | ruby | def default_features
{
entities: {
emotion: true,
sentiment: true,
limit: 2
},
keywords: {
emotion: true,
sentiment: true,
limit: 2
}
}
end | [
"def",
"default_features",
"{",
"entities",
":",
"{",
"emotion",
":",
"true",
",",
"sentiment",
":",
"true",
",",
"limit",
":",
"2",
"}",
",",
"keywords",
":",
"{",
"emotion",
":",
"true",
",",
"sentiment",
":",
"true",
",",
"limit",
":",
"2",
"}",
... | Default features if no features specified | [
"Default",
"features",
"if",
"no",
"features",
"specified"
] | c5b9118e7f7d91dbd95d9991bd499e1f70e26a25 | https://github.com/thededlier/WatsonNLPWrapper/blob/c5b9118e7f7d91dbd95d9991bd499e1f70e26a25/lib/WatsonNLPWrapper.rb#L53-L66 | train |
garytaylor/capybara_objects | lib/capybara_objects/page_object.rb | CapybaraObjects.PageObject.visit | def visit
raise ::CapybaraObjects::Exceptions::MissingUrl unless url.present?
page.visit url
validate!
self
end | ruby | def visit
raise ::CapybaraObjects::Exceptions::MissingUrl unless url.present?
page.visit url
validate!
self
end | [
"def",
"visit",
"raise",
"::",
"CapybaraObjects",
"::",
"Exceptions",
"::",
"MissingUrl",
"unless",
"url",
".",
"present?",
"page",
".",
"visit",
"url",
"validate!",
"self",
"end"
] | Visits the pre configured URL to make this page available
@raise ::CapybaraPageObjects::Exceptions::MissingUrl
@return [::CapybaraObjects::PageObject] self - allows chaining of methods | [
"Visits",
"the",
"pre",
"configured",
"URL",
"to",
"make",
"this",
"page",
"available"
] | 7cc2998400a35ceb6f9354cdf949fc59eddcdb12 | https://github.com/garytaylor/capybara_objects/blob/7cc2998400a35ceb6f9354cdf949fc59eddcdb12/lib/capybara_objects/page_object.rb#L41-L46 | train |
belsonheng/spidercrawl | lib/spidercrawl/request.rb | Spidercrawl.Request.curl | def curl
puts "fetching #{@uri.to_s}".green.on_black
start_time = Time.now
begin
c = @c
c.url = @uri.to_s
c.perform
end_time = Time.now
case c.response_code
when 200 then
page = Page.new(@uri, response_code: c.response_code,
... | ruby | def curl
puts "fetching #{@uri.to_s}".green.on_black
start_time = Time.now
begin
c = @c
c.url = @uri.to_s
c.perform
end_time = Time.now
case c.response_code
when 200 then
page = Page.new(@uri, response_code: c.response_code,
... | [
"def",
"curl",
"puts",
"\"fetching #{@uri.to_s}\"",
".",
"green",
".",
"on_black",
"start_time",
"=",
"Time",
".",
"now",
"begin",
"c",
"=",
"@c",
"c",
".",
"url",
"=",
"@uri",
".",
"to_s",
"c",
".",
"perform",
"end_time",
"=",
"Time",
".",
"now",
"cas... | Fetch a page from the given url using libcurl | [
"Fetch",
"a",
"page",
"from",
"the",
"given",
"url",
"using",
"libcurl"
] | 195b067f551597657ad61251dc8d485ec0b0b9c7 | https://github.com/belsonheng/spidercrawl/blob/195b067f551597657ad61251dc8d485ec0b0b9c7/lib/spidercrawl/request.rb#L32-L61 | train |
barkerest/incline | lib/incline/validators/email_validator.rb | Incline.EmailValidator.validate_each | def validate_each(record, attribute, value)
unless value.blank?
record.errors[attribute] << (options[:message] || 'is not a valid email address') unless value =~ VALID_EMAIL_REGEX
end
end | ruby | def validate_each(record, attribute, value)
unless value.blank?
record.errors[attribute] << (options[:message] || 'is not a valid email address') unless value =~ VALID_EMAIL_REGEX
end
end | [
"def",
"validate_each",
"(",
"record",
",",
"attribute",
",",
"value",
")",
"unless",
"value",
".",
"blank?",
"record",
".",
"errors",
"[",
"attribute",
"]",
"<<",
"(",
"options",
"[",
":message",
"]",
"||",
"'is not a valid email address'",
")",
"unless",
"... | Validates attributes to determine if they contain valid email addresses.
Does not perform an in depth check, but does verify that the format is valid. | [
"Validates",
"attributes",
"to",
"determine",
"if",
"they",
"contain",
"valid",
"email",
"addresses",
"."
] | 1ff08db7aa8ab7f86b223268b700bc67d15bb8aa | https://github.com/barkerest/incline/blob/1ff08db7aa8ab7f86b223268b700bc67d15bb8aa/lib/incline/validators/email_validator.rb#L29-L33 | train |
riddopic/garcun | lib/garcon/utility/interpolation.rb | Garcon.Interpolation.interpolate | def interpolate(item = self, parent = nil)
item = render item, parent
item.is_a?(Hash) ? ::Mash.new(item) : item
end | ruby | def interpolate(item = self, parent = nil)
item = render item, parent
item.is_a?(Hash) ? ::Mash.new(item) : item
end | [
"def",
"interpolate",
"(",
"item",
"=",
"self",
",",
"parent",
"=",
"nil",
")",
"item",
"=",
"render",
"item",
",",
"parent",
"item",
".",
"is_a?",
"(",
"Hash",
")",
"?",
"::",
"Mash",
".",
"new",
"(",
"item",
")",
":",
"item",
"end"
] | Interpolate provides a means of externally using Ruby string
interpolation mechinism.
@example
node[:ldap][:basedir] = '/opt'
node[:ldap][:homedir] = '%{basedir}/openldap/slap/happy'
interpolate(node[:ldap])[:homedir] # => "/opt/openldap/slap/happy"
@param [String] item
The string to interpolate.
@... | [
"Interpolate",
"provides",
"a",
"means",
"of",
"externally",
"using",
"Ruby",
"string",
"interpolation",
"mechinism",
"."
] | c2409bd8cf9c14b967a719810dab5269d69b42de | https://github.com/riddopic/garcun/blob/c2409bd8cf9c14b967a719810dab5269d69b42de/lib/garcon/utility/interpolation.rb#L44-L47 | train |
riddopic/garcun | lib/garcon/utility/interpolation.rb | Garcon.Interpolation.render | def render(item, parent = nil)
item = item.to_hash if item.respond_to?(:to_hash)
if item.is_a?(Hash)
item = item.inject({}) { |memo, (k,v)| memo[sym(k)] = v; memo }
item.inject({}) {|memo, (k,v)| memo[sym(k)] = render(v, item); memo}
elsif item.is_a?(Array)
item.map { |i| rende... | ruby | def render(item, parent = nil)
item = item.to_hash if item.respond_to?(:to_hash)
if item.is_a?(Hash)
item = item.inject({}) { |memo, (k,v)| memo[sym(k)] = v; memo }
item.inject({}) {|memo, (k,v)| memo[sym(k)] = render(v, item); memo}
elsif item.is_a?(Array)
item.map { |i| rende... | [
"def",
"render",
"(",
"item",
",",
"parent",
"=",
"nil",
")",
"item",
"=",
"item",
".",
"to_hash",
"if",
"item",
".",
"respond_to?",
"(",
":to_hash",
")",
"if",
"item",
".",
"is_a?",
"(",
"Hash",
")",
"item",
"=",
"item",
".",
"inject",
"(",
"{",
... | Provides recursive interpolation of node objects, using standard
string interpolation methods.
@param [String] item
The string to interpolate.
@param [String, Hash] parent
The string used for substitution.
@return [String]
@api private | [
"Provides",
"recursive",
"interpolation",
"of",
"node",
"objects",
"using",
"standard",
"string",
"interpolation",
"methods",
"."
] | c2409bd8cf9c14b967a719810dab5269d69b42de | https://github.com/riddopic/garcun/blob/c2409bd8cf9c14b967a719810dab5269d69b42de/lib/garcon/utility/interpolation.rb#L76-L88 | train |
chrisjones-tripletri/action_command | lib/action_command/executable_transaction.rb | ActionCommand.ExecutableTransaction.execute | def execute(result)
if ActiveRecord::Base.connection.open_transactions >= 1
super(result)
else
result.info('start_transaction')
ActiveRecord::Base.transaction do
super(result)
if result.ok?
result.info('end_transaction')
else
resu... | ruby | def execute(result)
if ActiveRecord::Base.connection.open_transactions >= 1
super(result)
else
result.info('start_transaction')
ActiveRecord::Base.transaction do
super(result)
if result.ok?
result.info('end_transaction')
else
resu... | [
"def",
"execute",
"(",
"result",
")",
"if",
"ActiveRecord",
"::",
"Base",
".",
"connection",
".",
"open_transactions",
">=",
"1",
"super",
"(",
"result",
")",
"else",
"result",
".",
"info",
"(",
"'start_transaction'",
")",
"ActiveRecord",
"::",
"Base",
".",
... | starts a transaction only if we are not already within one. | [
"starts",
"a",
"transaction",
"only",
"if",
"we",
"are",
"not",
"already",
"within",
"one",
"."
] | 9b9a8ba30e407ca6d88a62a164d1dc22ba149874 | https://github.com/chrisjones-tripletri/action_command/blob/9b9a8ba30e407ca6d88a62a164d1dc22ba149874/lib/action_command/executable_transaction.rb#L8-L23 | train |
hongshu-corp/ule_page | lib/ule_page/site_prism_extender.rb | UlePage.SitePrismExtender.element_collection | def element_collection(collection_name, *find_args)
build collection_name, *find_args do
define_method collection_name.to_s do |*runtime_args, &element_block|
self.class.raise_if_block(self, collection_name.to_s, !element_block.nil?)
page.all(*find_args)
end
end
end | ruby | def element_collection(collection_name, *find_args)
build collection_name, *find_args do
define_method collection_name.to_s do |*runtime_args, &element_block|
self.class.raise_if_block(self, collection_name.to_s, !element_block.nil?)
page.all(*find_args)
end
end
end | [
"def",
"element_collection",
"(",
"collection_name",
",",
"*",
"find_args",
")",
"build",
"collection_name",
",",
"find_args",
"do",
"define_method",
"collection_name",
".",
"to_s",
"do",
"|",
"*",
"runtime_args",
",",
"&",
"element_block",
"|",
"self",
".",
"cl... | why define this method?
if we use the elements method directly, it will be conflicted with RSpec.Mather.BuiltIn.All.elements.
I have not found one good method to solve the confliction. | [
"why",
"define",
"this",
"method?",
"if",
"we",
"use",
"the",
"elements",
"method",
"directly",
"it",
"will",
"be",
"conflicted",
"with",
"RSpec",
".",
"Mather",
".",
"BuiltIn",
".",
"All",
".",
"elements",
".",
"I",
"have",
"not",
"found",
"one",
"good"... | 599a1c1eb5c2df3b38b96896942d280284fd8ffa | https://github.com/hongshu-corp/ule_page/blob/599a1c1eb5c2df3b38b96896942d280284fd8ffa/lib/ule_page/site_prism_extender.rb#L11-L18 | train |
hongshu-corp/ule_page | lib/ule_page/site_prism_extender.rb | UlePage.SitePrismExtender.define_elements_js | def define_elements_js(model_class, excluded_props = [])
attributes = model_class.new.attributes.keys
attributes.each do |attri|
unless excluded_props.include? attri
selector = "#"+attri
# self.class.send "element", attri.to_sym, selector
element attri, selector
... | ruby | def define_elements_js(model_class, excluded_props = [])
attributes = model_class.new.attributes.keys
attributes.each do |attri|
unless excluded_props.include? attri
selector = "#"+attri
# self.class.send "element", attri.to_sym, selector
element attri, selector
... | [
"def",
"define_elements_js",
"(",
"model_class",
",",
"excluded_props",
"=",
"[",
"]",
")",
"attributes",
"=",
"model_class",
".",
"new",
".",
"attributes",
".",
"keys",
"attributes",
".",
"each",
"do",
"|",
"attri",
"|",
"unless",
"excluded_props",
".",
"in... | instead of the rails traditional form
in js mode, there is no prefix before the element name | [
"instead",
"of",
"the",
"rails",
"traditional",
"form",
"in",
"js",
"mode",
"there",
"is",
"no",
"prefix",
"before",
"the",
"element",
"name"
] | 599a1c1eb5c2df3b38b96896942d280284fd8ffa | https://github.com/hongshu-corp/ule_page/blob/599a1c1eb5c2df3b38b96896942d280284fd8ffa/lib/ule_page/site_prism_extender.rb#L66-L77 | train |
spiegela/MultiBitField | lib/multi_bit_field.rb | MultiBitField.ClassMethods.range_for | def range_for column_name, field_name
column = @@bitfields[column_name]
raise ArgumentError, "Unknown column for bitfield: #{column_name}" if column.nil?
return column[field_name] if column[field_name]
raise ArugmentError, "Unknown field: #{field_name} for column #{column_name}"
end | ruby | def range_for column_name, field_name
column = @@bitfields[column_name]
raise ArgumentError, "Unknown column for bitfield: #{column_name}" if column.nil?
return column[field_name] if column[field_name]
raise ArugmentError, "Unknown field: #{field_name} for column #{column_name}"
end | [
"def",
"range_for",
"column_name",
",",
"field_name",
"column",
"=",
"@@bitfields",
"[",
"column_name",
"]",
"raise",
"ArgumentError",
",",
"\"Unknown column for bitfield: #{column_name}\"",
"if",
"column",
".",
"nil?",
"return",
"column",
"[",
"field_name",
"]",
"if"... | Returns the column by name
+column_for
@param [ Symbol ] column_name column name that stores the bitfield integer | [
"Returns",
"the",
"column",
"by",
"name"
] | 53674ba73caea8d871510d02271b71edaa1335f1 | https://github.com/spiegela/MultiBitField/blob/53674ba73caea8d871510d02271b71edaa1335f1/lib/multi_bit_field.rb#L72-L77 | train |
spiegela/MultiBitField | lib/multi_bit_field.rb | MultiBitField.ClassMethods.reset_mask_for | def reset_mask_for column_name, *fields
fields = bitfields if fields.empty?
max = bitfield_max(column_name)
(0..max).sum{|i| 2 ** i} - only_mask_for(column_name, *fields)
end | ruby | def reset_mask_for column_name, *fields
fields = bitfields if fields.empty?
max = bitfield_max(column_name)
(0..max).sum{|i| 2 ** i} - only_mask_for(column_name, *fields)
end | [
"def",
"reset_mask_for",
"column_name",
",",
"*",
"fields",
"fields",
"=",
"bitfields",
"if",
"fields",
".",
"empty?",
"max",
"=",
"bitfield_max",
"(",
"column_name",
")",
"(",
"0",
"..",
"max",
")",
".",
"sum",
"{",
"|",
"i",
"|",
"2",
"**",
"i",
"}... | Returns a "reset mask" for a list of fields
+reset_mask_for :fields
@example
user.reset_mask_for :field
@param [ Symbol ] column name of the column these fields are in
@param [ Symbol ] field(s) name of the field(s) for the mask | [
"Returns",
"a",
"reset",
"mask",
"for",
"a",
"list",
"of",
"fields"
] | 53674ba73caea8d871510d02271b71edaa1335f1 | https://github.com/spiegela/MultiBitField/blob/53674ba73caea8d871510d02271b71edaa1335f1/lib/multi_bit_field.rb#L88-L92 | train |
spiegela/MultiBitField | lib/multi_bit_field.rb | MultiBitField.ClassMethods.increment_mask_for | def increment_mask_for column_name, *fields
fields = bitfields if fields.empty?
column = @@bitfields[column_name]
raise ArgumentError, "Unknown column for bitfield: #{column_name}" if column.nil?
fields.sum do |field_name|
raise ArugmentError, "Unknown field: #{field_name} for column #{c... | ruby | def increment_mask_for column_name, *fields
fields = bitfields if fields.empty?
column = @@bitfields[column_name]
raise ArgumentError, "Unknown column for bitfield: #{column_name}" if column.nil?
fields.sum do |field_name|
raise ArugmentError, "Unknown field: #{field_name} for column #{c... | [
"def",
"increment_mask_for",
"column_name",
",",
"*",
"fields",
"fields",
"=",
"bitfields",
"if",
"fields",
".",
"empty?",
"column",
"=",
"@@bitfields",
"[",
"column_name",
"]",
"raise",
"ArgumentError",
",",
"\"Unknown column for bitfield: #{column_name}\"",
"if",
"c... | Returns an "increment mask" for a list of fields
+increment_mask_for :fields
@example
user.increment_mask_for :field
@param [ Symbol ] column name of the column these fields are in
@param [ Symbol ] field(s) name of the field(s) for the mask | [
"Returns",
"an",
"increment",
"mask",
"for",
"a",
"list",
"of",
"fields"
] | 53674ba73caea8d871510d02271b71edaa1335f1 | https://github.com/spiegela/MultiBitField/blob/53674ba73caea8d871510d02271b71edaa1335f1/lib/multi_bit_field.rb#L103-L111 | train |
spiegela/MultiBitField | lib/multi_bit_field.rb | MultiBitField.ClassMethods.only_mask_for | def only_mask_for column_name, *fields
fields = bitfields if fields.empty?
column = @@bitfields[column_name]
max = bitfield_max(column_name)
raise ArgumentError, "Unknown column for bitfield: #{column_name}" if column.nil?
column.sum do |field_name, range|
fields.include?(field_na... | ruby | def only_mask_for column_name, *fields
fields = bitfields if fields.empty?
column = @@bitfields[column_name]
max = bitfield_max(column_name)
raise ArgumentError, "Unknown column for bitfield: #{column_name}" if column.nil?
column.sum do |field_name, range|
fields.include?(field_na... | [
"def",
"only_mask_for",
"column_name",
",",
"*",
"fields",
"fields",
"=",
"bitfields",
"if",
"fields",
".",
"empty?",
"column",
"=",
"@@bitfields",
"[",
"column_name",
"]",
"max",
"=",
"bitfield_max",
"(",
"column_name",
")",
"raise",
"ArgumentError",
",",
"\"... | Returns an "only mask" for a list of fields
+only_mask_for :fields
@example
user.only_mask_for :field
@param [ Symbol ] column name of the column these fields are in
@param [ Symbol ] field(s) name of the field(s) for the mask | [
"Returns",
"an",
"only",
"mask",
"for",
"a",
"list",
"of",
"fields"
] | 53674ba73caea8d871510d02271b71edaa1335f1 | https://github.com/spiegela/MultiBitField/blob/53674ba73caea8d871510d02271b71edaa1335f1/lib/multi_bit_field.rb#L122-L138 | train |
spiegela/MultiBitField | lib/multi_bit_field.rb | MultiBitField.ClassMethods.count_by | def count_by column_name, field
inc = increment_mask_for column_name, field
only = only_mask_for column_name, field
# Create super-special-bitfield-grouping-query w/ AREL
sql = arel_table.
project("count(#{primary_key}) as #{field}_count, (#{column_name} & #{only})/#{inc} as #{field}").
... | ruby | def count_by column_name, field
inc = increment_mask_for column_name, field
only = only_mask_for column_name, field
# Create super-special-bitfield-grouping-query w/ AREL
sql = arel_table.
project("count(#{primary_key}) as #{field}_count, (#{column_name} & #{only})/#{inc} as #{field}").
... | [
"def",
"count_by",
"column_name",
",",
"field",
"inc",
"=",
"increment_mask_for",
"column_name",
",",
"field",
"only",
"=",
"only_mask_for",
"column_name",
",",
"field",
"# Create super-special-bitfield-grouping-query w/ AREL",
"sql",
"=",
"arel_table",
".",
"project",
... | Counts resources grouped by a bitfield
+count_by :column, :fields
@example
user.count_by :counter, :monthly
@param [ Symbol ] column name of the column these fields are in
@param [ Symbol ] field(s) name of the field(s) to reset | [
"Counts",
"resources",
"grouped",
"by",
"a",
"bitfield"
] | 53674ba73caea8d871510d02271b71edaa1335f1 | https://github.com/spiegela/MultiBitField/blob/53674ba73caea8d871510d02271b71edaa1335f1/lib/multi_bit_field.rb#L179-L187 | train |
spiegela/MultiBitField | lib/multi_bit_field.rb | MultiBitField.InstanceMethods.reset_bitfields | def reset_bitfields column_name, *fields
mask = self.class.reset_mask_for column_name, *fields
self[column_name] = self[column_name] & mask
save
end | ruby | def reset_bitfields column_name, *fields
mask = self.class.reset_mask_for column_name, *fields
self[column_name] = self[column_name] & mask
save
end | [
"def",
"reset_bitfields",
"column_name",
",",
"*",
"fields",
"mask",
"=",
"self",
".",
"class",
".",
"reset_mask_for",
"column_name",
",",
"fields",
"self",
"[",
"column_name",
"]",
"=",
"self",
"[",
"column_name",
"]",
"&",
"mask",
"save",
"end"
] | Sets one or more bitfields to 0 within a column
+reset_bitfield :column, :fields
@example
user.reset_bitfield :column, :daily, :monthly
@param [ Symbol ] column name of the column these fields are in
@param [ Symbol ] field(s) name of the field(s) to reset | [
"Sets",
"one",
"or",
"more",
"bitfields",
"to",
"0",
"within",
"a",
"column"
] | 53674ba73caea8d871510d02271b71edaa1335f1 | https://github.com/spiegela/MultiBitField/blob/53674ba73caea8d871510d02271b71edaa1335f1/lib/multi_bit_field.rb#L210-L214 | train |
spiegela/MultiBitField | lib/multi_bit_field.rb | MultiBitField.InstanceMethods.increment_bitfields | def increment_bitfields column_name, *fields
mask = self.class.increment_mask_for column_name, *fields
self[column_name] = self[column_name] += mask
save
end | ruby | def increment_bitfields column_name, *fields
mask = self.class.increment_mask_for column_name, *fields
self[column_name] = self[column_name] += mask
save
end | [
"def",
"increment_bitfields",
"column_name",
",",
"*",
"fields",
"mask",
"=",
"self",
".",
"class",
".",
"increment_mask_for",
"column_name",
",",
"fields",
"self",
"[",
"column_name",
"]",
"=",
"self",
"[",
"column_name",
"]",
"+=",
"mask",
"save",
"end"
] | Increases one or more bitfields by 1 value
+increment_bitfield :column, :fields
@example
user.increment_bitfield :column, :daily, :monthly
@param [ Symbol ] column name of the column these fields are in
@param [ Symbol ] field(s) name of the field(s) to reset | [
"Increases",
"one",
"or",
"more",
"bitfields",
"by",
"1",
"value"
] | 53674ba73caea8d871510d02271b71edaa1335f1 | https://github.com/spiegela/MultiBitField/blob/53674ba73caea8d871510d02271b71edaa1335f1/lib/multi_bit_field.rb#L226-L230 | train |
openstax/connect-rails | lib/openstax/connect/current_user_manager.rb | OpenStax::Connect.CurrentUserManager.connect_current_user= | def connect_current_user=(user)
@connect_current_user = user || User.anonymous
@app_current_user = user_provider.connect_user_to_app_user(@connect_current_user)
if @connect_current_user.is_anonymous?
@session[:user_id] = nil
@cookies.delete(:secure_user_id)
else
@session... | ruby | def connect_current_user=(user)
@connect_current_user = user || User.anonymous
@app_current_user = user_provider.connect_user_to_app_user(@connect_current_user)
if @connect_current_user.is_anonymous?
@session[:user_id] = nil
@cookies.delete(:secure_user_id)
else
@session... | [
"def",
"connect_current_user",
"=",
"(",
"user",
")",
"@connect_current_user",
"=",
"user",
"||",
"User",
".",
"anonymous",
"@app_current_user",
"=",
"user_provider",
".",
"connect_user_to_app_user",
"(",
"@connect_current_user",
")",
"if",
"@connect_current_user",
".",... | Sets the current connect user, updates the app user, and also updates the
session and cookie state. | [
"Sets",
"the",
"current",
"connect",
"user",
"updates",
"the",
"app",
"user",
"and",
"also",
"updates",
"the",
"session",
"and",
"cookie",
"state",
"."
] | 4ac16cfa4316f9f0ba4df8b8d6dd960f90dbb962 | https://github.com/openstax/connect-rails/blob/4ac16cfa4316f9f0ba4df8b8d6dd960f90dbb962/lib/openstax/connect/current_user_manager.rb#L80-L93 | train |
vidibus/vidibus-encoder | lib/vidibus/encoder.rb | Vidibus.Encoder.register_format | def register_format(name, processor)
unless processor.new.is_a?(Vidibus::Encoder::Base)
raise(ArgumentError, 'The processor must inherit Vidibus::Encoder::Base')
end
@formats ||= {}
@formats[name] = processor
end | ruby | def register_format(name, processor)
unless processor.new.is_a?(Vidibus::Encoder::Base)
raise(ArgumentError, 'The processor must inherit Vidibus::Encoder::Base')
end
@formats ||= {}
@formats[name] = processor
end | [
"def",
"register_format",
"(",
"name",
",",
"processor",
")",
"unless",
"processor",
".",
"new",
".",
"is_a?",
"(",
"Vidibus",
"::",
"Encoder",
"::",
"Base",
")",
"raise",
"(",
"ArgumentError",
",",
"'The processor must inherit Vidibus::Encoder::Base'",
")",
"end"... | Register a new encoder format. | [
"Register",
"a",
"new",
"encoder",
"format",
"."
] | 71f682eeb28703b811fd7cd9f9b1b127a7c691c3 | https://github.com/vidibus/vidibus-encoder/blob/71f682eeb28703b811fd7cd9f9b1b127a7c691c3/lib/vidibus/encoder.rb#L23-L29 | train |
cknadler/rcomp | lib/rcomp/conf.rb | RComp.Conf.read_conf_file | def read_conf_file
conf = {}
if File.exists?(CONF_PATH) && File.size?(CONF_PATH)
# Store valid conf keys
YAML.load_file(CONF_PATH).each do |key, value|
if VALID_KEYS.include? key
conf[key] = value
else
say "Invalid configuration key: #{key}"
... | ruby | def read_conf_file
conf = {}
if File.exists?(CONF_PATH) && File.size?(CONF_PATH)
# Store valid conf keys
YAML.load_file(CONF_PATH).each do |key, value|
if VALID_KEYS.include? key
conf[key] = value
else
say "Invalid configuration key: #{key}"
... | [
"def",
"read_conf_file",
"conf",
"=",
"{",
"}",
"if",
"File",
".",
"exists?",
"(",
"CONF_PATH",
")",
"&&",
"File",
".",
"size?",
"(",
"CONF_PATH",
")",
"# Store valid conf keys",
"YAML",
".",
"load_file",
"(",
"CONF_PATH",
")",
".",
"each",
"do",
"|",
"k... | Read the config options from RComp's configuration file
Returns a Hash of config options | [
"Read",
"the",
"config",
"options",
"from",
"RComp",
"s",
"configuration",
"file"
] | 76fe71e1ef3b13923738ea6ab9cd502fe2f64f51 | https://github.com/cknadler/rcomp/blob/76fe71e1ef3b13923738ea6ab9cd502fe2f64f51/lib/rcomp/conf.rb#L66-L79 | train |
plukevdh/monet | lib/monet/baseline_control.rb | Monet.BaselineControl.rebase | def rebase(image)
new_path = @router.baseline_dir(image.name)
create_path_for_file(new_path)
FileUtils.move(image.path, new_path)
Monet::Image.new(new_path)
end | ruby | def rebase(image)
new_path = @router.baseline_dir(image.name)
create_path_for_file(new_path)
FileUtils.move(image.path, new_path)
Monet::Image.new(new_path)
end | [
"def",
"rebase",
"(",
"image",
")",
"new_path",
"=",
"@router",
".",
"baseline_dir",
"(",
"image",
".",
"name",
")",
"create_path_for_file",
"(",
"new_path",
")",
"FileUtils",
".",
"move",
"(",
"image",
".",
"path",
",",
"new_path",
")",
"Monet",
"::",
"... | returns a new image for the moved image | [
"returns",
"a",
"new",
"image",
"for",
"the",
"moved",
"image"
] | 4e2a413e70371d0b3a6b05a2675c7b4a28e6c30b | https://github.com/plukevdh/monet/blob/4e2a413e70371d0b3a6b05a2675c7b4a28e6c30b/lib/monet/baseline_control.rb#L67-L74 | train |
phildionne/associates | lib/associates/persistence.rb | Associates.Persistence.save | def save(*args)
return false unless valid?
ActiveRecord::Base.transaction do
begin
associates.all? do |associate|
send(associate.name).send(:save!, *args)
end
rescue ActiveRecord::RecordInvalid
false
end
end
end | ruby | def save(*args)
return false unless valid?
ActiveRecord::Base.transaction do
begin
associates.all? do |associate|
send(associate.name).send(:save!, *args)
end
rescue ActiveRecord::RecordInvalid
false
end
end
end | [
"def",
"save",
"(",
"*",
"args",
")",
"return",
"false",
"unless",
"valid?",
"ActiveRecord",
"::",
"Base",
".",
"transaction",
"do",
"begin",
"associates",
".",
"all?",
"do",
"|",
"associate",
"|",
"send",
"(",
"associate",
".",
"name",
")",
".",
"send",... | Persists each associated model
@return [Boolean] Wether or not all models are valid and persited | [
"Persists",
"each",
"associated",
"model"
] | 630edcc47340a73ad787feaf2cdf326b4487bb9f | https://github.com/phildionne/associates/blob/630edcc47340a73ad787feaf2cdf326b4487bb9f/lib/associates/persistence.rb#L16-L28 | train |
rlister/auger | lib/auger/project.rb | Auger.Project.connections | def connections(*roles)
if roles.empty?
@connections
else
@connections.select { |c| c.roles.empty? or !(c.roles & roles).empty? }
end
end | ruby | def connections(*roles)
if roles.empty?
@connections
else
@connections.select { |c| c.roles.empty? or !(c.roles & roles).empty? }
end
end | [
"def",
"connections",
"(",
"*",
"roles",
")",
"if",
"roles",
".",
"empty?",
"@connections",
"else",
"@connections",
".",
"select",
"{",
"|",
"c",
"|",
"c",
".",
"roles",
".",
"empty?",
"or",
"!",
"(",
"c",
".",
"roles",
"&",
"roles",
")",
".",
"emp... | return all connections, or those matching list of roles;
connections with no roles match all, or find intersection with roles list | [
"return",
"all",
"connections",
"or",
"those",
"matching",
"list",
"of",
"roles",
";",
"connections",
"with",
"no",
"roles",
"match",
"all",
"or",
"find",
"intersection",
"with",
"roles",
"list"
] | 45e220668251834cdf0cec78da5918aee6418d8e | https://github.com/rlister/auger/blob/45e220668251834cdf0cec78da5918aee6418d8e/lib/auger/project.rb#L54-L60 | train |
arvicco/poster | lib/poster/rss.rb | Poster.Rss.extract_data | def extract_data item, text_limit: 1200
link = item.link
desc = item.description
title = item.title.force_encoding('UTF-8')
# Extract main image
case
when desc.match(/\|.*\|/m)
img, terms, text = desc.split('|')
when desc.include?('|')
img, text = desc.split('|... | ruby | def extract_data item, text_limit: 1200
link = item.link
desc = item.description
title = item.title.force_encoding('UTF-8')
# Extract main image
case
when desc.match(/\|.*\|/m)
img, terms, text = desc.split('|')
when desc.include?('|')
img, text = desc.split('|... | [
"def",
"extract_data",
"item",
",",
"text_limit",
":",
"1200",
"link",
"=",
"item",
".",
"link",
"desc",
"=",
"item",
".",
"description",
"title",
"=",
"item",
".",
"title",
".",
"force_encoding",
"(",
"'UTF-8'",
")",
"# Extract main image",
"case",
"when",
... | Extract news data from a feed item | [
"Extract",
"news",
"data",
"from",
"a",
"feed",
"item"
] | a5f22f7cb02116ab4dc5b7f2bdb672306b3dac63 | https://github.com/arvicco/poster/blob/a5f22f7cb02116ab4dc5b7f2bdb672306b3dac63/lib/poster/rss.rb#L17-L57 | train |
rnhurt/google_anymote | lib/google_anymote/pair.rb | GoogleAnymote.Pair.start_pairing | def start_pairing
@gtv = GoogleAnymote::TV.new(@cert, host, 9551 + 1)
# Let the TV know that we want to pair with it
send_message(pair, OuterMessage::MessageType::MESSAGE_TYPE_PAIRING_REQUEST)
# Build the options and send them to the TV
options = Options.new
encoding = O... | ruby | def start_pairing
@gtv = GoogleAnymote::TV.new(@cert, host, 9551 + 1)
# Let the TV know that we want to pair with it
send_message(pair, OuterMessage::MessageType::MESSAGE_TYPE_PAIRING_REQUEST)
# Build the options and send them to the TV
options = Options.new
encoding = O... | [
"def",
"start_pairing",
"@gtv",
"=",
"GoogleAnymote",
"::",
"TV",
".",
"new",
"(",
"@cert",
",",
"host",
",",
"9551",
"+",
"1",
")",
"# Let the TV know that we want to pair with it",
"send_message",
"(",
"pair",
",",
"OuterMessage",
"::",
"MessageType",
"::",
"M... | Initializes the Pair class
@param [Object] cert SSL certificate for this client
@param [String] host hostname or IP address of the Google TV
@param [String] client_name name of the client your connecting from
@param [String] service_name name of the service (generally 'AnyMote')
@return an instance of Pair
Star... | [
"Initializes",
"the",
"Pair",
"class"
] | 2992aee3590df9e2cf6d31cebfba2e14be926b8f | https://github.com/rnhurt/google_anymote/blob/2992aee3590df9e2cf6d31cebfba2e14be926b8f/lib/google_anymote/pair.rb#L36-L61 | train |
rnhurt/google_anymote | lib/google_anymote/pair.rb | GoogleAnymote.Pair.complete_pairing | def complete_pairing(code)
# Send secret code to the TV to compete the pairing process
secret = Secret.new
secret.secret = encode_hex_secret(code)
outer = send_message(secret, OuterMessage::MessageType::MESSAGE_TYPE_SECRET)
# Clean up
@gtv.ssl_client.close
raise PairingFailed... | ruby | def complete_pairing(code)
# Send secret code to the TV to compete the pairing process
secret = Secret.new
secret.secret = encode_hex_secret(code)
outer = send_message(secret, OuterMessage::MessageType::MESSAGE_TYPE_SECRET)
# Clean up
@gtv.ssl_client.close
raise PairingFailed... | [
"def",
"complete_pairing",
"(",
"code",
")",
"# Send secret code to the TV to compete the pairing process",
"secret",
"=",
"Secret",
".",
"new",
"secret",
".",
"secret",
"=",
"encode_hex_secret",
"(",
"code",
")",
"outer",
"=",
"send_message",
"(",
"secret",
",",
"O... | Complete the pairing process
@param [String] code The code displayed on the Google TV we are trying to pair with. | [
"Complete",
"the",
"pairing",
"process"
] | 2992aee3590df9e2cf6d31cebfba2e14be926b8f | https://github.com/rnhurt/google_anymote/blob/2992aee3590df9e2cf6d31cebfba2e14be926b8f/lib/google_anymote/pair.rb#L67-L77 | train |
rnhurt/google_anymote | lib/google_anymote/pair.rb | GoogleAnymote.Pair.send_message | def send_message(msg, type)
# Build the message and get it's size
message = wrap_message(msg, type).serialize_to_string
message_size = [message.length].pack('N')
# Write the message to the SSL client and get the response
@gtv.ssl_client.write(message_size + message)
data = ""
... | ruby | def send_message(msg, type)
# Build the message and get it's size
message = wrap_message(msg, type).serialize_to_string
message_size = [message.length].pack('N')
# Write the message to the SSL client and get the response
@gtv.ssl_client.write(message_size + message)
data = ""
... | [
"def",
"send_message",
"(",
"msg",
",",
"type",
")",
"# Build the message and get it's size",
"message",
"=",
"wrap_message",
"(",
"msg",
",",
"type",
")",
".",
"serialize_to_string",
"message_size",
"=",
"[",
"message",
".",
"length",
"]",
".",
"pack",
"(",
"... | Format and send the message to the GoogleTV
@param [String] msg message to send
@param [Object] type type of message to send
@return [Object] the OuterMessage response from the TV | [
"Format",
"and",
"send",
"the",
"message",
"to",
"the",
"GoogleTV"
] | 2992aee3590df9e2cf6d31cebfba2e14be926b8f | https://github.com/rnhurt/google_anymote/blob/2992aee3590df9e2cf6d31cebfba2e14be926b8f/lib/google_anymote/pair.rb#L89-L105 | train |
rnhurt/google_anymote | lib/google_anymote/pair.rb | GoogleAnymote.Pair.wrap_message | def wrap_message(msg, type)
# Wrap it in an envelope
outer = OuterMessage.new
outer.protocol_version = 1
outer.status = OuterMessage::Status::STATUS_OK
outer.type = type
outer.payload = msg.serialize_to_string
return outer
end | ruby | def wrap_message(msg, type)
# Wrap it in an envelope
outer = OuterMessage.new
outer.protocol_version = 1
outer.status = OuterMessage::Status::STATUS_OK
outer.type = type
outer.payload = msg.serialize_to_string
return outer
end | [
"def",
"wrap_message",
"(",
"msg",
",",
"type",
")",
"# Wrap it in an envelope",
"outer",
"=",
"OuterMessage",
".",
"new",
"outer",
".",
"protocol_version",
"=",
"1",
"outer",
".",
"status",
"=",
"OuterMessage",
"::",
"Status",
"::",
"STATUS_OK",
"outer",
".",... | Wrap the message in an OuterMessage
@param [String] msg message to send
@param [Object] type type of message to send
@return [Object] a properly formatted OuterMessage | [
"Wrap",
"the",
"message",
"in",
"an",
"OuterMessage"
] | 2992aee3590df9e2cf6d31cebfba2e14be926b8f | https://github.com/rnhurt/google_anymote/blob/2992aee3590df9e2cf6d31cebfba2e14be926b8f/lib/google_anymote/pair.rb#L113-L122 | train |
rnhurt/google_anymote | lib/google_anymote/pair.rb | GoogleAnymote.Pair.encode_hex_secret | def encode_hex_secret secret
# TODO(stevenle): Something further encodes the secret to a 64-char hex
# string. For now, use adb logcat to figure out what the expected challenge
# is. Eventually, make sure the encoding matches the server reference
# implementation:
# http://code.google.co... | ruby | def encode_hex_secret secret
# TODO(stevenle): Something further encodes the secret to a 64-char hex
# string. For now, use adb logcat to figure out what the expected challenge
# is. Eventually, make sure the encoding matches the server reference
# implementation:
# http://code.google.co... | [
"def",
"encode_hex_secret",
"secret",
"# TODO(stevenle): Something further encodes the secret to a 64-char hex",
"# string. For now, use adb logcat to figure out what the expected challenge",
"# is. Eventually, make sure the encoding matches the server reference",
"# implementation:",
"# http://code... | Encode the secret from the TV into an OpenSSL Digest
@param [String] secret pairing code from the TV's screen
@return [Digest] OpenSSL Digest containing the encoded secret | [
"Encode",
"the",
"secret",
"from",
"the",
"TV",
"into",
"an",
"OpenSSL",
"Digest"
] | 2992aee3590df9e2cf6d31cebfba2e14be926b8f | https://github.com/rnhurt/google_anymote/blob/2992aee3590df9e2cf6d31cebfba2e14be926b8f/lib/google_anymote/pair.rb#L129-L148 | train |
robfors/ruby-sumac | lib/sumac/id_allocator.rb | Sumac.IDAllocator.free | def free(id)
enclosing_range_index = @allocated_ranges.index { |range| range.last >= id && range.first <= id }
enclosing_range = @allocated_ranges[enclosing_range_index]
if enclosing_range.size == 1
@allocated_ranges.delete(enclosing_range)
elsif enclosing_range.first == id
@allo... | ruby | def free(id)
enclosing_range_index = @allocated_ranges.index { |range| range.last >= id && range.first <= id }
enclosing_range = @allocated_ranges[enclosing_range_index]
if enclosing_range.size == 1
@allocated_ranges.delete(enclosing_range)
elsif enclosing_range.first == id
@allo... | [
"def",
"free",
"(",
"id",
")",
"enclosing_range_index",
"=",
"@allocated_ranges",
".",
"index",
"{",
"|",
"range",
"|",
"range",
".",
"last",
">=",
"id",
"&&",
"range",
".",
"first",
"<=",
"id",
"}",
"enclosing_range",
"=",
"@allocated_ranges",
"[",
"enclo... | Return +id+ back to the allocator so it can be allocated again in the future.
@note trying to free an unallocated id will cause undefined behavior
@return [void] | [
"Return",
"+",
"id",
"+",
"back",
"to",
"the",
"allocator",
"so",
"it",
"can",
"be",
"allocated",
"again",
"in",
"the",
"future",
"."
] | 524fa68b7d1bb10a74baa69cd594ab2b8cae20a3 | https://github.com/robfors/ruby-sumac/blob/524fa68b7d1bb10a74baa69cd594ab2b8cae20a3/lib/sumac/id_allocator.rb#L30-L43 | train |
barkerest/incline | lib/incline/extensions/action_view_base.rb | Incline::Extensions.ActionViewBase.full_title | def full_title(page_title = '')
aname = Rails.application.app_name.strip
return aname if page_title.blank?
"#{page_title.strip} | #{aname}"
end | ruby | def full_title(page_title = '')
aname = Rails.application.app_name.strip
return aname if page_title.blank?
"#{page_title.strip} | #{aname}"
end | [
"def",
"full_title",
"(",
"page_title",
"=",
"''",
")",
"aname",
"=",
"Rails",
".",
"application",
".",
"app_name",
".",
"strip",
"return",
"aname",
"if",
"page_title",
".",
"blank?",
"\"#{page_title.strip} | #{aname}\"",
"end"
] | Gets the full title of the page.
If +page_title+ is left blank, then the +app_name+ attribute of your application is returned.
Otherwise the +app_name+ attribute is appended to the +page_title+ after a pipe symbol.
# app_name = 'My App'
full_title # 'My App'
full_title 'Welcome' # 'We... | [
"Gets",
"the",
"full",
"title",
"of",
"the",
"page",
"."
] | 1ff08db7aa8ab7f86b223268b700bc67d15bb8aa | https://github.com/barkerest/incline/blob/1ff08db7aa8ab7f86b223268b700bc67d15bb8aa/lib/incline/extensions/action_view_base.rb#L24-L28 | train |
barkerest/incline | lib/incline/extensions/action_view_base.rb | Incline::Extensions.ActionViewBase.glyph | def glyph(name, size = '')
size =
case size.to_s.downcase
when 'small', 'sm'
'glyphicon-small'
when 'large', 'lg'
'glyphicon-large'
else
nil
end
name = name.to_s.strip
return nil if name.blank?
re... | ruby | def glyph(name, size = '')
size =
case size.to_s.downcase
when 'small', 'sm'
'glyphicon-small'
when 'large', 'lg'
'glyphicon-large'
else
nil
end
name = name.to_s.strip
return nil if name.blank?
re... | [
"def",
"glyph",
"(",
"name",
",",
"size",
"=",
"''",
")",
"size",
"=",
"case",
"size",
".",
"to_s",
".",
"downcase",
"when",
"'small'",
",",
"'sm'",
"'glyphicon-small'",
"when",
"'large'",
",",
"'lg'",
"'glyphicon-large'",
"else",
"nil",
"end",
"name",
"... | Shows a glyph with an optional size.
The glyph +name+ should be a valid {bootstrap glyph}[http://getbootstrap.com/components/#glyphicons] name.
Strip the prefixed 'glyphicon-' from the name.
The size can be left blank, or set to 'small' or 'large'.
glyph('cloud') # '<i class="glyphicon glyphicon-cloud"></i>... | [
"Shows",
"a",
"glyph",
"with",
"an",
"optional",
"size",
"."
] | 1ff08db7aa8ab7f86b223268b700bc67d15bb8aa | https://github.com/barkerest/incline/blob/1ff08db7aa8ab7f86b223268b700bc67d15bb8aa/lib/incline/extensions/action_view_base.rb#L53-L71 | train |
barkerest/incline | lib/incline/extensions/action_view_base.rb | Incline::Extensions.ActionViewBase.fmt_num | def fmt_num(value, places = 2)
return nil if value.blank?
value =
if value.respond_to?(:to_f)
value.to_f
else
nil
end
return nil unless value.is_a?(::Float)
"%0.#{places}f" % value.round(places)
end | ruby | def fmt_num(value, places = 2)
return nil if value.blank?
value =
if value.respond_to?(:to_f)
value.to_f
else
nil
end
return nil unless value.is_a?(::Float)
"%0.#{places}f" % value.round(places)
end | [
"def",
"fmt_num",
"(",
"value",
",",
"places",
"=",
"2",
")",
"return",
"nil",
"if",
"value",
".",
"blank?",
"value",
"=",
"if",
"value",
".",
"respond_to?",
"(",
":to_f",
")",
"value",
".",
"to_f",
"else",
"nil",
"end",
"return",
"nil",
"unless",
"v... | Formats a number with the specified number of decimal places.
The +value+ can be any valid numeric expression that can be converted into a float. | [
"Formats",
"a",
"number",
"with",
"the",
"specified",
"number",
"of",
"decimal",
"places",
"."
] | 1ff08db7aa8ab7f86b223268b700bc67d15bb8aa | https://github.com/barkerest/incline/blob/1ff08db7aa8ab7f86b223268b700bc67d15bb8aa/lib/incline/extensions/action_view_base.rb#L299-L312 | train |
barkerest/incline | lib/incline/extensions/action_view_base.rb | Incline::Extensions.ActionViewBase.panel | def panel(title, options = { }, &block)
options = {
type: 'primary',
size: 6,
offset: 3,
open_body: true
}.merge(options || {})
options[:type] = options[:type].to_s.downcase
options[:type] = 'primary' unless %w(primary success info warning danger).include... | ruby | def panel(title, options = { }, &block)
options = {
type: 'primary',
size: 6,
offset: 3,
open_body: true
}.merge(options || {})
options[:type] = options[:type].to_s.downcase
options[:type] = 'primary' unless %w(primary success info warning danger).include... | [
"def",
"panel",
"(",
"title",
",",
"options",
"=",
"{",
"}",
",",
"&",
"block",
")",
"options",
"=",
"{",
"type",
":",
"'primary'",
",",
"size",
":",
"6",
",",
"offset",
":",
"3",
",",
"open_body",
":",
"true",
"}",
".",
"merge",
"(",
"options",
... | Creates a panel with the specified title.
Valid options:
type::
Type can be :primary, :success, :info, :warning, or :danger. Default value is :primary.
size::
Size can be any value from 1 through 12. Default value is 6.
offset::
Offset can be any value from 1 through 12. Default value is 3.
... | [
"Creates",
"a",
"panel",
"with",
"the",
"specified",
"title",
"."
] | 1ff08db7aa8ab7f86b223268b700bc67d15bb8aa | https://github.com/barkerest/incline/blob/1ff08db7aa8ab7f86b223268b700bc67d15bb8aa/lib/incline/extensions/action_view_base.rb#L360-L386 | train |
Pistos/m4dbi | lib/m4dbi/model.rb | M4DBI.Model.delete | def delete
if self.class.hooks[:active]
self.class.hooks[:before_delete].each do |block|
self.class.hooks[:active] = false
block.yield self
self.class.hooks[:active] = true
end
end
st = prepare("DELETE FROM #{table} WHERE #{pk_clause}")
num_deleted ... | ruby | def delete
if self.class.hooks[:active]
self.class.hooks[:before_delete].each do |block|
self.class.hooks[:active] = false
block.yield self
self.class.hooks[:active] = true
end
end
st = prepare("DELETE FROM #{table} WHERE #{pk_clause}")
num_deleted ... | [
"def",
"delete",
"if",
"self",
".",
"class",
".",
"hooks",
"[",
":active",
"]",
"self",
".",
"class",
".",
"hooks",
"[",
":before_delete",
"]",
".",
"each",
"do",
"|",
"block",
"|",
"self",
".",
"class",
".",
"hooks",
"[",
":active",
"]",
"=",
"fal... | Returns true iff the record and only the record was successfully deleted. | [
"Returns",
"true",
"iff",
"the",
"record",
"and",
"only",
"the",
"record",
"was",
"successfully",
"deleted",
"."
] | 603d7fefb621fe34a940fa8e8b798ee581823cb3 | https://github.com/Pistos/m4dbi/blob/603d7fefb621fe34a940fa8e8b798ee581823cb3/lib/m4dbi/model.rb#L456-L480 | train |
HParker/sock-drawer | lib/sock/server.rb | Sock.Server.subscribe | def subscribe(subscription)
@logger.info "Subscribing to: #{subscription + '*'}"
pubsub.psubscribe(subscription + '*') do |chan, msg|
@logger.info "pushing c: #{chan} msg: #{msg}"
channel(chan).push(msg)
end
end | ruby | def subscribe(subscription)
@logger.info "Subscribing to: #{subscription + '*'}"
pubsub.psubscribe(subscription + '*') do |chan, msg|
@logger.info "pushing c: #{chan} msg: #{msg}"
channel(chan).push(msg)
end
end | [
"def",
"subscribe",
"(",
"subscription",
")",
"@logger",
".",
"info",
"\"Subscribing to: #{subscription + '*'}\"",
"pubsub",
".",
"psubscribe",
"(",
"subscription",
"+",
"'*'",
")",
"do",
"|",
"chan",
",",
"msg",
"|",
"@logger",
".",
"info",
"\"pushing c: #{chan} ... | subscribe fires a event on a EM channel whenever a message is fired on a pattern matching `name`.
@name (default: "sock-hook/") + '*' | [
"subscribe",
"fires",
"a",
"event",
"on",
"a",
"EM",
"channel",
"whenever",
"a",
"message",
"is",
"fired",
"on",
"a",
"pattern",
"matching",
"name",
"."
] | 87fffa745cedc3adbeec41a3afdd19a3fae92ab2 | https://github.com/HParker/sock-drawer/blob/87fffa745cedc3adbeec41a3afdd19a3fae92ab2/lib/sock/server.rb#L31-L37 | train |
LiveTyping/live-front-rails | lib/live-front/tab_helper.rb | LiveFront.TabHelper.nav_link | def nav_link(options = {}, &block)
c, a = fetch_controller_and_action(options)
p = options.delete(:params) || {}
klass = page_active?(c, a, p) ? 'active' : ''
# Add our custom class into the html_options, which may or may not exist
# and which may or may not already have a :class key
... | ruby | def nav_link(options = {}, &block)
c, a = fetch_controller_and_action(options)
p = options.delete(:params) || {}
klass = page_active?(c, a, p) ? 'active' : ''
# Add our custom class into the html_options, which may or may not exist
# and which may or may not already have a :class key
... | [
"def",
"nav_link",
"(",
"options",
"=",
"{",
"}",
",",
"&",
"block",
")",
"c",
",",
"a",
"=",
"fetch_controller_and_action",
"(",
"options",
")",
"p",
"=",
"options",
".",
"delete",
"(",
":params",
")",
"||",
"{",
"}",
"klass",
"=",
"page_active?",
"... | Navigation link helper
Returns an `li` element with an 'active' class if the supplied
controller(s) and/or action(s) are currently active. The content of the
element is the value passed to the block.
options - The options hash used to determine if the element is "active" (default: {})
:controller - O... | [
"Navigation",
"link",
"helper"
] | 605946ec748bab2a2a751fd7eebcbf9a0e99832c | https://github.com/LiveTyping/live-front-rails/blob/605946ec748bab2a2a751fd7eebcbf9a0e99832c/lib/live-front/tab_helper.rb#L43-L60 | train |
JoshMcKin/hot_tub | lib/hot_tub/sessions.rb | HotTub.Sessions.get_or_set | def get_or_set(key, pool_options={}, &client_block)
unless @_staged[key]
@mutex.synchronize do
@_staged[key] ||= [pool_options,client_block]
end
end
get(key)
end | ruby | def get_or_set(key, pool_options={}, &client_block)
unless @_staged[key]
@mutex.synchronize do
@_staged[key] ||= [pool_options,client_block]
end
end
get(key)
end | [
"def",
"get_or_set",
"(",
"key",
",",
"pool_options",
"=",
"{",
"}",
",",
"&",
"client_block",
")",
"unless",
"@_staged",
"[",
"key",
"]",
"@mutex",
".",
"synchronize",
"do",
"@_staged",
"[",
"key",
"]",
"||=",
"[",
"pool_options",
",",
"client_block",
"... | Adds session unless it already exists and returns
the session | [
"Adds",
"session",
"unless",
"it",
"already",
"exists",
"and",
"returns",
"the",
"session"
] | 44f22b0dfbca40bfe7cc4f7e6393122c88d7da0d | https://github.com/JoshMcKin/hot_tub/blob/44f22b0dfbca40bfe7cc4f7e6393122c88d7da0d/lib/hot_tub/sessions.rb#L133-L140 | train |
JoshMcKin/hot_tub | lib/hot_tub/sessions.rb | HotTub.Sessions.delete | def delete(key)
deleted = false
pool = nil
@mutex.synchronize do
pool = @_sessions.delete(key)
end
if pool
pool.shutdown!
deleted = true
HotTub.logger.info "[HotTub] #{key} was deleted from #{@name}." if HotTub.logger
end
deleted
end | ruby | def delete(key)
deleted = false
pool = nil
@mutex.synchronize do
pool = @_sessions.delete(key)
end
if pool
pool.shutdown!
deleted = true
HotTub.logger.info "[HotTub] #{key} was deleted from #{@name}." if HotTub.logger
end
deleted
end | [
"def",
"delete",
"(",
"key",
")",
"deleted",
"=",
"false",
"pool",
"=",
"nil",
"@mutex",
".",
"synchronize",
"do",
"pool",
"=",
"@_sessions",
".",
"delete",
"(",
"key",
")",
"end",
"if",
"pool",
"pool",
".",
"shutdown!",
"deleted",
"=",
"true",
"HotTub... | Deletes and shutdowns the pool if its found. | [
"Deletes",
"and",
"shutdowns",
"the",
"pool",
"if",
"its",
"found",
"."
] | 44f22b0dfbca40bfe7cc4f7e6393122c88d7da0d | https://github.com/JoshMcKin/hot_tub/blob/44f22b0dfbca40bfe7cc4f7e6393122c88d7da0d/lib/hot_tub/sessions.rb#L144-L156 | train |
JoshMcKin/hot_tub | lib/hot_tub/sessions.rb | HotTub.Sessions.reap! | def reap!
HotTub.logger.info "[HotTub] Reaping #{@name}!" if HotTub.log_trace?
@mutex.synchronize do
@_sessions.each_value do |pool|
break if @shutdown
pool.reap!
end
end
nil
end | ruby | def reap!
HotTub.logger.info "[HotTub] Reaping #{@name}!" if HotTub.log_trace?
@mutex.synchronize do
@_sessions.each_value do |pool|
break if @shutdown
pool.reap!
end
end
nil
end | [
"def",
"reap!",
"HotTub",
".",
"logger",
".",
"info",
"\"[HotTub] Reaping #{@name}!\"",
"if",
"HotTub",
".",
"log_trace?",
"@mutex",
".",
"synchronize",
"do",
"@_sessions",
".",
"each_value",
"do",
"|",
"pool",
"|",
"break",
"if",
"@shutdown",
"pool",
".",
"re... | Remove and close extra clients | [
"Remove",
"and",
"close",
"extra",
"clients"
] | 44f22b0dfbca40bfe7cc4f7e6393122c88d7da0d | https://github.com/JoshMcKin/hot_tub/blob/44f22b0dfbca40bfe7cc4f7e6393122c88d7da0d/lib/hot_tub/sessions.rb#L221-L230 | train |
anga/BetterRailsDebugger | lib/better_rails_debugger/parser/ruby/processor.rb | BetterRailsDebugger::Parser::Ruby.Processor.emit_signal | def emit_signal(signal_name, node)
@subscriptions ||= Hash.new()
@runner ||= BetterRailsDebugger::Parser::Ruby::ContextRunner.new self
(@subscriptions[signal_name] || {}).values.each do |block|
@runner.node = node
@runner.instance_eval &block
# block.call(node)
end
en... | ruby | def emit_signal(signal_name, node)
@subscriptions ||= Hash.new()
@runner ||= BetterRailsDebugger::Parser::Ruby::ContextRunner.new self
(@subscriptions[signal_name] || {}).values.each do |block|
@runner.node = node
@runner.instance_eval &block
# block.call(node)
end
en... | [
"def",
"emit_signal",
"(",
"signal_name",
",",
"node",
")",
"@subscriptions",
"||=",
"Hash",
".",
"new",
"(",
")",
"@runner",
"||=",
"BetterRailsDebugger",
"::",
"Parser",
"::",
"Ruby",
"::",
"ContextRunner",
".",
"new",
"self",
"(",
"@subscriptions",
"[",
"... | Call all subscriptions for the given signal
@param signal_name Symbol
@param args Hash | [
"Call",
"all",
"subscriptions",
"for",
"the",
"given",
"signal"
] | 2ac7af13b8ee12483bd9a92680d8f43042f1f1d5 | https://github.com/anga/BetterRailsDebugger/blob/2ac7af13b8ee12483bd9a92680d8f43042f1f1d5/lib/better_rails_debugger/parser/ruby/processor.rb#L10-L18 | train |
anga/BetterRailsDebugger | lib/better_rails_debugger/parser/ruby/processor.rb | BetterRailsDebugger::Parser::Ruby.Processor.subscribe_signal | def subscribe_signal(signal_name, step=:first_pass, &block)
key = SecureRandom.hex(5)
@subscriptions ||= Hash.new()
@subscriptions[signal_name] ||= Hash.new
@subscriptions[signal_name][key] = block
key
end | ruby | def subscribe_signal(signal_name, step=:first_pass, &block)
key = SecureRandom.hex(5)
@subscriptions ||= Hash.new()
@subscriptions[signal_name] ||= Hash.new
@subscriptions[signal_name][key] = block
key
end | [
"def",
"subscribe_signal",
"(",
"signal_name",
",",
"step",
"=",
":first_pass",
",",
"&",
"block",
")",
"key",
"=",
"SecureRandom",
".",
"hex",
"(",
"5",
")",
"@subscriptions",
"||=",
"Hash",
".",
"new",
"(",
")",
"@subscriptions",
"[",
"signal_name",
"]",... | Subscribe to a particular signal
@param signal_name Symbol
@param step Symbol May be :first_pass or :second_pass
@param block Proc | [
"Subscribe",
"to",
"a",
"particular",
"signal"
] | 2ac7af13b8ee12483bd9a92680d8f43042f1f1d5 | https://github.com/anga/BetterRailsDebugger/blob/2ac7af13b8ee12483bd9a92680d8f43042f1f1d5/lib/better_rails_debugger/parser/ruby/processor.rb#L24-L30 | train |
tbpgr/sublime_sunippetter | lib/sublime_sunippetter_dsl.rb | SublimeSunippetter.Dsl.add | def add(method_name, *args)
return if error?(method_name, *args)
has_do_block = args.include?('block@d')
has_brace_block = args.include?('block@b')
args = delete_block_args args
@target_methods << TargetMethod.new do |t|
t.method_name = method_name
t.args = args
t.h... | ruby | def add(method_name, *args)
return if error?(method_name, *args)
has_do_block = args.include?('block@d')
has_brace_block = args.include?('block@b')
args = delete_block_args args
@target_methods << TargetMethod.new do |t|
t.method_name = method_name
t.args = args
t.h... | [
"def",
"add",
"(",
"method_name",
",",
"*",
"args",
")",
"return",
"if",
"error?",
"(",
"method_name",
",",
"args",
")",
"has_do_block",
"=",
"args",
".",
"include?",
"(",
"'block@d'",
")",
"has_brace_block",
"=",
"args",
".",
"include?",
"(",
"'block@b'",... | init default values
add sunippet information | [
"init",
"default",
"values",
"add",
"sunippet",
"information"
] | a731a8a52fe457d742e78f50a4009b5b01f0640d | https://github.com/tbpgr/sublime_sunippetter/blob/a731a8a52fe457d742e78f50a4009b5b01f0640d/lib/sublime_sunippetter_dsl.rb#L18-L29 | train |
flyingmachine/whoops_logger | lib/whoops_logger/sender.rb | WhoopsLogger.Sender.send_message | def send_message(data)
# TODO: format
# TODO: validation
data = prepare_data(data)
logger.debug { "Sending request to #{url.to_s}:\n#{data}" } if logger
http =
Net::HTTP::Proxy(proxy_host, proxy_port, proxy_user, proxy_pass).
new(url.host, url.port)
http.read_timeou... | ruby | def send_message(data)
# TODO: format
# TODO: validation
data = prepare_data(data)
logger.debug { "Sending request to #{url.to_s}:\n#{data}" } if logger
http =
Net::HTTP::Proxy(proxy_host, proxy_port, proxy_user, proxy_pass).
new(url.host, url.port)
http.read_timeou... | [
"def",
"send_message",
"(",
"data",
")",
"# TODO: format",
"# TODO: validation",
"data",
"=",
"prepare_data",
"(",
"data",
")",
"logger",
".",
"debug",
"{",
"\"Sending request to #{url.to_s}:\\n#{data}\"",
"}",
"if",
"logger",
"http",
"=",
"Net",
"::",
"HTTP",
"::... | Sends the notice data off to Whoops for processing.
@param [Hash] data The notice to be sent off | [
"Sends",
"the",
"notice",
"data",
"off",
"to",
"Whoops",
"for",
"processing",
"."
] | e1db5362b67c58f60018c9e0d653094fbe286014 | https://github.com/flyingmachine/whoops_logger/blob/e1db5362b67c58f60018c9e0d653094fbe286014/lib/whoops_logger/sender.rb#L28-L60 | train |
ffmike/shoehorn | lib/shoehorn/documents_base.rb | Shoehorn.DocumentsBase.status | def status(inserter_id)
status_hash = Hash.new
xml = Builder::XmlMarkup.new
xml.instruct!
xml.Request(:xmlns => "urn:sbx:apis:SbxBaseComponents") do |xml|
connection.requester_credentials_block(xml)
xml.GetDocumentStatusCall do |xml|
xml.InserterId(inserter_id)
... | ruby | def status(inserter_id)
status_hash = Hash.new
xml = Builder::XmlMarkup.new
xml.instruct!
xml.Request(:xmlns => "urn:sbx:apis:SbxBaseComponents") do |xml|
connection.requester_credentials_block(xml)
xml.GetDocumentStatusCall do |xml|
xml.InserterId(inserter_id)
... | [
"def",
"status",
"(",
"inserter_id",
")",
"status_hash",
"=",
"Hash",
".",
"new",
"xml",
"=",
"Builder",
"::",
"XmlMarkup",
".",
"new",
"xml",
".",
"instruct!",
"xml",
".",
"Request",
"(",
":xmlns",
"=>",
"\"urn:sbx:apis:SbxBaseComponents\"",
")",
"do",
"|",... | Requires an inserter id from an upload call | [
"Requires",
"an",
"inserter",
"id",
"from",
"an",
"upload",
"call"
] | b3da6d2bc4bd49652ac76197d01077b14bafb70a | https://github.com/ffmike/shoehorn/blob/b3da6d2bc4bd49652ac76197d01077b14bafb70a/lib/shoehorn/documents_base.rb#L68-L84 | train |
DigitPaint/html_mockup | lib/html_mockup/release/processors/requirejs.rb | HtmlMockup::Release::Processors.Requirejs.rjs_check | def rjs_check(path = @options[:rjs])
rjs_command = rjs_file(path) || rjs_bin(path)
if !(rjs_command)
raise RuntimeError, "Could not find r.js optimizer in #{path.inspect} - try updating this by npm install -g requirejs"
end
rjs_command
end | ruby | def rjs_check(path = @options[:rjs])
rjs_command = rjs_file(path) || rjs_bin(path)
if !(rjs_command)
raise RuntimeError, "Could not find r.js optimizer in #{path.inspect} - try updating this by npm install -g requirejs"
end
rjs_command
end | [
"def",
"rjs_check",
"(",
"path",
"=",
"@options",
"[",
":rjs",
"]",
")",
"rjs_command",
"=",
"rjs_file",
"(",
"path",
")",
"||",
"rjs_bin",
"(",
"path",
")",
"if",
"!",
"(",
"rjs_command",
")",
"raise",
"RuntimeError",
",",
"\"Could not find r.js optimizer i... | Incase both a file and bin version are availble file version is taken
@return rjs_command to invoke r.js optimizer with | [
"Incase",
"both",
"a",
"file",
"and",
"bin",
"version",
"are",
"availble",
"file",
"version",
"is",
"taken"
] | 976edadc01216b82a8cea177f53fb32559eaf41e | https://github.com/DigitPaint/html_mockup/blob/976edadc01216b82a8cea177f53fb32559eaf41e/lib/html_mockup/release/processors/requirejs.rb#L88-L94 | train |
martinpoljak/types | lib/types.rb | Types.Type.match_type? | def match_type?(object)
result = object.kind_of_any? self.type_classes
if not result
result = object.type_of_any? self.type_types
end
return result
end | ruby | def match_type?(object)
result = object.kind_of_any? self.type_classes
if not result
result = object.type_of_any? self.type_types
end
return result
end | [
"def",
"match_type?",
"(",
"object",
")",
"result",
"=",
"object",
".",
"kind_of_any?",
"self",
".",
"type_classes",
"if",
"not",
"result",
"result",
"=",
"object",
".",
"type_of_any?",
"self",
".",
"type_types",
"end",
"return",
"result",
"end"
] | Matches object is of this type.
@param [Object] object object for type matching
@return [Boolean] +true+ if match, +false+ in otherwise | [
"Matches",
"object",
"is",
"of",
"this",
"type",
"."
] | 7742b90580a375de71b25344369bb76283962798 | https://github.com/martinpoljak/types/blob/7742b90580a375de71b25344369bb76283962798/lib/types.rb#L47-L54 | train |
doubleleft/hook-ruby | lib/hook-client/collection.rb | Hook.Collection.create | def create data
if data.kind_of?(Array)
# TODO: server should accept multiple items to create,
# instead of making multiple requests.
data.map {|item| self.create(item) }
else
@client.post @segments, data
end
end | ruby | def create data
if data.kind_of?(Array)
# TODO: server should accept multiple items to create,
# instead of making multiple requests.
data.map {|item| self.create(item) }
else
@client.post @segments, data
end
end | [
"def",
"create",
"data",
"if",
"data",
".",
"kind_of?",
"(",
"Array",
")",
"# TODO: server should accept multiple items to create,",
"# instead of making multiple requests.",
"data",
".",
"map",
"{",
"|",
"item",
"|",
"self",
".",
"create",
"(",
"item",
")",
"}",
... | Create an item into the collection
@param data [Hash, Array] item or array of items
@return [Hash, Array] | [
"Create",
"an",
"item",
"into",
"the",
"collection"
] | f6acdd89dfe6ed9161380300c2dff2f19f0f744a | https://github.com/doubleleft/hook-ruby/blob/f6acdd89dfe6ed9161380300c2dff2f19f0f744a/lib/hook-client/collection.rb#L35-L43 | train |
doubleleft/hook-ruby | lib/hook-client/collection.rb | Hook.Collection.where | def where fields = {}, operation = 'and'
fields.each_pair do |k, value|
field = (k.respond_to?(:field) ? k.field : k).to_s
comparation = k.respond_to?(:comparation) ? k.comparation : '='
# Range syntatic sugar
value = [ value.first, value.last ] if value.kind_of?(Range)
@... | ruby | def where fields = {}, operation = 'and'
fields.each_pair do |k, value|
field = (k.respond_to?(:field) ? k.field : k).to_s
comparation = k.respond_to?(:comparation) ? k.comparation : '='
# Range syntatic sugar
value = [ value.first, value.last ] if value.kind_of?(Range)
@... | [
"def",
"where",
"fields",
"=",
"{",
"}",
",",
"operation",
"=",
"'and'",
"fields",
".",
"each_pair",
"do",
"|",
"k",
",",
"value",
"|",
"field",
"=",
"(",
"k",
".",
"respond_to?",
"(",
":field",
")",
"?",
"k",
".",
"field",
":",
"k",
")",
".",
... | Add where clause to the current query.
Supported modifiers on fields: .gt, .gte, .lt, .lte, .ne, .in, .not_in, .nin, .like, .between, .not_between
@param fields [Hash] fields and values to filter
@param [String] operation (and, or)
@example
hook.collection(:movies).where({
:name => "Hook",
:ye... | [
"Add",
"where",
"clause",
"to",
"the",
"current",
"query",
"."
] | f6acdd89dfe6ed9161380300c2dff2f19f0f744a | https://github.com/doubleleft/hook-ruby/blob/f6acdd89dfe6ed9161380300c2dff2f19f0f744a/lib/hook-client/collection.rb#L92-L103 | train |
doubleleft/hook-ruby | lib/hook-client/collection.rb | Hook.Collection.order | def order fields
by_num = { 1 => 'asc', -1 => 'desc' }
ordering = []
fields.each_pair do |key, value|
ordering << [key.to_s, by_num[value] || value]
end
@ordering = ordering
self
end | ruby | def order fields
by_num = { 1 => 'asc', -1 => 'desc' }
ordering = []
fields.each_pair do |key, value|
ordering << [key.to_s, by_num[value] || value]
end
@ordering = ordering
self
end | [
"def",
"order",
"fields",
"by_num",
"=",
"{",
"1",
"=>",
"'asc'",
",",
"-",
"1",
"=>",
"'desc'",
"}",
"ordering",
"=",
"[",
"]",
"fields",
".",
"each_pair",
"do",
"|",
"key",
",",
"value",
"|",
"ordering",
"<<",
"[",
"key",
".",
"to_s",
",",
"by_... | Add order clause to the query.
@param fields [String] ...
@return [Collection] self | [
"Add",
"order",
"clause",
"to",
"the",
"query",
"."
] | f6acdd89dfe6ed9161380300c2dff2f19f0f744a | https://github.com/doubleleft/hook-ruby/blob/f6acdd89dfe6ed9161380300c2dff2f19f0f744a/lib/hook-client/collection.rb#L116-L124 | train |
qwertos/URIx-Util | lib/urix/urix.rb | URIx.URIx.claim_interface | def claim_interface
devices = usb.devices(:idVendor => VENDOR_ID, :idProduct => PRODUCT_ID)
unless devices.first then
return
end
@device = devices.first
@handle = @device.open
@handle.detach_kernel_driver(HID_INTERFACE)
@handle.claim_interface( HID_INTERFACE )
end | ruby | def claim_interface
devices = usb.devices(:idVendor => VENDOR_ID, :idProduct => PRODUCT_ID)
unless devices.first then
return
end
@device = devices.first
@handle = @device.open
@handle.detach_kernel_driver(HID_INTERFACE)
@handle.claim_interface( HID_INTERFACE )
end | [
"def",
"claim_interface",
"devices",
"=",
"usb",
".",
"devices",
"(",
":idVendor",
"=>",
"VENDOR_ID",
",",
":idProduct",
"=>",
"PRODUCT_ID",
")",
"unless",
"devices",
".",
"first",
"then",
"return",
"end",
"@device",
"=",
"devices",
".",
"first",
"@handle",
... | Creates a new URIx interface.
Claim the USB interface for this program. Must be
called to begin using the interface. | [
"Creates",
"a",
"new",
"URIx",
"interface",
".",
"Claim",
"the",
"USB",
"interface",
"for",
"this",
"program",
".",
"Must",
"be",
"called",
"to",
"begin",
"using",
"the",
"interface",
"."
] | a7b565543aad947ccdb3ffb869e98401b8efb798 | https://github.com/qwertos/URIx-Util/blob/a7b565543aad947ccdb3ffb869e98401b8efb798/lib/urix/urix.rb#L26-L38 | train |
qwertos/URIx-Util | lib/urix/urix.rb | URIx.URIx.set_output | def set_output pin, state
state = false if state == :low
state = true if state == :high
if ( @pin_states >> ( pin - 1 )).odd? && ( state == false ) or
( @pin_states >> ( pin - 1 )).even? && ( state == true ) then
mask = 0 + ( 1 << ( pin - 1 ))
@pin_states ^= mask
end
write_output
e... | ruby | def set_output pin, state
state = false if state == :low
state = true if state == :high
if ( @pin_states >> ( pin - 1 )).odd? && ( state == false ) or
( @pin_states >> ( pin - 1 )).even? && ( state == true ) then
mask = 0 + ( 1 << ( pin - 1 ))
@pin_states ^= mask
end
write_output
e... | [
"def",
"set_output",
"pin",
",",
"state",
"state",
"=",
"false",
"if",
"state",
"==",
":low",
"state",
"=",
"true",
"if",
"state",
"==",
":high",
"if",
"(",
"@pin_states",
">>",
"(",
"pin",
"-",
"1",
")",
")",
".",
"odd?",
"&&",
"(",
"state",
"==",... | Sets the state of a GPIO pin.
@param pin [Integer] ID of GPIO pin.
@param state [Boolean] State to set pin to. True == :high | [
"Sets",
"the",
"state",
"of",
"a",
"GPIO",
"pin",
"."
] | a7b565543aad947ccdb3ffb869e98401b8efb798 | https://github.com/qwertos/URIx-Util/blob/a7b565543aad947ccdb3ffb869e98401b8efb798/lib/urix/urix.rb#L54-L66 | train |
qwertos/URIx-Util | lib/urix/urix.rb | URIx.URIx.set_pin_mode | def set_pin_mode pin, mode
if ( @pin_modes >> ( pin - 1 )).odd? && ( mode == :input ) or
( @pin_modes >> ( pin - 1 )).even? && ( mode == :output ) then
mask = 0 + ( 1 << ( pin - 1 ))
@pin_modes ^= mask
end
end | ruby | def set_pin_mode pin, mode
if ( @pin_modes >> ( pin - 1 )).odd? && ( mode == :input ) or
( @pin_modes >> ( pin - 1 )).even? && ( mode == :output ) then
mask = 0 + ( 1 << ( pin - 1 ))
@pin_modes ^= mask
end
end | [
"def",
"set_pin_mode",
"pin",
",",
"mode",
"if",
"(",
"@pin_modes",
">>",
"(",
"pin",
"-",
"1",
")",
")",
".",
"odd?",
"&&",
"(",
"mode",
"==",
":input",
")",
"or",
"(",
"@pin_modes",
">>",
"(",
"pin",
"-",
"1",
")",
")",
".",
"even?",
"&&",
"(... | Sets the mode of a GPIO pin to input or output.
@param pin [Integer] ID of GPIO pin.
@param mode [Symbol] :input or :output | [
"Sets",
"the",
"mode",
"of",
"a",
"GPIO",
"pin",
"to",
"input",
"or",
"output",
"."
] | a7b565543aad947ccdb3ffb869e98401b8efb798 | https://github.com/qwertos/URIx-Util/blob/a7b565543aad947ccdb3ffb869e98401b8efb798/lib/urix/urix.rb#L73-L80 | train |
Montage-Inc/ruby-montage | lib/montage/client.rb | Montage.Client.auth | def auth
build_response("token") do
connection.post do |req|
req.headers.delete("Authorization")
req.url "auth/"
req.body = { username: username, password: password }.to_json
end
end
end | ruby | def auth
build_response("token") do
connection.post do |req|
req.headers.delete("Authorization")
req.url "auth/"
req.body = { username: username, password: password }.to_json
end
end
end | [
"def",
"auth",
"build_response",
"(",
"\"token\"",
")",
"do",
"connection",
".",
"post",
"do",
"|",
"req",
"|",
"req",
".",
"headers",
".",
"delete",
"(",
"\"Authorization\"",
")",
"req",
".",
"url",
"\"auth/\"",
"req",
".",
"body",
"=",
"{",
"username",... | Attempts to authenticate with the Montage API
* *Returns* :
- A hash containing a valid token or an error string, oh no! | [
"Attempts",
"to",
"authenticate",
"with",
"the",
"Montage",
"API"
] | 2e6f7e591f2f87158994c17ad9619fa29b716bad | https://github.com/Montage-Inc/ruby-montage/blob/2e6f7e591f2f87158994c17ad9619fa29b716bad/lib/montage/client.rb#L88-L96 | train |
Montage-Inc/ruby-montage | lib/montage/client.rb | Montage.Client.build_response | def build_response(resource_name)
response = yield
resource = response_successful?(response) ? resource_name : "error"
response_object = Montage::Response.new(response.status, response.body, resource)
set_token(response_object.token.value) if resource_name == "token" && response.success?
... | ruby | def build_response(resource_name)
response = yield
resource = response_successful?(response) ? resource_name : "error"
response_object = Montage::Response.new(response.status, response.body, resource)
set_token(response_object.token.value) if resource_name == "token" && response.success?
... | [
"def",
"build_response",
"(",
"resource_name",
")",
"response",
"=",
"yield",
"resource",
"=",
"response_successful?",
"(",
"response",
")",
"?",
"resource_name",
":",
"\"error\"",
"response_object",
"=",
"Montage",
"::",
"Response",
".",
"new",
"(",
"response",
... | Instantiates a response object based on the yielded block
* *Args* :
- +resource_name+ -> The name of the Montage resource
* *Returns* :
* A Montage::Response Object containing:
- A http status code
- The response body
- The resource name | [
"Instantiates",
"a",
"response",
"object",
"based",
"on",
"the",
"yielded",
"block"
] | 2e6f7e591f2f87158994c17ad9619fa29b716bad | https://github.com/Montage-Inc/ruby-montage/blob/2e6f7e591f2f87158994c17ad9619fa29b716bad/lib/montage/client.rb#L214-L223 | train |
Montage-Inc/ruby-montage | lib/montage/client.rb | Montage.Client.connection | def connection
@connect ||= Faraday.new do |f|
f.adapter :net_http
f.headers = connection_headers
f.url_prefix = "#{default_url_prefix}/api/v#{api_version}/"
f.response :json, content_type: /\bjson$/
end
end | ruby | def connection
@connect ||= Faraday.new do |f|
f.adapter :net_http
f.headers = connection_headers
f.url_prefix = "#{default_url_prefix}/api/v#{api_version}/"
f.response :json, content_type: /\bjson$/
end
end | [
"def",
"connection",
"@connect",
"||=",
"Faraday",
".",
"new",
"do",
"|",
"f",
"|",
"f",
".",
"adapter",
":net_http",
"f",
".",
"headers",
"=",
"connection_headers",
"f",
".",
"url_prefix",
"=",
"\"#{default_url_prefix}/api/v#{api_version}/\"",
"f",
".",
"respon... | Creates an Faraday connection instance for requests
* *Returns* :
- A Faraday connection object with an instance specific configuration | [
"Creates",
"an",
"Faraday",
"connection",
"instance",
"for",
"requests"
] | 2e6f7e591f2f87158994c17ad9619fa29b716bad | https://github.com/Montage-Inc/ruby-montage/blob/2e6f7e591f2f87158994c17ad9619fa29b716bad/lib/montage/client.rb#L245-L252 | train |
jimmyz/ruby-fs-stack | lib/ruby-fs-stack/familytree/communicator.rb | FamilytreeV2.Communicator.write_note | def write_note(options)
url = "#{Base}note"
note = Org::Familysearch::Ws::Familytree::V2::Schema::Note.new
note.build(options)
familytree = Org::Familysearch::Ws::Familytree::V2::Schema::FamilyTree.new
familytree.notes = [note]
res = @fs_communicator.post(url,familytree.to_json)
... | ruby | def write_note(options)
url = "#{Base}note"
note = Org::Familysearch::Ws::Familytree::V2::Schema::Note.new
note.build(options)
familytree = Org::Familysearch::Ws::Familytree::V2::Schema::FamilyTree.new
familytree.notes = [note]
res = @fs_communicator.post(url,familytree.to_json)
... | [
"def",
"write_note",
"(",
"options",
")",
"url",
"=",
"\"#{Base}note\"",
"note",
"=",
"Org",
"::",
"Familysearch",
"::",
"Ws",
"::",
"Familytree",
"::",
"V2",
"::",
"Schema",
"::",
"Note",
".",
"new",
"note",
".",
"build",
"(",
"options",
")",
"familytre... | Writes a note attached to the value ID of the specific person or relationship.
====Params
* <tt>options</tt> - Options for the note including the following:
* <tt>:personId</tt> - the person ID if attaching to a person assertion.
* <tt>:spouseIds</tt> - an Array of spouse IDs if creating a note attached to a s... | [
"Writes",
"a",
"note",
"attached",
"to",
"the",
"value",
"ID",
"of",
"the",
"specific",
"person",
"or",
"relationship",
"."
] | 11281818635984971026e750d32a5c4599557dd1 | https://github.com/jimmyz/ruby-fs-stack/blob/11281818635984971026e750d32a5c4599557dd1/lib/ruby-fs-stack/familytree/communicator.rb#L233-L242 | train |
jimmyz/ruby-fs-stack | lib/ruby-fs-stack/familytree/communicator.rb | FamilytreeV2.Communicator.combine | def combine(person_array)
url = Base + 'person'
version_persons = self.person person_array, :genders => 'none', :events => 'none', :names => 'none'
combine_person = Org::Familysearch::Ws::Familytree::V2::Schema::Person.new
combine_person.create_combine(version_persons)
familytree = Org::Fa... | ruby | def combine(person_array)
url = Base + 'person'
version_persons = self.person person_array, :genders => 'none', :events => 'none', :names => 'none'
combine_person = Org::Familysearch::Ws::Familytree::V2::Schema::Person.new
combine_person.create_combine(version_persons)
familytree = Org::Fa... | [
"def",
"combine",
"(",
"person_array",
")",
"url",
"=",
"Base",
"+",
"'person'",
"version_persons",
"=",
"self",
".",
"person",
"person_array",
",",
":genders",
"=>",
"'none'",
",",
":events",
"=>",
"'none'",
",",
":names",
"=>",
"'none'",
"combine_person",
... | Combines person into a new person
====Params
* <tt>person_array</tt> - an array of person IDs. | [
"Combines",
"person",
"into",
"a",
"new",
"person"
] | 11281818635984971026e750d32a5c4599557dd1 | https://github.com/jimmyz/ruby-fs-stack/blob/11281818635984971026e750d32a5c4599557dd1/lib/ruby-fs-stack/familytree/communicator.rb#L248-L258 | train |
mrsimonfletcher/roroacms | app/controllers/roroacms/admin/comments_controller.rb | Roroacms.Admin::CommentsController.edit | def edit
# add breadcrumb and set title
add_breadcrumb I18n.t("controllers.admin.comments.edit.breadcrumb")
set_title(I18n.t("controllers.admin.comments.edit.title"))
@comment = Comment.find(params[:id])
end | ruby | def edit
# add breadcrumb and set title
add_breadcrumb I18n.t("controllers.admin.comments.edit.breadcrumb")
set_title(I18n.t("controllers.admin.comments.edit.title"))
@comment = Comment.find(params[:id])
end | [
"def",
"edit",
"# add breadcrumb and set title",
"add_breadcrumb",
"I18n",
".",
"t",
"(",
"\"controllers.admin.comments.edit.breadcrumb\"",
")",
"set_title",
"(",
"I18n",
".",
"t",
"(",
"\"controllers.admin.comments.edit.title\"",
")",
")",
"@comment",
"=",
"Comment",
"."... | get and disply certain comment | [
"get",
"and",
"disply",
"certain",
"comment"
] | 62654a2f2a48e3adb3105f4dafb6e315b460eaf4 | https://github.com/mrsimonfletcher/roroacms/blob/62654a2f2a48e3adb3105f4dafb6e315b460eaf4/app/controllers/roroacms/admin/comments_controller.rb#L15-L21 | train |
mrsimonfletcher/roroacms | app/controllers/roroacms/admin/comments_controller.rb | Roroacms.Admin::CommentsController.update | def update
@comment = Comment.find(params[:id])
atts = comments_params
respond_to do |format|
if @comment.update_attributes(atts)
format.html { redirect_to edit_admin_comment_path(@comment), notice: I18n.t("controllers.admin.comments.update.flash.success") }
else
... | ruby | def update
@comment = Comment.find(params[:id])
atts = comments_params
respond_to do |format|
if @comment.update_attributes(atts)
format.html { redirect_to edit_admin_comment_path(@comment), notice: I18n.t("controllers.admin.comments.update.flash.success") }
else
... | [
"def",
"update",
"@comment",
"=",
"Comment",
".",
"find",
"(",
"params",
"[",
":id",
"]",
")",
"atts",
"=",
"comments_params",
"respond_to",
"do",
"|",
"format",
"|",
"if",
"@comment",
".",
"update_attributes",
"(",
"atts",
")",
"format",
".",
"html",
"{... | update the comment. You are able to update everything about the comment as an admin | [
"update",
"the",
"comment",
".",
"You",
"are",
"able",
"to",
"update",
"everything",
"about",
"the",
"comment",
"as",
"an",
"admin"
] | 62654a2f2a48e3adb3105f4dafb6e315b460eaf4 | https://github.com/mrsimonfletcher/roroacms/blob/62654a2f2a48e3adb3105f4dafb6e315b460eaf4/app/controllers/roroacms/admin/comments_controller.rb#L26-L43 | train |
mrsimonfletcher/roroacms | app/controllers/roroacms/admin/comments_controller.rb | Roroacms.Admin::CommentsController.destroy | def destroy
@comment = Comment.find(params[:id])
@comment.destroy
respond_to do |format|
format.html { redirect_to admin_comments_path, notice: I18n.t("controllers.admin.comments.destroy.flash.success") }
end
end | ruby | def destroy
@comment = Comment.find(params[:id])
@comment.destroy
respond_to do |format|
format.html { redirect_to admin_comments_path, notice: I18n.t("controllers.admin.comments.destroy.flash.success") }
end
end | [
"def",
"destroy",
"@comment",
"=",
"Comment",
".",
"find",
"(",
"params",
"[",
":id",
"]",
")",
"@comment",
".",
"destroy",
"respond_to",
"do",
"|",
"format",
"|",
"format",
".",
"html",
"{",
"redirect_to",
"admin_comments_path",
",",
"notice",
":",
"I18n"... | delete the comment | [
"delete",
"the",
"comment"
] | 62654a2f2a48e3adb3105f4dafb6e315b460eaf4 | https://github.com/mrsimonfletcher/roroacms/blob/62654a2f2a48e3adb3105f4dafb6e315b460eaf4/app/controllers/roroacms/admin/comments_controller.rb#L48-L57 | train |
mrsimonfletcher/roroacms | app/controllers/roroacms/admin/comments_controller.rb | Roroacms.Admin::CommentsController.bulk_update | def bulk_update
# This is what makes the update
func = Comment.bulk_update params
respond_to do |format|
format.html { redirect_to admin_comments_path, notice: func == 'ntd' ? I18n.t("controllers.admin.comments.bulk_update.flash.nothing_to_do") : I18n.t("controllers.admin.comments.bulk_updat... | ruby | def bulk_update
# This is what makes the update
func = Comment.bulk_update params
respond_to do |format|
format.html { redirect_to admin_comments_path, notice: func == 'ntd' ? I18n.t("controllers.admin.comments.bulk_update.flash.nothing_to_do") : I18n.t("controllers.admin.comments.bulk_updat... | [
"def",
"bulk_update",
"# This is what makes the update",
"func",
"=",
"Comment",
".",
"bulk_update",
"params",
"respond_to",
"do",
"|",
"format",
"|",
"format",
".",
"html",
"{",
"redirect_to",
"admin_comments_path",
",",
"notice",
":",
"func",
"==",
"'ntd'",
"?",... | bulk_update function takes all of the checked options and updates them with the given option selected. The options for the bulk update in comments area are
- Unapprove
- Approve
- Mark as Spam
- Destroy | [
"bulk_update",
"function",
"takes",
"all",
"of",
"the",
"checked",
"options",
"and",
"updates",
"them",
"with",
"the",
"given",
"option",
"selected",
".",
"The",
"options",
"for",
"the",
"bulk",
"update",
"in",
"comments",
"area",
"are",
"-",
"Unapprove",
"-... | 62654a2f2a48e3adb3105f4dafb6e315b460eaf4 | https://github.com/mrsimonfletcher/roroacms/blob/62654a2f2a48e3adb3105f4dafb6e315b460eaf4/app/controllers/roroacms/admin/comments_controller.rb#L66-L74 | train |
mrsimonfletcher/roroacms | app/controllers/roroacms/admin/comments_controller.rb | Roroacms.Admin::CommentsController.mark_as_spam | def mark_as_spam
comment = Comment.find(params[:id])
comment.comment_approved = "S"
comment.is_spam = "S"
respond_to do |format|
if comment.save
format.html { redirect_to admin_comments_path, notice: I18n.t("controllers.admin.comments.mark_as_spam.flash.success") }
else... | ruby | def mark_as_spam
comment = Comment.find(params[:id])
comment.comment_approved = "S"
comment.is_spam = "S"
respond_to do |format|
if comment.save
format.html { redirect_to admin_comments_path, notice: I18n.t("controllers.admin.comments.mark_as_spam.flash.success") }
else... | [
"def",
"mark_as_spam",
"comment",
"=",
"Comment",
".",
"find",
"(",
"params",
"[",
":id",
"]",
")",
"comment",
".",
"comment_approved",
"=",
"\"S\"",
"comment",
".",
"is_spam",
"=",
"\"S\"",
"respond_to",
"do",
"|",
"format",
"|",
"if",
"comment",
".",
"... | mark_as_spam function is a button on the ui and so need its own function. The function simply marks the comment as spam against the record in the database.
the record is then not visable unless you explicity tell the system that you want to see spam records. | [
"mark_as_spam",
"function",
"is",
"a",
"button",
"on",
"the",
"ui",
"and",
"so",
"need",
"its",
"own",
"function",
".",
"The",
"function",
"simply",
"marks",
"the",
"comment",
"as",
"spam",
"against",
"the",
"record",
"in",
"the",
"database",
".",
"the",
... | 62654a2f2a48e3adb3105f4dafb6e315b460eaf4 | https://github.com/mrsimonfletcher/roroacms/blob/62654a2f2a48e3adb3105f4dafb6e315b460eaf4/app/controllers/roroacms/admin/comments_controller.rb#L80-L91 | train |
Dev-Crea/swagger-docs-generator | lib/swagger_docs_generator/metadata/sort.rb | SwaggerDocsGenerator.Sort.sort_by_tag | def sort_by_tag
by_tag = Hash[@routes[:paths].sort_by do |_key, value|
value.first[1]['tags']
end]
place_readme_first(by_tag)
end | ruby | def sort_by_tag
by_tag = Hash[@routes[:paths].sort_by do |_key, value|
value.first[1]['tags']
end]
place_readme_first(by_tag)
end | [
"def",
"sort_by_tag",
"by_tag",
"=",
"Hash",
"[",
"@routes",
"[",
":paths",
"]",
".",
"sort_by",
"do",
"|",
"_key",
",",
"value",
"|",
"value",
".",
"first",
"[",
"1",
"]",
"[",
"'tags'",
"]",
"end",
"]",
"place_readme_first",
"(",
"by_tag",
")",
"en... | Sort routes by tags | [
"Sort",
"routes",
"by",
"tags"
] | 5d3de176aa1119cb38100b451bee028d66c0809d | https://github.com/Dev-Crea/swagger-docs-generator/blob/5d3de176aa1119cb38100b451bee028d66c0809d/lib/swagger_docs_generator/metadata/sort.rb#L20-L25 | train |
whistler/active-tracker | lib/active_tracker/tracker.rb | ActiveTracker.Tracker.method_missing | def method_missing(m, *args, &block)
if @tracker_names.include? m
@tracker_blocks[m] = block
else
super(name, *args, &block)
end
end | ruby | def method_missing(m, *args, &block)
if @tracker_names.include? m
@tracker_blocks[m] = block
else
super(name, *args, &block)
end
end | [
"def",
"method_missing",
"(",
"m",
",",
"*",
"args",
",",
"&",
"block",
")",
"if",
"@tracker_names",
".",
"include?",
"m",
"@tracker_blocks",
"[",
"m",
"]",
"=",
"block",
"else",
"super",
"(",
"name",
",",
"args",
",",
"block",
")",
"end",
"end"
] | store tracker code blocks | [
"store",
"tracker",
"code",
"blocks"
] | 5a618042f3f7f9425e31dc083b7b9b970cbcf0b9 | https://github.com/whistler/active-tracker/blob/5a618042f3f7f9425e31dc083b7b9b970cbcf0b9/lib/active_tracker/tracker.rb#L34-L40 | train |
jgoizueta/numerals | lib/numerals/rounding.rb | Numerals.Rounding.truncate | def truncate(numeral, round_up=nil)
check_base numeral
unless simplifying? # TODO: could simplify this just skiping on free?
n = precision(numeral)
if n == 0
return numeral if numeral.repeating? # or rails inexact...
n = numeral.digits.size
end
unless n >=... | ruby | def truncate(numeral, round_up=nil)
check_base numeral
unless simplifying? # TODO: could simplify this just skiping on free?
n = precision(numeral)
if n == 0
return numeral if numeral.repeating? # or rails inexact...
n = numeral.digits.size
end
unless n >=... | [
"def",
"truncate",
"(",
"numeral",
",",
"round_up",
"=",
"nil",
")",
"check_base",
"numeral",
"unless",
"simplifying?",
"# TODO: could simplify this just skiping on free?",
"n",
"=",
"precision",
"(",
"numeral",
")",
"if",
"n",
"==",
"0",
"return",
"numeral",
"if"... | Truncate a numeral and return also a round_up value with information about
the digits beyond the truncation point that can be used to round the truncated
numeral. If the numeral has already been truncated, the round_up result of
that prior truncation should be passed as the second argument. | [
"Truncate",
"a",
"numeral",
"and",
"return",
"also",
"a",
"round_up",
"value",
"with",
"information",
"about",
"the",
"digits",
"beyond",
"the",
"truncation",
"point",
"that",
"can",
"be",
"used",
"to",
"round",
"the",
"truncated",
"numeral",
".",
"If",
"the... | a195e75f689af926537f791441bf8d11590c99c0 | https://github.com/jgoizueta/numerals/blob/a195e75f689af926537f791441bf8d11590c99c0/lib/numerals/rounding.rb#L239-L290 | train |
jgoizueta/numerals | lib/numerals/rounding.rb | Numerals.Rounding.adjust | def adjust(numeral, round_up)
check_base numeral
point, digits = Flt::Support.adjust_digits(
numeral.point, numeral.digits.digits_array,
round_mode: @mode,
negative: numeral.sign == -1,
round_up: round_up,
base: numeral.base
)
if numeral.zero? && simplifyi... | ruby | def adjust(numeral, round_up)
check_base numeral
point, digits = Flt::Support.adjust_digits(
numeral.point, numeral.digits.digits_array,
round_mode: @mode,
negative: numeral.sign == -1,
round_up: round_up,
base: numeral.base
)
if numeral.zero? && simplifyi... | [
"def",
"adjust",
"(",
"numeral",
",",
"round_up",
")",
"check_base",
"numeral",
"point",
",",
"digits",
"=",
"Flt",
"::",
"Support",
".",
"adjust_digits",
"(",
"numeral",
".",
"point",
",",
"numeral",
".",
"digits",
".",
"digits_array",
",",
"round_mode",
... | Adjust a truncated numeral using the round-up information | [
"Adjust",
"a",
"truncated",
"numeral",
"using",
"the",
"round",
"-",
"up",
"information"
] | a195e75f689af926537f791441bf8d11590c99c0 | https://github.com/jgoizueta/numerals/blob/a195e75f689af926537f791441bf8d11590c99c0/lib/numerals/rounding.rb#L293-L308 | train |
kmcd/active_record-tableless_model | lib/active_record-tableless_model.rb | ActiveRecord::Base::TablelessModel.ClassMethods.column | def column(name, sql_type = :text, default = nil, null = true)
columns << ActiveRecord::ConnectionAdapters::Column.new(name.to_s, default, sql_type.to_s, null)
end | ruby | def column(name, sql_type = :text, default = nil, null = true)
columns << ActiveRecord::ConnectionAdapters::Column.new(name.to_s, default, sql_type.to_s, null)
end | [
"def",
"column",
"(",
"name",
",",
"sql_type",
"=",
":text",
",",
"default",
"=",
"nil",
",",
"null",
"=",
"true",
")",
"columns",
"<<",
"ActiveRecord",
"::",
"ConnectionAdapters",
"::",
"Column",
".",
"new",
"(",
"name",
".",
"to_s",
",",
"default",
"... | Creates an attribute corresponding to a database column.
N.B No table is created in the database
== Arguments
<tt>name</tt> :: column name, such as supplier_id in supplier_id int(11).
<tt>default</tt> :: type-casted default value, such as new in sales_stage varchar(20) default 'new'.
<tt>sql_type</tt> ... | [
"Creates",
"an",
"attribute",
"corresponding",
"to",
"a",
"database",
"column",
".",
"N",
".",
"B",
"No",
"table",
"is",
"created",
"in",
"the",
"database"
] | 42b84a0b2001bd3f000685bab7920c6fbf60e21b | https://github.com/kmcd/active_record-tableless_model/blob/42b84a0b2001bd3f000685bab7920c6fbf60e21b/lib/active_record-tableless_model.rb#L31-L33 | train |
rich-dtk/dtk-common | lib/gitolite/manager.rb | Gitolite.Manager.create_user | def create_user(username, rsa_pub_key, rsa_pub_key_name)
key_name = "#{username}@#{rsa_pub_key_name}"
key_path = @configuration.user_key_path(key_name)
if users_public_keys().include?(key_path)
raise ::Gitolite::Duplicate, "Public key (#{rsa_pub_key_name}) already exists for user (#{user... | ruby | def create_user(username, rsa_pub_key, rsa_pub_key_name)
key_name = "#{username}@#{rsa_pub_key_name}"
key_path = @configuration.user_key_path(key_name)
if users_public_keys().include?(key_path)
raise ::Gitolite::Duplicate, "Public key (#{rsa_pub_key_name}) already exists for user (#{user... | [
"def",
"create_user",
"(",
"username",
",",
"rsa_pub_key",
",",
"rsa_pub_key_name",
")",
"key_name",
"=",
"\"#{username}@#{rsa_pub_key_name}\"",
"key_path",
"=",
"@configuration",
".",
"user_key_path",
"(",
"key_name",
")",
"if",
"users_public_keys",
"(",
")",
".",
... | this should be depracated | [
"this",
"should",
"be",
"depracated"
] | 18d312092e9060f01d271a603ad4b0c9bef318b1 | https://github.com/rich-dtk/dtk-common/blob/18d312092e9060f01d271a603ad4b0c9bef318b1/lib/gitolite/manager.rb#L41-L52 | train |
triglav-dataflow/triglav-client-ruby | lib/triglav_client/api/messages_api.rb | TriglavClient.MessagesApi.send_messages | def send_messages(messages, opts = {})
data, _status_code, _headers = send_messages_with_http_info(messages, opts)
return data
end | ruby | def send_messages(messages, opts = {})
data, _status_code, _headers = send_messages_with_http_info(messages, opts)
return data
end | [
"def",
"send_messages",
"(",
"messages",
",",
"opts",
"=",
"{",
"}",
")",
"data",
",",
"_status_code",
",",
"_headers",
"=",
"send_messages_with_http_info",
"(",
"messages",
",",
"opts",
")",
"return",
"data",
"end"
] | Enqueues new messages
@param messages Messages to enqueue
@param [Hash] opts the optional parameters
@return [BulkinsertResponse] | [
"Enqueues",
"new",
"messages"
] | b2f3781d65ee032ba96eb703fbd789c713a5e0bd | https://github.com/triglav-dataflow/triglav-client-ruby/blob/b2f3781d65ee032ba96eb703fbd789c713a5e0bd/lib/triglav_client/api/messages_api.rb#L156-L159 | train |
buzzware/buzztools | lib/buzztools/file.rb | Buzztools.File.real_path | def real_path(aPath)
(path = Pathname.new(::File.expand_path(aPath))) && path.realpath.to_s
end | ruby | def real_path(aPath)
(path = Pathname.new(::File.expand_path(aPath))) && path.realpath.to_s
end | [
"def",
"real_path",
"(",
"aPath",
")",
"(",
"path",
"=",
"Pathname",
".",
"new",
"(",
"::",
"File",
".",
"expand_path",
"(",
"aPath",
")",
")",
")",
"&&",
"path",
".",
"realpath",
".",
"to_s",
"end"
] | make path real according to file system | [
"make",
"path",
"real",
"according",
"to",
"file",
"system"
] | 0823721974d521330ceffe099368ed8cac6209c3 | https://github.com/buzzware/buzztools/blob/0823721974d521330ceffe099368ed8cac6209c3/lib/buzztools/file.rb#L64-L66 | train |
buzzware/buzztools | lib/buzztools/file.rb | Buzztools.File.expand_magic_path | def expand_magic_path(aPath,aBasePath=nil)
aBasePath ||= Dir.pwd
path = aPath
if path.begins_with?('...')
rel_part = path.split3(/\.\.\.[\/\\]/)[2]
return find_upwards(aBasePath,rel_part)
end
path_combine(aBasePath,aPath)
end | ruby | def expand_magic_path(aPath,aBasePath=nil)
aBasePath ||= Dir.pwd
path = aPath
if path.begins_with?('...')
rel_part = path.split3(/\.\.\.[\/\\]/)[2]
return find_upwards(aBasePath,rel_part)
end
path_combine(aBasePath,aPath)
end | [
"def",
"expand_magic_path",
"(",
"aPath",
",",
"aBasePath",
"=",
"nil",
")",
"aBasePath",
"||=",
"Dir",
".",
"pwd",
"path",
"=",
"aPath",
"if",
"path",
".",
"begins_with?",
"(",
"'...'",
")",
"rel_part",
"=",
"path",
".",
"split3",
"(",
"/",
"\\.",
"\\... | allows special symbols in path
currently only ... supported, which looks upward in the filesystem for the following relative path from the basepath | [
"allows",
"special",
"symbols",
"in",
"path",
"currently",
"only",
"...",
"supported",
"which",
"looks",
"upward",
"in",
"the",
"filesystem",
"for",
"the",
"following",
"relative",
"path",
"from",
"the",
"basepath"
] | 0823721974d521330ceffe099368ed8cac6209c3 | https://github.com/buzzware/buzztools/blob/0823721974d521330ceffe099368ed8cac6209c3/lib/buzztools/file.rb#L86-L94 | train |
equallevel/grapple | lib/grapple/html_table_builder.rb | Grapple.HtmlTableBuilder.container | def container(inner_html)
html = ''
html << before_container
html << template.tag('div', container_attributes, true) + "\n"
html << inner_html
html << "</div>\n"
html << after_container
return html.html_safe
end | ruby | def container(inner_html)
html = ''
html << before_container
html << template.tag('div', container_attributes, true) + "\n"
html << inner_html
html << "</div>\n"
html << after_container
return html.html_safe
end | [
"def",
"container",
"(",
"inner_html",
")",
"html",
"=",
"''",
"html",
"<<",
"before_container",
"html",
"<<",
"template",
".",
"tag",
"(",
"'div'",
",",
"container_attributes",
",",
"true",
")",
"+",
"\"\\n\"",
"html",
"<<",
"inner_html",
"html",
"<<",
"\... | Wrap the table in a div | [
"Wrap",
"the",
"table",
"in",
"a",
"div"
] | 65dc1c141adaa3342f0985f4b09d34f6de49e31f | https://github.com/equallevel/grapple/blob/65dc1c141adaa3342f0985f4b09d34f6de49e31f/lib/grapple/html_table_builder.rb#L18-L26 | train |
blambeau/yargi | lib/yargi/markable.rb | Yargi.Markable.add_marks | def add_marks(marks=nil)
marks.each_pair {|k,v| self[k]=v} if marks
if block_given?
result = yield self
add_marks(result) if Hash===result
end
end | ruby | def add_marks(marks=nil)
marks.each_pair {|k,v| self[k]=v} if marks
if block_given?
result = yield self
add_marks(result) if Hash===result
end
end | [
"def",
"add_marks",
"(",
"marks",
"=",
"nil",
")",
"marks",
".",
"each_pair",
"{",
"|",
"k",
",",
"v",
"|",
"self",
"[",
"k",
"]",
"=",
"v",
"}",
"if",
"marks",
"if",
"block_given?",
"result",
"=",
"yield",
"self",
"add_marks",
"(",
"result",
")",
... | Add all marks provided by a Hash instance _marks_. | [
"Add",
"all",
"marks",
"provided",
"by",
"a",
"Hash",
"instance",
"_marks_",
"."
] | 100141e96d245a0a8211cd4f7590909be149bc3c | https://github.com/blambeau/yargi/blob/100141e96d245a0a8211cd4f7590909be149bc3c/lib/yargi/markable.rb#L46-L52 | train |
blambeau/yargi | lib/yargi/markable.rb | Yargi.Markable.to_h | def to_h(nonil=true)
return {} unless @marks
marks = @marks.dup
if nonil
marks.delete_if {|k,v| v.nil?}
end
marks
end | ruby | def to_h(nonil=true)
return {} unless @marks
marks = @marks.dup
if nonil
marks.delete_if {|k,v| v.nil?}
end
marks
end | [
"def",
"to_h",
"(",
"nonil",
"=",
"true",
")",
"return",
"{",
"}",
"unless",
"@marks",
"marks",
"=",
"@marks",
".",
"dup",
"if",
"nonil",
"marks",
".",
"delete_if",
"{",
"|",
"k",
",",
"v",
"|",
"v",
".",
"nil?",
"}",
"end",
"marks",
"end"
] | Converts this Markable to a Hash. When _nonil_ is true, nil mark values
do not lead to hash entries. | [
"Converts",
"this",
"Markable",
"to",
"a",
"Hash",
".",
"When",
"_nonil_",
"is",
"true",
"nil",
"mark",
"values",
"do",
"not",
"lead",
"to",
"hash",
"entries",
"."
] | 100141e96d245a0a8211cd4f7590909be149bc3c | https://github.com/blambeau/yargi/blob/100141e96d245a0a8211cd4f7590909be149bc3c/lib/yargi/markable.rb#L57-L64 | train |
DaQwest/dq-readability | lib/dq-readability.rb | DQReadability.Document.author | def author
# Let's grab this author:
# <meta name="dc.creator" content="Finch - http://www.getfinch.com" />
author_elements = @html.xpath('//meta[@name = "dc.creator"]')
unless author_elements.empty?
author_elements.each do |element|
if element['content']
return ele... | ruby | def author
# Let's grab this author:
# <meta name="dc.creator" content="Finch - http://www.getfinch.com" />
author_elements = @html.xpath('//meta[@name = "dc.creator"]')
unless author_elements.empty?
author_elements.each do |element|
if element['content']
return ele... | [
"def",
"author",
"# Let's grab this author:",
"# <meta name=\"dc.creator\" content=\"Finch - http://www.getfinch.com\" />",
"author_elements",
"=",
"@html",
".",
"xpath",
"(",
"'//meta[@name = \"dc.creator\"]'",
")",
"unless",
"author_elements",
".",
"empty?",
"author_elements",
".... | Look through the @html document looking for the author
Precedence Information here on the wiki: (TODO attach wiki URL if it is accepted)
Returns nil if no author is detected | [
"Look",
"through",
"the"
] | 6fe7830e1aba4867b4a263ee664d0987e8df039a | https://github.com/DaQwest/dq-readability/blob/6fe7830e1aba4867b4a263ee664d0987e8df039a/lib/dq-readability.rb#L262-L306 | train |
barkerest/barkest_core | app/helpers/barkest_core/users_helper.rb | BarkestCore.UsersHelper.gravatar_for | def gravatar_for(user, options = {})
options = { size: 80, default: :identicon }.merge(options || {})
options[:default] = options[:default].to_s.to_sym unless options[:default].nil? || options[:default].is_a?(Symbol)
gravatar_id = Digest::MD5::hexdigest(user.email.downcase)
size = options[:size]... | ruby | def gravatar_for(user, options = {})
options = { size: 80, default: :identicon }.merge(options || {})
options[:default] = options[:default].to_s.to_sym unless options[:default].nil? || options[:default].is_a?(Symbol)
gravatar_id = Digest::MD5::hexdigest(user.email.downcase)
size = options[:size]... | [
"def",
"gravatar_for",
"(",
"user",
",",
"options",
"=",
"{",
"}",
")",
"options",
"=",
"{",
"size",
":",
"80",
",",
"default",
":",
":identicon",
"}",
".",
"merge",
"(",
"options",
"||",
"{",
"}",
")",
"options",
"[",
":default",
"]",
"=",
"option... | Returns the Gravatar for the given user.
Based on the tutorial from [www.railstutorial.org](www.railstutorial.org).
The +user+ is the user you want to get the gravatar for.
Valid options:
* +size+ The size (in pixels) for the returned gravatar. The gravatar will be a square image using this
value as both... | [
"Returns",
"the",
"Gravatar",
"for",
"the",
"given",
"user",
"."
] | 3eeb025ec870888cacbc9bae252a39ebf9295f61 | https://github.com/barkerest/barkest_core/blob/3eeb025ec870888cacbc9bae252a39ebf9295f61/app/helpers/barkest_core/users_helper.rb#L21-L29 | train |
ujjwalt/neon | lib/helpers/argument_helpers.rb | Neon.ArgumentHelpers.extract_session | def extract_session(args)
if args.last.is_a?(Session::Rest) || args.last.is_a?(Session::Embedded)
args.pop
else
Session.current
end
end | ruby | def extract_session(args)
if args.last.is_a?(Session::Rest) || args.last.is_a?(Session::Embedded)
args.pop
else
Session.current
end
end | [
"def",
"extract_session",
"(",
"args",
")",
"if",
"args",
".",
"last",
".",
"is_a?",
"(",
"Session",
"::",
"Rest",
")",
"||",
"args",
".",
"last",
".",
"is_a?",
"(",
"Session",
"::",
"Embedded",
")",
"args",
".",
"pop",
"else",
"Session",
".",
"curre... | Extracts a session from the array of arguments if one exists at the end.
@param args [Array] an array of arguments of any type.
@return [Session] a session if the last argument is a valid session and pops it out of args.
Otherwise it returns the current session. | [
"Extracts",
"a",
"session",
"from",
"the",
"array",
"of",
"arguments",
"if",
"one",
"exists",
"at",
"the",
"end",
"."
] | 609769b16f051a100809131df105df29f98037fc | https://github.com/ujjwalt/neon/blob/609769b16f051a100809131df105df29f98037fc/lib/helpers/argument_helpers.rb#L11-L17 | train |
omegainteractive/comfypress | lib/comfypress/extensions/is_mirrored.rb | ComfyPress::IsMirrored.InstanceMethods.mirrors | def mirrors
return [] unless self.site.is_mirrored?
(Cms::Site.mirrored - [self.site]).collect do |site|
case self
when Cms::Layout then site.layouts.find_by_identifier(self.identifier)
when Cms::Page then site.pages.find_by_full_path(self.full_path)
when Cms::Snipp... | ruby | def mirrors
return [] unless self.site.is_mirrored?
(Cms::Site.mirrored - [self.site]).collect do |site|
case self
when Cms::Layout then site.layouts.find_by_identifier(self.identifier)
when Cms::Page then site.pages.find_by_full_path(self.full_path)
when Cms::Snipp... | [
"def",
"mirrors",
"return",
"[",
"]",
"unless",
"self",
".",
"site",
".",
"is_mirrored?",
"(",
"Cms",
"::",
"Site",
".",
"mirrored",
"-",
"[",
"self",
".",
"site",
"]",
")",
".",
"collect",
"do",
"|",
"site",
"|",
"case",
"self",
"when",
"Cms",
"::... | Mirrors of the object found on other sites | [
"Mirrors",
"of",
"the",
"object",
"found",
"on",
"other",
"sites"
] | 3b64699bf16774b636cb13ecd89281f6e2acb264 | https://github.com/omegainteractive/comfypress/blob/3b64699bf16774b636cb13ecd89281f6e2acb264/lib/comfypress/extensions/is_mirrored.rb#L21-L30 | train |
omegainteractive/comfypress | lib/comfypress/extensions/is_mirrored.rb | ComfyPress::IsMirrored.InstanceMethods.sync_mirror | def sync_mirror
return if self.is_mirrored || !self.site.is_mirrored?
(Cms::Site.mirrored - [self.site]).each do |site|
mirror = case self
when Cms::Layout
m = site.layouts.find_by_identifier(self.identifier_was || self.identifier) || site.layouts.new
m.attributes ... | ruby | def sync_mirror
return if self.is_mirrored || !self.site.is_mirrored?
(Cms::Site.mirrored - [self.site]).each do |site|
mirror = case self
when Cms::Layout
m = site.layouts.find_by_identifier(self.identifier_was || self.identifier) || site.layouts.new
m.attributes ... | [
"def",
"sync_mirror",
"return",
"if",
"self",
".",
"is_mirrored",
"||",
"!",
"self",
".",
"site",
".",
"is_mirrored?",
"(",
"Cms",
"::",
"Site",
".",
"mirrored",
"-",
"[",
"self",
".",
"site",
"]",
")",
".",
"each",
"do",
"|",
"site",
"|",
"mirror",
... | Creating or updating a mirror object. Relationships are mirrored
but content is unique. When updating need to grab mirrors based on
self.slug_was, new objects will use self.slug. | [
"Creating",
"or",
"updating",
"a",
"mirror",
"object",
".",
"Relationships",
"are",
"mirrored",
"but",
"content",
"is",
"unique",
".",
"When",
"updating",
"need",
"to",
"grab",
"mirrors",
"based",
"on",
"self",
".",
"slug_was",
"new",
"objects",
"will",
"use... | 3b64699bf16774b636cb13ecd89281f6e2acb264 | https://github.com/omegainteractive/comfypress/blob/3b64699bf16774b636cb13ecd89281f6e2acb264/lib/comfypress/extensions/is_mirrored.rb#L35-L71 | train |
omegainteractive/comfypress | lib/comfypress/extensions/is_mirrored.rb | ComfyPress::IsMirrored.InstanceMethods.destroy_mirror | def destroy_mirror
return if self.is_mirrored || !self.site.is_mirrored?
mirrors.each do |mirror|
mirror.is_mirrored = true
mirror.destroy
end
end | ruby | def destroy_mirror
return if self.is_mirrored || !self.site.is_mirrored?
mirrors.each do |mirror|
mirror.is_mirrored = true
mirror.destroy
end
end | [
"def",
"destroy_mirror",
"return",
"if",
"self",
".",
"is_mirrored",
"||",
"!",
"self",
".",
"site",
".",
"is_mirrored?",
"mirrors",
".",
"each",
"do",
"|",
"mirror",
"|",
"mirror",
".",
"is_mirrored",
"=",
"true",
"mirror",
".",
"destroy",
"end",
"end"
] | Mirrors should be destroyed | [
"Mirrors",
"should",
"be",
"destroyed"
] | 3b64699bf16774b636cb13ecd89281f6e2acb264 | https://github.com/omegainteractive/comfypress/blob/3b64699bf16774b636cb13ecd89281f6e2acb264/lib/comfypress/extensions/is_mirrored.rb#L74-L80 | train |
barkerest/shells | lib/shells/bash_common.rb | Shells.BashCommon.read_file | def read_file(path, use_method = nil)
if use_method
use_method = use_method.to_sym
raise ArgumentError, "use_method (#{use_method.inspect}) is not a valid method." unless file_methods.include?(use_method)
raise Shells::ShellError, "The #{use_method} binary is not available with this shell.... | ruby | def read_file(path, use_method = nil)
if use_method
use_method = use_method.to_sym
raise ArgumentError, "use_method (#{use_method.inspect}) is not a valid method." unless file_methods.include?(use_method)
raise Shells::ShellError, "The #{use_method} binary is not available with this shell.... | [
"def",
"read_file",
"(",
"path",
",",
"use_method",
"=",
"nil",
")",
"if",
"use_method",
"use_method",
"=",
"use_method",
".",
"to_sym",
"raise",
"ArgumentError",
",",
"\"use_method (#{use_method.inspect}) is not a valid method.\"",
"unless",
"file_methods",
".",
"inclu... | Reads from a file on the device. | [
"Reads",
"from",
"a",
"file",
"on",
"the",
"device",
"."
] | 674a0254f48cea01b0ae8979933f13892e398506 | https://github.com/barkerest/shells/blob/674a0254f48cea01b0ae8979933f13892e398506/lib/shells/bash_common.rb#L10-L21 | train |
barkerest/shells | lib/shells/bash_common.rb | Shells.BashCommon.sudo_exec | def sudo_exec(command, options = {}, &block)
sudo_prompt = '[sp:'
sudo_match = /\n\[sp:$/m
sudo_strip = /\[sp:[^\n]*\n/m
ret = exec("sudo -p \"#{sudo_prompt}\" bash -c \"#{command.gsub('"', '\\"')}\"", options) do |data,type|
test_data = data.to_s
desired_length = sudo_prompt.len... | ruby | def sudo_exec(command, options = {}, &block)
sudo_prompt = '[sp:'
sudo_match = /\n\[sp:$/m
sudo_strip = /\[sp:[^\n]*\n/m
ret = exec("sudo -p \"#{sudo_prompt}\" bash -c \"#{command.gsub('"', '\\"')}\"", options) do |data,type|
test_data = data.to_s
desired_length = sudo_prompt.len... | [
"def",
"sudo_exec",
"(",
"command",
",",
"options",
"=",
"{",
"}",
",",
"&",
"block",
")",
"sudo_prompt",
"=",
"'[sp:'",
"sudo_match",
"=",
"/",
"\\n",
"\\[",
"/m",
"sudo_strip",
"=",
"/",
"\\[",
"\\n",
"\\n",
"/m",
"ret",
"=",
"exec",
"(",
"\"sudo -... | Executes an elevated command using the 'sudo' command. | [
"Executes",
"an",
"elevated",
"command",
"using",
"the",
"sudo",
"command",
"."
] | 674a0254f48cea01b0ae8979933f13892e398506 | https://github.com/barkerest/shells/blob/674a0254f48cea01b0ae8979933f13892e398506/lib/shells/bash_common.rb#L40-L65 | train |
barkerest/shells | lib/shells/bash_common.rb | Shells.BashCommon.setup_prompt | def setup_prompt #:nodoc:
command = "PS1=#{options[:prompt]}"
sleep 1.0 # let shell initialize fully.
exec_ignore_code command, silence_timeout: 10, command_timeout: 10, timeout_error: true, get_output: false
end | ruby | def setup_prompt #:nodoc:
command = "PS1=#{options[:prompt]}"
sleep 1.0 # let shell initialize fully.
exec_ignore_code command, silence_timeout: 10, command_timeout: 10, timeout_error: true, get_output: false
end | [
"def",
"setup_prompt",
"#:nodoc:",
"command",
"=",
"\"PS1=#{options[:prompt]}\"",
"sleep",
"1.0",
"# let shell initialize fully.",
"exec_ignore_code",
"command",
",",
"silence_timeout",
":",
"10",
",",
"command_timeout",
":",
"10",
",",
"timeout_error",
":",
"true",
","... | Uses the PS1= command to set the prompt for the shell. | [
"Uses",
"the",
"PS1",
"=",
"command",
"to",
"set",
"the",
"prompt",
"for",
"the",
"shell",
"."
] | 674a0254f48cea01b0ae8979933f13892e398506 | https://github.com/barkerest/shells/blob/674a0254f48cea01b0ae8979933f13892e398506/lib/shells/bash_common.rb#L91-L95 | train |
tclaus/keytechkit.gem | lib/keytechKit/elements/data_dictionary/data_dictionary_handler.rb | KeytechKit.DataDictionaryHandler.getData | def getData(datadictionary_id)
# /DataDictionaries/{ID}|{Name}/data
parameter = { basic_auth: @auth }
response = self.class.get("/datadictionaries/#{datadictionary_id}/data", parameter)
if response.success?
response['Data']
else
raise response.response
end
end | ruby | def getData(datadictionary_id)
# /DataDictionaries/{ID}|{Name}/data
parameter = { basic_auth: @auth }
response = self.class.get("/datadictionaries/#{datadictionary_id}/data", parameter)
if response.success?
response['Data']
else
raise response.response
end
end | [
"def",
"getData",
"(",
"datadictionary_id",
")",
"# /DataDictionaries/{ID}|{Name}/data",
"parameter",
"=",
"{",
"basic_auth",
":",
"@auth",
"}",
"response",
"=",
"self",
".",
"class",
".",
"get",
"(",
"\"/datadictionaries/#{datadictionary_id}/data\"",
",",
"parameter",
... | Returns a hashed value with data | [
"Returns",
"a",
"hashed",
"value",
"with",
"data"
] | caa7a6bee32b75ec18a4004179ae10cb69d148c2 | https://github.com/tclaus/keytechkit.gem/blob/caa7a6bee32b75ec18a4004179ae10cb69d148c2/lib/keytechKit/elements/data_dictionary/data_dictionary_handler.rb#L28-L38 | train |
nepalez/immutability | lib/immutability/object.rb | Immutability.Object.at | def at(point)
ipoint = point.to_i
target = (ipoint < 0) ? (version + ipoint) : ipoint
return unless (0..version).include? target
detect { |state| target.equal? state.version }
end | ruby | def at(point)
ipoint = point.to_i
target = (ipoint < 0) ? (version + ipoint) : ipoint
return unless (0..version).include? target
detect { |state| target.equal? state.version }
end | [
"def",
"at",
"(",
"point",
")",
"ipoint",
"=",
"point",
".",
"to_i",
"target",
"=",
"(",
"ipoint",
"<",
"0",
")",
"?",
"(",
"version",
"+",
"ipoint",
")",
":",
"ipoint",
"return",
"unless",
"(",
"0",
"..",
"version",
")",
".",
"include?",
"target",... | Returns the state of the object at some point in the past
@param [#to_i] point
Either a positive number of target version,
or a negative number of version (snapshots) before the current one
+0+ stands for the first version.
@return [Object, nil] | [
"Returns",
"the",
"state",
"of",
"the",
"object",
"at",
"some",
"point",
"in",
"the",
"past"
] | 6f44a7e3dad9cbc51f40e5ec9b3810d1cc730a10 | https://github.com/nepalez/immutability/blob/6f44a7e3dad9cbc51f40e5ec9b3810d1cc730a10/lib/immutability/object.rb#L55-L61 | train |
notCalle/ruby-keytree | lib/key_tree/forest.rb | KeyTree.Forest.fetch | def fetch(key, *default)
trees.lazy.each do |tree|
catch do |ball|
return tree.fetch(key) { throw ball }
end
end
return yield(key) if block_given?
return default.first unless default.empty?
raise KeyError, %(key not found: "#{key}")
end | ruby | def fetch(key, *default)
trees.lazy.each do |tree|
catch do |ball|
return tree.fetch(key) { throw ball }
end
end
return yield(key) if block_given?
return default.first unless default.empty?
raise KeyError, %(key not found: "#{key}")
end | [
"def",
"fetch",
"(",
"key",
",",
"*",
"default",
")",
"trees",
".",
"lazy",
".",
"each",
"do",
"|",
"tree",
"|",
"catch",
"do",
"|",
"ball",
"|",
"return",
"tree",
".",
"fetch",
"(",
"key",
")",
"{",
"throw",
"ball",
"}",
"end",
"end",
"return",
... | Fetch a value from a forest
:call-seq:
fetch(key) => value
fetch(key, default) => value
fetch(key) { |key| } => value
The first form raises a +KeyError+ unless +key+ has a value. | [
"Fetch",
"a",
"value",
"from",
"a",
"forest"
] | 1a88c902c8b5d14f21fd350338776fc094eae8e3 | https://github.com/notCalle/ruby-keytree/blob/1a88c902c8b5d14f21fd350338776fc094eae8e3/lib/key_tree/forest.rb#L52-L62 | train |
notCalle/ruby-keytree | lib/key_tree/forest.rb | KeyTree.Forest.flatten | def flatten(&merger)
trees.reverse_each.reduce(Tree[]) do |result, tree|
result.merge!(tree, &merger)
end
end | ruby | def flatten(&merger)
trees.reverse_each.reduce(Tree[]) do |result, tree|
result.merge!(tree, &merger)
end
end | [
"def",
"flatten",
"(",
"&",
"merger",
")",
"trees",
".",
"reverse_each",
".",
"reduce",
"(",
"Tree",
"[",
"]",
")",
"do",
"|",
"result",
",",
"tree",
"|",
"result",
".",
"merge!",
"(",
"tree",
",",
"merger",
")",
"end",
"end"
] | Flattening a forest produces a tree with the equivalent view of key paths | [
"Flattening",
"a",
"forest",
"produces",
"a",
"tree",
"with",
"the",
"equivalent",
"view",
"of",
"key",
"paths"
] | 1a88c902c8b5d14f21fd350338776fc094eae8e3 | https://github.com/notCalle/ruby-keytree/blob/1a88c902c8b5d14f21fd350338776fc094eae8e3/lib/key_tree/forest.rb#L90-L94 | train |
notCalle/ruby-keytree | lib/key_tree/forest.rb | KeyTree.Forest.trees | def trees
Enumerator.new do |yielder|
remaining = [self]
remaining.each do |woods|
next yielder << woods if woods.is_a?(Tree)
woods.each { |wood| remaining << wood }
end
end
end | ruby | def trees
Enumerator.new do |yielder|
remaining = [self]
remaining.each do |woods|
next yielder << woods if woods.is_a?(Tree)
woods.each { |wood| remaining << wood }
end
end
end | [
"def",
"trees",
"Enumerator",
".",
"new",
"do",
"|",
"yielder",
"|",
"remaining",
"=",
"[",
"self",
"]",
"remaining",
".",
"each",
"do",
"|",
"woods",
"|",
"next",
"yielder",
"<<",
"woods",
"if",
"woods",
".",
"is_a?",
"(",
"Tree",
")",
"woods",
".",... | Return a breadth-first Enumerator for all the trees in the forest,
and any nested forests | [
"Return",
"a",
"breadth",
"-",
"first",
"Enumerator",
"for",
"all",
"the",
"trees",
"in",
"the",
"forest",
"and",
"any",
"nested",
"forests"
] | 1a88c902c8b5d14f21fd350338776fc094eae8e3 | https://github.com/notCalle/ruby-keytree/blob/1a88c902c8b5d14f21fd350338776fc094eae8e3/lib/key_tree/forest.rb#L98-L107 | train |
notCalle/ruby-keytree | lib/key_tree/forest.rb | KeyTree.Forest.key_paths | def key_paths
trees.reduce(Set.new) { |result, tree| result.merge(tree.key_paths) }
end | ruby | def key_paths
trees.reduce(Set.new) { |result, tree| result.merge(tree.key_paths) }
end | [
"def",
"key_paths",
"trees",
".",
"reduce",
"(",
"Set",
".",
"new",
")",
"{",
"|",
"result",
",",
"tree",
"|",
"result",
".",
"merge",
"(",
"tree",
".",
"key_paths",
")",
"}",
"end"
] | Return all visible key paths in the forest | [
"Return",
"all",
"visible",
"key",
"paths",
"in",
"the",
"forest"
] | 1a88c902c8b5d14f21fd350338776fc094eae8e3 | https://github.com/notCalle/ruby-keytree/blob/1a88c902c8b5d14f21fd350338776fc094eae8e3/lib/key_tree/forest.rb#L110-L112 | train |
barkerest/incline | lib/incline/extensions/string.rb | Incline::Extensions.String.to_byte_string | def to_byte_string
ret = self.gsub(/\s+/,'')
raise 'Hex string must have even number of characters.' unless ret.size % 2 == 0
raise 'Hex string must only contain 0-9 and A-F characters.' if ret =~ /[^0-9a-fA-F]/
[ret].pack('H*').force_encoding('ascii-8bit')
end | ruby | def to_byte_string
ret = self.gsub(/\s+/,'')
raise 'Hex string must have even number of characters.' unless ret.size % 2 == 0
raise 'Hex string must only contain 0-9 and A-F characters.' if ret =~ /[^0-9a-fA-F]/
[ret].pack('H*').force_encoding('ascii-8bit')
end | [
"def",
"to_byte_string",
"ret",
"=",
"self",
".",
"gsub",
"(",
"/",
"\\s",
"/",
",",
"''",
")",
"raise",
"'Hex string must have even number of characters.'",
"unless",
"ret",
".",
"size",
"%",
"2",
"==",
"0",
"raise",
"'Hex string must only contain 0-9 and A-F chara... | Converts a hex string into a byte string.
Whitespace in the string is ignored.
The string must only contain characters valid for hex (ie - 0-9, A-F, a-f).
The string must contain an even number of characters since each character only represents half a byte. | [
"Converts",
"a",
"hex",
"string",
"into",
"a",
"byte",
"string",
"."
] | 1ff08db7aa8ab7f86b223268b700bc67d15bb8aa | https://github.com/barkerest/incline/blob/1ff08db7aa8ab7f86b223268b700bc67d15bb8aa/lib/incline/extensions/string.rb#L13-L18 | train |
BDMADE/signup | app/helpers/signup/users_helper.rb | Signup.UsersHelper.remember | def remember(user)
user.remember
cookies.permanent.signed[:user_id] = user.id
cookies.permanent[:remember_token] = user.remember_token
end | ruby | def remember(user)
user.remember
cookies.permanent.signed[:user_id] = user.id
cookies.permanent[:remember_token] = user.remember_token
end | [
"def",
"remember",
"(",
"user",
")",
"user",
".",
"remember",
"cookies",
".",
"permanent",
".",
"signed",
"[",
":user_id",
"]",
"=",
"user",
".",
"id",
"cookies",
".",
"permanent",
"[",
":remember_token",
"]",
"=",
"user",
".",
"remember_token",
"end"
] | Remembers a user in a persistent session. | [
"Remembers",
"a",
"user",
"in",
"a",
"persistent",
"session",
"."
] | 59a4b9a2d0ab54eac853193d9f4ac4a2dbf3f8e0 | https://github.com/BDMADE/signup/blob/59a4b9a2d0ab54eac853193d9f4ac4a2dbf3f8e0/app/helpers/signup/users_helper.rb#L9-L13 | train |
BDMADE/signup | app/helpers/signup/users_helper.rb | Signup.UsersHelper.current_user | def current_user
if (user_id = session[:user_id])
@current_user ||= User.find_by(id: user_id)
elsif (user_id = cookies.signed[:user_id])
user = User.find_by(id: user_id)
if user && user.authenticated?(cookies[:remember_token])
log_in user
@current_user = user
... | ruby | def current_user
if (user_id = session[:user_id])
@current_user ||= User.find_by(id: user_id)
elsif (user_id = cookies.signed[:user_id])
user = User.find_by(id: user_id)
if user && user.authenticated?(cookies[:remember_token])
log_in user
@current_user = user
... | [
"def",
"current_user",
"if",
"(",
"user_id",
"=",
"session",
"[",
":user_id",
"]",
")",
"@current_user",
"||=",
"User",
".",
"find_by",
"(",
"id",
":",
"user_id",
")",
"elsif",
"(",
"user_id",
"=",
"cookies",
".",
"signed",
"[",
":user_id",
"]",
")",
"... | Returns the user corresponding to the remember token cookie. | [
"Returns",
"the",
"user",
"corresponding",
"to",
"the",
"remember",
"token",
"cookie",
"."
] | 59a4b9a2d0ab54eac853193d9f4ac4a2dbf3f8e0 | https://github.com/BDMADE/signup/blob/59a4b9a2d0ab54eac853193d9f4ac4a2dbf3f8e0/app/helpers/signup/users_helper.rb#L16-L26 | train |
RJMetrics/RJMetrics-ruby | lib/rjmetrics-client/client.rb | RJMetrics.Client.makeAuthAPICall | def makeAuthAPICall(url = API_BASE)
request_url = "#{url}/client/#{@client_id}/authenticate?apikey=#{@api_key}"
begin
response = RestClient.get(request_url)
return response
rescue RestClient::Exception => error
begin
response = JSON.parse(error.response)
un... | ruby | def makeAuthAPICall(url = API_BASE)
request_url = "#{url}/client/#{@client_id}/authenticate?apikey=#{@api_key}"
begin
response = RestClient.get(request_url)
return response
rescue RestClient::Exception => error
begin
response = JSON.parse(error.response)
un... | [
"def",
"makeAuthAPICall",
"(",
"url",
"=",
"API_BASE",
")",
"request_url",
"=",
"\"#{url}/client/#{@client_id}/authenticate?apikey=#{@api_key}\"",
"begin",
"response",
"=",
"RestClient",
".",
"get",
"(",
"request_url",
")",
"return",
"response",
"rescue",
"RestClient",
... | Authenticates with the RJMetrics Data Import API | [
"Authenticates",
"with",
"the",
"RJMetrics",
"Data",
"Import",
"API"
] | f09d014af873656e2deb049a4975428afabdf088 | https://github.com/RJMetrics/RJMetrics-ruby/blob/f09d014af873656e2deb049a4975428afabdf088/lib/rjmetrics-client/client.rb#L94-L114 | train |
devnull-tools/yummi | lib/yummi/table.rb | Yummi.Table.column | def column(index)
index = parse_index(index)
columns = []
@data.each do |row|
columns << row_to_array(row)[index].value
end
columns
end | ruby | def column(index)
index = parse_index(index)
columns = []
@data.each do |row|
columns << row_to_array(row)[index].value
end
columns
end | [
"def",
"column",
"(",
"index",
")",
"index",
"=",
"parse_index",
"(",
"index",
")",
"columns",
"=",
"[",
"]",
"@data",
".",
"each",
"do",
"|",
"row",
"|",
"columns",
"<<",
"row_to_array",
"(",
"row",
")",
"[",
"index",
"]",
".",
"value",
"end",
"co... | Retrieves the column at the given index. Aliases can be used | [
"Retrieves",
"the",
"column",
"at",
"the",
"given",
"index",
".",
"Aliases",
"can",
"be",
"used"
] | b31cc1ef9a9f4ca1c22e0b77a84a1995bde5c2df | https://github.com/devnull-tools/yummi/blob/b31cc1ef9a9f4ca1c22e0b77a84a1995bde5c2df/lib/yummi/table.rb#L174-L181 | train |
devnull-tools/yummi | lib/yummi/table.rb | Yummi.Table.header= | def header=(header)
header = [header] unless header.respond_to? :each
@header = normalize(header)
@aliases = header.map do |n|
n.downcase.gsub(' ', '_').gsub("\n", '_').to_sym
end if @aliases.empty?
end | ruby | def header=(header)
header = [header] unless header.respond_to? :each
@header = normalize(header)
@aliases = header.map do |n|
n.downcase.gsub(' ', '_').gsub("\n", '_').to_sym
end if @aliases.empty?
end | [
"def",
"header",
"=",
"(",
"header",
")",
"header",
"=",
"[",
"header",
"]",
"unless",
"header",
".",
"respond_to?",
":each",
"@header",
"=",
"normalize",
"(",
"header",
")",
"@aliases",
"=",
"header",
".",
"map",
"do",
"|",
"n",
"|",
"n",
".",
"down... | Sets the table header. If no aliases are defined, they will be defined as the texts
in lowercase with line breaks and spaces replaced by underscores.
Defining headers also limits the printed column to only columns that has a header
(even if it is empty).
=== Args
+header+::
Array containing the texts for dis... | [
"Sets",
"the",
"table",
"header",
".",
"If",
"no",
"aliases",
"are",
"defined",
"they",
"will",
"be",
"defined",
"as",
"the",
"texts",
"in",
"lowercase",
"with",
"line",
"breaks",
"and",
"spaces",
"replaced",
"by",
"underscores",
"."
] | b31cc1ef9a9f4ca1c22e0b77a84a1995bde5c2df | https://github.com/devnull-tools/yummi/blob/b31cc1ef9a9f4ca1c22e0b77a84a1995bde5c2df/lib/yummi/table.rb#L201-L207 | train |
devnull-tools/yummi | lib/yummi/table.rb | Yummi.Table.colorize | def colorize(indexes, params = {}, &block)
[*indexes].each do |index|
index = parse_index(index)
if index
obj = extract_component(params, &block)
component[:colorizers][index] = obj
else
colorize_null params, &block
end
end
end | ruby | def colorize(indexes, params = {}, &block)
[*indexes].each do |index|
index = parse_index(index)
if index
obj = extract_component(params, &block)
component[:colorizers][index] = obj
else
colorize_null params, &block
end
end
end | [
"def",
"colorize",
"(",
"indexes",
",",
"params",
"=",
"{",
"}",
",",
"&",
"block",
")",
"[",
"indexes",
"]",
".",
"each",
"do",
"|",
"index",
"|",
"index",
"=",
"parse_index",
"(",
"index",
")",
"if",
"index",
"obj",
"=",
"extract_component",
"(",
... | Sets a component to colorize a column.
The component must respond to +call+ with the column value (or row if used with
#using_row) as the arguments and return a color or +nil+ if default color should be
used. A block can also be used.
=== Args
+indexes+::
The column indexes or its aliases
+params+::
A h... | [
"Sets",
"a",
"component",
"to",
"colorize",
"a",
"column",
"."
] | b31cc1ef9a9f4ca1c22e0b77a84a1995bde5c2df | https://github.com/devnull-tools/yummi/blob/b31cc1ef9a9f4ca1c22e0b77a84a1995bde5c2df/lib/yummi/table.rb#L283-L293 | train |
Subsets and Splits
SQL Console for semeru/code-text-ruby
Retrieves 20,000 non-null code samples labeled as Ruby, providing a basic overview of the dataset but without deeper analysis.